Memory game, good structure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kempablavitt
    New Member
    • Nov 2008
    • 1

    Memory game, good structure

    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..
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    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:
    [code=Python]>>> g = Game(6)
    >>> g['C3']=10
    >>> g['C3']
    10
    >>> g['C4']
    '-'
    >>> print g
    0 1 2 3 4 5
    A - - - - - -
    B - - - - - -
    C - - - 10 - -
    D - - - - - -
    E - - - - - -
    F - - - - - -
    >>>[/code]

    Comment

    Working...