CVS: TapestryBook/hangman1/src/hangman1 Win.java,NONE,1.1 Game.java,1.1,1.2 Visit.java,1.1,1.2 Guess.java,1.2,1.3 Lose.java,1.2,1.3
Howard Lewis Ship <[email protected]>
| Newsgroups | gmane.comp.java.tapestry.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tapestry/TapestryBook/hangman1/src/hangman1
In directory sc8-pr-cvs1:/tmp/cvs-serv2685/hangman1/src/hangman1
Modified Files:
Game.java Visit.java Guess.java Lose.java
Added Files:
Win.java
Log Message:
Add in Win page.
--- NEW FILE: Win.java ---
package hangman1;
import net.sf.tapestry.IAsset;
import net.sf.tapestry.IRequestCycle;
import net.sf.tapestry.html.BasePage;
/**
*
* Page displayed when the user wins ... succesfully guesses
* all the letters in the word.
*
* @author Howard Lewis Ship
* @version $Id: Win.java,v 1.1 2003/01/14 16:44:39 hship Exp $
*
**/
public class Win extends BasePage
{
private char _letter;
/**
* This method must return the page back to its pristine state.
*
**/
public void initialize()
{
_letter = 0;
}
public char getLetter()
{
return _letter;
}
public void setLetter(char letter)
{
_letter = letter;
}
public IAsset getDigitImage(int digit)
{
return getAsset("digit" + digit);
}
public IAsset getScaffoldImage(int missesLeft)
{
return getAsset("scaffold" + missesLeft);
}
public String getLetterLabel()
{
char upper = Character.toUpperCase(_letter);
return new Character(upper).toString();
}
public IAsset getLetterImage()
{
if (_letter == '_')
return getAsset("dash");
return getAsset(new Character(_letter).toString());
}
/**
* Listener method; invokes {@link hangman1.Visit#startGame(IRequestCycle)}.
*
**/
public void playAgain(IRequestCycle cycle)
{
Visit visit = (Visit) getVisit();
visit.startGame(cycle);
}
}
Index: Game.java
===================================================================
RCS file: /cvsroot/tapestry/TapestryBook/hangman1/src/hangman1/Game.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Game.java 13 Jan 2003 19:02:30 -0000 1.1
--- Game.java 14 Jan 2003 16:44:43 -0000 1.2
***************
*** 29,34 ****
/**
! * Indicates which letters the user has already guessed. 'A' is at position 0,
! * 'B' at position 1, and so on, up to 'Z' at position 25.
*
**/
--- 29,34 ----
/**
! * Indicates which letters the user has already guessed. 'A' is at index 0,
! * 'B' at index 1, and so on, up to 'Z' at index 25.
*
**/
***************
*** 38,42 ****
/**
* Set to true when the user succesfully guesses the word
! * (a slots in the letters are filled in).
*
**/
--- 38,42 ----
/**
* Set to true when the user succesfully guesses the word
! * (all slots in the letters are filled in).
*
**/
***************
*** 108,112 ****
_letters = new char[count];
! for (int i = 0; i < _letters.length; i++)
_letters[i] = '_';
--- 108,112 ----
_letters = new char[count];
! for (int i = 0; i < count; i++)
_letters[i] = '_';
***************
*** 121,125 ****
* a failure occurs; when enough failures occur, there's a loss.
*
! * @returns true if further guesses are allowed (this guess did not result in a win or a loss),
* or false if further guesses are not allowed (the user guessed the word, or used up
* all possible failures).
--- 121,125 ----
* a failure occurs; when enough failures occur, there's a loss.
*
! * @return true if further guesses are allowed (this guess did not result in a win or a loss),
* or false if further guesses are not allowed (the user guessed the word, or used up
* all possible failures).
***************
*** 187,190 ****
--- 187,195 ----
return true;
+ }
+
+ public String getTargetWord()
+ {
+ return _targetWord;
}
}
Index: Visit.java
===================================================================
RCS file: /cvsroot/tapestry/TapestryBook/hangman1/src/hangman1/Visit.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Visit.java 13 Jan 2003 19:02:27 -0000 1.1
--- Visit.java 14 Jan 2003 16:44:43 -0000 1.2
***************
*** 27,31 ****
// On the other hand, the Game is specifically for this
! // Visit.
if (_game == null)
--- 27,31 ----
// On the other hand, the Game is specifically for this
! // Visit and only this Visit.
if (_game == null)
Index: Guess.java
===================================================================
RCS file: /cvsroot/tapestry/TapestryBook/hangman1/src/hangman1/Guess.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Guess.java 14 Jan 2003 12:56:24 -0000 1.2
--- Guess.java 14 Jan 2003 16:44:44 -0000 1.3
***************
*** 46,59 ****
}
! public IAsset getFailureImage(int failureCount)
{
! return getAsset("digit" + failureCount);
}
! public IAsset getScaffoldImage(int failureCount)
{
! return getAsset("scaffold" + failureCount);
}
public String getLetterLabel()
{
--- 46,78 ----
}
! /**
! * Returns the asset for an image corresponding
! * to the number.
! *
! **/
!
! public IAsset getDigitImage(int digit)
{
! return getAsset("digit" + digit);
}
! /**
! * Returns an asset for an image used to present the
! * scaffold, showing the indicating number
! * of remaining misses.
! *
! **/
!
! public IAsset getScaffoldImage(int missesLeft)
{
! return getAsset("scaffold" + missesLeft);
}
+ /**
+ * The {@link Game} stores the letters of the target word as lower case,
+ * but the UI looks better if the labels on the images are in upper case.
+ *
+ **/
+
public String getLetterLabel()
{
***************
*** 63,66 ****
--- 82,91 ----
}
+ /**
+ * Returns the image for the current letter (which may be an underscore
+ * as well).
+ *
+ **/
+
public IAsset getLetterImage()
{
***************
*** 125,129 ****
* Returns the letter corresponding to the
* current {@link #getGuessIndex() guess index}
! * as a letter between 'a' and 'z'.
*
**/
--- 150,154 ----
* Returns the letter corresponding to the
* current {@link #getGuessIndex() guess index}
! * as a letter between 'a' and 'z'.
*
**/
***************
*** 158,165 ****
--- 183,195 ----
public void makeGuess(IRequestCycle cycle)
{
+ // Java wraps the char as an instance of Character
+
Character guess = (Character) cycle.getServiceParameters()[0];
char ch = guess.charValue();
+ // Get the Visit and cast it to our application-specific
+ // class.
+
Visit visit = (Visit) getVisit();
Index: Lose.java
===================================================================
RCS file: /cvsroot/tapestry/TapestryBook/hangman1/src/hangman1/Lose.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Lose.java 14 Jan 2003 12:56:24 -0000 1.2
--- Lose.java 14 Jan 2003 16:44:46 -0000 1.3
***************
*** 47,50 ****
--- 47,55 ----
}
+ /**
+ * Listener method; invokes {@link hangman1.Visit#startGame(IRequestCycle)}.
+ *
+ **/
+
public void playAgain(IRequestCycle cycle)
{
-------------------------------------------------------
This SF.NET email is sponsored by: FREE SSL Guide from Thawte
are you planning your Web Server Security? Click here to get a FREE
Thawte SSL guide and find the answers to all your SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en