How to make a unit in php + mysql?

Well, I want to create an online game, and I need to somehow make a unit, please help.
If possible, then in detail, otherwise I have never done this. Unit must have: Attack and HP.
Thanks in advance. )


Answer 1, authority 100%

Come on, folks. So let the person learn. The easiest way is to send books.

class Unit{
const START_ATTACK_MIN = 1;
const START_ATTACK_MAX = 10;
const START_HP_MIN = 5;
const START_HP_MAX = 20;
const AMOUNT_OF_RACES = 5;
private $attack;
private $hp;
private $race;
  function __construct($attack=false,$hp=false,$race=false){
    if($attack===false){
      $this->attack = rand(START_ATTACK_MAX,START_ATTACK_MAX);
    }else{
      $this->attack = $attack;
    }
    if($hp===false){
      $this->hp = rand(START_HP_MAX,START_HP_MAX);
    }else{
        $this->hp = $hp;
    }   
    if($race===false){
      $this->race = rand(0,AMOUNT_OF_RACES);
    }else{
      $this->race = $race;
    }  
    //  -      :
    //| race_id | min_attack | max_attack | min_hp | max_hp | race_name | 
    //select `min_attack`,`max_attack`,`min_hp`,`max_hp` from `races` order by rand() limit 1
  }
  //:
  function attack(&$unit_object){
    if($this->race != $unit_object->getRace()){
        $unit_object->hurt($this);
    }
  }
  // :
  function hurt(&$unit_object){
    $this->hp -= $unit_object->getAttack();  
    if($this->hp<1){
        $this->deth();
    }
  }
  // :
  function getAttack(){
    return $this->attack;
  }
  function getRace(){
    return $this->race;
  }
  // HP  :       .
  //:
  function deth(){
    //  ,   .
    $this->__destruct();
    //   -  ,   :
    //delete from `units` where id=`$this->id`
  }
}

Answer 2, authority 33%

Read books, articles, think over algorithms, actions and try, experiment!) And if there are problems in the code or at some points, contact the forum… And if you’re too lazy, hire a developer)

In essence, start simple:

  1. Create a unit (simple, at least a cube on the screen).

  2. Add movement (left, right, forward, backward).

  3. Attack, jumping, etc.

4. Various bonuses.

Not so difficult, more understandable and experience of course…