Changeset 12150 for code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.cc
- Timestamp:
- Dec 5, 2018, 11:54:14 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.cc
r12136 r12150 16 16 this->gameStage = NOT_READY; 17 17 this->active_player = 1; 18 19 int n = 8; 18 this->initial_reinforcements_left = 5; 19 this->empty_provinces_left = 0; 20 21 int n = 3; 20 22 for(int i = 0;i < n;i++){ 21 23 WagnisPlayer* p = new WagnisPlayer(context); … … 41 43 42 44 this->gameStage = CHOOSE_PROVINCE_STAGE; 45 this->empty_provinces_left = this->provinceCount(); 43 46 this->players.at(0)->gameStage = this->gameStage; 44 this->players.at(0)->is_active = true; 47 this->players.at(0)->setActive(true); 48 this->players.at(0)->reinforcements = 0; 45 49 orxout()<<"Player "<<1<<"\'s turn. Please choose province."<<endl; 46 50 } … … 66 70 switch(this->gameStage){ 67 71 case CHOOSE_PROVINCE_STAGE:{ 68 player->is_active = false; 69 if(this->active_player < this->players.size()){ 70 this->active_player++; 72 player->setActive(false); 73 this->empty_provinces_left -= 1; 74 if(this->empty_provinces_left > 0){ 75 //Still empty provinces left 76 orxout()<<"DEBUG: Empty provs: "<<this->empty_provinces_left<<endl; 77 78 if(this->active_player < this->players.size()){ 79 this->active_player++; 80 }else{ 81 this->active_player = 1; 82 } 83 71 84 WagnisPlayer* next = this->players[this->active_player - 1]; 72 85 next->gameStage = CHOOSE_PROVINCE_STAGE; 73 next->is_active = true; 86 next->setActive(true); 87 next->reinforcements = 0; 74 88 orxout()<<"Player "<<next->Player_ID<<"\'s turn. Please choose province."<<endl; 75 89 }else{ 90 //no empty provinces left 91 orxout()<<"DEBUG: Empty provs: "<<this->empty_provinces_left<<endl; 76 92 this->active_player = 1; 77 93 WagnisPlayer* next = this->players[this->active_player - 1]; 78 94 next->gameStage = REINFORCEMENT_STAGE; 79 95 this->gameStage = REINFORCEMENT_STAGE; 80 next->is_active = true; 96 next->setActive(true); 97 next->reinforcements = 1; 81 98 orxout()<<"Player "<<next->Player_ID<<"\'s turn. Reinforcement."<<endl; 82 99 } … … 84 101 } 85 102 case REINFORCEMENT_STAGE:{ 103 104 if(this->initial_reinforcements_left > 0){ 105 player->setActive(false); 106 if(this->active_player == this->players.size()){ 107 //Last player finished this round of initial troops. 108 this->initial_reinforcements_left -= 1; 109 WagnisPlayer* next = this->players.at(0); 110 this->active_player = 1; 111 next->setActive(true); 112 next->gameStage = REINFORCEMENT_STAGE; 113 if(this->initial_reinforcements_left > 0){ 114 //Still more troops left to place and player 1 is next. 115 next->reinforcements = 1; 116 }else{ 117 //No more troops left to place and player 1 is next. 118 next->reinforcements = provincesOfPlayerCounter(1); 119 } 120 }else{ 121 //Player who finished was not the last player 122 WagnisPlayer* next = this->players.at(this->active_player); 123 this->active_player += 1; 124 next->setActive(true); 125 next->gameStage = REINFORCEMENT_STAGE; 126 next->reinforcements = 1; 127 } 128 break; 129 } 130 //Standard Reinforcement 131 86 132 player->gameStage = ATTACK_STAGE; 87 133 this->gameStage = ATTACK_STAGE; … … 96 142 } 97 143 case MOVE_STAGE:{ 98 player-> is_active = false;144 player->setActive(false); 99 145 if(this->active_player < this->players.size()){ 100 146 this->active_player++; … … 106 152 next->gameStage = REINFORCEMENT_STAGE; 107 153 this->gameStage = REINFORCEMENT_STAGE; 108 next-> is_active = true;154 next->setActive(true); 109 155 break; 110 156 } … … 143 189 } 144 190 191 //Counts legit provinces(not including buttons) 192 int Wagnis::provinceCount(){ 193 int n = 0; 194 for(WagnisProvince* p: this->gameBoard->provs){ 195 if(p != nullptr){ 196 if(p->ID < 1000){ 197 n++; 198 } 199 }else{ 200 orxout()<<"Nullpointer found in provines!!!"<<endl; 201 } 202 } 203 return n; 204 } 205 206 int Wagnis::provincesOfPlayerCounter(int player){ 207 int n = 0; 208 for(WagnisProvince* p:this->gameBoard->provs){ 209 if(p != nullptr){ 210 if(p->getOwner_ID() == player){ 211 n++; 212 } 213 }else{ 214 orxout()<<"Nullpointer found in provines!!!"<<endl; 215 } 216 } 217 return n; 218 } 219 145 220 146 221
Note: See TracChangeset
for help on using the changeset viewer.