It would be hard to obscure the hands from the other player so he might need to have a key that, when held, would show one player's hand, and another to show the other player's hand, etc. The machine should be good at "shuffling" the deck, tracking a discard pile, what's in each player's hand, etc. We could also pit two computer players against each other a la WarGames.Ī card game for two humans might be decent. We had to make a computer player that would never lose, so it was a bit more involved. Making it for 2 human players is quite easy. In a college course we programmed tic-tac-toe in Java, but allowed for a computer player. It could be multiplayer with different keys used to select each choice per player. You can spice it up with point values that decrease with time to respond/incorrect guesses. If((new String(word)).equals(new String(star))) ("You're out!!! The word is Not_Matched\n") ("Found " foundCount " matches for " test) ("Sorry, didn't find any matches for " test) Temp = testChar //Update the temp array from * to the correct character While((foundPos = secretWord.indexOf(testChar, foundPos 1)) != -1) Int foundCount = 0 //How many matches did we find Int len = secretWord.length() //Store the length which will be used to see if puzzle was solved.Ĭhar temp = new char //Store a temp array which will be displayed to the user Initialize the characters to * and when a match is found, using, reveal the found characters: String secretWord = userInput.next() Store a array of characters that is the same length as the secret word. NewDisplaySecret = displaySecret.charAt(i) //old stateĭisplaySecret = new String(newDisplaySecret) ĭamn I was sure there was some kind of setCharAt(int) method. NewDisplaySecret = secret.charAt(i) //newly guessed character now position contains the index of guess inside secret, or Feel free to ask further questions in the comments!ĮDIT: Some more help String secret = "example-text" įor (int i = 0 i < secret.length() i ) I think from that you'll find the solution easily. The other method can replace the character at a given position inside a string with another character. ![]() And since you don't accept duplicate letters, that'll also be the only occurrence.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |