From FANG
|
001 packagepackage is used to name the directory or folder a class is in scg.ch10;
002
003 importimport means to make the classes and/or packages available in this program java.util.ArrayList;
004
005 importimport means to make the classes and/or packages available in this program fang2.attributes.Location2D;
006 importimport means to make the classes and/or packages available in this program fang2.core.Game;
007 importimport means to make the classes and/or packages available in this program fang2.sprites.CompositeSprite;
008
009 /**
010 * A "picked letter board" forfor is a looping structure for repeatedly executing a block of code playing a letter guessing game. The
011 * letters are displayed in alphabetic order in 2 lines (2 10-character
012 * and 1 6-character line). Letters have two states: ready and used. The
013 * sprite supports checking ifif executes the next statement only if the condition in parenthesis evaluates to true there has been a mouse click on one of
014 * the ready letters.
015 */
016 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects AlphabetSelector
017 extendsextends means to customize or extend the functionality of a class CompositeSprite {open braces start code blocks and must be matched with a close brace
018 /** 2d layout of the letters inside thisthis means the current object (the implicit parameter) sprite */
019 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) ArrayList<ArrayList<LetterSprite>>this performs a bit-wise right shift letters;
020
021 /**
022 * Construct a newnew is used to create objects by calling the constructor alphabet selector. Make the letter layout.
023 */
024 publicpublic is used to indicate unrestricted access (any other class can have access) AlphabetSelector() {open braces start code blocks and must be matched with a close brace
025 letters =this assignment operator makes the left side equal to the right side makeLetters();
026 unselectAll();
027 }close braces end code blocks and must match an earlier open brace
028
029 /**
030 * What character was selected? If click is on a ready LetterSprite,
031 * the LetterSprite will be marked used and the letter of the sprite
032 * will be returned. Returns the nullnull is the value used to refer to a non-existant object character ifif executes the next statement only if the condition in parenthesis evaluates to true there is no ready
033 * letter selected.
034 *
035 * @returnnull the letter of the ready (now used) LetterSprite clicked on
036 * ifif executes the next statement only if the condition in parenthesis evaluates to true there was one; nullnull is the value used to refer to a non-existant object charchar is the type for a single letter or symbol and it is short for character ('\0') otherwise
037 */
038 publicpublic is used to indicate unrestricted access (any other class can have access) charchar is the type for a single letter or symbol and it is short for character selectedChar() {open braces start code blocks and must be matched with a close brace
039 charchar is the type for a single letter or symbol and it is short for character letter =this assignment operator makes the left side equal to the right side '\0';
040 Location2D outsideClick =this assignment operator makes the left side equal to the right side Game.getCurrentGame().getClick2D();
041 ifif executes the next statement only if the condition in parenthesis evaluates to true (outsideClick !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
042 Location2D insideClick =this assignment operator makes the left side equal to the right side getFrameLocation(outsideClick);
043 LetterSprite letterSprite =this assignment operator makes the left side equal to the right side selectedChar(insideClick);
044 ifif executes the next statement only if the condition in parenthesis evaluates to true (letterSprite !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
045 letterSprite.startUsed();
046 letter =this assignment operator makes the left side equal to the right side letterSprite.getLetter();
047 }close braces end code blocks and must match an earlier open brace
048 }close braces end code blocks and must match an earlier open brace
049 returnreturn means to provide the result of the method and/or cease execution of the method immediately letter;
050 }close braces end code blocks and must match an earlier open brace
051
052 /**
053 * Reset all letter sprites to their ready state; reset the selection
054 * board.
055 */
056 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value unselectAll() {open braces start code blocks and must be matched with a close brace
057 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer row =this assignment operator makes the left side equal to the right side 0; row !=this is the not equals operator which evaluates to true if both sides are different letters.size(); ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
058 ArrayList<LetterSprite> currRow =this assignment operator makes the left side equal to the right side letters.get(row);
059 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer column =this assignment operator makes the left side equal to the right side 0; column !=this is the not equals operator which evaluates to true if both sides are different currRow.size(); ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
060 LetterSprite curr =this assignment operator makes the left side equal to the right side currRow.get(column);
061 curr.startReady();
062 }close braces end code blocks and must match an earlier open brace
063 }close braces end code blocks and must match an earlier open brace
064 }close braces end code blocks and must match an earlier open brace
065
066 /**
067 * Construct the array of LetterSprites. The array of LetterSprites is
068 * scaled to fit across a width of 1.0 (-0.5 to 0.5).
069 *
070 * @returnnull the newly created list of lists of LetterSprites.
071 */
072 privateprivate is used to restrict access to the current class only ArrayList<ArrayList<LetterSprite>>this performs a bit-wise right shift makeLetters() {open braces start code blocks and must be matched with a close brace
073 finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions letterScale =this assignment operator makes the left side equal to the right side 1.0 / (10/*letters*/ +adds two numbers together or concatenates Strings together 9/*spaces*/);
074 ArrayList<ArrayList<LetterSprite>>this performs a bit-wise right shift theLetters =this assignment operator makes the left side equal to the right side
075 newnew is used to create objects by calling the constructor ArrayList<ArrayList<LetterSprite>>this performs a bit-wise right shift();
076 charchar is the type for a single letter or symbol and it is short for character letter =this assignment operator makes the left side equal to the right side 'a';
077 doubledouble is the type for numbers that can contain decimal fractions rowY =this assignment operator makes the left side equal to the right side -2 * letterScale;
078 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer row =this assignment operator makes the left side equal to the right side 0; row !=this is the not equals operator which evaluates to true if both sides are different 3; ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
079 intint is the type for whole numbers and it is short for integer lettersInRow =this assignment operator makes the left side equal to the right side 10;
080 ifif executes the next statement only if the condition in parenthesis evaluates to true (row ==this is the comparison operator which evaluates to true if both sides are the same 2) {open braces start code blocks and must be matched with a close brace
081 lettersInRow =this assignment operator makes the left side equal to the right side 6;
082 }close braces end code blocks and must match an earlier open brace
083 ArrayList<LetterSprite> currRow =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ArrayList<LetterSprite>();
084 doubledouble is the type for numbers that can contain decimal fractions columnX =this assignment operator makes the left side equal to the right side 0 -
085 ((letterScale * (lettersInRow +adds two numbers together or concatenates Strings together lettersInRow - 1)) / 2.0);
086 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer column =this assignment operator makes the left side equal to the right side 0; column !=this is the not equals operator which evaluates to true if both sides are different lettersInRow; ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
087 LetterSprite curr =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor LetterSprite(letter);
088 curr.setWidth(letterScale);
089 curr.leftJustify();
090 curr.setLocation(columnX, rowY);
091 addSprite(curr);
092
093 currRow.add(curr);
094 columnX +=this increases the variable on the left by the value on the right 2 * letterScale;
095 ++this is the increment operator, which increases the variable by 1letter;// lowercase letters are adjacent
096 }close braces end code blocks and must match an earlier open brace
097 theLetters.add(currRow);
098 rowY +=this increases the variable on the left by the value on the right 2 * letterScale;
099 }close braces end code blocks and must match an earlier open brace
100 returnreturn means to provide the result of the method and/or cease execution of the method immediately theLetters;
101 }close braces end code blocks and must match an earlier open brace
102
103 /**
104 * What LetterSprite (ifif executes the next statement only if the condition in parenthesis evaluates to true any) does the given click location intersect?
105 * Returns the LetterSprite clicked on ifif executes the next statement only if the condition in parenthesis evaluates to true it is ready. If no sprite is
106 * clicked on or the clicked LetterSprite is already used, returns
107 * nullnull is the value used to refer to a non-existant object.
108 *
109 * @paramthis is the Javadoc tag for documenting the purpose of parameters insideClick mouse click in sprite coordinates.
110 *
111 * @returnnull the ready LetterSprite intersecting the click ifif executes the next statement only if the condition in parenthesis evaluates to true there is
112 * one; nullnull is the value used to refer to a non-existant object otherwise
113 */
114 privateprivate is used to restrict access to the current class only LetterSprite selectedChar(Location2D insideClick) {open braces start code blocks and must be matched with a close brace
115 LetterSprite selected =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
116 ifif executes the next statement only if the condition in parenthesis evaluates to true (insideClick !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
117 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer row =this assignment operator makes the left side equal to the right side 0; row !=this is the not equals operator which evaluates to true if both sides are different letters.size(); ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
118 ArrayList<LetterSprite> currRow =this assignment operator makes the left side equal to the right side letters.get(row);
119 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer column =this assignment operator makes the left side equal to the right side 0; column !=this is the not equals operator which evaluates to true if both sides are different currRow.size(); ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
120 LetterSprite curr =this assignment operator makes the left side equal to the right side currRow.get(column);
121 ifif executes the next statement only if the condition in parenthesis evaluates to true (curr.intersects(insideClick) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) curr.isReady()) {open braces start code blocks and must be matched with a close brace
122 selected =this assignment operator makes the left side equal to the right side curr;
123 }close braces end code blocks and must match an earlier open brace
124 }close braces end code blocks and must match an earlier open brace
125 }close braces end code blocks and must match an earlier open brace
126 }close braces end code blocks and must match an earlier open brace
127 returnreturn means to provide the result of the method and/or cease execution of the method immediately selected;
128 }close braces end code blocks and must match an earlier open brace
129 }close braces end code blocks and must match an earlier open brace
130
131 //Uploaded on Mon Mar 29 21:38:51 EDT 2010
|
Download/View scg/ch10/AlphabetSelector.java