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 = 3; |
---|
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 | } |
---|
46 | |
---|
47 | //Tick |
---|
48 | void Wagnis::tick(float dt){ |
---|
49 | SUPER(Wagnis,tick,dt); |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | /** |
---|
55 | * Callback function for Player classes. Needs to be called for the game to go on. |
---|
56 | * arg: player: pointer to the player which finished his stage. |
---|
57 | * (used to deactivate player after finishing) |
---|
58 | * enum GameStage { NOT_READY, CHOOSE_PROVINCE_STAGE, REINFORCEMENT_STAGE, ATTACK_STAGE, MOVE_STAGE }; |
---|
59 | **/ |
---|
60 | void Wagnis::playerFinishedStageCallback(WagnisPlayer* player){ |
---|
61 | |
---|
62 | if(this->active_player != player->Player_ID){ |
---|
63 | orxout()<<"shit happend. This player should not be activ. Wagnis::playerFinishedStage was called from wrong player"<<endl; |
---|
64 | } |
---|
65 | switch(this->gameStage){ |
---|
66 | case CHOOSE_PROVINCE_STAGE:{ |
---|
67 | player->is_active = false; |
---|
68 | if(this->active_player < this->players.size()){ |
---|
69 | this->active_player++; |
---|
70 | WagnisPlayer* next = this->players[this->active_player-1]; |
---|
71 | next->gameStage = CHOOSE_PROVINCE_STAGE; |
---|
72 | next->is_active = true; |
---|
73 | orxout()<<"Player "<<next->Player_ID<<"\'s turn. Please choose province"<<endl; |
---|
74 | }else{ |
---|
75 | this->active_player = 1; |
---|
76 | WagnisPlayer* next = this->players[this->active_player-1]; |
---|
77 | next->gameStage = REINFORCEMENT_STAGE; |
---|
78 | this->gameStage = REINFORCEMENT_STAGE; |
---|
79 | next->is_active = true; |
---|
80 | orxout()<<"Player "<<next->Player_ID<<"\'s turn. Reinforcement"<<endl; |
---|
81 | } |
---|
82 | break; |
---|
83 | } |
---|
84 | case REINFORCEMENT_STAGE:{ |
---|
85 | break; |
---|
86 | } |
---|
87 | case ATTACK_STAGE:{ |
---|
88 | break; |
---|
89 | } |
---|
90 | case MOVE_STAGE:{ |
---|
91 | break; |
---|
92 | } |
---|
93 | default:{} |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | //Creates and links all needed classes |
---|
101 | void Wagnis::createGame(){ |
---|
102 | orxout() << "Game creation started" << endl; |
---|
103 | |
---|
104 | if(!findGameBoard()){ |
---|
105 | orxout() << "Error: GameBoard not found" << endl; |
---|
106 | } |
---|
107 | |
---|
108 | //this->gameBoard->initializeNeighbors(); |
---|
109 | |
---|
110 | //for(WagnisPlayer* p: this->players){ |
---|
111 | //this->playerEntered(p); |
---|
112 | //} |
---|
113 | |
---|
114 | orxout() << "Game creation finished" << endl; |
---|
115 | } |
---|
116 | |
---|
117 | //Finds the pointer to the gameBoard |
---|
118 | bool Wagnis::findGameBoard(){ |
---|
119 | for (WagnisGameboard* gb : ObjectList<WagnisGameboard>()){ |
---|
120 | this->gameBoard = gb; |
---|
121 | orxout()<<"Gameboard pointer found and added"<<endl; |
---|
122 | return true; |
---|
123 | } |
---|
124 | return false; |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | |
---|