From 579dcbd41c0cda476fdc177a932da373bf70311e Mon Sep 17 00:00:00 2001 From: Sacha Ligthert Date: Fri, 1 Dec 2023 23:08:17 +0100 Subject: [PATCH] Added score; Keep track of movement; --- game.go | 1 + player.go | 9 +++++++++ types.go | 1 + 3 files changed, 11 insertions(+) diff --git a/game.go b/game.go index 41ef0e4..0c7a804 100644 --- a/game.go +++ b/game.go @@ -47,6 +47,7 @@ func initialize() (Game, error) { x: 40, y: 12, }, + score: 0, moves: 0, teleports: 0, }, diff --git a/player.go b/player.go index d65db39..6902daa 100644 --- a/player.go +++ b/player.go @@ -10,41 +10,50 @@ func (g *Game) movePlayer(game *Game, press int) { if press == Left { if game.player.position.x != 2 { game.player.position.x-- + game.player.moves++ } } else if press == Right { if game.player.position.x != 78 { game.player.position.x++ + game.player.moves++ } } else if press == Up { if game.player.position.y != 1 { game.player.position.y-- + game.player.moves++ } } else if press == Down { if game.player.position.y != 22 { game.player.position.y++ + game.player.moves++ } } else if press == upleft { if game.player.position.x != 2 && game.player.position.y != 1 { game.player.position.x-- game.player.position.y-- + game.player.moves++ } } else if press == upright { if game.player.position.x != 78 && game.player.position.y != 1 { game.player.position.x++ game.player.position.y-- + game.player.moves++ } } else if press == downright { if game.player.position.x != 78 && game.player.position.y != 22 { game.player.position.x++ game.player.position.y++ + game.player.moves++ } } else if press == downleft { if game.player.position.x != 2 && game.player.position.y != 22 { game.player.position.x-- game.player.position.y++ + game.player.moves++ } } else if press == teleport { game.teleport(game) + game.player.teleports++ } } diff --git a/types.go b/types.go index 21e57f1..87071e9 100644 --- a/types.go +++ b/types.go @@ -21,6 +21,7 @@ type Position struct { type Player struct { position Position + score int moves int teleports int }