Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory game with cards  RSS feed

 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, i need some help with my academic project because i am a very beginner. I have to creat a memory game with cards where a player should find two copies from 26 different cards. There is a basic game with one player or a team. Also, there are some variations of the game (e.g double game or trio-quertet). In the first part of the project we are asked to design only the classes and the methods without code. If someone has a idea and wants to help me, let me know it in order to send more information...
 
Jason Bullers
Ranch Hand
Posts: 115
11
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start with the basic game with one player. You can always evolve your design as you add new functionality to the game. So, assuming that you are making a memory game for one person to play, what do you need to for that game? Don't think about this in terms of classes and implementations yet, think about this more in terms of what "entities" (nouns) might exist and what behaviours (verbs) those entities might support (or how they might interact). Once you have that figured out at a high level, it should be a little easier to figure out what you need to model in your application.

EDIT: Try that and let us know what you come up with, and then we can move forward from there.
 
Liutauras Vilda
Marshal
Posts: 4670
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Sure. Please show us what have you done so far and where you stuck.

If you got written steps in english how you are going to do it, just post them here, in case you finished all that already and started coding, please post actual code.
Don't forget to UseCodeTags (<- link) when posting actual code to make your code readable. Thank you.
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, first of all let me give you the assignment...
The basic game contains 2 copies of 26 different images that we place in a field( 4 lines, 13 columns). The game can be played by a player(count his steps-opening pairs) or by a team (when someone find a pair he playes again). Now we have some variatios :
1) Someone who found a pair doesn't play again, but continues the next one (team game only).
2)Double game (2 copies of 52 different images) in field( 8 x 13).
3)Trio-quartet, we have 3/4 copies in 26 different images.
4) We place the cards in random ( no field).
5)Someone in team game decides not to play.
6)When we open a pair, the cards change places.
7)The pairs,trio,quartet are opened in order, a number is written at the image.
8)Battle, only two players who play in two fields(4 x 13), one for each one. Each field contains 52 different pictures -like double game. Each player can open cards only from his field. One of them begin opening a card and the other one responds . If the two cards are similar, the second one wins the pair. Then the first player is changed.

Finally, when we have more than one player, one of them can be controlled by computer with 3 memory levels( a(goldfish)-> remember nothing, b(kangaroo)-> remember the half, c(elephant) -> remember everything )
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now, i have a plan in my mind but i am very confused ! I think, i should use abstract classes and interfaces... I need some help with the classes and the methods that i will use (parent-children, abstract classes, interfaces)



Interfaces : DoubleGame, TrioQuartet, Battle, OpenCardsInOrder
A parent class Player and children Single,Team
Classes field and image.

[HENRY: fixed code tags]
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't ask for code, i would try to do it by myself, i only need a plan for the classes and the methods... help me guys, it's too difficult !!
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Wow. That game has a large number of game modes and features. Do you really need to work through (have a plan) for all the game modes and features before you can start development?

Christina Tzogka wrote:I don't ask for code, i would try to do it by myself, i only need a plan for the classes and the methods... help me guys, it's too difficult !!


How about narrowing it down to one mode and one feature first? And with that, how about narrowing it down to a small subset of that? etc. It looks difficult because it is a lot. Plan out a small piece at a time.

Henry
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry, my project is separeted in two parts. In the first i must send only the classes and the methods without code so i should have a complete plan. I tied to narrow it down but i got confused again. I asked for help for the basic game but i wrote the assignment so you can get a idea for the whole project...
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christina Tzogka wrote:Henry, my project is separeted in two parts. In the first i must send only the classes and the methods without code so i should have a complete plan. I tied to narrow it down but i got confused again. I asked for help for the basic game but i wrote the assignment so you can get a idea for the whole project...


As Liutauras mentioned, please tell us what you did so far, and where are you stuck (confused). We can't give you any hints in the right direction, if we don't know what issues you are having.

Henry
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already posted what i have done so far ! As i have mentioned many times i need an idea about the basic game because i don't know if my work is right and i can't imagine something else... I asked from you only some advises about the classes that i should use and some tips !!
 
Liutauras Vilda
Marshal
Posts: 4670
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christina Tzogka wrote:my project is separeted in two parts. In the first i must send only the classes and the methods without code so i should have a complete plan.
Sorry for a late reply. I hope your assignment due date isn't by the end of Monday.
Lets start by bringing some clarity into it. The problem is intepretations (these usually are wrong). Please post exact assignment requirements, then tell us what do you think, how the first part of your assignment should be looking like and we can strat from there.
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't worry, there is no problem, i have some days...
I tried to translate exactly the assignment because it is greek. Let's start with the basic game. It can be played by 1 player or a team ( i think i need a parent class Player and children Single-Team). I have also creat a class Board with the list of the cards and some methods ( you can see the code some post before ). Now i don't know how to connect Player with Board, viz how a player could start the game.
 
Liutauras Vilda
Marshal
Posts: 4670
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christina Tzogka wrote:my project is separeted in two parts. In the first i must send only the classes and the methods without code
Stop wandering. What have you got here? In which form these should be sent? *.java files or diagram?

From the previous code you posted I see you provided defined methods implementations, does that mean you submitted first part already?
 
Liutauras Vilda
Marshal
Posts: 4670
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Henry suggested, do not try to do too much in one go. Try to divide whole problem into smaller problems, then with those do the same - into subproblems.
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I told you that the project is separated in 2 parts. In first part i have to submit only a design of the game, empty classes anf methods. Then, in the second part ( in a month) i will complete the project ( code ).
I will send .java files.
No, it is only something i found in google about memory game with cards, i only add cards in list. Of course i didn't submitted the first part because all i send you are only thoughts.
 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's start with the first few sentences:
The basic game contains 2 copies of 26 different images that we place in a field( 4 lines, 13 columns).

This tells us you need images and a field. It looks like you have Card and Board, which is fine.

The game can be played by a player(count his steps-opening pairs) or by a team (when someone find a pair he playes again).

So you need a Player class and maybe a Team class. You probably need a Game class that lets a Player pick to cards and records when they're fliped and when the game ends.

Now what do you need in a Card class? You need an image, probably represented by an imageFileName field. If the imageFileNames of the two cards equal, you have a match, so you probably should override the equals() method in Card. The Card will need to know when it's flipped.

Are you getting the process here? Try to carry on and fill out what I've started.
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute thank you, you help me to creat a first plan of the project ! I want to ask about interfaces, do you think i will need them for the variations which are mentioned in the assignment ? For example : double game can be an interface or an other class maybe a child ?
 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were to use an interface, I would call it Game. I'd put all the method signatures in it, then implement SingleGame and DoubleGame from it. The idea is that SingleGame and DoubleGame are both types of Game. As such, they share a lot of behavior. That behavior is codified in the Game interface but implemented in SingleGame and DoubleGame.
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so in that way i can creat TrioQuartet,Battle( variation 8. from assignment) that also implement Game ? Also, how i could separate the person player from the player who is controlled by computer (i mentioned it in the assignment) ? I will need another class but Player ?
 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christina Tzogka wrote:Ok, so in that way i can creat TrioQuartet,Battle( variation 8. from assignment) that also implement Game ?

I would think so. The nice thing about implementing an interface is that if you use Game as the type of variable, you know that certain behavior is shared. For instance, maybe you would have a method called endGame(). You would know there is this method for all implementations, although how the game end may be different.

Also, how i could separate the person player from the player who is controlled by computer (i mentioned it in the assignment) ? I will need another class but Player ?

You could again use a Player interface and implement LivePlayer and ComputerPlayer. Now you could have a method like getMove() and it would be implemented differently for the two kinds of Player.
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've actually had a memory game project before although the features were drastically simplified compared to what it seems like you are doing. As people have hinted at, your version is a pretty involved project and its good that you have about a month. Still, the bulk of the project is actually the graphical user interface. Its difficult to display images correctly in a grid-like layout and be able to process mouseclicks in the appropriate manner. In the initial phase of just setting up how your program might work without a GUI it looks like you might be overthinking your project. Honestly a card class and a board class aren't even really necessary. All you're doing is comparing multiple cards for equivalency, the cards themselves don't really have any sort of functionality. Your board is really just an array of cards, there isn't anything the board itself does. The tricky part is later that you have to keep track of what cards are appropriately face up and face down to be displayed graphically, but you really don't need specific classes to do this, just some sort of array-like data structure. Of course its OK to have a Card and Board class if that makes it easier to conceptualize things (or its required by the assignment for some reason), but at the very least you should take some strong consideration into what methods those classes actually need (not very many, and possibly even zero). To do all this I think its better to think of adding 26 different objects to the array twice, instead of adding 52 different objects.
 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure this is the best advice for a beginner. They should learn to build and use classes as much as possible for all but the simplest programs (three or four lines). Classes are much easier to debug and maintain and once you get the hang of it, and I think they are easier to program with too.
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I'm not sure this is the best advice for a beginner. They should learn to build and use classes as much as possible for all but the simplest programs (three or four lines). Classes are much easier to debug and maintain and once you get the hang of it, and I think they are easier to program with too.


I generally agree with what you're saying, just for specifically the card and board I don't like creating classes. The project as a whole should have several other classes and give plenty of practice.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christina Tzogka wrote:Ok, so in that way i can creat TrioQuartet,Battle( variation 8. from assignment) that also implement Game ? Also, how i could separate the person player from the player who is controlled by computer (i mentioned it in the assignment) ? I will need another class but Player ?

I think you're getting a bit bogged down in the "how" already, when what you should be focusing on is the "what".

And a big hint is that they've asked you for classes and some method signatures, but no code.

Here's my tips:
  • While you're still trying to work out what you need, turn your computer OFF.
  • Get out a pack of playing cards and play the game yourself, trying to match cards by colour - ie, if you turn over the 8, it is ONLY matched by the 8, and if you turn over the 8, it is ONLY matched by the 8. That gives you 26 symbols to match, which is in line with your requirements, and will give you a feel for what actually needs to be done visually. For example, I'm not quite sure what is meant by "When we open a pair, the cards change places", so maybe you can work that out yourself.
  • Follow Henry's advice, and deal with one thing at a time - ie, put together a "basic" game first. There'll be plenty of time to deal with the other stuff later; but if THAT doesn't work, then there's no point in agonising about all the different variants.
  • You could also try a bit of lexical analysis; but to do that, you need a copy of the instructions as you were given them, and nothing else.

  • HIH

    Winston
     
    Christina Tzogka
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Guys, thank you all for your help ! Now i am focusing on the basic game, i will follow your advices !
     
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!