fix coord system and class
This commit is contained in:
parent
ddea33ef6b
commit
1f58cd2c03
|
@ -76,20 +76,22 @@ type StateJSON =
|
|||
}
|
||||
|
||||
type State(board: Board) =
|
||||
let mutable _playerLocation = { x = 1; y = 1 }
|
||||
member this.boardString = floorToString board
|
||||
member this.playerLocation = { x = 1; y = 1 }
|
||||
member this.playerLocation = _playerLocation
|
||||
member this.JSON = {
|
||||
board = this.boardString
|
||||
playerLocation = this.playerLocation
|
||||
playerLocation = _playerLocation
|
||||
}
|
||||
member this.cmd cmd =
|
||||
match cmd with
|
||||
| Move d ->
|
||||
match d with
|
||||
| North -> this.playerLocation = { x = this.playerLocation.x + 1; y = this.playerLocation.y }
|
||||
| South -> this.playerLocation = { x = this.playerLocation.x - 1; y = this.playerLocation.y }
|
||||
| East -> this.playerLocation = { x = this.playerLocation.x; y = this.playerLocation.y + 1 }
|
||||
| West -> this.playerLocation = { x = this.playerLocation.x; y = this.playerLocation.y - 1 }
|
||||
| _ -> true
|
||||
// Note that the coordinate system is pinned to NW
|
||||
| North -> _playerLocation <- { x = _playerLocation.x; y = _playerLocation.y - 1 }
|
||||
| South -> _playerLocation <- { x = _playerLocation.x; y = _playerLocation.y + 1 }
|
||||
| East -> _playerLocation <- { x = _playerLocation.x + 1; y = _playerLocation.y }
|
||||
| West -> _playerLocation <- { x = _playerLocation.x - 1; y = _playerLocation.y }
|
||||
| _ -> ()
|
||||
|
||||
let mutable Current = State(newBoard())
|
||||
|
|
|
@ -16,4 +16,12 @@ let TestFloorToString() =
|
|||
]
|
||||
let actual = floorToString floor
|
||||
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