-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample2.rb
149 lines (129 loc) · 2.52 KB
/
example2.rb
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
# coding: utf-8
type Character
{
init(attack, agility, health)
{
@attack = attack
@agility = agility
@health = health
#slots = {"sword" = RustySword, "helmet" = nil, "chest" = nil}
}
}
kratos = Character.new(8, 5, 20)
bossman = Character.new(3, 2, 13)
minion = Character.new(1, 1, 4)
# ============================================================
# Aggregering problem!
# Hur ska en karaktär i spelet äga ett svärd?
# ============================================================
# type Sword
# {
# init(attack, agility)
# {
# @attack = attack
# @agility = agility
# }
# }
# rusty_sword = Sword.new(8, 1)
event Forest
{
init
{
chest_opened = False
boss_defeated = False
}
run
{
write("You enter a dark forest. The wind is howling.")
write("1. Walk to the right.")
write("2. Walk forward.")
write_if(not boss_defeated)("3. Initiate battle with Bossman.")
write_if(not chest_opended)("4. Open the chest.")
counter = 0
for option in option_list
{
write(counter + " " + option)
counter += 1
}
choice = read()
case choice
when 1
{
run(Desert)
}
when 2
{
write("You won!")
}
when 3
{
run(Battle1)
}
when 4
{
write("You got rusty sword which gives you +5 agility!")
Kratos.agility += 5
chest_opened = True
continue
}
}
}
# new version
event Battle
{
init
{
bossman = Character.new(3, 2, 13)
minions = []
for i in (0, 5) # create 5 minions
{
minions.append(Character.new(1, 1, 4))
}
}
run
{
write("The Bossman shouts at you: DIE!")
write ("1. Attack.")
choice = read()
case choice
when 1
{
while True
{
bossman.health -= kratos.attack
for i in minions
}
}
}
# old version
event Battle
{
#Boss.new("Bossman")
$minion_damage = 10
boss_hp = 10
boss_damage = 5
run
{
write("The Bossman shouts at you: DIE!")
while boss_hp > 0
{
write ("1. Attack.")
choice = read()
case choice
when 1
{
boss_hp -= Kratos.damage
Kratos.hp -= boss_damage
if Kratos.hp < 0
write("You have been slain...")
else if boss_hp < 0
Forest1
else
stay
}
}
}
}
#----- Huvudprogram -----
$kratos = Character.new(8, 5, 20)
run(Forest1)