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