X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=manager%2Fstratego.h;h=fe73aa13ff0b4311c3d10acea02c493f9b6dd610;hp=877af2d19ad7df952a6367ea6741a6088d746a2a;hb=7f7bc05439b70b3139086086608996de3c9ae2ed;hpb=f91a915d6f64f9d35e867d26e8ddb9c1b1ab0c1e diff --git a/manager/stratego.h b/manager/stratego.h index 877af2d..fe73aa1 100644 --- a/manager/stratego.h +++ b/manager/stratego.h @@ -6,10 +6,11 @@ #include -#ifdef GRAPHICS + #include "graphics.h" #include "array.h" -#endif //GRAPHICS + +#include /** * Contains classes for a game of Stratego @@ -25,9 +26,10 @@ class Piece 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 + typedef enum {RED=0, BLUE=1, NONE=2, BOTH=3} Colour; //Used for the allegiance of the pieces - terrain counts as NONE. - Piece(const Type & newType, const Colour & newColour) : type(newType), colour(newColour) {} + Piece(const Type & newType, const Colour & newColour) : type(newType), colour(newColour), beenRevealed(false) {} virtual ~Piece() {} @@ -46,12 +48,14 @@ class Piece static Type GetType(char fromToken); + int PieceValue() const {if (type == BOMB || type == FLAG) {return 0;} return (int)(type) - (int)(SPY) + 1;} //Attributes of the piece const Type type; const Colour colour; - #ifdef GRAPHICS + bool beenRevealed; + public: class TextureManager : public Graphics::TextureManager, private Array @@ -85,10 +89,12 @@ class Piece - #endif //GRAPHICS + }; +#include "movementresult.h" + /** * A Stratego board */ @@ -100,9 +106,10 @@ class Board virtual ~Board(); //Destructor void Print(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board - #ifdef GRAPHICS - void Draw(const Piece::Colour & reveal=Piece::BOTH); //Draw board - #endif //GRAPHICS + void PrintPretty(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board using colour + + void Draw(const Piece::Colour & reveal=Piece::BOTH, bool showRevealed = true); //Draw board + bool AddPiece(int x, int y, const Piece::Type & newType, const Piece::Colour & newColour); //Add piece to board @@ -112,25 +119,34 @@ class Board typedef enum {UP, DOWN, LEFT, RIGHT} Direction; - 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 - //WARNING: Some of the MovementResults are returned by the Controller class in "controller.h", in Controller::MakeMove + static bool LegalResult(const MovementResult & result) { - return (result == OK || result == DIES || result == KILLS || result == BOTH_DIE); - } + 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)); + } MovementResult MovePiece(int x, int y, const Direction & direction, int multiplier=1,const Piece::Colour & colour=Piece::NONE); //Move piece from position in direction - static Board theBoard; + Piece::Colour winner; int Width() const {return width;} int Height() const {return height;} + + int MobilePieces(const Piece::Colour & colour) const; + int TotalPieceValue(const Piece::Colour & colour) const; + bool RemovePiece(Piece * piece); private: int width; int height; Piece ** * board; + std::vector pieces; }; #endif //STRATEGO_H