Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.cc @ 12134

Last change on this file since 12134 was 12133, checked in by stadlero, 6 years ago

Wagnis now progresses through stages

File size: 4.1 KB
RevLine 
[12114]1
2
3
[12068]4#include "Wagnis.h"
5
6
[12114]7
8namespace orxonox{
9
10RegisterClass(Wagnis);
11
[12119]12//Constructor
[12114]13Wagnis::Wagnis(Context* context) : Deathmatch(context){
14    RegisterObject(Wagnis);
[12119]15    this->gameBoard = nullptr;
[12124]16    this->gameStage = NOT_READY;
[12130]17    this->active_player = 1;
[12124]18
19    int n = 3;
[12132]20    for(int i = 0;i < n;i++){
[12124]21        WagnisPlayer* p = new WagnisPlayer(context);
[12132]22        p->Player_ID = i+1;
[12130]23        p->master = this;
[12124]24        this->players.push_back(p);
25    }
[12114]26}
27//Destructor
28Wagnis::~Wagnis(){}
29
30
[12119]31//Runs the game
32void Wagnis::start(){
[12130]33    Deathmatch::start();
34    if(this->gameStage == NOT_READY){
35        this->createGame();
[12132]36
37        for(WagnisPlayer* ptr: this->players){
38            ptr->gameBoard = this->gameBoard;
39        }
[12130]40    }
41
[12132]42    this->gameStage = CHOOSE_PROVINCE_STAGE;
43    this->players.at(0)->gameStage = this->gameStage;
44    this->players.at(0)->is_active = true;
[12133]45    orxout()<<"Player "<<1<<"\'s turn. Please choose province."<<endl;
[12114]46}
47
[12124]48//Tick
49void Wagnis::tick(float dt){
50    SUPER(Wagnis,tick,dt);
51}
52
[12130]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 **/
[12132]61void Wagnis::playerFinishedStageCallback(WagnisPlayer* player){
[12130]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;
[12132]69            if(this->active_player < this->players.size()){
[12130]70                this->active_player++;
[12133]71                WagnisPlayer* next = this->players[this->active_player - 1];
[12132]72                next->gameStage = CHOOSE_PROVINCE_STAGE;
73                next->is_active = true;
[12133]74                orxout()<<"Player "<<next->Player_ID<<"\'s turn. Please choose province."<<endl;
[12130]75            }else{
76                this->active_player = 1;
[12133]77                WagnisPlayer* next = this->players[this->active_player - 1];
[12132]78                next->gameStage = REINFORCEMENT_STAGE;
79                this->gameStage = REINFORCEMENT_STAGE;
80                next->is_active = true;
[12133]81                orxout()<<"Player "<<next->Player_ID<<"\'s turn. Reinforcement."<<endl;
[12130]82            }
83            break;
84        }
85        case REINFORCEMENT_STAGE:{
[12133]86            player->gameStage = ATTACK_STAGE;
87            this->gameStage = ATTACK_STAGE;
88            orxout()<<"Player "<<player->Player_ID<<"\'s turn. Attack."<<endl;
[12132]89            break;
[12130]90        }
91        case ATTACK_STAGE:{
[12133]92            player->gameStage = MOVE_STAGE;
93            this->gameStage = MOVE_STAGE;
94            orxout()<<"Player "<<player->Player_ID<<"\'s turn. Move."<<endl;
[12132]95            break;
[12130]96        }
97        case MOVE_STAGE:{
[12133]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;
[12132]109            break;
[12130]110        }
[12132]111        default:{}
[12130]112    }
113}
114
115
116
117
[12119]118//Creates and links all needed classes
[12130]119void Wagnis::createGame(){
120    orxout() << "Game creation started" << endl;
[12114]121
[12124]122    if(!findGameBoard()){
[12130]123        orxout() << "Error: GameBoard not found" << endl;
[12124]124    }
125
[12130]126    //this->gameBoard->initializeNeighbors();
127
128    //for(WagnisPlayer* p: this->players){
129        //this->playerEntered(p);
130    //}
131   
132    orxout() << "Game creation finished" << endl;
[12119]133}
134
[12124]135//Finds the pointer to the gameBoard
136bool Wagnis::findGameBoard(){
137    for (WagnisGameboard* gb : ObjectList<WagnisGameboard>()){
138        this->gameBoard = gb;
[12130]139        orxout()<<"Gameboard pointer found and added"<<endl;
[12124]140        return true;
141    }
142    return false;
143}
[12119]144
145
146
147
148
149
150
151
152
153
154
155
156
157}
158
159
[12068]160       
161   
Note: See TracBrowser for help on using the repository browser.