Skip to content

Commit

Permalink
Add moral
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Mar 2, 2020
1 parent 34e4b4a commit 57052af
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
5 changes: 4 additions & 1 deletion ai/src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ instance FromJSON Team

data Skill
= HitFromBack
| Leader
| Ranged
| Unique
deriving (Generic, Show)

instance ToJSON Skill
Expand All @@ -43,6 +45,7 @@ data Creature
creatureName :: String,
hp :: Int,
attack :: Int,
moral :: Maybe Int,
victoryPoints :: Int,
skills :: Maybe [Skill]
}
Expand Down Expand Up @@ -91,7 +94,7 @@ someFunc = do
print decoding2
print allDecoding
where
creature :: Creature = Creature Human "archer" 1 1 2 Nothing
creature :: Creature = Creature Human "archer" 1 1 (Just 2) 2 Nothing
creatureJSON = "{ \"team\":\"Human\", \"name\":\"spearman\", \"hp\":2, \"attack\":1, \"victory_points\":2, \"skills\":[\"HitFromBack\"]}"
creature2JSON = "{ \"team\":\"Human\", \"foobar\":\"ignore\", \"name\":\"spearman\", \"hp\":2, \"attack\":1, \"victory_points\":2}"
decoding :: Either String Creature = eitherDecode creatureJSON
Expand Down
5 changes: 3 additions & 2 deletions cardgen/src/commonMain/kotlin/com/hgames/pcw/creatures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private fun findTeam(s: String?): Team? {
return Team.values().firstOrNull { it.name.equals(s, true) }
}

data class Creature(val name: String, val team: Team, var hps: Int, val attack: Int, val victoryPoints: Int, val skills: List<Skill>) {
data class Creature(val name: String, val team: Team, var hps: Int, val attack: Int, val moral: Int?, val victoryPoints: Int, val skills: List<Skill>) {

companion object {

Expand All @@ -46,6 +46,7 @@ data class Creature(val name: String, val team: Team, var hps: Int, val attack:
val team: Team = findTeam(teamString) ?: throw IllegalStateException("No such team: $teamString")
val hp: Int = map["hp"] as? Int ?: throw IllegalStateException(genErrMsg("hp"))
val attack: Int = map["attack"] as? Int ?: throw IllegalStateException(genErrMsg("attack"))
val moral: Int? = map["moral"] as? Int ?: null
val victoryPoints: Int = map["victory_points"] as? Int
?: throw IllegalStateException(genErrMsg("victory_points"))
val skills: List<Skill> = readSkill(map["skills"])
Expand All @@ -56,7 +57,7 @@ data class Creature(val name: String, val team: Team, var hps: Int, val attack:
val h: Int = map["h"] as? Int ?: 72 // default
val rect = RectangleInt(x, y, w, h)

return Pair(Creature(name, team, hp, attack, victoryPoints, skills), rect)
return Pair(Creature(name, team, hp, attack, moral, victoryPoints, skills), rect)
}

private fun readSkill(input: Any?): List<Skill> {
Expand Down
3 changes: 2 additions & 1 deletion cardgen/src/commonMain/kotlin/com/hgames/pcw/skill.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ enum class Skill {
HitFromBack,
Flammable,
Leader,
Ranged;
Ranged,
Unique;

companion object {

Expand Down
14 changes: 7 additions & 7 deletions cardgen/src/commonMain/resources/data.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"creatures": [
{ "team":"Human", "name":"spearman", "hp":2, "attack":1, "victory_points":2, "skills":["HitFromBack"], "x":72, "y":0 },
{ "team":"Human", "name":"swordsman", "hp":2, "attack":1, "victory_points":2, "x":0, "y":0 },
{ "team":"Human", "name":"archer", "hp":2, "attack":1, "victory_points":2, "skills":["Ranged"], "x":144, "y":0 },
{ "team":"Human", "name":"general", "hp":3, "attack":3, "victory_points":5, "skills":["Leader"], "x":216, "y":0 },
{ "team":"Human", "name":"spearman", "hp":2, "attack":1, "moral":3, "victory_points":2, "x":72, "y":0, "skills":["HitFromBack"] },
{ "team":"Human", "name":"swordsman", "hp":2, "attack":1, "moral":3, "victory_points":2, "x":0, "y":0 },
{ "team":"Human", "name":"archer", "hp":2, "attack":1, "moral":3, "victory_points":2, "x":144, "y":0, "skills":["Ranged"] },
{ "team":"Human", "name":"general", "hp":3, "attack":3, "moral":5, "victory_points":5, "x":216, "y":0, "skills":["Leader", "Unique"] },
{ "team":"Undead", "name":"skeleton", "hp":1, "attack":1, "victory_points":1, "x":0, "y":72 },
{ "team":"Undead", "name":"vampire", "hp":3, "attack":3, "victory_points":5, "x":72, "y":72 },
{ "team":"Undead", "name":"archer", "hp":1, "attack":1, "victory_points":1, "skills":["Ranged"], "x":144, "y":72 },
{ "team":"Undead", "name":"mummy", "hp":5, "attack":2, "victory_points":2,"skills":["Flammable"], "x":216, "y":72 }
{ "team":"Undead", "name":"vampire", "hp":3, "attack":3, "victory_points":5, "x":72, "y":72 },
{ "team":"Undead", "name":"archer", "hp":1, "attack":1, "victory_points":1, "x":144, "y":72, "skills":["Ranged"]},
{ "team":"Undead", "name":"mummy", "hp":5, "attack":2, "victory_points":2, "x":216, "y":72, "skills":["Flammable"]}
],
"neutral": [
{ "name": "health" ,"tile":"red_potion", "text": "Heals 1 HP" },
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pkgs.mkShell {
buildInputs = with pkgs; [
ormolu gmp
ormolu # gmp
];
}

Expand Down

0 comments on commit 57052af

Please sign in to comment.