org.jboss.as.quickstarts.numberguess
Class Game

java.lang.Object
  extended by org.jboss.as.quickstarts.numberguess.Game
All Implemented Interfaces:
Serializable

@Named
@SessionScoped
public class Game
extends Object
implements Serializable

Game contains all the business logic for the application, and also serves as the controller for the JSF view.

It contains properties for the number to be guessed, the current guess, the smallest and biggest numbers guessed so far (as this is a higher/lower game we can prevent them entering numbers that they should know are wrong), and the number of remainingGuesses.

The check() method, and reset() methods provide the business logic whilst the validateNumberRange(FacesContext, UIComponent, Object) method provides feedback to the user.

Author:
Pete Muir
See Also:
Serialized Form

Constructor Summary
Game()
           
 
Method Summary
 void check()
          Check whether the current guess is correct, and update the biggest/smallest guesses as needed.
 int getBiggest()
           
 int getGuess()
           
 int getNumber()
           
 int getRemainingGuesses()
           
 int getSmallest()
           
 void reset()
          Reset the game, by putting all values back to their defaults, and getting a new random number.
 void setGuess(int guess)
           
 void validateNumberRange(javax.faces.context.FacesContext context, javax.faces.component.UIComponent toValidate, Object value)
          A JSF validation method which checks whether the guess is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Game

public Game()
Method Detail

getNumber

public int getNumber()

getGuess

public int getGuess()

setGuess

public void setGuess(int guess)

getSmallest

public int getSmallest()

getBiggest

public int getBiggest()

getRemainingGuesses

public int getRemainingGuesses()

check

public void check()
Check whether the current guess is correct, and update the biggest/smallest guesses as needed. Give feedback to the user if they are correct.


reset

@PostConstruct
public void reset()
Reset the game, by putting all values back to their defaults, and getting a new random number. We also call this method when the user starts playing for the first time using @PostConstruct to set the initial values.


validateNumberRange

public void validateNumberRange(javax.faces.context.FacesContext context,
                                javax.faces.component.UIComponent toValidate,
                                Object value)
A JSF validation method which checks whether the guess is valid. It might not be valid because there are no guesses left, or because the guess is not in range.



Copyright © 2011. All Rights Reserved.