From 5f9b578749cf980fbcd3b2475cb1429696be452a Mon Sep 17 00:00:00 2001 From: TIMOTHY LOH YAO WEN <101448711@student.swin.edu.au> Date: Tue, 10 Mar 2020 20:09:52 +1100 Subject: [PATCH] add game timer logic to Snap and have the game started when the spacebar is pressed --- src/GameLogic/Snap.cs | 10 +++++++++- src/SnapGame.cs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/GameLogic/Snap.cs b/src/GameLogic/Snap.cs index 42894a1a7..b91c5c86e 100644 --- a/src/GameLogic/Snap.cs +++ b/src/GameLogic/Snap.cs @@ -37,6 +37,7 @@ public class Snap public Snap () { _deck = new Deck (); + _gameTimer = SwinGame.CreateTimer(); } /// @@ -91,7 +92,8 @@ public void Start() _started = true; _deck.Shuffle (); // Return the cards and shuffle - FlipNextCard (); // Flip the first card... + FlipNextCard (); // Flip the first card... + _gameTimer.Start(); } } @@ -112,6 +114,11 @@ public void FlipNextCard() public void Update() { //TODO: implement update to automatically slip cards! + if (_gameTimer.Ticks > _flipTime) + { + _gameTimer.Reset(); + FlipNextCard(); + } } /// @@ -143,6 +150,7 @@ public void PlayerHit (int player) // stop the game... _started = false; + _gameTimer.Stop(); } #region Snap Game Unit Tests diff --git a/src/SnapGame.cs b/src/SnapGame.cs index ec78e9072..25764ae64 100644 --- a/src/SnapGame.cs +++ b/src/SnapGame.cs @@ -24,7 +24,7 @@ private static void HandleUserInput(Snap myGame) if (SwinGame.KeyTyped (KeyCode.vk_SPACE)) { - myGame.FlipNextCard (); + myGame.Start (); } }