-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanaParser.cpp
153 lines (127 loc) · 3.27 KB
/
anaParser.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* We had talked about using the fields library and Ron was working on
porting it over here, so I'll set this up using that.
string command;
//Hey, Michaela here. This would be easier with strstr(), if you
//wanted to simplify searching strings. It'd just need to be with
//c_strings instead
Ron - began implementing the use of vectors that containing valid synonyms for each action
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <cctype>
#include "fields.h"
using namespace std;
const int USE = 0;
const int MOVE = 1;
const int ATTACK = 2;
const int CHECK = 3;
const int TAKE = 4;
const int HELP = 5;
const int SKILL = 6;
const int TALK = 7;
const int MAP = 8;
const vector<string> use_vec = {"use", "drink", "eat", "consume"};
const vector<string> move_vec = {"go", "walk", "run", "move"};
const vector<string> attack_vec = {"attack", "hit"};
const vector<string> check_vec = {"check", "scan", "look", "examine"};
const vector<string> take_vec = {"take", "pickup", "grab", "snatch"};
int action () {
int selection;
//open inputstruct for reading stdin
IS is = new_inputstruct(NULL);
//pull player action -- return on fail
if(get_line(is) < 0);
return 0;
//coverts all letters to lower case
for (int i = 0; i < is->NF; i++)
for (j = 0; fields[i][j] != 0; j++)
tolower(field[i][j]);
//check for action word synonyms
selections = synonyms(is->fields[0]);
//call function for given action
switch(selection){
case MOVE:
actionMove(is);
break;
case USE:
actionUse(is);
break;
case ATTACK:
actionAttack(is);
break;
case CHECK:
actionCheck(is);
break;
case TAKE:
actionTake(is);
break;
case HELP:
actionHelp();
break;
default:
badinput();
}
//free memory and return
jettison_inputstruct(is);
return 1;
}
//move character
void actionMove(IS is) {
return;
}
//use an item
void actionUse(IS is) {
return;
}
//attack designated target
void actionAttack(IS is) {
return;
}
//look at available enemy stats
void actionCheck(IS is) {
return;
}
//pickup/take item
void actionTake(IS is) {
return;
}
//input assistance
void actionHelp() {
std::cout << "Try using an item, skill or spell." << endl
<< "You can check on the status of enemies and allies or list skills and spells." << endl;
<< "If you want to know what something will do, try an action." << endl;
return;
}
//incorrect input
void badInput() {
cout << "Invalid input. Type 'help' for help." << endl;
return;
}
//gets command based on synonyms
int synonyms(char* b) {
for(i = 0; i < use_vec.size(); i++) {
if(strcmp(b,use_vec[i] == 0)
return(USE);
}
for(i = 0; i < move_vec.size(); i++) {
if(strcmp(b,move_vec[i] == 0)
return(MOVE);
}
for(i = 0; i < attack_vec.size(); i++) {
if(strcmp(b,attack_vec[i] == 0)
return(ATTACK);
}
for(i = 0; i < check_vec.size(); i++) {
if(strcmp(b,check_vec[i] == 0)
return(CHECK);
}
for(i = 0; i < take_vec.size(); i++) {
if(strcmp(b,take_vec[i] == 0)
return(TAKE);
}
if(strcmp(b,"help") == 0)
return(HELP);
}