Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.textflex.txtfl
Class Txtfl  view Txtfl download Txtfl.java

java.lang.Object
  extended bycom.textflex.txtfl.Txtfl
All Implemented Interfaces:
java.lang.Runnable

public class Txtfl
extends java.lang.Object
implements java.lang.Runnable

The central tXtFL class. Starts, perpetuates, and closes the game. The game start calls the teams, sets up the number of players, and hands over control to the game model. The game model solicits user play choices, generates computer moves, and creates the random component of each play's results. After perpetuating plays until the clock runs out, the game model transfers control to the end game, which displays and writes game, season, and team statistics.


Field Summary
static java.lang.String ABOUT
           
static java.lang.String BACK
           
static java.lang.String BLOCKED
           
private static java.net.Socket client
           
private static int colWidth
           
static java.lang.String COMPLETE
           
private  DrivePlay currDrivePlay
           
private  java.lang.String defender
           
private  java.lang.String deliverer
           
private  int deliveryDist
           
private static org.eclipse.swt.widgets.Display disp
           
private  int down
           
private static org.eclipse.swt.widgets.Combo driveCombo
           
private  int drivePlayIndex
           
private  DrivePlay[][] drives
           
private  int drivesIndex
           
static java.lang.String END_GAME
           
static java.lang.String EXTRA_POINT
           
static java.lang.String FIELD_GOAL
           
static java.lang.String FUMBLE
           
static java.lang.String FUMBLE_RECOVERY
           
private static int genericIndex
           
static java.lang.String GOOD
           
private static boolean graphics
           
private static org.eclipse.swt.widgets.Text histDisp
           
static java.lang.String INCOMPLETE
           
private  boolean inPlay
           
private static InputRetriever input
           
private static org.eclipse.swt.widgets.Label inputLbl
           
private static boolean inputReturned
           
private static java.lang.String inputText
           
static java.lang.String INTERCEPTION
           
private static java.lang.String introText
           
private static boolean isCurrentDriveSelected
           
static java.lang.String KICK_OFF
           
static java.lang.String KICK_OFF_DROPKICK
           
private static java.io.BufferedReader netIn
           
private static java.io.PrintWriter netOut
           
private static boolean networking
           
static java.lang.String NEW_GAME
           
private  boolean newDrive
           
private static boolean newGame
           
private  boolean nextPlayNewDrive
           
static java.lang.String NO_GOOD
           
private  java.text.NumberFormat numFormat
           
static java.lang.String OPTIONS
           
private  java.lang.String[] optionsChoices
           
private  boolean overtime
           
static java.lang.String PASS
           
static java.lang.String PASS_RUSH
           
static java.lang.String PAT
           
private  java.lang.String[] playCategories
           
static java.lang.String PLAYS
           
private  java.lang.String playType
           
private  java.lang.String playTypeSpecific
           
static java.lang.String PUNT
           
private  int quarter
           
static java.lang.String QUIT
           
private  java.lang.String recipient
           
private  int recipientDist
           
static java.lang.String RESTORE_GAME
           
private  boolean restoredGame
           
static java.lang.String RETURN
           
static java.lang.String ROSTER
           
static java.lang.String RUSH
           
static java.lang.String SACK
           
static java.lang.String SAFETY
           
static java.lang.String SAFETY_KICK
           
static java.lang.String SAFETY_KICK_DROPKICK
           
static java.lang.String SAFETY_KICK_PLACEKICK
           
static java.lang.String SAFETY_KICK_PUNT
           
static java.lang.String SAVE_GAME
           
private static java.net.ServerSocket server
           
static java.lang.String STATS
           
private static java.io.BufferedReader sysIn
           
private static Team teamA
           
private static Team teamB
           
private static org.eclipse.swt.widgets.Text textDisp
           
private static org.eclipse.swt.widgets.Text textRead
           
static java.lang.String THE_DEFENSE
           
static java.lang.String THE_GOAL_POSTS
           
private static java.lang.Thread thread
           
private  int time
           
static java.lang.String TURNOVER_ON_DOWNS
           
static java.lang.String TWO_POINT_CONVERSION_PASS
           
static java.lang.String TWO_POINT_CONVERSION_RUSH
           
private  boolean twoPlayer
           
private  int yardline
           
private  int ydsToGo
           
 
Constructor Summary
Txtfl()
          Constructs the central tXtFL class.
 
Method Summary
 void about(Team team)
          Display information about tXtFL as a program.
static void addComboEntry(java.lang.String entry, org.eclipse.swt.widgets.Combo combo, boolean select)
          Adds an entry to a combo box.
 void addDrivePlay(DrivePlay drivePlay, boolean newDrive)
          Adds a play to the array of drives and their plays.
static void appendToTextDisp(java.lang.String dispTxt, org.eclipse.swt.widgets.Text dispArea)
          Appends text to the display output text area.
 int autoPlayCategory(Team team)
          Probabilistically choose the appropriate play category.
 int blockingFumble(Play[] play, int blocking)
          Front-end for fumbles behind the line of scrimmage during normal, non-try plays.
 int blockingFumble(Play[] play, int blocking, boolean tryAttempt)
          Front-end for fumbles behind the line of scrimmage, fumbles that the defensive line usually causes.
 boolean checkFumble(Play play, int dist)
          Checks if the play results in a fumble.
 Play[] choosePlay()
          Solicits play calls according to the number of users and whether each user is presently on offense or defense.
 void cleanUp()
          Cleans up system resources before exiting.
 void coinToss()
          Allows selection of the coin toss and determination of which team receives the kickoff first.
 void coinTossKickoff()
           
 void createDisplay()
          Creates the SWT Graphical User Interface display.
 void drivePlayHistDisp()
           
 double dropkickDist(Play play, int protection, int intendedDist)
          Handles place kicking distances.
 void endGame()
          Closes the game.
 void endGame(boolean premature)
          Closes the game.
 boolean fairCatch()
          Selects fair catch choice.
 void fieldGoalPlay(Play[] play)
          Kicks a field goal attempt Handles the yards, time, down, and yards to go changes.
 void finalStats()
          Determines the winner and displays the final game statistics.
 void firstDown()
          Handles first downs.
 int fumble(Play[] play, int dist)
          Front-end to general fumbles, as opposed to those during try attempts.
 int fumble(Play[] play, int dist, boolean tryAttempt)
          Handles fumbles.
 boolean gameRestorer()
          Restores a saved game from the selected file.
 void gameSaver()
           
 boolean gameSelection()
           
static java.lang.String getChoice(java.io.BufferedReader stdin)
          Front-end for getting a choice from the human user via the command line or input text area.
static java.lang.String getChoice(java.io.BufferedReader stdin, java.io.PrintWriter stdout)
          Gets a choice from the human user via the command line or input text area.
static int getChoiceOrRandom(java.io.BufferedReader stdin, int range)
          Front-end for getting a numerical choice from the human user via the command line or input text area, with the option of having the computer choose randomly.
static int getChoiceOrRandom(java.io.BufferedReader stdin, int range, int rdmRange)
          Front-end for getting a numerical choice from the human user via the command line or input text area, with the option of having the computer choose randomly.
static int getChoiceOrRandom(java.io.BufferedReader stdin, java.io.PrintWriter stdout, int range)
          Front-end for getting a numerical choice from the human user via the command line or input text area, with the option of having the computer choose randomly.
static int getChoiceOrRandom(java.io.BufferedReader stdin, java.io.PrintWriter stdout, int range, int rdmRange)
          Gets a numerical choice from the human user via the command line or input text area, with the option of having the computer choose randomly.
static int getChoiceOrRandomExclude(java.io.BufferedReader stdin, int range, int exclude)
          Front-end for getting numerical choice from human input via command-line or input text area, or choosing randomly at the user's discretion, while excluding a given value, such as an already selected number.
static int getChoiceOrRandomExclude(java.io.BufferedReader stdin, java.io.PrintWriter stdout, int range, int exclude)
          Gets a numerical choice from the human user via the command line input area, or chooses randomly at the user's discretion, while excluding a given value, such as an already selected number.
static int getChoiceOverRange(java.io.BufferedReader stdin, int range)
          Front-end for getting a choice within a given numberical range from the human user via the command line or input text area.
static int getChoiceOverRange(java.io.BufferedReader stdin, java.io.PrintWriter stdout, int range)
          Gets a numerical choice within a give numberical range from the human user via the command line or input text area.
static int getChoiceOverRangeOrBlank(java.io.BufferedReader stdin, int range)
          Front-end for getting a choice within a given numerical range or an empty response from the human user via the command line or input text area.
static int getChoiceOverRangeOrBlank(java.io.BufferedReader stdin, java.io.PrintWriter stdout, int range)
          Gets a numerical choice within a given range or an empty response from the human user via the command line or input text area.
static int getComboCount(org.eclipse.swt.widgets.Combo combo)
          Retrieves the number of entries in the given combo box.
static int getComboIndex(org.eclipse.swt.widgets.Combo combo)
          Retrieves the selected index from the combo box.
 Team getDefense()
          Gets the team currently on defense.
 java.io.File getDirFromBase(java.lang.String dir)
          Gets a directory in Txtfl's base directory.
 boolean getGraphics()
          Gets the graphics setting
static java.lang.String getInput(java.io.BufferedReader stdin)
           
static java.lang.String getInput(java.io.BufferedReader stdin, java.io.PrintWriter stdout)
          Retrieves input from the user via either the command-line or the graphical input text area.
 java.io.BufferedReader getInputStream(Team team)
          Gets the appropriate input stream for the given team.
 int getNumberChoice(java.lang.String[] options, java.lang.String request, Team team)
          Solicits the user to choose a number from a given list.
 int getNumberChoice(java.lang.String[] options, java.lang.String request, Team team, boolean newLine)
          Solicits the user to choose a number from a given list.
 Team getOffense()
          Gets the team currently on offense.
 java.io.PrintWriter getOutputStream(Team team)
          Gets the appropriate output stream for the given team.
 java.lang.String[] getPlayCategories()
          Gets the current play categories list.
 int getPlayCategoryIndex(java.lang.String category)
          Gets the index of the given play category.
 java.lang.String getStringChoice(java.lang.String question, java.lang.String[] answers, boolean ignoreDefault, java.io.BufferedReader stdin)
          Solicits responses to string-based questions, such as 'y' or 'n' rather than numerical choices from a list.
 java.lang.String getStringChoice(java.lang.String question, java.lang.String[] answers, boolean ignoreDefault, java.io.BufferedReader stdin, java.io.PrintWriter stdout)
          Solicits responses to string-based questions, such as 'y' or 'n' rather than numerical choices from a list.
static java.io.BufferedReader getSysIn()
          Get the default input stream
static java.lang.String getTextDisp(org.eclipse.swt.widgets.Text dispArea)
          Retrieves the text from the text input area.
 void incompletion()
          Handles incomplete passes.
 int intOrFumble(Play[] play, int dist)
          Calculates yard changes in the return after an interception or fumble.
static void ioBugHandler(java.io.IOException e)
          Display I/O error information and show where to report it.
static boolean isNetworkTeam(Team team)
          Check if the team is the client machine's team.
 boolean isSide(java.lang.String s)
          Checks if play is by the sideline.
 double kick(Play play)
          Handles kickoffs kicks.
 void kickoffDropkickPlay(Play[] play)
          Kicks off the football through the dropkick technique.
 void kickoffPlay(Play[] play)
          Kicks off the football from a tee.
 double kickWidth(Play play, int protection, double goalPostDist, double intendedDist)
          Handles side-to-side distance in place kicks.
static void main(java.lang.String[] args)
          Creates a Txtfl intance, starting the football simulator.
 void networkSetup()
           
 void options(java.lang.String option, Team team)
          Front-end for the options.
 java.lang.String optionsChoice(Team team)
          Selects the game option.
 int pass(Play[] play, int block)
          Handles passes.
 int passGenerator(Play[] play)
          Front-end for general passes, as opposed to those during conversion attempts or otherwise.
 int passGenerator(Play[] play, boolean tryAttempt)
          Applies the pass.
 void passPlay(Play[] play)
          Passes the football and handles the yards, time, down, and yards to go changes.
 int passRush(Play[] play)
          Generates the pass rush value difference.
 void patPlay(Play[] play)
          Handles point-after-touchdowns (PAT) kicks.
 double placekickDist(Play play, int protection, int intendedDist)
          Handles place kicking distances.
 int placekickRush(Play[] play)
          Handles place kick rushing on the line.
 void play(Play[] play)
          Front-end for the football action.
 java.lang.String playCategory(boolean auto, Team team)
          Selects the appropriate play category.
 Play playChoice(java.lang.String category, Team team, boolean auto)
          Selects a play.
 void playerMode()
          Allows the user to select the number of users and networking options.
 boolean playFourthDown()
          Determines whether the computer will choose to punt or play on fourth down.
 void playGame()
          The game model.
 void plays(Team team)
          Presents and accepts the play options.
static void print(java.lang.String dispTxt)
           
static void printDirected(java.lang.String dispTxt, java.lang.String altToNet, java.lang.String altToLocal, Team team, boolean question)
          Prints alternative text to the local and networked displays.
 int printList(java.lang.String[] items, int col, int width)
          Prints a list of items in the given number of columns, with the given minimum characters per column.
 int printList(java.lang.String[] items, int col, int width, Team team)
          Prints a list of items in the given number of columns, with the given minimum characters per column.
static void println(java.lang.String dispTxt)
           
static void printlnLocal(java.lang.String dispTxt)
          Prints a new line of output on the local, non-networked display.
static void printlnLocalQuestion(java.lang.String dispTxt)
          Prints a new line of output on the local, non-networked display, including both the command-line and the graphical input label, if available.
static void printlnToInputer(java.lang.String dispTxt, java.io.PrintWriter stdout)
           
static void printlnToInputer(java.lang.String dispTxt, Team team)
           
static void printLocal(java.lang.String dispTxt)
          Prints output on the local, non-networked display, on the current line.
static void printLocalQuestion(java.lang.String dispTxt)
          Prints output on the local, non-networked display, including both the command-line's current line and the graphical input label, if available.
static void printQuestion(java.lang.String dispTxt)
          Prints output to both the local displays, including the graphical input label, and network displays.
static void printToInputer(java.lang.String dispTxt, java.io.PrintWriter stdout)
           
static void printToInputer(java.lang.String dispTxt, Team team)
           
static void printToInputLabel(java.lang.String dispTxt)
          Replaces the input label's text.
 double[] punt(Play play, int protection)
          Handles punt distances and hange time.
 int puntGenerator(Play[] play, double[] punt, int runDist)
          Applies the punt play.
 void puntPlay(Play[] play)
          Punts the football.
 int puntProtection(Play[] play)
          Handles punts protection and rushing.
 void quarterAdvance()
          Handles advances of the game quarter.
 void quit()
          Quits the game after double-checking with the user.
static java.lang.String read(java.io.BufferedReader in)
          Reads from an input buffer.
 int returnGenerator(Play[] play, double runDist)
          Applies return yardage, such as the distance punt returners cover after receiving the ball.
 void roster(Team team)
          Presents and accepts the roster options.
 void run()
          Runs tXtFL's thread, the game loop.
 int run(Play[] play)
          Handles rushes.
 int runAfterCatch(Play[] play)
          Handles the run-after-the-catch in pass plays.
 int runAfterKickoff(Play[] play)
          Handles kick returns.
 int runAfterPunt(Play[] play, double dist, double hang)
          Handles the punt return.
 int runGenerator(Play[] play)
          Front-end for general rush plays, as opposed to those during conversion attempts or otherwise.
 int runGenerator(Play[] play, boolean tryAttempt)
          Applies the running play.
 void runPlay(Play[] play)
          Rushes the football for an "on-the-ground," non-pass offensive play.
 int sack(int blocking)
          Handles sacks.
 void safety()
          Handles safeties.
 void safetyKickDropkickPlay(Play[] play)
          Dropkicks the ball after safeties.
 void safetyKickPlacekickPlay(Play[] play)
          Placekicks the ball after safeties.
 void safetyKickPuntPlay(Play[] play)
          Punts the ball after safeties.
 void setAdjustedYdsToGo(int yards)
          Adjusts first down yards-to-go to account for positions 10 yards or fewer from the opponent's endzone.
 void setPlayCategories(java.lang.String category)
          Sets the categories for the given play type.
 void setPlayType(java.lang.String category)
          Sets the currently chosen play category.
static void setTextDisp(java.lang.String dispTxt, org.eclipse.swt.widgets.Text dispArea)
          Sets the text in the text input area.
static void sleep(int millis)
          Temporarily halts the thread.
 void startGame()
           
 void stats(Team team)
           
 void swapPossession()
          Switches ball possession from the current offense to the current defense.
 void teamSelection()
          Allows the user to select the teams.
 int timeBetweenPlays(Play[] play, boolean pass, int totDist)
          Generates the time between plays.
 void touchdown()
          Handles touchdowns.
 boolean tryFieldGoal()
          Determines whether the computer selects punt or field goal.
 boolean tryPass(int down)
          Determine whether to pass or run the ball.
 boolean tryTwoPoint()
          Determines whether the computer attempts an extra point or an extra two points.
 void turnoverOnDowns()
          Handles loss of possession from exceeding four downs.
 void twoPointPassPlay(Play[] play)
          Handles 2-point pass attempts after touchdowns Includes the opportunity to score from a safetying the defense.
 void twoPointRunPlay(Play[] play)
          Handles 2-point run attempts after touchdowns Includes the opportunity to score from a safetying the defense.
 void updateGameStats(int timeChange)
          Refreshes the game statistics, calling functions to check for touchdowns, first downs, turnover on downs, and quarter changes, including overtime.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCOMPLETE

public static final java.lang.String INCOMPLETE
See Also:
Constant Field Values

COMPLETE

public static final java.lang.String COMPLETE
See Also:
Constant Field Values

INTERCEPTION

public static final java.lang.String INTERCEPTION
See Also:
Constant Field Values

FUMBLE

public static final java.lang.String FUMBLE
See Also:
Constant Field Values

FUMBLE_RECOVERY

public static final java.lang.String FUMBLE_RECOVERY
See Also:
Constant Field Values

RUSH

public static final java.lang.String RUSH
See Also:
Constant Field Values

PUNT

public static final java.lang.String PUNT
See Also:
Constant Field Values

SACK

public static final java.lang.String SACK
See Also:
Constant Field Values

PASS

public static final java.lang.String PASS
See Also:
Constant Field Values

BLOCKED

public static final java.lang.String BLOCKED
See Also:
Constant Field Values

RETURN

public static final java.lang.String RETURN
See Also:
Constant Field Values

TURNOVER_ON_DOWNS

public static final java.lang.String TURNOVER_ON_DOWNS
See Also:
Constant Field Values

GOOD

public static final java.lang.String GOOD
See Also:
Constant Field Values

NO_GOOD

public static final java.lang.String NO_GOOD
See Also:
Constant Field Values

THE_DEFENSE

public static final java.lang.String THE_DEFENSE
See Also:
Constant Field Values

THE_GOAL_POSTS

public static final java.lang.String THE_GOAL_POSTS
See Also:
Constant Field Values

SAFETY

public static final java.lang.String SAFETY
See Also:
Constant Field Values

SAFETY_KICK

public static final java.lang.String SAFETY_KICK
See Also:
Constant Field Values

SAFETY_KICK_PUNT

public static final java.lang.String SAFETY_KICK_PUNT
See Also:
Constant Field Values

SAFETY_KICK_PLACEKICK

public static final java.lang.String SAFETY_KICK_PLACEKICK
See Also:
Constant Field Values

SAFETY_KICK_DROPKICK

public static final java.lang.String SAFETY_KICK_DROPKICK
See Also:
Constant Field Values

KICK_OFF

public static final java.lang.String KICK_OFF
See Also:
Constant Field Values

KICK_OFF_DROPKICK

public static final java.lang.String KICK_OFF_DROPKICK
See Also:
Constant Field Values

FIELD_GOAL

public static final java.lang.String FIELD_GOAL
See Also:
Constant Field Values

TWO_POINT_CONVERSION_PASS

public static final java.lang.String TWO_POINT_CONVERSION_PASS
See Also:
Constant Field Values

TWO_POINT_CONVERSION_RUSH

public static final java.lang.String TWO_POINT_CONVERSION_RUSH
See Also:
Constant Field Values

PAT

public static final java.lang.String PAT
See Also:
Constant Field Values

OPTIONS

public static final java.lang.String OPTIONS
See Also:
Constant Field Values

PASS_RUSH

public static final java.lang.String PASS_RUSH
See Also:
Constant Field Values

STATS

public static final java.lang.String STATS
See Also:
Constant Field Values

ROSTER

public static final java.lang.String ROSTER
See Also:
Constant Field Values

NEW_GAME

public static final java.lang.String NEW_GAME
See Also:
Constant Field Values

SAVE_GAME

public static final java.lang.String SAVE_GAME
See Also:
Constant Field Values

RESTORE_GAME

public static final java.lang.String RESTORE_GAME
See Also:
Constant Field Values

ABOUT

public static final java.lang.String ABOUT
See Also:
Constant Field Values

END_GAME

public static final java.lang.String END_GAME
See Also:
Constant Field Values

QUIT

public static final java.lang.String QUIT
See Also:
Constant Field Values

BACK

public static final java.lang.String BACK
See Also:
Constant Field Values

PLAYS

public static final java.lang.String PLAYS
See Also:
Constant Field Values

EXTRA_POINT

public static final java.lang.String EXTRA_POINT
See Also:
Constant Field Values

teamA

private static Team teamA

teamB

private static Team teamB

twoPlayer

private boolean twoPlayer

networking

private static boolean networking

playCategories

private java.lang.String[] playCategories

optionsChoices

private java.lang.String[] optionsChoices

inPlay

private boolean inPlay

newGame

private static boolean newGame

introText

private static java.lang.String introText

quarter

private int quarter

time

private int time

down

private int down

ydsToGo

private int ydsToGo

yardline

private int yardline

playType

private java.lang.String playType

numFormat

private java.text.NumberFormat numFormat

overtime

private boolean overtime

restoredGame

private boolean restoredGame

colWidth

private static int colWidth

sysIn

private static java.io.BufferedReader sysIn

netOut

private static java.io.PrintWriter netOut

netIn

private static java.io.BufferedReader netIn

server

private static java.net.ServerSocket server

client

private static java.net.Socket client

graphics

private static boolean graphics

thread

private static java.lang.Thread thread

input

private static InputRetriever input

disp

private static org.eclipse.swt.widgets.Display disp

textDisp

private static org.eclipse.swt.widgets.Text textDisp

histDisp

private static org.eclipse.swt.widgets.Text histDisp

inputLbl

private static org.eclipse.swt.widgets.Label inputLbl

textRead

private static org.eclipse.swt.widgets.Text textRead