39e887310d6e43f23f858eb3f4f580afd601166f
[progcomp2012.git] / manager / stratego.h
1 #ifndef STRATEGO_H
2 #define STRATEGO_H
3
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 #include <assert.h>
8
9
10         #include "graphics.h"
11         #include "array.h"
12
13
14 /**
15  * Contains classes for a game of Stratego
16  */
17
18
19 /**
20  * Class for a game piece
21  */
22 class Piece
23 {
24         public:
25                 typedef enum {ERROR=14,BOMB=13,MARSHAL=12, GENERAL=11, COLONEL=10, MAJOR=9, CAPTAIN=8, LIEUTENANT=7, SERGEANT=6, MINER=5, SCOUT=4, SPY=3, FLAG=2,BOULDER=1, NOTHING=0} Type; //Type basically defines how strong the piece is
26                 
27
28                 typedef enum {RED=0, BLUE=1, NONE=2, BOTH=3} Colour; //Used for the allegiance of the pieces - terrain counts as NONE.
29
30                 Piece(const Type & newType, const Colour & newColour) : type(newType), colour(newColour) {}
31                 virtual ~Piece() {}
32
33
34                 //Operators compare the strength of two pieces
35                 bool operator==(const Piece & equ) const {return type == equ.type;}
36                 bool operator<(const Piece & equ) const {return type < equ.type;}
37                 bool operator>(const Piece & equ) const {return type > equ.type;}
38                 
39                 bool operator!=(const Piece & equ) const {return !operator==(equ);}
40                 bool operator<=(const Piece & equ) const {return (operator<(equ) || operator==(equ));}
41                 bool operator>=(const Piece & equ) const {return (operator>(equ) || operator==(equ));}
42
43                 //Contains the characters used to identify piece types when the board is printed to a stream
44                 static  char tokens[];
45                 static int maxUnits[];
46
47                 static Type GetType(char fromToken);
48
49
50                 //Attributes of the piece
51                 const Type type; 
52                 const Colour colour;
53
54                 public:
55
56                         class TextureManager : public Graphics::TextureManager<LUint>, private Array<Texture*>
57                         {
58                                 public:
59                                         TextureManager() : Graphics::TextureManager<LUint>(), Array<Texture*>() {}
60                                         virtual ~TextureManager();
61
62                                         virtual Texture & operator[](const LUint & at);
63                         };
64                         static TextureManager textures;
65
66                         static Graphics::Colour GetGraphicsColour(const Piece::Colour & colour)
67                         {
68                                 switch (colour)
69                                 {
70                                         case RED:
71                                                 return Graphics::Colour(1,0,0);
72                                                 break;
73                                         case BLUE:
74                                                 return Graphics::Colour(0,0,1);
75                                                 break;
76                                         case NONE:
77                                                 return Graphics::Colour(0.5,0.5,0.5);
78                                                 break;
79                                         case BOTH:
80                                                 return Graphics::Colour(1,0,1);
81                                                 break;
82                                 }
83                         }
84
85                         
86                         
87
88                 
89 };
90
91 #include "movementresult.h"
92
93 /**
94  * A Stratego board
95  */
96 class Board
97 {
98         public:
99                 Board(int newWidth, int newHeight); //Constructor
100
101                 virtual ~Board(); //Destructor
102
103                 void Print(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board
104                 void PrintPretty(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board using colour
105                 
106                 void Draw(const Piece::Colour & reveal=Piece::BOTH); //Draw board
107                 
108
109                 bool AddPiece(int x, int y, const Piece::Type & newType, const Piece::Colour & newColour); //Add piece to board
110
111
112                 Piece * GetPiece(int x, int y); //Retrieve piece from a location on the board
113
114
115                 typedef enum {UP, DOWN, LEFT, RIGHT} Direction;
116
117                 
118                 
119                 static bool LegalResult(const MovementResult & result)
120                 {
121                         return (result == MovementResult::OK || result == MovementResult::DIES || result == MovementResult::KILLS || result == MovementResult::BOTH_DIE || result == MovementResult::VICTORY || result == MovementResult::DRAW);
122                 }       
123
124                 MovementResult MovePiece(int x, int y, const Direction & direction, int multiplier=1,const Piece::Colour & colour=Piece::NONE); //Move piece from position in direction
125         
126
127                 Piece::Colour winner;
128
129                 int Width() const {return width;}
130                 int Height() const {return height;}
131         private:
132                 int width;
133                 int height;
134                 Piece ** * board;
135 };
136
137 #endif //STRATEGO_H
138
139 //EOF
140
141

UCC git Repository :: git.ucc.asn.au