Week 3 of Game Programming 1 – Classes

In this week of game programming, we have worked with classes. A class holds values, the amount and type of values is decided by the programmer. To learn how classes work, we had a bunch of different assignments. The assignment I chose to focus on was to make a deck of cards. I chose to focus on this because it demonstrate really well how classes work together. I made a class called Card, this class held the types Integer and String. The class made cards containing those types which was sent to the class Deck, which put the cards in an Array. From the array, the program could shuffle and pick out cards, every card in the array was unique. What was not programmed was the process to remove cards from the deck.

Shown below is a snapshot from the class Card: In this class all the cards is created, the cards is then put in the deck via a for loop in the Deck class.

Card::Card(int num)
{
if (num < 13)
{
int a = 0;
a++;
int m_num = a;
m_suit = "Hearts";
}
if (12 < num < 27)
{
int a = 0;
a++;
int m_num = a;
m_suit = "Spades";
}
if (26 < num < 40)
{
int a = 0;
a++;
int m_num = a;
m_suit = "Clubs";
}
if (39 < num <= 52)
{
int a = 0;
a++;
int m_num = a;
m_suit = "Diamonds";
}
} 

About Axel Vesterlund

2014  Programming