-
Notifications
You must be signed in to change notification settings - Fork 0
/
levelOne.swift
206 lines (168 loc) · 7.33 KB
/
levelOne.swift
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import Curses
class LevelOne {
private var answer1 = ""
private var answer2 = ""
private var answer3 = ""
private var movement = false
private var house = false
private var car = false
private var take = false
func storyTellingOne() {
///////////////////////////////////////////
// Tells the story and current situation //
///////////////////////////////////////////
currentCursorY = 0
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("You awake in a cold, cold place. You dont know where you are, or how you got here. All you know is your name: \(name).")
currentCursorY += 1
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("You see a path near where you wake up, it splits into two up ahead.")
currentCursorY += 1
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("Your two choices are the left path and the right path. The left path leads to the house and the right path leads to the car.")
currentCursorY += 1
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("What do you do?")
// Waits for user response
currentCursorY = 10
answer1 = mainWindow.getStringFromTextField(at:Point(x:0, y:currentCursorY), maxCharacters: 100, fieldColorPair:whiteOnBlack)
// Processes the response from the user
let stringArray = answer1.components(separatedBy: " ")
let filteredTokens = NLP().stemming(stringArray: stringArray)
let lemmatizedTokens = NLP().lemmatization(stringArray: filteredTokens)
// Uses the left over array and looks for keywords
for word in lemmatizedTokens {
switch word {
case "go":
movement = true
case "house", "left":
house = !house
break
case "car", "right":
car = !car
break
case "no":
car = !car
house = !house
default:
currentCursorY = 9
mainWindow.write("Please enter a valid response")
}
}
// Using the response, sends the user to the next section
if movement && car {
storyTellingCar()
} else if movement && house {
storyTellingHouse()
}
}
func storyTellingCar() {
/////////////////////
// Tells the story //
/////////////////////
mainWindow.clear()
currentCursorY = 1
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("You walk to the car to look for anything that can help you.")
currentCursorY = 2
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("In the trunk of the car, you see a woodcutting axe. This could be useful to you.")
currentCursorY = 3
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("Do you take the axe?")
currentCursorY = 4
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
// Waits for new user response
currentCursorY = 10
answer2 = mainWindow.getStringFromTextField(at:Point(x:0, y:currentCursorY), maxCharacters: 100, fieldColorPair:whiteOnBlack)
//
// Again filteres the response from the user
//
let stringArray = answer2.components(separatedBy: " ")
let filteredTokens = NLP().stemming(stringArray: stringArray)
let lemmatizedTokens = NLP().lemmatization(stringArray: filteredTokens)
for word in lemmatizedTokens {
switch word {
case "take":
take = !take
weapon = !weapon
case "axe":
weapon = !weapon
case "no":
take = !take
weapon = !weapon
break
default:
currentCursorY = 9
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("Please enter a valid response")
}
}
if take && weapon {
inventory[0] = "axe"
currentCursorY = 11
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("You chose to take the axe, good choice \(name).")
} else {
currentCursorY = 11
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("You chose to leave the axe, you might regret that decision \(name).")
}
currentCursorY = 12
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("Press F2 to proceed to the next level")
}
func storyTellingHouse() {
mainWindow.clear()
currentCursorY = 1
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("You chose to go to the house to see if there is anything you can find.")
currentCursorY = 2
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("You look around the house and find a safe that is slightly open, which has a gun in it.")
currentCursorY = 3
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("Do you take the gun?")
currentCursorY = 10
answer3 = mainWindow.getStringFromTextField(at:Point(x:0, y:currentCursorY), maxCharacters: 100, fieldColorPair:whiteOnBlack)
let stringArray = answer3.components(separatedBy: " ")
let filteredTokens = NLP().stemming(stringArray: stringArray)
let lemmatizedTokens = NLP().lemmatization(stringArray: filteredTokens)
for word in lemmatizedTokens {
switch word {
case "take":
take = !take
weapon = !weapon
case "gun":
weapon = !weapon
case "no":
take = !take
weapon = !weapon
break
default:
currentCursorY = 9
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("Please enter a valid response")
}
}
if take && weapon {
inventory[0] = "gun"
currentCursorY = 11
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("You chose to take the gun, good choice \(name).")
} else {
currentCursorY = 11
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("You chose to leave the gun, you might regret that decision \(name).")
}
currentCursorY = 12
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("Press F2 to proceed to the next level")
}
func isWeaponObtained() -> Bool {
return weapon
}
func getInv() -> [String] {
return inventory
}
}