From 7594830aaab72ae49e591e26b427ebc34c2badcb Mon Sep 17 00:00:00 2001 From: ricoria12 <101225396@students.swinburne.edu.my> Date: Thu, 11 Mar 2021 17:54:30 +0800 Subject: [PATCH 1/3] Update Deck.cs --- src/GameLogic/Deck.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/GameLogic/Deck.cs b/src/GameLogic/Deck.cs index 4b30d8f89..ebbd08ad2 100644 --- a/src/GameLogic/Deck.cs +++ b/src/GameLogic/Deck.cs @@ -55,6 +55,23 @@ public int CardsRemaining public void Shuffle() { //TODO: implement shuffle! + for(int i =0; i < 52; i++) + { + if(_cards[i].FaceUp) _cards[i].TurnOver(); + } + Random rnd = new Random(); + + //for each card (no need to shuffle last card) + for(int i = 0; i < 52 - 1; i++); + { + //pick a random index + int rndIdx = rnd.Next(52 - i); + + Card temp = _cards[i]; + _cards[i] = _cards[i + rndIdx]; + _cards[i + rndIdx] = temp; + } + _topCard = 0; } /// From 10ea6fde637265715f8099fbc0170709ac0885cd Mon Sep 17 00:00:00 2001 From: GC <101225383@students.swinburne.edu.my> Date: Thu, 11 Mar 2021 18:05:25 +0800 Subject: [PATCH 2/3] Update SnapGame.cs --- src/SnapGame.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/SnapGame.cs b/src/SnapGame.cs index ec78e9072..c9b42b12a 100644 --- a/src/SnapGame.cs +++ b/src/SnapGame.cs @@ -26,6 +26,22 @@ private static void HandleUserInput(Snap myGame) { myGame.FlipNextCard (); } + if(myGame.IsStarted) + { + if (SwinGame.KeyTyped (KeyCode.vk_LSHIFT)&& + SwinGame.KeyTyped (KeyCode.vk_RSHIFT)) + { + //TODO: add sound effects + } + else if (SwinGame.KeyTyped (KeyCode.vk_LSHIFT)) + { + myGame.PlayerHit(0); + } + else if (SwinGame.KeyTyped (KeyCode.vk_RSHIFT)) + { + myGame.PlayerHit(1); + } + } } /// From 6e3dca49ec53b7d05ab56194fff31ecf1c846a34 Mon Sep 17 00:00:00 2001 From: Snowiewie <80443587+Snowiewie@users.noreply.github.com> Date: Thu, 11 Mar 2021 18:09:40 +0800 Subject: [PATCH 3/3] add game timer logic to Snap and have the game started when the spacebar is pressed --- src/GameLogic/Snap.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/GameLogic/Snap.cs b/src/GameLogic/Snap.cs index 42894a1a7..af89d3f79 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,11 @@ public void FlipNextCard() public void Update() { //TODO: implement update to automatically slip cards! + if (_gameTimer.Ticks > _flipTime) + { + _gameTimer.Reset (); + FlipNextCard (); + } } ///