View Single Post
Old 02-17-2013, 09:31 PM   PM User | #12
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You're still doing a bit too much work. You're letting the guess decide if it should flip each character, when this operation has already been done with the initialization of the word. All you need to do is flip it if it matches:
PHP Code:
}else if(source == guess){
            
boolean bGuessMatched false;
            
char[] currentWord this.wordField.getText().toCharArray();
            
char guessChar guessField.getText().charAt(0);
                       
            for (
int i 0actualWord.length(); ++i)
            {
                if (
actualWord.charAt(i) == guessChar)
                {
                    
currentWord[i] = actualWord.charAt(i);
                    
bGuessMatched true;
                }
            }
            if (!
bGuessMatched)
            {
                --
this.newErrorCount;
                
this.errorField.setText(this.newErrorCount "");
            }
            
            
this.wordField.setText(new String(currentWord));            
        } 
Like that. If you want to insensitively compare, you can do so by using the static Character class methods .toUpperCase or .toLowerCase on each of the chars during comparison. That way 'T' and 't' will both match 'T' and 't'.
After this, you just need to deal with the win / lose functionality based on the error counter.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
kyledkatz (02-17-2013)