diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml new file mode 100644 index 000000000..347cb805b --- /dev/null +++ b/.github/workflows/dotnet-core.yml @@ -0,0 +1,25 @@ +name: .NET Core + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.301 + - name: Install dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: Test + run: dotnet test --no-restore --verbosity normal diff --git a/Resources/fonts/ChunkFive.otf b/Resources/fonts/ChunkFive.otf new file mode 100644 index 000000000..7711f20f9 Binary files /dev/null and b/Resources/fonts/ChunkFive.otf differ diff --git a/Resources/images/cardsBoard.png b/Resources/images/cardsBoard.png new file mode 100644 index 000000000..23f715a57 Binary files /dev/null and b/Resources/images/cardsBoard.png differ diff --git a/obj/x86/Debug-Windows/CardGames.csprojAssemblyReference.cache b/obj/x86/Debug-Windows/CardGames.csprojAssemblyReference.cache new file mode 100644 index 000000000..f39feb355 Binary files /dev/null and b/obj/x86/Debug-Windows/CardGames.csprojAssemblyReference.cache differ diff --git a/src/GameLogic/Deck.cs b/src/GameLogic/Deck.cs index 4b30d8f89..7d040a34a 100644 --- a/src/GameLogic/Deck.cs +++ b/src/GameLogic/Deck.cs @@ -54,7 +54,22 @@ 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; } /// diff --git a/src/GameLogic/Snap.cs b/src/GameLogic/Snap.cs index 42894a1a7..4886f95bc 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(); } } @@ -111,7 +113,11 @@ public void FlipNextCard() /// public void Update() { - //TODO: implement update to automatically slip cards! + if (_gameTimer.Ticks > _flipTime) + { + _gameTimer.Reset (); + FlipNextCard (); + }//automatically slip cards! } /// @@ -143,6 +149,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..a1c71571e 100644 --- a/src/SnapGame.cs +++ b/src/SnapGame.cs @@ -11,7 +11,8 @@ 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 - } + SwinGame.LoadFontNamed ("GameFont", "Chunkfive.otf", 24); + } /// /// Respond to the user input -- with requests affecting myGame @@ -25,6 +26,7 @@ private static void HandleUserInput(Snap myGame) if (SwinGame.KeyTyped (KeyCode.vk_SPACE)) { myGame.FlipNextCard (); + myGame.Start (); } } @@ -34,16 +36,16 @@ private static void HandleUserInput(Snap myGame) /// The details of the game -- mostly top card and scores. private static void DrawGame(Snap myGame) { - SwinGame.ClearScreen(Color.White); + SwinGame.DrawBitmap("cardsBoard.png", 0, 0); // 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); + SwinGame.DrawText ("Top Card is " + top.ToString (), Color.White,"GameFont", 0, 30); + SwinGame.DrawText ("Player 1 score: " + myGame.Score(0), Color.White,"GameFont", 0, 30); + SwinGame.DrawText ("Player 2 score: " + myGame.Score(1), Color.White,"GameFont", 0, 30); + SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), top.CardIndex, 521, 153); } else { @@ -51,7 +53,7 @@ private static void DrawGame(Snap myGame) } // Draw the back of the cards... to represent the deck - SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), 52, 160, 50); + SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), 52, 155, 153); //Draw onto the screen SwinGame.RefreshScreen(60); @@ -86,4 +88,4 @@ public static void Main() } } } -} \ No newline at end of file +}