From FANG
|
001 packagepackage is used to name the directory or folder a class is in scg.ch14.gamestuff;
002
003 importimport means to make the classes and/or packages available in this program java.util.Scanner;
004
005 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 Item
006 extendsextends means to customize or extend the functionality of a class GameObject {open braces start code blocks and must be matched with a close brace
007 /**
008 * Read one item from the given scanner
009 *
010 * @paramthis is the Javadoc tag for documenting the purpose of parameters gameObjectScanner scanner open forfor is a looping structure for repeatedly executing a block of code input
011 *
012 * @returnnull the newnew is used to create objects by calling the constructor Item or nullnull is the value used to refer to a non-existant object ifif executes the next statement only if the condition in parenthesis evaluates to true there is a problem
013 */
014 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) Item readObjectFromFile(Scanner gameObjectScanner) {open braces start code blocks and must be matched with a close brace
015 String classID =this assignment operator makes the left side equal to the right side gameObjectScanner.next();
016 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to trueclassID.equalsIgnoreCase("Item")) {open braces start code blocks and must be matched with a close brace
017 returnreturn means to provide the result of the method and/or cease execution of the method immediately nullnull is the value used to refer to a non-existant object;// not the expected type of object; punt
018 }close braces end code blocks and must match an earlier open brace
019
020 String endClassID =this assignment operator makes the left side equal to the right side "/" +adds two numbers together or concatenates Strings together classID;
021
022 Item it =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Item();
023 GameObject.processAttributes(gameObjectScanner, endClassID, it);
024 returnreturn means to provide the result of the method and/or cease execution of the method immediately it;
025 }close braces end code blocks and must match an earlier open brace
026
027 /** how much does thisthis means the current object (the implicit parameter) item hurt critters susceptible to it? */
028 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer attackStrength;
029
030 /** Description added to owner's description */
031 privateprivate is used to restrict access to the current class only String ownedDescription;
032
033 /** object to which thisthis means the current object (the implicit parameter) item belongs */
034 privateprivate is used to restrict access to the current class only GameObject owner;
035
036 /**
037 * the uuid of the owner of thisthis means the current object (the implicit parameter) item; the item is either in a
038 * Location or on a Critter
039 */
040 privateprivate is used to restrict access to the current class only String ownerID;
041
042
043 /**
044 * Initialize the item.
045 */
046 publicpublic is used to indicate unrestricted access (any other class can have access) Item() {open braces start code blocks and must be matched with a close brace
047 attackStrength =this assignment operator makes the left side equal to the right side 0;
048 ownedDescription =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
049 }close braces end code blocks and must match an earlier open brace
050
051 /**
052 * Get the current attack strength of thisthis means the current object (the implicit parameter) item.
053 *
054 * @returnnull attack strength
055 */
056 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getAttackStrength() {open braces start code blocks and must be matched with a close brace
057 returnreturn means to provide the result of the method and/or cease execution of the method immediately attackStrength;
058 }close braces end code blocks and must match an earlier open brace
059
060 /**
061 * @returnnull the ownedDescription
062 */
063 publicpublic is used to indicate unrestricted access (any other class can have access) String getOwnedDescription() {open braces start code blocks and must be matched with a close brace
064 returnreturn means to provide the result of the method and/or cease execution of the method immediately ownedDescription;
065 }close braces end code blocks and must match an earlier open brace
066
067 /**
068 * @returnnull the owner
069 */
070 publicpublic is used to indicate unrestricted access (any other class can have access) GameObject getOwner() {open braces start code blocks and must be matched with a close brace
071 returnreturn means to provide the result of the method and/or cease execution of the method immediately owner;
072 }close braces end code blocks and must match an earlier open brace
073
074 /**
075 * Get the UUID of the current owner of thisthis means the current object (the implicit parameter) item.
076 *
077 * @returnnull the UUID of the owner
078 */
079 publicpublic is used to indicate unrestricted access (any other class can have access) String getOwnerID() {open braces start code blocks and must be matched with a close brace
080 ifif executes the next statement only if the condition in parenthesis evaluates to true (owner !=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
081 returnreturn means to provide the result of the method and/or cease execution of the method immediately owner.getUUID();
082 }close braces end code blocks and must match an earlier open brace
083 returnreturn means to provide the result of the method and/or cease execution of the method immediately ownerID;
084 }close braces end code blocks and must match an earlier open brace
085
086 /**
087 * set the owner of thisthis means the current object (the implicit parameter) item
088 */
089 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value give(GameObject owner) {open braces start code blocks and must be matched with a close brace
090 thisthis means the current object (the implicit parameter).owner =this assignment operator makes the left side equal to the right side owner;
091 }close braces end code blocks and must match an earlier open brace
092
093 /**
094 * Set the attackStrength.
095 *
096 * @paramthis is the Javadoc tag for documenting the purpose of parameters attackStrength newnew is used to create objects by calling the constructor attackStrength value
097 */
098 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setAttackStrength(intint is the type for whole numbers and it is short for integer attackStrength) {open braces start code blocks and must be matched with a close brace
099 thisthis means the current object (the implicit parameter).attackStrength =this assignment operator makes the left side equal to the right side attackStrength;
100 }close braces end code blocks and must match an earlier open brace
101
102 /**
103 * @paramthis is the Javadoc tag for documenting the purpose of parameters ownedDescription the ownedDescription to set
104 */
105 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setOwnedDescription(String ownedDescription) {open braces start code blocks and must be matched with a close brace
106 thisthis means the current object (the implicit parameter).ownedDescription =this assignment operator makes the left side equal to the right side ownedDescription;
107 }close braces end code blocks and must match an earlier open brace
108
109 /**
110 * @paramthis is the Javadoc tag for documenting the purpose of parameters owner the owner to set
111 */
112 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setOwner(GameObject owner) {open braces start code blocks and must be matched with a close brace
113 thisthis means the current object (the implicit parameter).owner =this assignment operator makes the left side equal to the right side owner;
114 }close braces end code blocks and must match an earlier open brace
115
116 /**
117 * Handle, ifif executes the next statement only if the condition in parenthesis evaluates to true possible, the given name/value pair
118 *
119 * @paramthis is the Javadoc tag for documenting the purpose of parameters attribute name of the attribute
120 * @paramthis is the Javadoc tag for documenting the purpose of parameters value the value of the attribute
121 *
122 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true the attribute was handled at thisthis means the current object (the implicit parameter) level; falsefalse is a value for the boolean type and means not true
123 * otherwise.
124 */
125 @Override
126 protectedprotected is used to restrict access to the current class and subclasses only booleanboolean is a type that is either true or false handleAttributeValuePair(String attribute,
127 String value) {open braces start code blocks and must be matched with a close brace
128 ifif executes the next statement only if the condition in parenthesis evaluates to true (super.handleAttributeValuePair(attribute, value)) {open braces start code blocks and must be matched with a close brace
129 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
130 }close braces end code blocks and must match an earlier open brace
131
132 ifif executes the next statement only if the condition in parenthesis evaluates to true (attribute.equalsIgnoreCase("owner")) {open braces start code blocks and must be matched with a close brace
133 ownerID =this assignment operator makes the left side equal to the right side value.toLowerCase();
134 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
135 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (attribute.equalsIgnoreCase("ownedDescription")) {open braces start code blocks and must be matched with a close brace
136 setOwnedDescription(value);
137 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
138 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (attribute.equalsIgnoreCase("attackStrength")) {open braces start code blocks and must be matched with a close brace
139 setAttackStrength(Integer.parseInt(value));
140 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
141 }close braces end code blocks and must match an earlier open brace
142
143 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
144 }close braces end code blocks and must match an earlier open brace
145
146 /**
147 * Internal toString helper method.
148 *
149 * @returnnull A string representation of the fields.
150 */
151 @Override
152 protectedprotected is used to restrict access to the current class and subclasses only String toStringGuts() {open braces start code blocks and must be matched with a close brace
153 returnreturn means to provide the result of the method and/or cease execution of the method immediately super.toStringGuts() +adds two numbers together or concatenates Strings together "\n" +adds two numbers together or concatenates Strings together "ownerID = " +adds two numbers together or concatenates Strings together getOwnerID() +adds two numbers together or concatenates Strings together
154 "\n" +adds two numbers together or concatenates Strings together "attackStrength = " +adds two numbers together or concatenates Strings together attackStrength +adds two numbers together or concatenates Strings together "\n";
155 }close braces end code blocks and must match an earlier open brace
156 }close braces end code blocks and must match an earlier open brace
157
158 //Uploaded on Mon Mar 29 21:41:43 EDT 2010
|
Download/View scg/ch14/gamestuff/Item.java