-
Notifications
You must be signed in to change notification settings - Fork 0
/
Input.cpp
66 lines (50 loc) · 1.65 KB
/
Input.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "Input.h"
using namespace std;
void Input::move() {
bool isValid = false;
while (!isValid) {
cout << "Enter the position of the piece that you would like to move: ";
string coords;
cin >> coords;
char pos1 = coords[0];
int first = coords[0] - 'a';
int sec = coords[1] - '0';
if (pos1 >= 'a' && pos1 <= 'h' && sec >= 1 && sec <= 8) {
isValid = true;
initialX = first + 1;
initialY = sec;
} else {
cout << "Invalid Input, please enter the position of the piece again." << endl;
}
}
isValid = false;
while (!isValid) {
cout << "Enter the final position of the piece you would like to move to: ";
string coords;
cin >> coords;
char pos1 = coords[0];
int first = coords[0] - 'a';
int sec = coords[1] - '0';
if (pos1 >= 'a' && pos1 <= 'h' && sec >= 1 && sec <= 8) {
isValid = true;
finalX = first + 1;
finalY = sec;
} else {
cout << "Invalid Input, please enter the position again." << endl;
}
}
}
bool Input::moveTest(string input) {
cout << "Enter the position of the piece that you would like to move: " << endl;
string coords = input;
char pos1 = (tolower(coords[0]));
int first = coords[0] - 'a';
int sec = coords[1] - '0';
int size = coords.length();
if (pos1 >= 'a' && pos1 <= 'h' && sec >= 1 && sec <= 8 && size == 2) {
return true;
}
else {
return false;
}
}