Wheel of Fortune

Hi I've developed a game similar to wheel of fortune but is stuck with a piece of code ....can some point me to the right direction. What I need is to stop the player once he/she has press all the letters that spell out the word. This is the algorithm when the user presses the letter button.

for (int i = 0; i < 26; i++)

{

if (str.equals(alphab))

{

disableButtons();

btnSpin.setEnabled(true);

btnGuess.setEnabled(true);

btnBuy.setEnabled(true);

++ButSelected;

But[ButSelected]=i;

alphaButton.setEnabled(false);

// CheckLetter(alphab, (char)(65+i));

CheckLetter(""+(char)(65+i),(char)(65+i));

if (missedLetters>=8)

{

disableButtons();

lbl5.setVisible(true);

//btnNewGame.setEnabled(true);

}

[842 byte] By [LowRida] at [2007-9-27 16:07:37]
# 1
I am sorry I need more information before I can help you. What is happening in your prog? I need the code for all the methods being called.
Virum at 2007-7-6 0:26:19 > top of Java-index,Other Topics,Java Game Development...
# 2
Can we see how it works so far (wab page applet?)
shishthemoomin at 2007-7-6 0:26:19 > top of Java-index,Other Topics,Java Game Development...
# 3

It's not clear what your code snippet is doing or how the game works, but I've certainly watched many an episode of Wheel of Fortune, so here are some tips that may be useful. (Everything presented here should be simple, just to communicate the general ideas. It is by no means an exhaustive treatment of the subject.)

In Wheel of Fortune, the game can end when all letters have been filled in. Two methods to check this include:

METHOD 1: Set up an array (or bit vector) where each element corresponds to a letter of the answer. For example:

boolean answer[];

answer = new boolean[5];

for (int x=0; x<5; x++) {

answer[x] = false;

}

This could be used for five-letter answers, like "paper" or "bring". Every time a letter is turned over (revealed), change its answer[] element to true. When all letters have been revealed, the player wins.

int count = 0;

for (int x=0; x<5; x++) {

if (answer[x]) {

count++;

}

}

if (count == 5) {

// player has won

}

METHOD 2: If there are only 26 letters that can be used in an answer, track which letters are hidden in the answer. The player wins when all letters are revealed.

boolean hidden[];

hidden = new boolean[26];

for (int x=0; x<26; x++) {

hidden[x] = false; // by default, nothing is hidden

}

/* Now set hidden[y] to true, where y is a letter used

* in the answer. For example, if then answer is "attic", and

* a=0, t=19, i=8, c=2, then hidden[0]=true, hidden[19]=true,

* hidden[8]=true, and hidden[2]=true.

* When a letter is guessed, set its corresponding hidden element to

* false. The player wins when all hidden elements are false. (Meaning

* that there are no more letters that can be guessed and revealed.)

*/

Again, all the above code is simple, but I hope it communicates a couple methods you can use to determine whether a player has won a round in a Wheel of Fortune style game.

tsphillips at 2007-7-6 0:26:19 > top of Java-index,Other Topics,Java Game Development...
# 4

The problem there is that it involves looping over an array either 26 or the size of the answer characters long. With the second scheme, you might use a HashSet containing Character objects; you could remove a Character when it is picked, and the player wins when the Set is empty; or you could be even more efficient and use an int--at 32 bits, it's plently large to hold 26 booleans, whereas the java boolean probably ends up being at least a halfword. (Plus the object overhead for the array.) This way you could flip the appropriate bit when a user picks a letter, and when the int is 0, the player wins.

Dorceon at 2007-7-6 0:26:19 > top of Java-index,Other Topics,Java Game Development...
# 5
Judging from the initial post, I felt that optimisations would just cloud the issue.Tom
tsphillips at 2007-7-6 0:26:19 > top of Java-index,Other Topics,Java Game Development...