#18 Started conversion to Game
This commit is contained in:
parent
d4fbcda73b
commit
de02c7113f
11 changed files with 300 additions and 112 deletions
|
@ -1,7 +1,10 @@
|
|||
module ParseGameSpec where
|
||||
|
||||
import Test.Hspec
|
||||
import RPGEngine.Parse.StructureElement
|
||||
import RPGEngine.Parse.StructElement
|
||||
import RPGEngine.Data
|
||||
import RPGEngine.Parse.Core
|
||||
import RPGEngine.Parse.Game
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
|
@ -14,39 +17,118 @@ spec = do
|
|||
pending
|
||||
|
||||
describe "Player" $ do
|
||||
it "TODO: Simple player" $ do
|
||||
pending
|
||||
it "cannot die" $ do
|
||||
let input = "player: { hp: infinite, inventory: [] }"
|
||||
correct = Player {
|
||||
playerHp = Prelude.Nothing,
|
||||
inventory = []
|
||||
}
|
||||
Right (Entry (Tag "player") struct) = parseWith structElement input
|
||||
structToPlayer struct `shouldBe` correct
|
||||
|
||||
it "without inventory" $ do
|
||||
let input = "player: { hp: 50, inventory: [] }"
|
||||
correct = Player {
|
||||
playerHp = Just 50,
|
||||
inventory = []
|
||||
}
|
||||
Right (Entry (Tag "player") struct) = parseWith structElement input
|
||||
structToPlayer struct `shouldBe` correct
|
||||
|
||||
it "with inventory" $ do
|
||||
let input = "player: { hp: 50, inventory: [ { id: \"dagger\", x: 0, y: 0, name: \"Dolk\", description: \"Basis schade tegen monsters\", useTimes: infinite, value: 10, actions: {} } ] }"
|
||||
correct = Player {
|
||||
playerHp = Just 50,
|
||||
inventory = [
|
||||
Item {
|
||||
itemId = "dagger",
|
||||
itemX = 0,
|
||||
itemY = 0,
|
||||
itemName = "Dolk",
|
||||
itemDescription = "Basis schade tegen monsters",
|
||||
itemActions = [],
|
||||
itemValue = Just 10,
|
||||
useTimes = Prelude.Nothing
|
||||
}
|
||||
]
|
||||
}
|
||||
Right (Entry (Tag "player") struct) = parseWith structElement input
|
||||
structToPlayer struct `shouldBe` correct
|
||||
|
||||
describe "Inventory" $ do
|
||||
it "TODO: Empty inventory" $ do
|
||||
describe "Layout" $ do
|
||||
it "simple" $ do
|
||||
pending
|
||||
it "TODO: Singleton inventory" $ do
|
||||
pending
|
||||
it "TODO: Filled inventory" $ do
|
||||
pending
|
||||
|
||||
|
||||
describe "Items" $ do
|
||||
it "TODO: Simple item" $ do
|
||||
pending
|
||||
-- Check id
|
||||
-- Check x
|
||||
-- Check y
|
||||
-- Check name
|
||||
-- Check description
|
||||
-- Check useTimes
|
||||
-- Check value
|
||||
-- Check actions
|
||||
it "simple" $ do
|
||||
let input = "{ id: \"dagger\", x: 0, y: 0, name: \"Dagger\", description: \"Basic dagger you found somewhere\", useTimes: infinite, value: 10, actions: {} }"
|
||||
correct = Item {
|
||||
itemId = "dagger",
|
||||
itemX = 0,
|
||||
itemY = 0,
|
||||
itemName = "Dagger",
|
||||
itemDescription = "Basic dagger you found somewhere",
|
||||
itemValue = Just 10,
|
||||
itemActions = [],
|
||||
useTimes = Prelude.Nothing
|
||||
}
|
||||
Right struct = parseWith structElement input
|
||||
structToItem struct `shouldBe` correct
|
||||
|
||||
it "with actions" $ do
|
||||
let input = "{ id: \"key\", x: 3, y: 1, name: \"Doorkey\", description: \"Unlocks a secret door\", useTimes: 1, value: 0, actions: { [not(inventoryFull())] retrieveItem(key), [] leave() } }"
|
||||
correct = Item {
|
||||
itemId = "key",
|
||||
itemX = 3,
|
||||
itemY = 1,
|
||||
itemName = "Doorkey",
|
||||
itemDescription = "Unlocks a secret door",
|
||||
itemActions = [
|
||||
([], Leave),
|
||||
([Not InventoryFull], RetrieveItem "key")
|
||||
],
|
||||
itemValue = Just 0,
|
||||
useTimes = Just 1
|
||||
}
|
||||
Right struct = parseWith structElement input
|
||||
structToItem struct `shouldBe` correct
|
||||
|
||||
describe "Actions" $ do
|
||||
it "TODO: Simple action" $ do
|
||||
pending
|
||||
|
||||
it "no conditions" $ do
|
||||
let input = "{[] leave()}"
|
||||
correct = [([], Leave)]
|
||||
Right struct = parseWith structElement input
|
||||
structToActions struct `shouldBe` correct
|
||||
|
||||
it "single condition" $ do
|
||||
let input = "{ [inventoryFull()] useItem(itemId)}"
|
||||
correct = [([InventoryFull], UseItem "itemId")]
|
||||
Right struct = parseWith structElement input
|
||||
structToActions struct `shouldBe` correct
|
||||
|
||||
it "multiple conditions" $ do
|
||||
let input = "{ [not(inventoryFull()), inventoryContains(itemId)] increasePlayerHp(itemId)}"
|
||||
correct = [([Not InventoryFull, InventoryContains "itemId"], IncreasePlayerHp "itemId")]
|
||||
Right struct = parseWith structElement input
|
||||
structToActions struct `shouldBe` correct
|
||||
|
||||
describe "Entities" $ do
|
||||
it "TODO: Simple entity" $ do
|
||||
pending
|
||||
|
||||
describe "Level" $ do
|
||||
it "TODO: Simple layout" $ do
|
||||
pending
|
||||
it "Simple layout" $ do
|
||||
let input = "{ layout: { | * * * * * * \n| * s . . e *\n| * * * * * *\n}, items: [], entities: [] }"
|
||||
correct = Level {
|
||||
RPGEngine.Data.layout = [
|
||||
[Blocked, Blocked, Blocked, Blocked, Blocked, Blocked],
|
||||
[Blocked, Entrance, Walkable, Walkable, Exit, Blocked],
|
||||
[Blocked, Blocked, Blocked, Blocked, Blocked, Blocked]
|
||||
],
|
||||
items = [],
|
||||
entities = []
|
||||
}
|
||||
Right struct = parseWith structElement input
|
||||
structToLevel struct `shouldBe` correct
|
||||
it "TODO: Complex layout" $ do
|
||||
pending
|
Reference in a new issue