fix coord system and class
This commit is contained in:
parent
ddea33ef6b
commit
1f58cd2c03
|
@ -20,13 +20,13 @@ type Env =
|
||||||
| Floor
|
| Floor
|
||||||
| Trap
|
| Trap
|
||||||
| Player
|
| Player
|
||||||
|
|
||||||
type Board = Env list list
|
type Board = Env list list
|
||||||
|
|
||||||
type Cast = {
|
type Cast = {
|
||||||
spell: string
|
spell: string
|
||||||
direction: Direction
|
direction: Direction
|
||||||
}
|
}
|
||||||
type Command =
|
type Command =
|
||||||
| Move of Direction
|
| Move of Direction
|
||||||
| Refresh
|
| Refresh
|
||||||
|
@ -76,20 +76,22 @@ type StateJSON =
|
||||||
}
|
}
|
||||||
|
|
||||||
type State(board: Board) =
|
type State(board: Board) =
|
||||||
|
let mutable _playerLocation = { x = 1; y = 1 }
|
||||||
member this.boardString = floorToString board
|
member this.boardString = floorToString board
|
||||||
member this.playerLocation = { x = 1; y = 1 }
|
member this.playerLocation = _playerLocation
|
||||||
member this.JSON = {
|
member this.JSON = {
|
||||||
board = this.boardString
|
board = this.boardString
|
||||||
playerLocation = this.playerLocation
|
playerLocation = _playerLocation
|
||||||
}
|
}
|
||||||
member this.cmd cmd =
|
member this.cmd cmd =
|
||||||
match cmd with
|
match cmd with
|
||||||
| Move d ->
|
| Move d ->
|
||||||
match d with
|
match d with
|
||||||
| North -> this.playerLocation = { x = this.playerLocation.x + 1; y = this.playerLocation.y }
|
// Note that the coordinate system is pinned to NW
|
||||||
| South -> this.playerLocation = { x = this.playerLocation.x - 1; y = this.playerLocation.y }
|
| North -> _playerLocation <- { x = _playerLocation.x; y = _playerLocation.y - 1 }
|
||||||
| East -> this.playerLocation = { x = this.playerLocation.x; y = this.playerLocation.y + 1 }
|
| South -> _playerLocation <- { x = _playerLocation.x; y = _playerLocation.y + 1 }
|
||||||
| West -> this.playerLocation = { x = this.playerLocation.x; y = this.playerLocation.y - 1 }
|
| East -> _playerLocation <- { x = _playerLocation.x + 1; y = _playerLocation.y }
|
||||||
| _ -> true
|
| West -> _playerLocation <- { x = _playerLocation.x - 1; y = _playerLocation.y }
|
||||||
|
| _ -> ()
|
||||||
|
|
||||||
let mutable Current = State(newBoard())
|
let mutable Current = State(newBoard())
|
||||||
|
|
|
@ -16,4 +16,12 @@ let TestFloorToString() =
|
||||||
]
|
]
|
||||||
let actual = floorToString floor
|
let actual = floorToString floor
|
||||||
let expected = "+-+\n|.|\n+-+\n"
|
let expected = "+-+\n|.|\n+-+\n"
|
||||||
Assert.AreEqual(actual, expected)
|
Assert.AreEqual(expected, actual)
|
||||||
|
|
||||||
|
[<Test>]
|
||||||
|
let TestStateMovement() =
|
||||||
|
let current = State(newBoard())
|
||||||
|
let expected = 2
|
||||||
|
current.cmd (Move South) |> ignore
|
||||||
|
let actual = current.playerLocation.y
|
||||||
|
Assert.AreEqual(expected, actual)
|
Loading…
Reference in New Issue