This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

How do I play again as the same 'player'?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I currently have a Player class private instances, getters, and setters as well as a game class.

For the game, I ask the player for their name. It is saved in the object class. Every player has a $500 balance.
The game is called 21 of Dice and basically, it is like Blackjack in a sense that if you happen to beat the dealer (or computer) you win $100 and if you lose or tie, you lose $50.

When I play the game each time, it is creating a new player. I want it to be possible that I want to play as the same player with the updated balance. Any help would be greatly appreciated.

Here is my Player class:





Here is my Game class:


 
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of calling your play21method from your playAgainmethod, call your playAgainmethod from your play21Method, make it return a boolean and put your playmethod, except for the playercreation in a do whileloop that calls the playAgainmethod, when the player presses y it reurns true and otherwise false
 
Master Rancher
Posts: 3733
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you post the code that you are executing?
How do you execute the program?

I don't see where the playGame method is called.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to Illustrate:

 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic