-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHumanConsolePlayer.cpp
37 lines (28 loc) · 1022 Bytes
/
HumanConsolePlayer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Yael Hacmon, ID 313597897
* Roni Fultheim, ID 313465965
*/
#include "HumanConsolePlayer.h"
#include <iostream>
#include <limits>
using namespace std;
//constructor calling the parent class's (Player's) constructor
HumanConsolePlayer::HumanConsolePlayer(const std::string& name, const Color& c): Player(name, c) {}
Location HumanConsolePlayer::getNextMove() {
int row, column;
//ask the player to insert chosen location in the format (row column), space separated
cout << "Please enter your next move, row then column (separated by space): ";
cin >> row >> column;
//input validation
while (cin.fail()) {
//clearing stream
cin.clear();
//ignoring the rest of the input
cin.ignore(numeric_limits<streamsize>::max(), '\n');
//re-asking for move
cout << "Illegal move format. Please enter your next move, row then column (separated by space): ";
cin >> row >> column;
}
//translate to c++ indexing (starting from 0, not 1) and return as location
return Location (row-1, column-1);
}