• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cow racing game design and planning  RSS feed

 
Ranch Hand
Posts: 291
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

i am designing a text based cow racing betting game (keeping to the them of things)

i havent started coding yet but am just trying to plan out before i get started.

here is the basic plan...

introduction

asks players name

menu driven system

1) place bet
2) see race cards (shows what races are on)
3) Have lunch (spend some of your winnings)
4) Go to the ATM (for more money)

so im planning to have a function for each section

but im battling on how i can design this to be easy to manage and add to in future etc.

i have nobody to help me and am trying to complete this exercise...for something like this am i better off using different classes etc

any feedback appreciated on what the best way is to tackle this...thanks for reading
 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry...forgot to mention...obviously there is more happening after the main menu...bet checking,adding to winnings, minus money when spent on lunch etc etc...just trying to work out what the best way is to ti it all together
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't sound like you are thinking object-oriented when approaching this.
 
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you think through this look for nouns, they tend to become classes, and look for verbs, they tend to become methods.

Possible nouns: Player, Race, Contestant, Bet.

Look for has-a relationships, e.g. a Player has money and a name, a Race has contestants. These become fields (a.k.a. instance variables).

Verb examples: a Player can add or subtract money.

Continue the process of dividing the problem into smaller and smaller pieces until you have a good idea as to how you might code it.
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon ninpoja wrote:
i havent started coding yet but am just trying to plan out before i get started...

Plus one for that!
 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i really want to start thinking OOP!!!

but layout and design are really not clear to me...

if i want a main menu...should that be in its own class...or just in the main method (yes i know everything is in a class,but should it be its own file.)
or should the whole thing be in one class and have methods control the program..like CowRacing.playerBets CowRacing.raceBegins etc etc

thanks
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, you want as little in main() as possible, which often means just one line.

See MainIsAPain (that's a link, I hope).  Nope, try this instead.

If you want to start OOP, then sure, put make a Menu class.
 
Carey Brown
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon ninpoja wrote:if i want a main menu...should that be in its own class...or just in the main method (yes i know everything is in a class,but should it be its own file.)
or should the whole thing be in one class and have methods control the program..like CowRacing.playerBets CowRacing.raceBegins etc etc

"Menu" could be designed as a class in its own file or as a subclass inside CowRacing. Seeing as your project description has been limited so far it is hard to tell. So far you only have one small menu and probably another prompt for the amount you want to bet. Because we're only talking about a small amount of code and there is no state associated with these prompts, creating a class might be overkill. I would certainly put them in their own methods so that your controlling method becomes very clear and not cluttered with the details of prompting and checking for and handling errors.


"Menu" class, or not, can be decided at a later time. Start with clear methods and if your menus and prompts become unwieldy refactor them into a Menu class.

These classes: Player, Race, Contestant, are not so ambiguous though and are fundamental to the design. The all have a state (i.e. data) associated with them and some sort of behavior (i.e. methods). By creating these as classes you are encapsulating their data and behavior. Encapsulation is a fundamental concept to OOP.

 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you guys think i should start to do things OOP or is there a right time to start doing it? i have written quite a few small programs that do different things,but none used OOP...your thoughts?
...busy reading main is a pain....very good...any java OOP material you would recommend? good stuff on this site?

thanks for the help
 
Carey Brown
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The time for OOP is now. As you progress you'll find less and less of your code is procedural, though all code has some procedural sections.

OOP: Encapsulation, Inheritance, Polymorphism.

Your OOP designs will always include encapsulation but may, or may not include inheritance or polymorphism except as provided by Java itself. You'll find your programs become much cleaner as you OOP improves with the benefits of readability, maintainability. OOP allows you to tackle bigger problems without the code getting out of control.
 
Carey Brown
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon ninpoja wrote:i have written quite a few small programs that do different things,but none used OOP...your thoughts?

You might, as an exercise, revisit those small programs and look for data/behavior/relationships that might have benefited from OOP.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon ninpoja wrote:. . . or is there a right time to start doing [OOP]? . . .
In my opinion the right time to start with OOP is about one minute before you write your first ever program
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!