-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevelTwo.swift
86 lines (71 loc) · 3.28 KB
/
levelTwo.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
import Curses
class LevelTwo {
private var battleAnswer = ""
private var fight = false
private var flight = false
private var damage = 0
func getRandomRunStory() -> String {
let runStories = ["You try to run but trip and the bear kills you.", "You try to run but the bear is faster than you.", "You try to run but fall and die."]
let randomNum = Int.random(in: 0 ... 2)
return runStories[randomNum]
}
func battleBear() {
while true {
mainWindow.clear()
mainWindow.write("While searching you hear a sound nearby.")
currentCursorY = 1
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("Its a wild bear that is about to attack you.")
currentCursorY = 2
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write("What do you do?")
currentCursorY = 10
battleAnswer = mainWindow.getStringFromTextField(at:Point(x:0, y:currentCursorY), maxCharacters: 100, fieldColorPair:whiteOnBlack)
let stringArray = battleAnswer.components(separatedBy: " ")
let filteredTokens = NLP().stemming(stringArray: stringArray)
let lemmatizedTokens = NLP().lemmatization(stringArray: filteredTokens)
for word in lemmatizedTokens {
switch word {
case "run":
flight = true
case "fight":
fight = true
case "inventory":
currentCursorY = 8
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
print(inventory)
default:
currentCursorY = 9
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
}
}
switch inventory[0] {
case "gun":
damage = Int.random(in: 15 ... 20)
case "axe":
damage = Int.random(in: 10 ... 20)
default:
damage = 0
}
if fight {
currentCursorY = 8
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
if LevelOne().getInv()[0] == "gun" && damage >= 17 {
mainWindow.write("You shot the bear and survived")
} else if LevelOne().getInv()[0] == "axe" && damage >= 16 {
mainWindow.write("You fought the bear with your axe and survived")
} else if LevelOne().isWeaponObtained() && damage < 16 {
mainWindow.write("You were not able to kill the bear. Try again")
} else {
mainWindow.write("You didnt have a weapon, so you couldnt defend yourself against the bear.")
}
break
} else {
currentCursorY = 10
mainWindow.cursor.position = Point(x: 0, y: currentCursorY)
mainWindow.write(getRandomRunStory())
break
}
}
}
}