1 | |
---|
2 | |
---|
3 | |
---|
4 | #include "Wagnis.h" |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | namespace orxonox{ |
---|
9 | |
---|
10 | RegisterClass(Wagnis); |
---|
11 | |
---|
12 | //Constructor |
---|
13 | Wagnis::Wagnis(Context* context) : Deathmatch(context){ |
---|
14 | RegisterObject(Wagnis); |
---|
15 | this->gameBoard = nullptr; |
---|
16 | this->gameStage = NOT_READY; |
---|
17 | this->active_player = 1; |
---|
18 | |
---|
19 | int n = 8; |
---|
20 | for(int i = 0;i < n;i++){ |
---|
21 | WagnisPlayer* p = new WagnisPlayer(context); |
---|
22 | p->Player_ID = i+1; |
---|
23 | p->master = this; |
---|
24 | this->players.push_back(p); |
---|
25 | } |
---|
26 | } |
---|
27 | //Destructor |
---|
28 | Wagnis::~Wagnis(){} |
---|
29 | |
---|
30 | |
---|
31 | //Runs the game |
---|
32 | void Wagnis::start(){ |
---|
33 | Deathmatch::start(); |
---|
34 | if(this->gameStage == NOT_READY){ |
---|
35 | this->createGame(); |
---|
36 | |
---|
37 | for(WagnisPlayer* ptr: this->players){ |
---|
38 | ptr->gameBoard = this->gameBoard; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | this->gameStage = CHOOSE_PROVINCE_STAGE; |
---|
43 | this->players.at(0)->gameStage = this->gameStage; |
---|
44 | this->players.at(0)->is_active = true; |
---|
45 | orxout()<<"Player "<<1<<"\'s turn. Please choose province."<<endl; |
---|
46 | } |
---|
47 | |
---|
48 | //Tick |
---|
49 | void Wagnis::tick(float dt){ |
---|
50 | SUPER(Wagnis,tick,dt); |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | /** |
---|
56 | * Callback function for Player classes. Needs to be called for the game to go on. |
---|
57 | * arg: player: pointer to the player which finished his stage. |
---|
58 | * (used to deactivate player after finishing) |
---|
59 | * enum GameStage { NOT_READY, CHOOSE_PROVINCE_STAGE, REINFORCEMENT_STAGE, ATTACK_STAGE, MOVE_STAGE }; |
---|
60 | **/ |
---|
61 | void Wagnis::playerFinishedStageCallback(WagnisPlayer* player){ |
---|
62 | |
---|
63 | if(this->active_player != player->Player_ID){ |
---|
64 | orxout()<<"shit happend. This player should not be activ. Wagnis::playerFinishedStage was called from wrong player"<<endl; |
---|
65 | } |
---|
66 | switch(this->gameStage){ |
---|
67 | case CHOOSE_PROVINCE_STAGE:{ |
---|
68 | player->is_active = false; |
---|
69 | if(this->active_player < this->players.size()){ |
---|
70 | this->active_player++; |
---|
71 | WagnisPlayer* next = this->players[this->active_player - 1]; |
---|
72 | next->gameStage = CHOOSE_PROVINCE_STAGE; |
---|
73 | next->is_active = true; |
---|
74 | orxout()<<"Player "<<next->Player_ID<<"\'s turn. Please choose province."<<endl; |
---|
75 | }else{ |
---|
76 | this->active_player = 1; |
---|
77 | WagnisPlayer* next = this->players[this->active_player - 1]; |
---|
78 | next->gameStage = REINFORCEMENT_STAGE; |
---|
79 | this->gameStage = REINFORCEMENT_STAGE; |
---|
80 | next->is_active = true; |
---|
81 | orxout()<<"Player "<<next->Player_ID<<"\'s turn. Reinforcement."<<endl; |
---|
82 | } |
---|
83 | break; |
---|
84 | } |
---|
85 | case REINFORCEMENT_STAGE:{ |
---|
86 | player->gameStage = ATTACK_STAGE; |
---|
87 | this->gameStage = ATTACK_STAGE; |
---|
88 | orxout()<<"Player "<<player->Player_ID<<"\'s turn. Attack."<<endl; |
---|
89 | break; |
---|
90 | } |
---|
91 | case ATTACK_STAGE:{ |
---|
92 | player->gameStage = MOVE_STAGE; |
---|
93 | this->gameStage = MOVE_STAGE; |
---|
94 | orxout()<<"Player "<<player->Player_ID<<"\'s turn. Move."<<endl; |
---|
95 | break; |
---|
96 | } |
---|
97 | case MOVE_STAGE:{ |
---|
98 | player->is_active = false; |
---|
99 | if(this->active_player < this->players.size()){ |
---|
100 | this->active_player++; |
---|
101 | }else{ |
---|
102 | this->active_player = 1; |
---|
103 | } |
---|
104 | WagnisPlayer* next = this->players[this->active_player - 1]; |
---|
105 | orxout()<<"Player "<<next->Player_ID<<"\'s turn. Reinforcement."<<endl; |
---|
106 | next->gameStage = REINFORCEMENT_STAGE; |
---|
107 | this->gameStage = REINFORCEMENT_STAGE; |
---|
108 | next->is_active = true; |
---|
109 | break; |
---|
110 | } |
---|
111 | default:{} |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | //Creates and links all needed classes |
---|
119 | void Wagnis::createGame(){ |
---|
120 | orxout() << "Game creation started" << endl; |
---|
121 | |
---|
122 | if(!findGameBoard()){ |
---|
123 | orxout() << "Error: GameBoard not found" << endl; |
---|
124 | } |
---|
125 | |
---|
126 | //this->gameBoard->initializeNeighbors(); |
---|
127 | |
---|
128 | //for(WagnisPlayer* p: this->players){ |
---|
129 | //this->playerEntered(p); |
---|
130 | //} |
---|
131 | |
---|
132 | orxout() << "Game creation finished" << endl; |
---|
133 | } |
---|
134 | |
---|
135 | //Finds the pointer to the gameBoard |
---|
136 | bool Wagnis::findGameBoard(){ |
---|
137 | for (WagnisGameboard* gb : ObjectList<WagnisGameboard>()){ |
---|
138 | this->gameBoard = gb; |
---|
139 | orxout()<<"Gameboard pointer found and added"<<endl; |
---|
140 | return true; |
---|
141 | } |
---|
142 | return false; |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | |
---|
161 | |
---|