X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=manager%2Fgame.cpp;fp=manager%2Fgame.cpp;h=ce655d7f4c9fd3af8fee8f8404894d92532d06f3;hp=b4fcc62311a4e72945a74e875744db40d7e20817;hb=17a20de4017ccfadef219d830a28ecccfe6f5106;hpb=2120cc40abf9e3fd763c84a1e09b61064bb40be6 diff --git a/manager/game.cpp b/manager/game.cpp index b4fcc62..ce655d7 100644 --- a/manager/game.cpp +++ b/manager/game.cpp @@ -404,14 +404,34 @@ MovementResult Game::Play() MovementResult result = MovementResult::OK; turnCount = 1; string buffer; + + Piece::Colour toReveal = reveal; + + red->Message("START"); - //logMessage("START\n"); + + + while (!Board::HaltResult(result) && (turnCount < maxTurns || maxTurns < 0)) { + if (red->HumanController()) + toReveal = Piece::RED; + if (printBoard) + { + system("clear"); + if (turnCount == 0) + fprintf(stdout, "START:\n"); + else + fprintf(stdout, "%d BLUE:\n", turnCount); + theBoard.PrintPretty(stdout, toReveal); + fprintf(stdout, "\n\n"); + } + if (graphicsEnabled) + theBoard.Draw(toReveal); turn = Piece::RED; logMessage( "%d RED: ", turnCount); @@ -421,16 +441,25 @@ MovementResult Game::Play() logMessage( "%s\n", buffer.c_str()); if (Board::HaltResult(result)) break; - if (graphicsEnabled) - theBoard.Draw(reveal); + + if (stallTime > 0) + Wait(stallTime); + else + ReadUserCommand(); + + if (blue->HumanController()) + toReveal = Piece::BLUE; if (printBoard) { system("clear"); fprintf(stdout, "%d RED:\n", turnCount); - theBoard.PrintPretty(stdout, reveal); + theBoard.PrintPretty(stdout, toReveal); fprintf(stdout, "\n\n"); } - Wait(stallTime); + if (graphicsEnabled) + theBoard.Draw(toReveal); + + turn = Piece::BLUE; logMessage( "%d BLU: ", turnCount); @@ -444,18 +473,13 @@ MovementResult Game::Play() - if (graphicsEnabled) - theBoard.Draw(reveal); - if (printBoard) - { - system("clear"); - fprintf(stdout, "%d BLUE:\n", turnCount); - theBoard.PrintPretty(stdout, reveal); - fprintf(stdout, "\n\n"); - } - - Wait(stallTime); + + if (stallTime > 0) + Wait(stallTime); + else + ReadUserCommand(); + if (theBoard.MobilePieces(Piece::BOTH) == 0) result = MovementResult::DRAW; @@ -493,6 +517,20 @@ int Game::logMessage(const char * format, ...) return result; } +/** + * Waits for a user command + * Currently ignores the command. + */ +void Game::ReadUserCommand() +{ + fprintf(stdout, "Waiting for user to press enter...\n"); + string command(""); + for (char c = fgetc(stdin); c != '\n' && (int)(c) != EOF; c = fgetc(stdin)) + { + command += c; + } +} + MovementResult FileController::QuerySetup(const char * opponentName, std::string setup[]) { @@ -538,3 +576,5 @@ MovementResult FileController::QueryMove(std::string & buffer) buffer = string(s); return MovementResult::OK; } + +