Changeset 12127 for code/branches/wagnis_HS18/src/modules
- Timestamp:
- Nov 28, 2018, 11:57:48 AM (6 years ago)
- 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 30 30 SUPER(WagnisPlayer, tick, dt); 31 31 32 if(this->is_active){ 32 if(this->is_active) 33 { 33 34 for(WagnisProvince* prov:this->gameBoard->provs){ 34 35 if(prov->getHealth() < prov->getMaxHealth()){ … … 43 44 } 44 45 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)))){ 46 48 47 49 this->province_selection_changed = false; … … 49 51 case CHOOSE_PROVINCE_STAGE: 50 52 { 51 break; 52 } 53 if (checkMove(SET_TROOPS_INITIAL)) 54 this->target_province->owner_ID = this->Player_ID; 55 56 break; 57 } 58 53 59 case REINFORCEMENT_STAGE: 54 60 { 61 if (checkMove(SET_TROOPS)) 62 this->target_province->troops += 1; 63 55 64 break; 56 65 } 57 66 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 58 98 break; 59 99 } 60 100 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 } 61 107 break; 62 108 } … … 73 119 } 74 120 //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) 76 122 { 77 123 if (move_type == ATTACK) 78 124 { 79 if (isNeighbour(this->origin_province, this->target_province))// TODO:provinces neighbours125 if (isNeighbour(this->origin_province, this->target_province))//provinces neighbours 80 126 { 81 127 if (this->origin_province->getOwner_ID() == this->Player_ID) //origin belongs to player … … 89 135 if (move_type == MOVE) 90 136 { 91 if (existPath(this->origin_province, this->target_province))// TODO:path exists, all belong to same player137 if (existPath(this->origin_province, this->target_province))//path exists, all belong to same player 92 138 { 93 139 if (this->origin_province->getOwner_ID() == this->Player_ID)//origin belongs to player … … 105 151 if (move_type == SET_TROOPS_INITIAL) 106 152 { 107 if (this->target_province->getOwner_ID() == 0)//target belongs to nobody153 if (this->target_province->getOwner_ID() == -1)//target belongs to nobody 108 154 return true; 109 155 } … … 131 177 //private function for CheckMove 132 178 //checks if provinces are neighbours for move 133 bool WagnisPlayer::isNeighbour(WagnisProvince* ,WagnisProvince*)179 bool WagnisPlayer::isNeighbour(WagnisProvince* origin, WagnisProvince* target) 134 180 { 135 for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i)136 { 137 if (t his->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]) 138 184 return true; 139 185 } … … 144 190 //private function for CheckMove 145 191 //checks if path is complete with provinces owned by player 146 bool WagnisPlayer::existPath(WagnisProvince* ,WagnisProvince*)192 bool WagnisPlayer::existPath(WagnisProvince* origin, WagnisProvince* target) 147 193 { 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)) 149 195 return true; 150 196 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); 155 201 } 156 202 -
code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h
r12124 r12127 31 31 32 32 void playerTurn(); 33 bool checkMove( WagnisProvince*,WagnisProvince*,MoveType);33 bool checkMove(MoveType); 34 34 void setTroops(WagnisProvince*); 35 35 void attack(WagnisProvince*,WagnisProvince*); … … 46 46 WagnisProvince* origin_province; 47 47 WagnisProvince* target_province; 48 bool isNeighbour(WagnisProvince*, WagnisProvince*);49 bool existPath(WagnisProvince*, WagnisProvince*);48 bool isNeighbour(WagnisProvince*, WagnisProvince*); 49 bool existPath(WagnisProvince*, WagnisProvince*); 50 50 }; 51 51 }
Note: See TracChangeset
for help on using the changeset viewer.