aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scalevalapokalypsi.iml1
-rw-r--r--src/scalevalapokalypsi/Model/Action.scala1
-rw-r--r--src/scalevalapokalypsi/Model/Adventure.scala8
-rw-r--r--src/scalevalapokalypsi/Model/Entities/Entity.scala72
-rw-r--r--src/scalevalapokalypsi/Model/Entities/Player.scala6
-rw-r--r--src/scalevalapokalypsi/Model/Item.scala4
6 files changed, 63 insertions, 29 deletions
diff --git a/scalevalapokalypsi.iml b/scalevalapokalypsi.iml
index a76f8e7..c38826d 100644
--- a/scalevalapokalypsi.iml
+++ b/scalevalapokalypsi.iml
@@ -8,5 +8,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="scala-sdk-3.3.0" level="application" />
+ <orderEntry type="library" name="scala-sdk-3.3.0" level="application" />
</component>
</module> \ No newline at end of file
diff --git a/src/scalevalapokalypsi/Model/Action.scala b/src/scalevalapokalypsi/Model/Action.scala
index a781ee8..52ba165 100644
--- a/src/scalevalapokalypsi/Model/Action.scala
+++ b/src/scalevalapokalypsi/Model/Action.scala
@@ -33,6 +33,7 @@ class Action(input: String):
result.map((true, _))
case "rest" => Some((true, actor.rest()))
case "get" => Some((false, actor.pickUp(this.modifiers)))
+ case "inventory" => Some((false, actor.inventory))
case "say" =>
val to = "to"
val recipient = modifiers.reverse.takeWhile(_ != ' ').reverse
diff --git a/src/scalevalapokalypsi/Model/Adventure.scala b/src/scalevalapokalypsi/Model/Adventure.scala
index 9347bfa..57f0dfd 100644
--- a/src/scalevalapokalypsi/Model/Adventure.scala
+++ b/src/scalevalapokalypsi/Model/Adventure.scala
@@ -14,8 +14,8 @@ import scalevalapokalypsi.Model.Entities.*
*/
class Adventure(val playerNames: Vector[String]):
- private val middle = Area("Forest", "You are somewhere in the forest. There are a lot of trees here.\nBirds are singing.")
- private val northForest = Area("Forest", "You are somewhere in the forest. A tangle of bushes blocks further passage north.\nBirds are singing.")
+ private val middle = Area("Forest", "Olet keskellä metsää. Metsä on täynnä puita.\nLintua laulaa.")
+ private val northForest = Area("Forest", "Olet keskellä metsää. Tiheä pensaikko estää sinua kulkemasta pohjoiseen. \nLintua laulaa.")
private val southForest = Area("Forest", "The forest just goes on and on.")
private val clearing = Area("Forest Clearing", "You are at a small clearing in the middle of forest.\nNearly invisible, twisted paths lead in many directions.")
private val tangle = Area("Tangle of Bushes", "You are in a dense tangle of bushes. It's hard to see exactly where you're going.")
@@ -29,11 +29,11 @@ class Adventure(val playerNames: Vector[String]):
tangle.setNeighbors(Vector("north" -> northForest, "east" -> home, "south" -> southForest, "west" -> northForest))
home.setNeighbors(Vector("west" -> tangle))
- clearing.addItem(Item("battery", "It's a small battery cell. Looks new."))
+ clearing.addItem(Item("battery", "It's a small battery cell. Looks new.", 1))
southForest.addItem(Item(
"laulukäärö",
"Jukranpujut, löysit laulukäärön!\n" +
- "Et vielä voi tehdä sillä mitään, koska et edes osaa laula."
+ "Et vielä voi tehdä sillä mitään, koska et edes osaa laula.", 1
))
val entities: Map[String, Entity] = Map()
diff --git a/src/scalevalapokalypsi/Model/Entities/Entity.scala b/src/scalevalapokalypsi/Model/Entities/Entity.scala
index e7cd45c..c7bc180 100644
--- a/src/scalevalapokalypsi/Model/Entities/Entity.scala
+++ b/src/scalevalapokalypsi/Model/Entities/Entity.scala
@@ -15,13 +15,14 @@ class Entity(
val name: String,
initialLocation: Area,
initialHP: Int = 100,
- val maxHP: Int = 100
+ val maxHP: Int = 100,
+ val maxInventoryWeight: Int = 10
):
private var currentLocation: Area = initialLocation
private var quitCommandGiven = false // one-way flag
- private val inventory: Map[String, Item] = Map()
private var hp = initialHP
+ private var items: Map[String, (Int, Item)] = Map()
// TODO: add logic for choosing from multiplu lines - can depend on HP etc.
/** Gets a verse to sing when attacking against this entity.
@@ -33,7 +34,7 @@ class Entity(
def takeDamage(amount: Int): Unit =
hp -= amount
if hp < 0 then
- println("Oh no, I died!")
+ println("Voi ei, kuolin!")
/** Returns a description of the physical condition of this entity,
* i.e. the damage it has taken.
@@ -86,42 +87,51 @@ class Entity(
(oldEntities.size)
(s"${this.name} leaves this location.")
)
- //val arriving = newEntities.map(n => n.zip(
- // Vector.fill
- // (n.size)
- // (s"${this.name} arrives here.")
- //)).getOrElse(Vector())
val self = Vector((this, s"You go $direction."))
Some(Event(
(leaving ++ self).toMap,
- s"$name arrives here."
+ s"$name saapuu tänne."
))
else None
def pickUp(itemName: String): Event =
this.currentLocation.removeItem(itemName) match
case Some(i) =>
- this.inventory += i.name -> i
- Event(
- immutable.Map.from(Vector((this, s"You pick up the ${i.name}"))),
- s"$name picks up the ${i.name}"
- )
+ val inventoryWeight = items.values.map(p => p(1).weight).sum
+ if inventoryWeight + i.weight > maxInventoryWeight then
+ Event(
+ immutable.Map.from(Vector((this, s"Voimasi eivät riitä kannattelemaan esinettä ${i.name}, koska kannat liikaa"))),
+ s"")
+ else
+ if items.contains(i.name) then
+ val (current, _) = items(i.name)
+ this.items += i.name -> (current + 1, i)
+ else
+ this.items += i.name -> (1, i)
+ Event(
+ immutable.Map.from(Vector((this, s"Poimit esineen ${i.name}"))),
+ s"$name poimi esineen ${i.name}"
+ )
case None => Event(
- immutable.Map.from(Vector((this, s"There is no $itemName here to pick up."))),
- s"${this.name} tries to pick up something but gets just dirt in their hands."
+ immutable.Map.from(Vector((this, s"Täällä ei ole esinettä $itemName noukittavaksi."))),
+ s"${this.name} yritti ottaa jotakin, mutta sai vain likaa käsilleen."
)
def drop(itemName: String): Event =
- this.inventory.remove(itemName) match
- case Some(item) =>
+ this.items.remove(itemName) match
+ case Some((current, item)) if current > 0 =>
+ if current - 1 == 0 then
+ this.items -= item.name
+ else
+ this.items += itemName -> (current - 1, item)
this.currentLocation.addItem(item)
Event(
- immutable.Map.from(Vector((this, s"You drop the $itemName"))),
- s"$name drops the $itemName"
+ immutable.Map.from(Vector((this, s"Pudotit esineen $itemName"))),
+ s"$name Pudotti esineen $itemName"
)
case None => Event(
- immutable.Map.from(Vector((this, "You don't have that!"))),
- s"$name reaches their backpack to drop $itemName but miserably fails to find it there."
+ immutable.Map.from(Vector((this, "Sinulla ei ole tätä esinettä!"))),
+ s"$name yritti tonkia rpustaan esineen $itemName mutta ei löytänyt sitä."
)
def sayTo(entity: Entity, message: String): Event =
@@ -163,9 +173,25 @@ class Entity(
* @param itemName the name to check
* @return whether this entity has this item and can drop it
*/
- def canDrop(itemName: String): Boolean = this.inventory.contains(itemName)
+ def canDrop(itemName: String): Boolean = this.items.contains(itemName)
/** Returns a brief description of the player’s state, for debugging purposes. */
override def toString = s"${this.name} at ${this.location.name}"
+
+ def inventory: Event =
+ if this.items.isEmpty then
+ Event(
+ immutable.Map.from(Vector((this, s"Sinulla ei ole esineitä"))),
+ s"")
+ else
+ var inventoryList = List[String]()
+ for (name, (count, item)) <- this.items do
+ inventoryList = inventoryList :+ s"$name $count (${item.description})"
+ Event(
+ immutable.Map.from(Vector((this, s"Kannat repussasi:\n" + inventoryList.mkString("\n")))),
+ s"")
+
+
+
end Entity
diff --git a/src/scalevalapokalypsi/Model/Entities/Player.scala b/src/scalevalapokalypsi/Model/Entities/Player.scala
index cac5bf1..1dd5187 100644
--- a/src/scalevalapokalypsi/Model/Entities/Player.scala
+++ b/src/scalevalapokalypsi/Model/Entities/Player.scala
@@ -1,6 +1,6 @@
package scalevalapokalypsi.Model.Entities
-import scala.collection.mutable.Buffer
+import scala.collection.mutable.{Buffer, Map}
import scalevalapokalypsi.Model.*
/** A `Player` object represents a player character controlled by one real-life player
@@ -18,6 +18,7 @@ class Player(name: String, initialLocation: Area) extends Entity(name, initialLo
private val observedEvents: Buffer[Event] = Buffer.empty
private var pendingSingEffect: Option[SingEffect] = None
+
override def observeString(observation: String): Unit =
this.observations.append(observation)
override def observe(event: Event): Unit =
@@ -71,4 +72,7 @@ class Player(name: String, initialLocation: Area) extends Entity(name, initialLo
))
event.foreach(this.location.observeEvent(_))
+
+
+
end Player
diff --git a/src/scalevalapokalypsi/Model/Item.scala b/src/scalevalapokalypsi/Model/Item.scala
index c1ebaa1..cccb489 100644
--- a/src/scalevalapokalypsi/Model/Item.scala
+++ b/src/scalevalapokalypsi/Model/Item.scala
@@ -9,10 +9,12 @@ import scala.annotation.targetName
* @param name the item’s name
* @param description the item’s description
*/
-class Item(val name: String, val description: String):
+class Item(val name: String, val description: String, val weight: Int):
/** Returns a short textual representation of the item (its name, that is). */
override def toString = this.name
+
+
end Item