Skip to content
Binary file modified Resources/images/Cards.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/images/cardsBoard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion src/GameLogic/Deck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,21 @@ public int CardsRemaining
/// </summary>
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;
}

/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions src/GameLogic/Snap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Snap
public Snap ()
{
_deck = new Deck ();
_gameTimer = SwinGame.CreateTimer ();
}

/// <summary>
Expand Down Expand Up @@ -92,6 +93,7 @@ public void Start()
_deck.Shuffle (); // Return the cards and shuffle

FlipNextCard (); // Flip the first card...
_gameTimer.Start();
}
}

Expand All @@ -112,6 +114,11 @@ public void FlipNextCard()
public void Update()
{
//TODO: implement update to automatically slip cards!
if (_gameTimer.Ticks > _flipTime)
{
_gameTimer.Reset ();
FlipNextCard ();
}
}

/// <summary>
Expand Down Expand Up @@ -143,6 +150,7 @@ public void PlayerHit (int player)

// stop the game...
_started = false;
_gameTimer.Stop ();
}

#region Snap Game Unit Tests
Expand Down
11 changes: 6 additions & 5 deletions src/SnapGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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.BitmapSetCellDetails (cards, 167, 250, 13, 5, 53); // set the cells in the bitmap to match the cards
}

/// <summary>
Expand All @@ -24,7 +24,7 @@ private static void HandleUserInput(Snap myGame)

if (SwinGame.KeyTyped (KeyCode.vk_SPACE))
{
myGame.FlipNextCard ();
myGame.Start ();
}
}

Expand All @@ -34,7 +34,7 @@ private static void HandleUserInput(Snap myGame)
/// <param name="myGame">The details of the game -- mostly top card and scores.</param>
private static void DrawGame(Snap myGame)
{
SwinGame.ClearScreen(Color.White);
SwinGame.DrawBitmap("cardsBoard.png", 0, 0);

// Draw the top card
Card top = myGame.TopCard;
Expand All @@ -43,11 +43,12 @@ private static void DrawGame(Snap myGame)
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.DrawCell (SwinGame.BitmapNamed ("Cards"), top.CardIndex, 521, 153);

}
else
{
SwinGame.DrawText ("No card played yet...", Color.RoyalBlue, 0, 20);
SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), 52, 155, 153);
}

// Draw the back of the cards... to represent the deck
Expand Down