-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
51 lines (47 loc) · 1005 Bytes
/
main.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
#include<iostream>
#include "player.h"
using namespace std;
void executeCommand(string);
vector<string> splitCommand(string);
Player player(0,0,direction::East);
int main(){
while (true)
{
string command;
cout << "What do you want me to do?" << endl;
getline(cin, command);
executeCommand(command);
}
return 0;
}
void executeCommand(string command){
vector<string> cmd = splitCommand(command);
if(cmd.size() != 2)
{
cout << "Sorry, the command is invalid." << endl;
}
else
{
player.performAction(cmd[0],cmd[1]);
cout << player.getPlayerMessage() << endl;
}
}
vector<string> splitCommand(string command)
{
vector<string> cmd;
string word;
for(auto x : command)
{
if(x == ' ')
{
cmd.push_back(word);
word = "";
}
else
{
word = word + x;
}
}
cmd.push_back(word);
return cmd;
}