Win a copy of Java XML & JSON this week in the XML and Related Technologies 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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

 
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:


 
Master Rancher
Posts: 1043
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • 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
 
Rancher
Posts: 3353
33
  • 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
Master Rancher
Posts: 1043
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to Illustrate:

 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!