Skip to content
Open
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 (1).zip
Binary file not shown.
15 changes: 14 additions & 1 deletion 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 @@ -91,7 +92,8 @@ public void Start()
_started = true;
_deck.Shuffle (); // Return the cards and shuffle

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

Expand All @@ -110,7 +112,13 @@ public void FlipNextCard()
/// the game to update its internal state.
/// </summary>
public void Update()

{
if (_gameTimer.Ticks > _flipTime)
{
_gameTimer.Reset ();
FlipNextCard ();
}
//TODO: implement update to automatically slip cards!
}

Expand Down Expand Up @@ -140,9 +148,14 @@ 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
48 changes: 42 additions & 6 deletions src/SnapGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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-Regular.otf", 12);
}

/// <summary>
/// Respond to the user input -- with requests affecting myGame
Expand All @@ -24,8 +25,27 @@ 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>
Expand All @@ -40,18 +60,34 @@ 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);

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
SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), 52, 160, 50);
// SwinGame.DrawCell (SwinGame.BitmapNamed ("Cards"), 52, 160, 50);

//Draw onto the screen
SwinGame.RefreshScreen(60);
Expand Down