1 #include "human_controller.h"
5 #include <iostream> //Really I can't be bothered with fscanf any more
9 MovementResult Human_Controller::QuerySetup(const char * opponentName, string setup[])
12 static bool shownMessage = false;
16 fprintf(stdout, "WARNING: GUI not fully supported. You will be forced to use the default setup.\n");
19 fprintf(stdout,"Enter %d x %d Setup grid\n", Game::theGame->theBoard.Width(), 4);
20 fprintf(stdout,"Please enter one line at a time.\n");
21 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]);
26 fprintf(stdout, "You are RED and occupy the top 4 rows of the board.\n");
27 fprintf(stdout, "NOTE: Enter \"DEFAULT\" to use the setup:\n");
28 fprintf(stdout, "FB8sB479B8\nBB31555583\n6724898974\n967B669999\n");
31 fprintf(stdout, "You are BLUE and occupy the bottom 4 rows of the board.\n");
32 fprintf(stdout, "NOTE: Enter \"DEFAULT\" to use the setup:\n");
33 fprintf(stdout, "967B669999\n6724898974\nBB31555583\nFB8sB479B8\n");
36 fprintf(stdout, "WARNING: Unknown colour error! Please exit the game.\n");
49 setup[0] = "FB8sB479B8";
50 setup[1] = "BB31555583";
51 setup[2] = "6724898974";
52 setup[3] = "967B669999";
55 setup[0] = "967B669999";
56 setup[1] = "6724898974";
57 setup[2] = "BB31555583";
58 setup[3] = "FB8sB479B8";
64 return MovementResult::OK;
67 for (int y = 0; y < 4; ++y)
70 if (y == 0 && setup[0] == "DEFAULT")
75 setup[0] = "FB8sB479B8";
76 setup[1] = "BB31555583";
77 setup[2] = "6724898974";
78 setup[3] = "967B669999";
81 setup[0] = "967B669999";
82 setup[1] = "6724898974";
83 setup[2] = "BB31555583";
84 setup[3] = "FB8sB479B8";
93 assert(cin.get() == '\n');
95 return MovementResult::OK;
98 MovementResult Human_Controller::QueryMove(string & buffer)
100 static bool shownMessage = false;
103 if (!graphicsEnabled)
105 fprintf(stdout, "Please enter your move in the format:\n X Y DIRECTION [MULTIPLIER=1]\n");
106 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)]);
113 #ifdef BUILD_GRAPHICS
117 fprintf(stdout, "Click to move!\n");
118 SDL_Event event; int mouseClick = 0;
120 int x[] = {-1, -1}; int y[] = {-1, -1};
121 while (mouseClick < 2)
124 while (SDL_PollEvent(&event))
129 Game::theGame->logMessage("Exit called by human player!\n");
132 case SDL_MOUSEBUTTONDOWN:
133 switch (event.button.button)
135 case SDL_BUTTON_LEFT:
136 SDL_GetMouseState(&x[mouseClick], &y[mouseClick]);
137 x[mouseClick] /= 32; y[mouseClick] /= 32; //Adjust based on graphics grid size
141 s << x[0] << " " << y[0] << " ";
144 else if (mouseClick == 1)
146 int xDist = x[1] - x[0];
147 int yDist = y[1] - y[0];
148 int magnitude = max(abs(xDist), abs(yDist));
149 if (abs(xDist) > abs(yDist))
164 s << " " << magnitude;
175 fprintf(stdout, "Move complete!\n");
179 #endif //BUILD_GRAPHICS
182 for (char in = fgetc(stdin); in != '\n'; in = fgetc(stdin))
190 return MovementResult::OK;