943,728 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1539
  • Python RSS
Nov 20th, 2008
0

Memory game

Expand Post »
Hi!
I need help with a memory game. I dont know how to do when I want the users choice to appear. The function guessing. I want the user to first write e.g. A1 and then B2. and the doldmatris() is the one with the words. Then the start function will get the words so you can see and if the words the same they should stay there and still appear. Anyone with any ideas of how I can do?thank you

and if you see something that can be done with a nicer coding please give me the advice

Python Syntax (Toggle Plain Text)
  1. import random
  2. class Matrix(object):
  3. def __init__(self, cols, rows, letters):
  4. letters = ['A','B','C','D','E','F']
  5. print ' 1 2 3 4 5 6'
  6. self.cols = cols
  7. self.rows = rows
  8.  
  9. self.matrix = []
  10. for i in range(rows):
  11. ea_row = []
  12. for j in range(cols):
  13. ea_row.append('---')
  14. self.matrix.append(ea_row)
  15.  
  16.  
  17. def setitem(self, col, row, v):
  18. self.matrix[col][row] = v
  19.  
  20. def getitem(self, col, row):
  21. return self.matrix[col][row]
  22.  
  23. #Print out the letters
  24. def __repr__(self):
  25. outStr = ""
  26. for i in range(self.rows):
  27. outStr += '%s %s\n' % (letters[i], self.matrix[i])
  28. return outStr
  29.  
  30. def start():
  31. start = Matrix(6,6,0)
  32. print start
  33.  
  34. #Hidden matrix to import the words from the list and
  35. #then compare with the other matrix
  36. def doldmatris():
  37. infile = open('memo.txt', 'r')
  38. words = infile.readlines()
  39. infile.close()
  40.  
  41. index = 0
  42. while index < len(words):
  43. words[index] = words[index].rstrip('\n')
  44. index += 1
  45.  
  46. random.shuffle(words)
  47.  
  48. index = 1
  49. dold = []
  50. for i in range(6):
  51. ia_row = []
  52. for j in range(6):
  53. ia_row.append(words[i])
  54. i +=1
  55. dold.append(ia_row)
  56.  
  57. return dold
  58.  
  59. def guessing():
  60. row = raw_input('Which row? (A-F)').lower()
  61. col = input('Which column? (1-6)')
  62.  
  63. return guess
  64. def main():
  65. start()
  66. doldmatris()
  67. guessing()
  68.  
  69. main()
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kempablavitt is offline Offline
2 posts
since Nov 2008
Nov 26th, 2008
0

Re: Memory game

Is this game supposed to be like the card game memory?

Where you turn over two cards and if they match you count the pair (usually removing the cards) and if not flip them back over?

So for each user turn:
the user should pick a first card
you 'turn face up' the first card
(display the grid)
the user should pick a second card
you 'turn face up' the second card
(display the grid)
if the cards match, remove the cards from play
if the cards do not match, turn then back 'face down'
(display the grid)

until the user has either matched all of the cards or quit

This means that each location in the grid has one of 3 states: face down, face up, empty

If you would like further assistance, please implement more of the code. It would also be nice if your posted code would at least compile, and if you want to use an external file, a sample of what that file was intended to contain would also be useful.

PS- As an alternative design to the 'scrolling text' method you are using, if you are at least passing familiar with the python graphic support, this application would lend itself well to a grid of buttons. Although it would be a very different approach from what you have, I think the result would be more user friendly.
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: help with this program
Next Thread in Python Forum Timeline: Auth Object





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC