By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

Memory game, good structure

P: 1
Hi.

I need some help with a memory game. How should I structure it before I begin to write it.
Is it good to have a class that defines a matrix for the play board and something like that?
Or should I use functions that defines lists and for-slings? Whats the easiest way? Im thinking about lists, and then functions to do all the commands from the user and everything else.

its going to look something like this:

1 2 3 4 5 6
A - - - - - -
B - - - - - -
C - - - - - -
D - - - - - -
E - - - - - -
F - - - - - -
==================
choice1: A5

1 2 3 4 5 6
A - - - - kul -
B - - - - - -
C - - - - - -
D - - - - - -
E - - - - - -
F - - - - - -
==================
choice2: B7 etc..
Nov 6 '08 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
I would create a class object and initialize a dictionary. The rows (A,B,C,D...) would be the dictionary keys and the values would be lists. Provide overload methods __str__, __setitem__, and __getitem__ to print, set individual cells, and retrieve individual cells. You can add whatever methods from there to suit your game. Possible interaction:
Expand|Select|Wrap|Line Numbers
  1. >>> g = Game(6)
  2. >>> g['C3']=10
  3. >>> g['C3']
  4. 10
  5. >>> g['C4']
  6. '-'
  7. >>> print g
  8.            0     1     2     3     4     5
  9.      A     -     -     -     -     -     -
  10.      B     -     -     -     -     -     -
  11.      C     -     -     -    10     -     -
  12.      D     -     -     -     -     -     -
  13.      E     -     -     -     -     -     -
  14.      F     -     -     -     -     -     -
  15. >>>
Nov 6 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.