X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=manager%2Fhuman_controller.cpp;fp=manager%2Fhuman_controller.cpp;h=5e3e1768c0d43505db04ea566e971decf8c28194;hp=0000000000000000000000000000000000000000;hb=4a3c0478160e7e9b637a12e7cf22f8da61b66ad2;hpb=53a666903d770b14969f542d6548e267e5017b31 diff --git a/manager/human_controller.cpp b/manager/human_controller.cpp new file mode 100644 index 0000000..5e3e176 --- /dev/null +++ b/manager/human_controller.cpp @@ -0,0 +1,63 @@ +#include "human_controller.h" + +#include "game.h" + +#include //Really I can't be bothered with fscanf any more + +using namespace std; + +MovementResult Human_Controller::QuerySetup(const char * opponentName, string setup[]) +{ + + static bool shownMessage = false; + if (!shownMessage) + { + if (graphicsEnabled) + fprintf(stderr, "GUI not yet supported! Please use CLI\n"); + fprintf(stdout,"Enter %d x %d Setup grid\n", Game::theGame->theBoard.Width(), 4); + fprintf(stdout,"Please enter one line at a time, using the following allowed characters:\n"); + for (Piece::Type rank = Piece::FLAG; rank <= Piece::BOMB; rank = Piece::Type((int)(rank) + 1)) + { + fprintf(stdout,"%c x %d\n", Piece::tokens[(int)rank], Piece::maxUnits[(int)rank]); + } + fprintf(stdout, "You must place at least the Flag (%c). Use '%c' for empty squares.\n", Piece::tokens[(int)Piece::FLAG], Piece::tokens[(int)Piece::NOTHING]); + fprintf(stdout, "NOTE: Player RED occupies the top four rows, and BLUE occupies the bottom four rows.\n"); + + shownMessage = true; + } + + + + for (int y = 0; y < 4; ++y) + cin >> setup[y]; + assert(cin.get() == '\n'); + + return MovementResult::OK; +} + +MovementResult Human_Controller::QueryMove(string & buffer) +{ + static bool shownMessage = false; + if (!shownMessage) + { + if (graphicsEnabled) + fprintf(stderr, "GUI not yet supported! Please use the CLI\n"); + fprintf(stdout, "Please enter your move in the format:\n X Y DIRECTION [MULTIPLIER=1]\n"); + fprintf(stdout, "Where X and Y indicate the coordinates of the piece to move;\n DIRECTION is one of UP, DOWN, LEFT or RIGHT\n and MULTIPLIER is optional (and only valid for scouts (%c))\n", Piece::tokens[(int)(Piece::SCOUT)]); + shownMessage = true; + } + + + + + buffer.clear(); + for (char in = fgetc(stdin); in != '\n'; in = fgetc(stdin)) + { + buffer += in; + } + + + + return MovementResult::OK; + +}