15 * Contains classes for a game of Stratego
20 * Class for a game piece
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
29 typedef enum {RED=0, BLUE=1, NONE=2, BOTH=3} Colour; //Used for the allegiance of the pieces - terrain counts as NONE.
31 Piece(const Type & newType, const Colour & newColour) : type(newType), colour(newColour), beenRevealed(false) {}
35 //Operators compare the strength of two pieces
36 bool operator==(const Piece & equ) const {return type == equ.type;}
37 bool operator<(const Piece & equ) const {return type < equ.type;}
38 bool operator>(const Piece & equ) const {return type > equ.type;}
40 bool operator!=(const Piece & equ) const {return !operator==(equ);}
41 bool operator<=(const Piece & equ) const {return (operator<(equ) || operator==(equ));}
42 bool operator>=(const Piece & equ) const {return (operator>(equ) || operator==(equ));}
44 //Contains the characters used to identify piece types when the board is printed to a stream
46 static int maxUnits[];
48 static Type GetType(char fromToken);
50 int PieceValue() const {if (type == BOMB || type == FLAG) {return 0;} return (int)(type) - (int)(SPY) + 1;}
52 //Attributes of the piece
61 class TextureManager : public Graphics::TextureManager<LUint>, private Array<Texture*>
64 TextureManager() : Graphics::TextureManager<LUint>(), Array<Texture*>() {}
65 virtual ~TextureManager();
67 virtual Texture & operator[](const LUint & at);
69 static TextureManager textures;
71 static Graphics::Colour GetGraphicsColour(const Piece::Colour & colour)
76 return Graphics::Colour(1,0,0);
79 return Graphics::Colour(0,0,1);
82 return Graphics::Colour(0.5,0.5,0.5);
85 return Graphics::Colour(1,0,1);
89 #endif //BUILD_GRAPHICS
96 #include "movementresult.h"
104 Board(int newWidth, int newHeight); //Constructor
106 virtual ~Board(); //Destructor
108 void Print(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board
109 void PrintPretty(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board using colour
111 #ifdef BUILD_GRAPHICS
112 void Draw(const Piece::Colour & reveal=Piece::BOTH, bool showRevealed = true); //Draw board
113 #endif //BUILD_GRAPHICS
115 bool AddPiece(int x, int y, const Piece::Type & newType, const Piece::Colour & newColour); //Add piece to board
118 Piece * GetPiece(int x, int y); //Retrieve piece from a location on the board
121 typedef enum {UP, DOWN, LEFT, RIGHT} Direction;
125 static bool LegalResult(const MovementResult & result)
127 return (result == MovementResult::OK || result == MovementResult::DIES || result == MovementResult::KILLS || result == MovementResult::BOTH_DIE || result == MovementResult::VICTORY_FLAG || result == MovementResult::VICTORY_ATTRITION || result == MovementResult::DRAW || result == MovementResult::DRAW_DEFAULT || result == MovementResult::SURRENDER);
130 static bool HaltResult(const MovementResult & result)
132 return (result == MovementResult::VICTORY_FLAG || result == MovementResult::VICTORY_ATTRITION || result == MovementResult::DRAW || result == MovementResult::DRAW_DEFAULT || result == MovementResult::SURRENDER || !LegalResult(result));
135 MovementResult MovePiece(int x, int y, const Direction & direction, int multiplier=1,const Piece::Colour & colour=Piece::NONE); //Move piece from position in direction
138 Piece::Colour winner;
140 int Width() const {return width;}
141 int Height() const {return height;}
143 int MobilePieces(const Piece::Colour & colour) const;
144 int TotalPieceValue(const Piece::Colour & colour) const;
145 bool RemovePiece(Piece * piece);
150 std::vector<Piece*> pieces;