-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattle.scala
81 lines (69 loc) · 2.1 KB
/
Battle.scala
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
import io.threadcso._
object Battle {
val WarriorMaxSp = 10
val SwordStabSpCost = 3
val SwordStabDamage = 1
val DragonMaxSp = 20
val FireSpitSpCost = 3
val FireSpitDamage = 1
val damageWarrior = OneOne[Int]
val damageDragon = OneOne[Int]
def warrior(inflictDamage: ![Int], receiveDamage: ?[Int]) = proc {
var hp : Int = 3
var sp : Int = 3
var damage: Int = 0
println("Come here you @(*&% beast!")
while(hp > 0) {
if(sp < WarriorMaxSp) {
println("Warrior sharpens their sword and recovers 1 SP")
sp = sp + 1
} else {
println("Warrior throws Stopped")
throw new io.threadcso.processimplementation.Stopped()
}
alt(
(sp >= SwordStabSpCost &&& inflictDamage) =!=> { SwordStabDamage } ==> {
sp = sp - SwordStabSpCost
println("Warrior stabs dragon with their sword")
}
|
(hp > 0 &&& receiveDamage) =?=> {
damage => hp = hp - damage
println("Warrior receives " + damage + " damage")
}
)
}
println("Warrior's dead")
}
def dragon(inflictDamage: ![Int], receiveDamage: ?[Int]) = proc {
var hp : Int = 3
var sp : Int = 3
println("Ggggrrrrrrrr")
while(hp > 0) {
if(sp < DragonMaxSp) {
sp = sp + 1
println("Dragon regurgitates fire and recovers 1 SP. Now it has " + sp)
} else {
println("Dragon throws Stopped")
throw new io.threadcso.processimplementation.Stopped()
}
alt(
((hp > 0 && sp >= FireSpitSpCost) &&& inflictDamage) =!=> { FireSpitDamage } ==> {
println("Dragon spits fire all over the warrior"); sp = sp - FireSpitSpCost
}
|
(hp > 0 &&& receiveDamage) =?=> {
damage => hp = hp - damage
println("Dragon receives " + damage + " damage")
}
)
println("Dragon's HP/SP: " + hp + "/" + sp)
}
println("Dragon's dead")
}
def main(args: Array[String]) {
println("Let the battle begin!")
(warrior(damageDragon, damageWarrior) || dragon(damageWarrior, damageDragon))()
exit
}
}