Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12127


Ignore:
Timestamp:
Nov 28, 2018, 11:57:48 AM (5 years ago)
Author:
samuelbl
Message:

Player moves implemented

Location:
code/branches/wagnis_HS18/src/modules/wagnis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc

    r12119 r12127  
    3030        SUPER(WagnisPlayer, tick, dt);
    3131
    32         if(this->is_active){
     32        if(this->is_active)
     33        {
    3334            for(WagnisProvince* prov:this->gameBoard->provs){
    3435                if(prov->getHealth() < prov->getMaxHealth()){
     
    4344            }
    4445
    45             if(this->province_selection_changed && this->origin_province != nullptr && this->target_province != nullptr){
     46            if((this->province_selection_changed && this->origin_province != nullptr && this->target_province != nullptr)
     47            ||(this->province_selection_changed && this->target_province != nullptr && ((gamestage == CHOOSE_PROVINCE_STAGE)||(gamestage == REINFORCEMENT_STAGE)))){
    4648               
    4749                this->province_selection_changed = false;
     
    4951                    case CHOOSE_PROVINCE_STAGE:
    5052                    {   
    51                         break;
    52                     }
     53                        if (checkMove(SET_TROOPS_INITIAL))
     54                            this->target_province->owner_ID = this->Player_ID;
     55                       
     56                        break;
     57                    }
     58                   
    5359                    case REINFORCEMENT_STAGE:
    5460                    {
     61                        if (checkMove(SET_TROOPS))
     62                            this->target_province->troops += 1;
     63                       
    5564                        break;
    5665                    }
    5766                    case ATTACK_STAGE:{
     67
     68                        if (checkMove(ATTACK))
     69                        {
     70                            while ((this->origin_province->troops > 1) && (this->target_province->troops > 0)) //still troops available
     71                            {
     72                                while ((this->origin_province->troops >= 4) && (this->target_province->troops >= 2))
     73                                {
     74                                    //normal fight, 3 attackers, 2 defenders
     75                                }
     76
     77                                if ((this->origin_province->troops == 3) && (this->target_province->troops >= 2))
     78                                {
     79                                    //2 attackers, 2 defenders
     80                                }
     81
     82                                if((this->origin_province->troops == 2) && (this->target_province->troops >= 2))
     83                                {
     84                                    //1 attacker, 2 defenders
     85                                }
     86
     87                                //TODO: implement other cases
     88                            }
     89
     90                            if (this->target_province->troops == 0) //attacker won
     91                            {
     92                                this->target_province->owner_ID = this->Player_ID;
     93                                this->target_province->troops = (this->origin_province->troops - 1);
     94                                this->origin_province->troops = 1;
     95                            }
     96                        }
     97                       
    5898                        break;
    5999                    }
    60100                    case MOVE_STAGE:{
     101
     102                        if (checkMove(MOVE))
     103                        {
     104                            this->target_province->troops += ((this->origin_province->troops) - 1);
     105                            this->origin_province->troops = 1;
     106                        }
    61107                        break;
    62108                    }
     
    73119    }
    74120    //checks if a move is valid, possible MoveTypes: ATTACK, MOVE, SET_TROOPS, SET_TROOPS_INITIAL
    75     bool WagnisPlayer::checkMove(WagnisProvince*,WagnisProvince*,MoveType move_type)
     121    bool WagnisPlayer::checkMove(MoveType move_type)
    76122    {
    77123        if (move_type == ATTACK)
    78124        {
    79             if (isNeighbour(this->origin_province, this->target_province))//TODO: provinces neighbours
     125            if (isNeighbour(this->origin_province, this->target_province))//provinces neighbours
    80126            {
    81127                if (this->origin_province->getOwner_ID() == this->Player_ID) //origin belongs to player
     
    89135        if (move_type == MOVE)
    90136        {
    91             if (existPath(this->origin_province, this->target_province))//TODO: path exists, all belong to same player
     137            if (existPath(this->origin_province, this->target_province))//path exists, all belong to same player
    92138            {
    93139                if (this->origin_province->getOwner_ID() == this->Player_ID)//origin belongs to player
     
    105151        if (move_type == SET_TROOPS_INITIAL)
    106152        {
    107             if (this->target_province->getOwner_ID() == 0)//target belongs to nobody
     153            if (this->target_province->getOwner_ID() == -1)//target belongs to nobody
    108154                return true;
    109155        }
     
    131177    //private function for CheckMove
    132178    //checks if provinces are neighbours for move
    133     bool WagnisPlayer::isNeighbour(WagnisProvince*,WagnisProvince*)
     179    bool WagnisPlayer::isNeighbour(WagnisProvince* origin, WagnisProvince* target)
    134180    {
    135         for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i)
    136         {
    137             if (this->target_province == this->origin_province->neighbors[i])
     181        for (unsigned int i = 0; i < origin->neighbors.size(); ++i)
     182        {
     183            if (target == origin->neighbors[i])
    138184                return true;
    139185        }
     
    144190    //private function for CheckMove
    145191    //checks if path is complete with provinces owned by player
    146     bool WagnisPlayer::existPath(WagnisProvince*,WagnisProvince*)
     192    bool WagnisPlayer::existPath(WagnisProvince* origin, WagnisProvince* target)
    147193    {
    148         if (this->origin_province->getOwner_ID() == this->target_province->getOwner_ID() && isNeighbour(this->origin_province, this->target_province))
     194        if (origin->getOwner_ID() == target->getOwner_ID() && isNeighbour(origin, target))
    149195            return true;
    150196       
    151         for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i)
    152         {
    153             if (this->origin_province->getOwner_ID() == this->origin_province->neighbors[i]->getOwner_ID())
    154                 return existPath(this->origin_province->neighbors[i], this->target_province);
     197        for (unsigned int i = 0; i < origin->neighbors.size(); ++i)
     198        {
     199            if (origin->getOwner_ID() == origin->neighbors[i]->getOwner_ID())
     200                return existPath(origin->neighbors[i], target);
    155201        }
    156202           
  • code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h

    r12124 r12127  
    3131
    3232        void playerTurn();
    33         bool checkMove(WagnisProvince*,WagnisProvince*,MoveType);
     33        bool checkMove(MoveType);
    3434        void setTroops(WagnisProvince*);
    3535        void attack(WagnisProvince*,WagnisProvince*);
     
    4646        WagnisProvince* origin_province;
    4747        WagnisProvince* target_province;
    48         bool isNeighbour(WagnisProvince*,WagnisProvince*);
    49         bool existPath(WagnisProvince*,WagnisProvince*);
     48        bool isNeighbour(WagnisProvince*, WagnisProvince*);
     49        bool existPath(WagnisProvince*, WagnisProvince*);
    5050    };
    5151}
Note: See TracChangeset for help on using the changeset viewer.