My number guessing game has two users. They both get one guess at a random number per round until one gets it right. At the end, it has to show their wrong answers and how many guesses it took them. Heres what I have so far
But I'm completely lost now. How do I get the answer to save as player 1's guess? And then how would I make it so its player 2's turn? Where do I go from here to get my end result basically. Any help appreciated
Games are basically state machines, there are many phases that have to complete in the game as the game is played, not just player 1 through player k's turn, but as you are encountering saving data, checking for wins, and etc. You need an object that can hold the guesses. How many players and how many guesses--you don't know. So you need to make something that will hold an undefined number of records of an undefined number of players.
Look at collections for data stores, simply put: you need a collection of collections. I like ArrayLists, that is a personal preference, but look through the API and see what you want to use.
The other problem of keeping track, I would suggest looking at state machines and write the process on paper to see how many states you have to implement.
BTW: each turn could be a state, but if you treat it as such, you have the problem of a varying number of states, look at having each turn broken into states, and then over a loop to keep track of the player (state of which turn). So you have a 2 dimensional state system.
Game programming rarely, if ever, has structure or progresses in linear fashion.
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Welcome to the Ranch
You are right to use a Random object, but I think you are using the wrong version of nextInt.
Never use == false or == true. They are poor style and error‑prone.
if (b == true) ... but
if (b) ... Not
if (b == false) ... but
if (!b) ...
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking