Now that I have a deck of cards built, it’s time to write a game. The first game I’ll write will be war, because it’s the simplest game I know.

Here are the rules:

  • A standard deck is divided evenly between two players.
  • Each player draws their top card to play.
  • The player with the highest cardvalue wins (aces are high).
    • The winner keeps both cards played and adds them to the bottom of his stack.
  • If both players draw cards of equal value, the players go to “war.”
    • Each player lays three cards face down.
      • If a player runs out of cards during a “war,” then he may play his last card as his face-up card.
    • The players choose a card from the three to turn face up.
    • The higher card wins, with the winner adding all of the cards to the bottom of his hand.
    • If both players choose cards of equal value, they go to “war” again.
  • The player to collect all the cards in the deck wins.

Continue reading »

 

Today as I was designing the object model for War (see: James Games), I decided to write a small console application to help with some testing. Early in the process, I had to deal with the typical task of getting user-input. Typical code for getting input looks something like this:

static void Main(string[] args)
{
    Console.WriteLine("How many players?");
    int numberOfPlayers = int.Parse(Console.ReadLine());
    Console.WriteLine(String.Format("Creating game for {0} players...", numberOfPlayers));

    // More code...
}

Continue reading »

 

In my last article, I defined a deck of cards as “a complete set of cards,” but it’s really not that simple. Though most games require one card of each face & suit combination (as in a standard 52-card deck), not all of them do. Some games, such as Mille, require multiple decks whereas other games, such as Spanish 21, require some of the standard cards to be removed. Therefore, to build “deck” functionality, we need:

  • A way to maintain an arbitrary list of cards.
  • An abstract way to supply an initial set of cards to the deck.
  • A method for shuffling the cards. Continue reading »
 

I’ve decided that in 2012 I’d like to do some technical blogging. I’ve been writing software since I was in high school and I fully expect coding to be a lifelong hobby and an occasional profession. This series of blog posts, and the software I’ll be developing along the way, will serve as a framework to help me continue to enjoy my passion for software development.

To get things started with blogging, I’ve decided to create an open source project on GitHub. The project will be a set of libraries for writing card games using C# and the Microsoft .NET Framework. I’m calling the project “James Games” (pardon my lack of creativity). The goal of James Games is to serve as a vehicle for:

  • Having fun.
  • Learning and applying good design.
  • Exploring technology that are new (to me).

Continue reading »

© 2011 James Tharpe Suffusion theme by Sayontan Sinha