CVS: Tapestry/examples/Tutorial/src/tutorial/hangman Visit.java,1.6,1.6.2.1 HangmanGame.java,1.6.2.1,1.6.2.2 Guess.java,1.12,1.12.2.1 Home.java,1.10,1.10.2.1 Failed.page,1.5,NONE Guess.html,1.2,NONE Home.html,1.2,NONE Hangman.application,1.8,NONE Failed.html,1.2,NONE Success.page,1.5,NONE Guess.page,1.5,NONE Home.page,1.4,NONE Success.html,1.2,NONE

Howard Lewis Ship <[email protected]>
Newsgroups gmane.comp.java.tapestry.cvs
Message-ID <[email protected]>
Update of /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/hangman
In directory sc8-pr-cvs1:/tmp/cvs-serv10583/examples/Tutorial/src/tutorial/hangman

Modified Files:
      Tag: hship-2-3
	Visit.java HangmanGame.java Guess.java Home.java 
Removed Files:
      Tag: hship-2-3
	Failed.page Guess.html Home.html Hangman.application 
	Failed.html Success.page Guess.page Home.page Success.html 
Log Message:
Reorganize the tutorials to use new 2.4 features.

Index: Visit.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/hangman/Visit.java,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -C2 -d -r1.6 -r1.6.2.1
*** Visit.java	27 Nov 2002 17:58:51 -0000	1.6
--- Visit.java	2 Jan 2003 03:15:29 -0000	1.6.2.1
***************
*** 35,48 ****
              "universe" };
  
!     private List wordList;
  
!     private HangmanGame game;
  
      public HangmanGame getGame()
      {
!         if (game == null)
!             game = new HangmanGame();
  
!         return game;
      }
  
--- 35,48 ----
              "universe" };
  
!     private List _wordList;
  
!     private HangmanGame _game;
  
      public HangmanGame getGame()
      {
!         if (_game == null)
!             _game = new HangmanGame();
  
!         return _game;
      }
  
***************
*** 59,66 ****
      private String getWord()
      {
!         if (wordList == null)
!             wordList = new ArrayList();
  
!         if (wordList.size() == 0)
          {
              // Create a list of words that the user will see and shuffle them
--- 59,66 ----
      private String getWord()
      {
!         if (_wordList == null)
!             _wordList = new ArrayList();
  
!         if (_wordList.size() == 0)
          {
              // Create a list of words that the user will see and shuffle them
***************
*** 68,78 ****
              // user has seen them all.
  
!             wordList.addAll(Arrays.asList(words));
!             Collections.shuffle(wordList);
          }
  
          // Remove the last word in the list.
  
!         return (String) wordList.remove(wordList.size() - 1);
      }
  }
--- 68,78 ----
              // user has seen them all.
  
!             _wordList.addAll(Arrays.asList(words));
!             Collections.shuffle(_wordList);
          }
  
          // Remove the last word in the list.
  
!         return (String) _wordList.remove(_wordList.size() - 1);
      }
  }

Index: HangmanGame.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/hangman/HangmanGame.java,v
retrieving revision 1.6.2.1
retrieving revision 1.6.2.2
diff -C2 -d -r1.6.2.1 -r1.6.2.2
*** HangmanGame.java	4 Dec 2002 03:32:05 -0000	1.6.2.1
--- HangmanGame.java	2 Jan 2003 03:15:29 -0000	1.6.2.2
***************
*** 14,156 ****
  public class HangmanGame implements Serializable
  {
! 	private char[] word;
! 	private char[] guessed;
! 	private boolean[] used;
! 	private int lettersLeft;
  
! 	private int missed;
! 	private int maxMisses;
  
! 	private static final int N_LETTERS = 26;
  
! 	/**
! 	 *  Starts a new game, resetting the number of misses.
! 	 *
! 	 **/
  
! 	public void start(String word, int maxMisses)
! 	{
! 		this.word = word.toUpperCase().toCharArray();
  
! 		guessed = new char[this.word.length];
! 		for (int i = 0; i < this.word.length; i++)
! 			guessed[i] = '_';
  
! 		if (used == null)
! 			used = new boolean[N_LETTERS];
  
! 		for (int i = 0; i < N_LETTERS; i++)
! 			used[i] = false;
  
! 		lettersLeft = this.word.length;
! 		missed = 0;
! 		this.maxMisses = maxMisses;
! 	}
  
! 	/**
! 	 *  Returns true when the maximum number of misses has been reached.
! 	 *
! 	 **/
  
! 	public boolean getFailed()
! 	{
! 		return missed >= maxMisses;
! 	}
  
! 	/**
! 	 *  Returns true when all letters have been guessed.
! 	 *
! 	 **/
  
! 	public boolean getDone()
! 	{
! 		return lettersLeft == 0;
! 	}
  
! 	/**
! 	 *  Returns an array of characters, each position is either a correctly guessed
! 	 *  letter, or an underscore (for an as-yet unguessed letter).
! 	 *
! 	 **/
  
! 	public char[] getGuessed()
! 	{
! 		return guessed;
! 	}
  
! 	/**
! 	 *  Returns the word being guessed.
! 	 *
! 	 **/
  
! 	public String getWord()
! 	{
! 		return new String(word);
! 	}
  
! 	/**
! 	 *  Guesses a letter.  Returns the number of letters left to guess.
! 	 *
! 	 *  @param letter a single letter, in the range 'A' to 'Z'.
! 	 *
! 	 *  @throws GameException if the letter doesn't appear
! 	 *  in the word.
! 	 *
! 	 **/
  
! 	public void guess(char letter) throws GameException
! 	{
! 		boolean found = false;
  
! 		used[letter - 'A'] = true;
  
! 		for (int i = 0; i < word.length; i++)
! 		{
! 			if (word[i] == letter)
! 			{
! 				found = true;
! 				// Replace the underscore with the actual letter
! 				guessed[i] = letter;
! 				lettersLeft--;
! 			}
! 		}
  
! 		if (!found)
! 		{
! 			missed++;
! 			throw new GameException("'" + letter + "' is not in the word.");
! 		}
! 	}
  
! 	/**
! 	 *  Returns an array of unused letters that may be guessed.
! 	 *
! 	 **/
  
! 	public char[] getUnusedLetters()
! 	{
! 		char[] buffer = new char[N_LETTERS];
! 		int length = 0;
  
! 		for (char letter = 'A'; letter <= 'Z'; letter++)
! 		{
! 			if (!used[letter - 'A'])
! 				buffer[length++] = letter;
! 		}
  
! 		char[] result = new char[length];
! 		System.arraycopy(buffer, 0, result, 0, length);
  
! 		return result;
! 	}
  
! 	public int getMissed()
! 	{
! 		return missed;
! 	}
  
! 	public int getMaxMisses()
! 	{
! 		return maxMisses;
! 	}
  }
--- 14,156 ----
  public class HangmanGame implements Serializable
  {
!     private char[] _word;
!     private char[] _guessed;
!     private boolean[] _used;
!     private int _lettersLeft;
  
!     private int _missed;
!     private int _maxMisses;
  
!     private static final int N_LETTERS = 26;
  
!     /**
!      *  Starts a new game, resetting the number of misses.
!      *
!      **/
  
!     public void start(String word, int maxMisses)
!     {
!         _word = word.toUpperCase().toCharArray();
  
!         _guessed = new char[_word.length];
!         for (int i = 0; i < _word.length; i++)
!             _guessed[i] = '_';
  
!         if (_used == null)
!             _used = new boolean[N_LETTERS];
  
!         for (int i = 0; i < N_LETTERS; i++)
!             _used[i] = false;
  
!         _lettersLeft = _word.length;
!         _missed = 0;
!         _maxMisses = maxMisses;
!     }
  
!     /**
!      *  Returns true when the maximum number of misses has been reached.
!      *
!      **/
  
!     public boolean getFailed()
!     {
!         return _missed >= _maxMisses;
!     }
  
!     /**
!      *  Returns true when all letters have been guessed.
!      *
!      **/
  
!     public boolean getDone()
!     {
!         return _lettersLeft == 0;
!     }
  
!     /**
!      *  Returns an array of characters, each position is either a correctly guessed
!      *  letter, or an underscore (for an as-yet unguessed letter).
!      *
!      **/
  
!     public char[] getGuessed()
!     {
!         return _guessed;
!     }
  
!     /**
!      *  Returns the word being guessed.
!      *
!      **/
  
!     public String getWord()
!     {
!         return new String(_word);
!     }
  
!     /**
!      *  Guesses a letter.  Returns the number of letters left to guess.
!      *
!      *  @param letter a single letter, in the range 'A' to 'Z'.
!      *
!      *  @throws GameException if the letter doesn't appear
!      *  in the word.
!      *
!      **/
  
!     public void guess(char letter) throws GameException
!     {
!         boolean found = false;
  
!         _used[letter - 'A'] = true;
  
!         for (int i = 0; i < _word.length; i++)
!         {
!             if (_word[i] == letter)
!             {
!                 found = true;
!                 // Replace the underscore with the actual letter
!                 _guessed[i] = letter;
!                 _lettersLeft--;
!             }
!         }
  
!         if (!found)
!         {
!             _missed++;
!             throw new GameException("'" + letter + "' is not in the word.");
!         }
!     }
  
!     /**
!      *  Returns an array of unused letters that may be guessed.
!      *
!      **/
  
!     public char[] getUnusedLetters()
!     {
!         char[] buffer = new char[N_LETTERS];
!         int length = 0;
  
!         for (char letter = 'A'; letter <= 'Z'; letter++)
!         {
!             if (!_used[letter - 'A'])
!                 buffer[length++] = letter;
!         }
  
!         char[] result = new char[length];
!         System.arraycopy(buffer, 0, result, 0, length);
  
!         return result;
!     }
  
!     public int getMissed()
!     {
!         return _missed;
!     }
  
!     public int getMaxMisses()
!     {
!         return _maxMisses;
!     }
  }

Index: Guess.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/hangman/Guess.java,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -C2 -d -r1.12 -r1.12.2.1
*** Guess.java	27 Nov 2002 17:58:51 -0000	1.12
--- Guess.java	2 Jan 2003 03:15:29 -0000	1.12.2.1
***************
*** 16,33 ****
  public class Guess extends BasePage
  {
!     private HangmanGame game;
!     private String error;
  
!     public void detach()
      {
!         game = null;
!         error = null;
! 
!         super.detach();
      }
  
      public String getError()
      {
!         return error;
      }
  
--- 16,31 ----
  public class Guess extends BasePage
  {
!     private HangmanGame _game;
!     private String _error;
  
!     public void initialize()
      {
!         _game = null;
!         _error = null;
      }
  
      public String getError()
      {
!         return _error;
      }
  
***************
*** 35,40 ****
      {
          Object[] parameters = cycle.getServiceParameters();
!         char letter = ((Character)parameters[0]).charValue();
!         
          HangmanGame game = getGame();
  
--- 33,38 ----
      {
          Object[] parameters = cycle.getServiceParameters();
!         char letter = ((Character) parameters[0]).charValue();
! 
          HangmanGame game = getGame();
  
***************
*** 45,49 ****
          catch (GameException ex)
          {
!             error = ex.getMessage();
  
              if (game.getFailed())
--- 43,47 ----
          catch (GameException ex)
          {
!             _error = ex.getMessage();
  
              if (game.getFailed())
***************
*** 68,77 ****
      public String getGuessed()
      {
!         StringBuffer buffer;
!         char[] guessed;
! 
!         guessed = getGame().getGuessed();
  
!         buffer = new StringBuffer(2 * guessed.length);
          for (int i = 0; i < guessed.length; i++)
          {
--- 66,72 ----
      public String getGuessed()
      {
!         char[] guessed = getGame().getGuessed();
  
!         StringBuffer buffer = new StringBuffer(2 * guessed.length);
          for (int i = 0; i < guessed.length; i++)
          {
***************
*** 92,102 ****
      private HangmanGame getGame()
      {
!         if (game == null)
          {
              Visit visit = (Visit) getVisit();
!             game = visit.getGame();
          }
  
!         return game;
      }
  
--- 87,97 ----
      private HangmanGame getGame()
      {
!         if (_game == null)
          {
              Visit visit = (Visit) getVisit();
!             _game = visit.getGame();
          }
  
!         return _game;
      }
  

Index: Home.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/hangman/Home.java,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -C2 -d -r1.10 -r1.10.2.1
*** Home.java	27 Nov 2002 17:58:51 -0000	1.10
--- Home.java	2 Jan 2003 03:15:30 -0000	1.10.2.1
***************
*** 20,56 ****
      public static final int HARD = 3;
  
!     private int misses;
!     private String error;
  
!     public void detach()
      {
!         misses = 0;
!         error = null;
! 
!         super.detach();
      }
  
      public int getMisses()
      {
!         return misses;
      }
  
!     public void setMisses(int value)
      {
!         misses = value;
  
!         fireObservedChange("misses", value);
      }
  
      public String getError()
      {
!         return error;
      }
  
      public void formSubmit(IRequestCycle cycle)
      {
!         if (misses == 0)
          {
!             error = "Please select a game difficulty.";
              return;
          }
--- 20,54 ----
      public static final int HARD = 3;
  
!     private int _misses;
!     private String _error;
  
!     public void initialize()
      {
!         _misses = 0;
!         _error = null;
      }
  
      public int getMisses()
      {
!         return _misses;
      }
  
!     public void setMisses(int misses)
      {
!         _misses = misses;
  
!         fireObservedChange("misses", misses);
      }
  
      public String getError()
      {
!         return _error;
      }
  
      public void formSubmit(IRequestCycle cycle)
      {
!         if (_misses == 0)
          {
!             _error = "Please select a game difficulty.";
              return;
          }
***************
*** 58,62 ****
          Visit visit = (Visit) getVisit();
  
!         visit.start(misses);
  
          cycle.setPage("Guess");
--- 56,60 ----
          Visit visit = (Visit) getVisit();
  
!         visit.start(_misses);
  
          cycle.setPage("Guess");

--- Failed.page DELETED ---

--- Guess.html DELETED ---

--- Home.html DELETED ---

--- Hangman.application DELETED ---

--- Failed.html DELETED ---

--- Success.page DELETED ---

--- Guess.page DELETED ---

--- Home.page DELETED ---

--- Success.html DELETED ---



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.