Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc @ 12105

Last change on this file since 12105 was 12105, checked in by samuelbl, 5 years ago

Player update

File size: 3.1 KB
Line 
1
2
3
4
5
6
7#include "WagnisPlayer.h"
8#include <vector>
9#include <string>
10
11namespace orxonox
12{
13    RegisterClass(WagnisPlayer);
14
15    //Constructor
16    WagnisPlayer::WagnisPlayer(Context* context,WagnisGameboard* gb) : Baseclass(context){
17        RegisterObject(WagnisPlayer);
18        this->origin = nullptr;
19        this->target = nullptr;
20        this->gameBoard = gb;
21    }
22    //Destructor
23    WagnisPlayer::~WagnisPlayer(){
24
25    }
26    //Manages a Players turn
27    void WagnisPlayer::playerTurn(){
28       
29    }
30    //checks if a move is valid, possible MoveTypes: ATTACK, MOVE, SET_TROOPS, SET_TROOPS_INITIAL
31    bool WagnisPlayer::checkMove(WagnisProvince*,WagnisProvince*,MoveType)
32    {
33        if (MoveType == ATTACK)
34        {
35            if (isNeighbour(this->origin, this->target))//TODO: provinces neighbours
36            {
37                if (this->origin->getOwner_ID() == this->Player_ID) //origin belongs to player
38                {
39                    if (this->target->getOwner_ID() != this->Player_ID)//target belongs to enemy
40                        return true;
41                }
42            }
43        }
44
45        if (MoveType == MOVE)
46        {
47            if (existPath(this->origin, this->target))//TODO: path exists, all belong to same player
48            {
49                if (this->origin->getOwner_ID() == this->Player_ID)//origin belongs to player
50                    return true;
51            }
52
53        }
54
55        if (MoveType == SET_Troops)
56        {
57            if (this->target->getOwner_ID() == this->Player_ID)//target belongs to player
58                return true;
59        }
60
61        if (MoveType == SET_TROOPS_INITIAL)
62        {
63            if (this->target->getOwner_ID() == 0)//target belongs to nobody
64                return true;
65        }
66       
67        return false;
68    }
69   
70    //
71    void WagnisPlayer::setTroops(WagnisProvince*){
72
73    }
74    void WagnisPlayer::attack(WagnisProvince*,WagnisProvince*){
75
76    }
77    void WagnisPlayer::moveTroops(WagnisProvince*,WagnisProvince*){
78
79    }
80    //Return a "Player x" String
81    std::string WagnisPlayer::toString(){
82        std::string str = "Player ";
83        str.append(std::to_string(Player_ID);
84        return str;
85    }
86
87    //private function for CheckMove
88    //checks if provinces are neighbours for move
89    bool WagnisPlayer::isNeighbour(WagnisProvince*,WagnisProvince*)
90    {
91        for (int i = 0; i < this->origin->neighbors.size(); ++i)
92        {
93            if (this->target == this->origin->neighbors(i))
94                return true;
95        }
96
97        return false;
98    }
99
100    //private function for CheckMove
101    //checks if path is complete with provinces owned by player
102    bool WagnisPlayer::existPath(WagnisProvince*,WagnisProvince*)
103    {
104        if (this->origin->getOwner_ID() == this->target->getOwner_ID() && isNeighbour(this->origin, this->target))
105            return true;
106       
107        for (int i = 0; i < this->origin->neighbors.size(); ++i)
108        {
109            if (this->origin->getOwner_ID() == this->origin->neighbors(i)->getOwner_ID())
110                return existPath(this->origin->neighbors(i), this->target);
111        }
112           
113        return false;
114    }
115}
Note: See TracBrowser for help on using the repository browser.