First actual commit
[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 #ifdef GRAPHICS
10         #include "graphics.h"
11         #include "array.h"
12 #endif //GRAPHICS
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         #ifdef GRAPHICS
55                 public:
56
57                         class TextureManager : public Graphics::TextureManager<LUint>, private Array<Texture*>
58                         {
59                                 public:
60                                         TextureManager() : Graphics::TextureManager<LUint>(), Array<Texture*>() {}
61                                         virtual ~TextureManager();
62
63                                         virtual Texture & operator[](const LUint & at);
64                         };
65                         static TextureManager textures;
66
67                         static Graphics::Colour GetGraphicsColour(const Piece::Colour & colour)
68                         {
69                                 switch (colour)
70                                 {
71                                         case RED:
72                                                 return Graphics::Colour(1,0,0);
73                                                 break;
74                                         case BLUE:
75                                                 return Graphics::Colour(0,0,1);
76                                                 break;
77                                         case NONE:
78                                                 return Graphics::Colour(0.5,0.5,0.5);
79                                                 break;
80                                         case BOTH:
81                                                 return Graphics::Colour(1,0,1);
82                                                 break;
83                                 }
84                         }
85
86                         
87                         
88         #endif //GRAPHICS
89                 
90 };
91
92 /**
93  * A Stratego board
94  */
95 class Board
96 {
97         public:
98                 Board(int newWidth, int newHeight); //Constructor
99
100                 virtual ~Board(); //Destructor
101
102                 void Print(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board
103                 #ifdef GRAPHICS
104                         void Draw(const Piece::Colour & reveal=Piece::BOTH); //Draw board
105                 #endif //GRAPHICS
106
107                 bool AddPiece(int x, int y, const Piece::Type & newType, const Piece::Colour & newColour); //Add piece to board
108
109
110                 Piece * GetPiece(int x, int y); //Retrieve piece from a location on the board
111
112
113                 typedef enum {UP, DOWN, LEFT, RIGHT} Direction;
114
115                 typedef enum {OK, DIES, KILLS, BOTH_DIE, NO_BOARD, INVALID_POSITION, NO_SELECTION, NOT_YOUR_UNIT, IMMOBILE_UNIT, INVALID_DIRECTION, POSITION_FULL, VICTORY, BAD_RESPONSE, NO_MOVE} MovementResult; //The possible results from a move
116                 //WARNING: Some of the MovementResults are returned by the Controller class in "controller.h", in Controller::MakeMove
117                 
118                 static bool LegalResult(const MovementResult & result)
119                 {
120                         return (result == OK || result == DIES || result == KILLS || result == BOTH_DIE);
121                 }       
122
123                 MovementResult MovePiece(int x, int y, const Direction & direction, int multiplier=1,const Piece::Colour & colour=Piece::NONE); //Move piece from position in direction
124                 static Board theBoard;
125
126                 Piece::Colour winner;
127
128                 int Width() const {return width;}
129                 int Height() const {return height;}
130         private:
131                 int width;
132                 int height;
133                 Piece ** * board;
134 };
135
136 #endif //STRATEGO_H
137
138 //EOF
139
140

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