Design

Started by
2 comments, last by ToohrVyk 15 years, 3 months ago
Okay i need to design a game , im gonna base it on the pairs game where u select 2 cards and see if they match. Just wondering how you would recommend desiging it - in school we just pseudocode cause those programs are easzy (there in visual basic) so is there reccommended steps , or different steps for object orientated programming ?? trying to design it well so i can update it Cheers Catkill
Advertisement
I would start by making a card class, that can store card information and it's state(hidden, flipped or flipped&matched). You'll have to decide now if you want to store the card's location in each card or in a single matrix.

The card class should be able to draw the card on screen, check itself against other cards, etc.
-----------------------------------------Everyboddy need someboddy!
Quote:Just wondering how you would recommend desiging it
We can't recommend a certain way of designing your game. That's because there's no indication of what's right. It's possible to comment on the implications of a certain design choice, and in that sense say what is definitely a bad idea, but saying what is good is more difficult.

Quote:so is there reccommended steps
No.

Quote:or different steps for object orientated programming
Is it meaningful to use OOP and where? That's up to you.

As a programmer, you'll have to make design choices. You'll have to do so by thinking about the implications of each design choice. someboddy gave certain suggestions, but I can state a counter argument to each. He suggests making a card class to store state information. But do you need to do that? How many cards are there? 4 suits * 13 ranks. How many states are there? x 3. That number is well within the precision of a single integer. Why not use an integer to represent a card, and use a set of computations to figure out the suit, rank, and state of the card?

He talks about deciding whether to store the card's location in each card. Does a card have to have a location? If I take a deck of cards, and remove one card, where is that removed card located? Should a card even have a concept of location? Or is that a concept external to the card? What about a single matrix? Can you use a single matrix? Sure, you might say. But what if in each round of the game, only a small subset of the cards is used. And you use a new subset of cards in each game? Can you still use a single matrix?

More and more questions.
I would follow the following design:

  • Number all card pairs from 0 to N-1.
  • Create a 2D array of integers, representing the board of cards, where each cell is the number of the pair that card belongs to.
  • Store the pair the currently revealed card belongs to.
  • Create an array of booleans, representing whether a certain pair has already been solved or not.
  • Put all of these in a single "board" class.


Mostly, something like this:
class board{  int cards[W][H];  bool solved[W*H/2];  boost::optional<int> revealed;};

This topic is closed to new replies.

Advertisement