From 3cadb443630e451c35390a22ca967363a98ed544 Mon Sep 17 00:00:00 2001 From: Nahid-29 Date: Thu, 29 Aug 2024 12:42:24 +0600 Subject: [PATCH 1/3] 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, 11 insertions(+), 1 deletion(-) diff --git a/src/GameLogic/Snap.cs b/src/GameLogic/Snap.cs index 42894a1a7..625db455c 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 (); } /// @@ -92,6 +93,7 @@ public void Start() _deck.Shuffle (); // Return the cards and shuffle FlipNextCard (); // Flip the first card... + _gameTimer.Start(); } } @@ -112,6 +114,13 @@ public void FlipNextCard() public void Update() { //TODO: implement update to automatically slip cards! + + if (_gameTimer.Ticks > _flipTime) + { + _gameTimer.Reset (); + FlipNextCard (); + } + } /// @@ -143,6 +152,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..f4a337c9d 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 (); } } From ca556edb8e4dc4aef88a5b915a95efc0fe5f9263 Mon Sep 17 00:00:00 2001 From: Nahid-29 Date: Wed, 11 Sep 2024 20:46:03 +0600 Subject: [PATCH 2/3] Edit --- src/SnapGame.cs | 51 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/SnapGame.cs b/src/SnapGame.cs index f4a337c9d..ae098c543 100644 --- a/src/SnapGame.cs +++ b/src/SnapGame.cs @@ -6,7 +6,31 @@ namespace CardGames { public class SnapGame { - public static void LoadResources() + private static void DrawGame(Snap myGame) + { + SwinGame.ClearScreen(Color.White); + + // Draw the top card + Card top = myGame.TopCard; + if (top != null) + { + SwinGame.DrawText ("Top Card is " + top.ToString (), Color.RoyalBlue, 0, 20); + SwinGame.DrawText ("Player 1 score: " + myGame.Score(0), Color.RoyalBlue, 0, 30); + SwinGame.DrawText ("Player 2 score: " + myGame.Score(1), Color.RoyalBlue, 0, 40); + SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), top.CardIndex, 350, 50); + } + else + { + SwinGame.DrawText ("No card played yet...", Color.RoyalBlue, 0, 20); + } + + // Draw the back of the cards... to represent the deck + SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), 52, 160, 50); + + //Draw onto the screen + SwinGame.RefreshScreen(60); + } + public static void LoadResources() { Bitmap cards; cards = SwinGame.LoadBitmapNamed ("Cards", "Cards.png"); @@ -32,30 +56,7 @@ private static void HandleUserInput(Snap myGame) /// Draws the game to the Window. /// /// The details of the game -- mostly top card and scores. - private static void DrawGame(Snap myGame) - { - SwinGame.ClearScreen(Color.White); - - // Draw the top card - Card top = myGame.TopCard; - if (top != null) - { - SwinGame.DrawText ("Top Card is " + top.ToString (), Color.RoyalBlue, 0, 20); - SwinGame.DrawText ("Player 1 score: " + myGame.Score(0), Color.RoyalBlue, 0, 30); - SwinGame.DrawText ("Player 2 score: " + myGame.Score(1), Color.RoyalBlue, 0, 40); - SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), top.CardIndex, 350, 50); - } - else - { - SwinGame.DrawText ("No card played yet...", Color.RoyalBlue, 0, 20); - } - - // Draw the back of the cards... to represent the deck - SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), 52, 160, 50); - - //Draw onto the screen - SwinGame.RefreshScreen(60); - } + /// /// Updates the game -- it should flip the cards itself once started! From 3e8c1f729915526e0f95c3d2464720d84cac7f83 Mon Sep 17 00:00:00 2001 From: Nahid-29 Date: Wed, 11 Sep 2024 20:50:12 +0600 Subject: [PATCH 3/3] Edit SnapGame --- src/SnapGame.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/SnapGame.cs b/src/SnapGame.cs index ae098c543..4b85f27e0 100644 --- a/src/SnapGame.cs +++ b/src/SnapGame.cs @@ -6,7 +6,13 @@ namespace CardGames { public class SnapGame { - private static void DrawGame(Snap myGame) + public static void LoadResources() + { + Bitmap cards; + cards = SwinGame.LoadBitmapNamed ("Cards", "Cards.png"); + SwinGame.BitmapSetCellDetails (cards, 82, 110, 13, 5, 53); // set the cells in the bitmap to match the cards + } + private static void DrawGame(Snap myGame) { SwinGame.ClearScreen(Color.White); @@ -30,12 +36,7 @@ private static void DrawGame(Snap myGame) //Draw onto the screen SwinGame.RefreshScreen(60); } - public static void LoadResources() - { - Bitmap cards; - cards = SwinGame.LoadBitmapNamed ("Cards", "Cards.png"); - SwinGame.BitmapSetCellDetails (cards, 82, 110, 13, 5, 53); // set the cells in the bitmap to match the cards - } + /// /// Respond to the user input -- with requests affecting myGame