Skip to content
Open

B1 #94

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Resources/fonts/Chunkfive.otf
Binary file not shown.
3 changes: 2 additions & 1 deletion src/GameLogic/Deck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ public class Deck
{
private readonly Card[] _cards = new Card[52];
private int _topCard;
private int num1;
/// <summary>
/// Creates a new Deck with 52 Cards. The first card
/// will be the top of the Deck.
/// </summary>
public Deck ()
{
num1 = 1000;
int i = 0;

for (Suit s = Suit.CLUB; s <= Suit.SPADE; s++)
Expand Down
17 changes: 15 additions & 2 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 @@ -111,8 +113,13 @@ public void FlipNextCard()
/// </summary>
public void Update()
{
//TODO: implement update to automatically slip cards!
}
//TODO: implement update to automatically slip cards!
if (_gameTimer.Ticks > _flipTime)
{
_gameTimer.Reset();
FlipNextCard();
}
}

/// <summary>
/// Gets the player's score.
Expand Down Expand Up @@ -140,9 +147,15 @@ public void PlayerHit (int player)
_score[player]++;
//TODO: consider playing a sound here...
}
else if (player >= 0 && player < _score.Length)
{
_score[player]--;
}


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

#region Snap Game Unit Tests
Expand Down
30 changes: 25 additions & 5 deletions src/SnapGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ 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", "Chuckfive.otf", 12);

}

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

if (SwinGame.KeyTyped (KeyCode.vk_SPACE))
{
myGame.FlipNextCard ();
myGame.Start();
}
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);
}
}
}
}

/// <summary>
/// Draws the game to the Window.
Expand All @@ -40,9 +59,9 @@ private static void DrawGame(Snap myGame)
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.DrawText ("Top Card is " + top.ToString (), Color.RoyalBlue, "GameFont", 0, 20);
SwinGame.DrawText ("Player 1 score: " + myGame.Score(0), Color.RoyalBlue, "GameFont", 0, 30);
SwinGame.DrawText ("Player 2 score: " + myGame.Score(1), Color.RoyalBlue, "GameFont", 0, 40);
SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), top.CardIndex, 350, 50);
}
else
Expand All @@ -64,6 +83,7 @@ private static void DrawGame(Snap myGame)
private static void UpdateGame(Snap myGame)
{
myGame.Update(); // just ask the game to do this...

}

public static void Main()
Expand Down