Professional Documents
Culture Documents
GAMES
Modeling Practice -
Candy Land in .NET Part
1: Overview
5 years ago by Matthew Jones ∙ 4 min read
This is Part 1 of a two-part series detailing how to simulate the Hasbro board game Candy Land as
a C# console project.
Anybody remember the game Candy Land? You know, the simple colors and sweets game that little
children play to learn how to play board games? The one that requires absolutely zero skill or
reading comprehension to play?
Lemme break it down for those of you who haven't seen this game before. Players draw cards
which have simple colors (red, orange, yellow, blue, green, purple) on them, and then move to the
next matching space with that color. There are also seven "specialty" spaces with pictures of sweet
items on them, and if you draw the card with that item you go directly to that space (which also
means you could move backwards by drawing a specialty card). The rst player to reach the end of
the path wins.
Only two complications arise on the board: a couple spaces have black licorice on them, and if you
land on one of those space your next turn is skipped (which doesn't make any sense to me, seeing
as black licorice is delicious); and there are two shortcuts on the board that can be accessed by
landing on their starting spaces.
Simple enough, right? Here's the interesting part: the game is deterministic. Once the cards are
shuf ed, a person who can see the deck of cards will know who will win the game.
That means that we can write a program to simulate playing the game, and it wouldn't be too hard.
Guess what we're gonna do? Let's build a command line Candy Land simulator in C# and .NET!
Basically Awesome
Thanks for reading! Would you care to
buy me a coffee?
Before we can do anything else, we need to model the components of Candy Land as C# classes. In
any game of Candy Land, there are three basic components:
However, there are also three higher-level objects, which are comprised of the basic objects.
3. The game itself, which comprises the board, the deck, and the players.
We'll need all six of these objects to play a game; the latter three we will deal with in Part 2 of this
series. For now, let's start with the players.
Note the property CurrentLocation . We need a way to store what space the player currently resides
on, and IMO the best place to put that is in the Player class itself. We'll explain the IsSkipped
property in the BoardSpace section.
The property IsWinner is a ag that the Game object will look at after each turn; as soon as one
Player has IsWinner set to true, the game is over.
Now that we've got Player de ned, we need to take a look at something that is common to the
BoardSpace and Card classes: CandyColor.
Since these thirteen "values" are available to both cards and spaces, we're going to make an
Enumeration to represent them (because I like enums), and we'll call that Enum CandyColor:
Wait, you say, what is "rainbow? Note that board's nal space has all the colors, signifying that you
can draw any color to land on it and win the game. As we'll see in later parts of this series, it's not
strictly necessary to represent this space, but I'm going to do so for posterity.
With the common values de ned, we can start building the Card and BoardSpace classes.
Licorice spaces which cause any player that lands on one to have their next turn skipped (this is
why we have the Player.IsSkipped property).
Now that we've got all of our Game Components de ned, we can start writing code to set up the
game itself. We'll do that in Part 2 of this series, where we discuss Programming the Game.
Modeling Ti et to Ride
in C# Part 6: Structure, Modeling Ti et to Ride Modeling Ti et to Ride
Scoring, and in C# Part 5: Player in C# Part 4: Player
Drawba s Drawing Cards Claiming Routes
Login
Add a comment
Powered by Commento
Speaking