Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
TDT4240-group23
SpaceCheckers
Commits
34136e4e
Commit
34136e4e
authored
Apr 20, 2021
by
morkolai
Browse files
checks if move is legal before move
parent
7894b4ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
CheckersClient/core/src/com/mygdx/game/model/Game.kt
View file @
34136e4e
...
...
@@ -35,9 +35,13 @@ class Game(gameState: GameState, playerIds: LinkedHashSet<Int>) {
return
this
.
gameState
.
getBoardState
().
fields
[
cubeCoordinates
]
?.
hasPiece
()
==
true
}
fun
isLegalMove
(
fromCoordinates
:
Vector3
,
toCoordinates
:
Vector3
):
Boolean
{
return
getGameState
()
?.
getGameMode
()
?.
getPossibleMoves
(
fromCoordinates
)
?.
contains
(
toCoordinates
)
?:
false
}
fun
movePiece
(
fromCoordinates
:
Vector3
,
toCoordinates
:
Vector3
,
playerId
:
Int
,
gameController
:
GameController
):
Boolean
{
// Check if players turn
if
(
playerId
==
playerTurnId
)
{
if
(
playerId
==
playerTurnId
&&
isLegalMove
(
fromCoordinates
,
toCoordinates
)
)
{
// TODO: Check if valid move
val
pieceMoved
:
Boolean
=
this
.
gameState
.
getBoardState
().
movePiece
(
fromCoordinates
,
toCoordinates
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment