-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameController.scala
33 lines (26 loc) · 932 Bytes
/
GameController.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
package controller
import trainingGround.Barracks
import troops._
import common._
import camp._
object GameController {
private var armyCamp = ArmyCamp(List[Trooper]())
def updateArmyCampStatus(list : List[Trooper]) ={
armyCamp = ArmyCamp(list)
}
def printCampStatus = armyCamp.toString()
def trainTroops(troopType:Int,noOfTroops:Int) ={
// val troopsList = troopType match{
// case 1 => List.fill(noOfTroops)(Archer)
// case 2 => List.fill(noOfTroops)(Barbarian)
// }
val troopsList = List.fill(troopType)(Archer) ++ List.fill(noOfTroops)(Barbarian)
Barracks.addTroops(troopsList).output match{
case Left(ex) =>
println("Troops cannot be added as it exceeds the Barracks capacity")
case Right(data) =>
updateArmyCampStatus(armyCamp.listOfTroops ++ data.list)
println("Training complete. Troops are available in the troop camp")
}
}
}