X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=judge%2Fmanager%2Fstratego.cpp;h=c9716cf3f6df67831ddd86040346ec172858aeeb;hp=410b70a29116c32828069680997ce964466cdafd;hb=refs%2Fheads%2Fnetworking;hpb=1a03b2543b67f0551e62babec4cd119f1e0e4640 diff --git a/judge/manager/stratego.cpp b/judge/manager/stratego.cpp index 410b70a..c9716cf 100644 --- a/judge/manager/stratego.cpp +++ b/judge/manager/stratego.cpp @@ -14,12 +14,9 @@ int Piece::maxUnits[] = {0,0,1,1,8,5,4,4,4,3,2,1,1,6,0}; - +#ifdef BUILD_GRAPHICS Piece::TextureManager Piece::textures; - - - Piece::TextureManager::~TextureManager() { Array::Iterator i(*this); @@ -41,7 +38,7 @@ Texture & Piece::TextureManager::operator[](const LUint & at) } return *(Array::operator[](at)); } - +#endif //BUILD_GRAPHICS /** * Gets the type of a piece, based off a character token @@ -60,6 +57,27 @@ Piece::Type Piece::GetType(char fromToken) return Piece::BOULDER; } +/** + * Gets the opposite to the indicated colour + */ +Piece::Colour Piece::OppositeColour(const Colour & colour) +{ + switch (colour) + { + case Piece::RED: + return Piece::BLUE; + break; + case Piece::BLUE: + return Piece::RED; + break; + case Piece::BOTH: + return Piece::BOTH; + break; + case Piece::NONE: + return Piece::NONE; + } +} + /** * Construct a new, empty board * @param newWidth - the width of the board @@ -139,7 +157,7 @@ void Board::Print(FILE * stream, const Piece::Colour & reveal) * @param stream - the stream to print information to * @param reveal - Pieces matching this colour will have their identify revealed, other pieces will be shown as '#' */ -void Board::PrintPretty(FILE * stream, const Piece::Colour & reveal) +void Board::PrintPretty(FILE * stream, const Piece::Colour & reveal, bool showRevealed) { for (int y=0; y < height; ++y) { @@ -150,7 +168,8 @@ void Board::PrintPretty(FILE * stream, const Piece::Colour & reveal) { fprintf(stream, "."); } - else if (piece->colour != Piece::NONE && (piece->colour == reveal || reveal == Piece::BOTH)) + else if ((piece->colour != Piece::NONE && (piece->colour == reveal || reveal == Piece::BOTH)) + || (piece->beenRevealed && showRevealed)) { switch (piece->colour) { @@ -197,7 +216,7 @@ void Board::PrintPretty(FILE * stream, const Piece::Colour & reveal) } - +#ifdef BUILD_GRAPHICS /** * Draw the board state to graphics * @param reveal - Pieces matching this colour will be revealed. If Piece::BOTH, all pieces will be revealed @@ -206,6 +225,7 @@ void Board::PrintPretty(FILE * stream, const Piece::Colour & reveal) */ void Board::Draw(const Piece::Colour & reveal, bool showRevealed) { + if (!Graphics::Initialised()) { fprintf(stderr, "ERROR - Board::Draw called whilst graphics disabled!!!\n"); @@ -256,6 +276,7 @@ void Board::Draw(const Piece::Colour & reveal, bool showRevealed) Graphics::UpdateScreen(); } +#endif //BUILD_GRAPHICS /** * Adds a piece to the board @@ -323,6 +344,8 @@ MovementResult Board::MovePiece(int x, int y, const Direction & direction, int m { return MovementResult(MovementResult::IMMOBILE_UNIT); } + if (multiplier < 1) + return MovementResult(MovementResult::INVALID_DIRECTION); //Don't allow moves that don't actually move forward if (multiplier > 1 && target->type != Piece::SCOUT) { return MovementResult(MovementResult::INVALID_DIRECTION); //Can only move a scout multiple times. @@ -376,7 +399,7 @@ MovementResult Board::MovePiece(int x, int y, const Direction & direction, int m if (defender->type == Piece::FLAG) { winner = target->colour; - return MovementResult(MovementResult::VICTORY); + return MovementResult(MovementResult::VICTORY_FLAG); } else if (defender->type == Piece::BOMB) {