[SOLVED] algorithm Scheme game Java graph software Go COMP1022P Assignment:

$25

File Name: algorithm_Scheme_game_Java_graph_software_Go_COMP1022P_Assignment:.zip
File Size: 621.72 KB

5/5 - (1 vote)

COMP1022P Assignment:
Resources
Starting project
Sample demo program (no source code)
Demo procedures (will be posted here; please refresh this webpage after its release)

Mastermind
Submission method Frequently asked questions
Please check the sample demo program and FAQ first before you ask for clarifications. For fairness, we also wont debug or fix your coding problems for anyone as explained in FAQ.
Introduction

You are going to complete a classic board game called Mastermind in this assignment. Some background information about the game may be found here if you are interested in that. While there are different variations of the game, you will need to follow exactly what is described in this assignment description for this assignment.
There are 2 parts of this game. You are only required to finish the part 1 and submit it before the part 1 deadline on or before 11:59:00am, Nov 9th (Saturday morning), and then demonstrate your work during your lab section on Nov 12th 15th (you must go to the lab section to which you are officially enrolled). For part 2, the submission deadline is 11:59:00am, Nov 23th (Saturday morning), and the demonstration shall be done during your lab section on Nov 26th 29th. Demonstration is required for getting your assignment score after you submit your work to Canvas. No demo make-up will be arranged unless you have received prior email approval from Wallace or your instructor, or you are absent due to a justified reason (e.g. sick leave, with a medical certificate as the proof).
The demo procedure for each part will be posted on this page a day after the deadlines, i.e.,
Part 1 demo procedure will be posted here sometime on Nov10th (Sunday) afternoon. Part 2 demo procedure will be posted here sometime on Nov24th (Sunday) afternoon.
You are required to study and practice the demo procedure before you attend your demo session to make sure you know how to demo your work properly and smoothly. Your demo time is limited. Procedure will be posted and announced before the demo sessions.
After you have finished Part 1, you are advised to start Part 2 as soon as you can. Due to the packed schedule, no postponement of the deadlines is possible, so please start early.
The board
A mastermind game board looks like this at the beginning:

The top row is reserved for the special characters which will be introduced later.
special characters
( Block ojects)
The left 73 region is the play area where any of the 4 peg objects (i.e. the Wombat, Dolphin, Pig, and Elephant objects) can be placed by the user to guess the secret. 734peg objects
( Wombat Dolphin Pig Elephant objects)
The right 73 region is the balloon area where a judge would put balloons (i.e. the YellowBalloon and OrangeBalloon objects) to indicate how
correct the user guess is. 73(YellowBalloonOrange Ballon ojects)
There are 3 judges, and a naughty guy sitting at the top-left on the top-row brown blocks. From left to right, they are the Judge, the NiceJudge,
FriendJudge, and the NaughtyGuy. 3JudgeNiceJudgeFriendJudgeNaugthyGuy
The secret

When the game starts (i.e. when the Mastermind world is being constructed), a secret will be chosen randomly. The secret is a string that represents the peg sequence that the user has to guess. The secret string always consists of exactly 3 lowercase characters, and each character represents a peg at the corresponding position. w represents a wombat peg, d represents a dolphin peg, p represents a pig peg, and e represents an elephant peg. For example,
Just below it, there are two areas that are separated by the brown blocks (i.e. the Block objects) in the middle.
wde represents
(Mastermind World) 3peg w Wombatd Dolphinp Pige Elephant ,wde
Guessing the secret
The user can guess the secret by placing pegs to the play area. It is illustrated as follows.

Create a new peg object (any of the 4):
e.g. right click on Pig and choose new Pig()
Place it to the play area:

What it looks like after completing the guess (3 pegs in a row) that represents pdw:
pdw(3):

Judging the guess
After placing the pegs to the play area, any of the 3 judges can be asked to judge the guess and provide feedback with balloons.
In the following illustration, we will continue with our last example where the user guessed pdw. Also, assume the random secret is wde. Right-click on the first judge (Judge) and choose void judgeRow(int row) of Judge:
3 pdw wde(judge)void judgeRow(int row):

On the dialog that just appears, input the row number that you want the judge to look at. Notice that the row number starts from 1 as the row 0 is used by the judges and the naughty guy. That is, the first row in the play area is row 1, and the last row in the play area is row 7. After inputting the row number, click OK.
10 17 OK
Then, the judge result will be shown on the same row in the balloon area. The judge result is 1 orange balloon as there is only one correctly guessed peg (the dolphin peg in the 2nd position). Different judges have different judging criteria. Those different criteria will be explained in another section.
1( d)

Testing the static methods
You will complete many static methods. To test them, you may call them from the menu that can be invoked by right-clicking on the corresponding class item on the right.

Part 1 requirements
Download the starting project, and complete the implementation of following methods:
In the MastermindWorld class:
public static void initialize()
public static void generateSecret() public static void clearBalloons(int row) public static void clearAllBalloons()
In the Judge class:
public void judgeRow(int row) public void judgeCurrentRow() public void judgeAllRows()
Read the detailed descriptions of those methods here. You are welcome to add new methods and variables if you think they would be helpful. Part 2 requirements
Continue with the finished work you did in part 1, and complete the implementation of following methods:
In the MastermindWorld class:
public static void saveGame() throws Exception public static void loadGame() throws Exception public static void showScore()
public static int calculateRowScore(int row) public static int calculateMaxScore()
public static void updateHighscores() throws Exception (optional bonus part; see here for explanation) In the NiceJudge class:
public void judgeRow(int row) In the FriendJudge class:
public void judgeRow(int row) In the NaughtyGuy class:
public void cheat() public void superCheat()

Read the detailed descriptions of those methods here. You are welcome to add new methods and class properties if you think they would be helpful.
Submission
For each part, you must zip your whole mastermind assignment folder and submit the zip file only. For how to zip the whole folder, you may refer to the video here (for Windows 7) or here (for MacOS). Only a zip file should be uploaded not rar file, not 7z file, not tar file, etc.. You may make multiple submissions and only the latest submission will be graded.
You will be using Canvas to submit your zip file. Go here for Part 1 or here for Part 2. You should submit your work early to avoid any kind of submission problem in the last minute.
After your submission, you must download your submitted zip file back from Canvas, unzip it, and open it in Greenfoot to make sure it works. It is very important because submitting the wrong file may give you zero mark for all the hardwork you put in.
There will be a penalty of -1 point (out of a maximum 100 points) for every minute you are late for the first 30 minutes. For instance, since the deadline of part 1 is 11:59:00 on Nov 9th, if you submit your solution at 12:20:00 on the same day, there will be a penalty of -21 points from your assignment part 1. After the first 30 minutes, until exactly 24 hours after the deadline (i.e. 11:59:00am on Nov 10th for part 1), the penalty remains -30 points. However, if you are late for more than 24 hours, you will get 0 for your assignment. The lowest grade you may get from an assignment is zero: any negative score after the deduction due to late penalty (and any other penalties) will be reset to zero.
About plagiarism
If you get caught cheating, both you and the other person get zero for the assignment. It doesnt matter if you only copied a little. UST rules say that the penalty is the same for both people. There may also be additional penalties other than just getting zero for the assignment. You are responsible for keeping your own work safe from being accessed or referenced by others in any way. However, discussing with others is fine as thats different from direct copying. Also be reminded that the plagiarism detection software are very robust nowadays, and on top of that we will also examine your works manually.
FAQ
1. Q: My code doesnt work / there is an error, here is the code, can you help me fix it?
A: As the assignment is a major course assessment, to be fair, you are supposed to work on it on your own and we should not finish the tasks for you. We might provide some very general hints to you, but we shall not fix the problem for you.
2. Q: Some strange problem happens with the Greenfoot. For example, the terminal/console window doesnt open properly. What can I do? A: In that case, you may try to use the latest version here. Windows users may use the standalone version on that page.
3. Q: When I tried to drag the NaughtyGuy, the Block under the NaughtyGuy was dragged instead. What to do?
A: Apparently this is a Greenfoot-version-specific problem when a newer version of Greenfoot (e.g. 3.6) is used. In that case, you can
simply drag the Block away and then drag the NaughtyGuy. In the demo session, we dont mind you doing that as well, so dont worry.
4. Q: Can I produce extra output in the console? Can I change the given code? Can I use an alternative approach?
A: Yes, yes, and yes. As long as your work fulfills all the written description. It is recommended that you follow our suggested approach, but feel free to use an alternative one. However, during the live demo session, we may ask you to make changes to your code so that the secret is always a certain secret (e.g. pwd) for testing purposes you need to be confident that you know your own code very well so that you can make the changes correctly in your alternative solution. Again, demo procedure will be released beforehand, so be prepared.

Part 1 requirements
For all the methods, you may also try the demo program to see what is expected. After reading the descriptions carefully and checking with the demo program, you are welcome to ask us for clarification if the requirement is still unclear to you. We also maintain a FAQ for frequently asked questions, if any, at the bottom of the previous page.
In the MastermindWorld class:
public static void initialize()
This method is called in the MastermindWorld constructor as you can see from the provided source code. It should create the initial board by placing the objects in the world exactly as shown below. Read the previous description to see what each object is. MastermindWorld

Hint: You may use the static method MastermindWorld.addObject to easily add an object to the world. Read the
documentation of the method (above the method in the code) to learn how to use it. Those provided methods are
already completed and you are not required to understand the code inside them to utilize them.
:MastermindWorldaddObject ()
public static void generateSecret()
This method is also called in the MastermindWorld constructor. It is used to generate a 3-character secret and put that to the static variable secret and also print it out on the terminal.

MastermindWorld3secret
If implemented correctly, the secret is very likely to be different everytime you restart your program by clicking the Reset button at the bottom of Greenfoot as it is randomly chosen.
GreenfootReset
Hint: Use the provided method getRandomNumber to generate a random number in a specific range. A usual, read its documentation for usage instruction. Think about how to use a random number to pick a random peg character (i.e., w, d, p, or e). :getRandomNumber
peg(:wdpe)
Hint: Use + to append a character to the end of secret. For example, the statement secret = secret + w; can be used to add the character w to the end of the secret. Repeat that 3 times, and you will have www in the secret. Be reminded to set the secret to an empty string first, i.e., secret = ;
Hint: Use System.out.println(The secret is + secret); to print the message in the terminal. :+secretsecret = secret + w;w
wwwsecret secret = ;
public static void clearBalloons(int row) system.out.println(The secret is + secret),
It removes all the existing balloons in the balloon area on the specified row (specified by a row number). Other rows should not be affected.
( row number )
Note: You can assume that the row parameter is always in the valid range of [1,7].
:row[1,7]
Hint: Use the removeBalloons method. Read the documentation in the code for its usage instruction.
:
public static void clearAllBalloons()
It removes all the existing balloons in the balloon area on all rows.
In the Judge class:
public void judgeRow(int row)
Judge the row as specified by the parameter. Among the 3 different judges, the Judges rule is the simplest. Only orange balloons will be placed as the feedback. An orange balloon is placed when a peg is guessed completely correctly (both the type (i.e. which animal it is) and position). The orange balloons should be placed left-aligned in the balloon area on the same row. The following is an example. Assume the secret is wde.
You guess edp by placing the pegs (elephant, dolphin, pig) in the play area on the first row (i.e. row 1):
(()) wde

Then you run the judgeRow method from the Judge (the left-most judge at the top), and input 1 as the parameter.
Judge(Judge)judgeRow1
The feedback will be shown in the balloon area. Since the secret is wde and the guess is edp, only the 2nd peg is guessed completely correctly, so the feedback is 1 orange balloon. Notice that the orange balloon is placed left-aligned in the balloon area on the same row.
wdeedpd 1

Then you try another guess on the second row (i.e. row 2). The guess this time is pde.
(row 2)pde

And you run the judgeRow method with parameter being 2.
The result is 2 orange balloons as the second peg and the third peg are guessed completely correctly.
2judgeRow 2peg

You try another guess on the 3rd row (i.e. row 3). The guess this time is wde.
(row 3)wde

And you run the judgeRow method with parameter being 3.
You get 3 orange balloons as all 3 pegs are guessed completely correctly.
3judgeRow 33

Note: for simplicity, you can assume that when the method is called on row N, the row N already has exactly 3 pegs placed in the play area. :NN3 play area
Note: before placing the balloons, any existing balloon that is on the same row should be removed first through the use of the MastermindWorld.clearBalloons method which is to be completed by you. Because of that, in the source code we provided to you, the method MastermindWorld.clearBalloons is called at the beginning of the judgeRow method.
:MastermindWorldMastermindWorld.clearBalloons Note: You can assume that the row parameter is always in the valid range of [1, 7]. MastermindWorldclear
row[1,7] judgeRow Hint: Use the MastermindWorld.getObjectChar and MastermindWorld.addObject methods. Read the documentation
in the code for their usage instructions.
:MastermindWorldgetObjectCharMastermindWorldaddObject
Hint: To get a character from the secret, you may use MastermindWorld.secret.charAt(x) where x is the character index (starts from 0) of the character that you want to retrieve. For example, assume the secret is wde, MastermindWorld.secret.charAt(0) will return w and MastermindWorld.secret.charAt(2) will return e.
:secretMastermindWorld.secret.charAt(x)x(0) wdeMastermindWorld.secret.charAt(0)wMastermindWorld.secret.charAt(2)e
public void judgeCurrentRow()
Judge the row which the judge is currently located at.

For example, if the board is like the following at first. Notice that we have manually dragged the judge to row 2. You can assume the user would always drag the Judge to the middle column.
judge2

Calling the method judgeCurrentRow would give the following where only row 2 has been judged (assume the secret is dwp):
judgeCurrentRow, 2(dwp):

public void judgeAllRows()
Judge all the rows. You can assume every row is either totally complete with 3 pegs or have nothing on it.
For example, if the board is like this at first:
3:

Calling the method judgeAllRows would give the following (assume the secret is dwp):
judgeAllRows(dwp):

Part 2 requirements
For all the methods, you may also try the demo program to see what is expected. After reading the descriptions carefully and checking with the demo program, you are welcome to ask us for clarification if the requirement is still unclear to you. We also maintain a FAQ for frequently asked questions, if any, at the bottom of the previous page.
In the NiceJudge class:
It is the second judge at the top. It inherits from Judge, that means you can use all the public methods that are defined there.
Judgepublic public void judgeRow(int row)
Judge the row as specified by the parameter.
Similar to the Judge in part 1, put the balloons in the balloon area on the same row. 1
NiceJudge uses both orange balloons and yellow balloons. Orange balloons mean a peg was guessed completely correctly, i.e., both its position and type are correct.
NiceJudge
Yellow balloons are for the pegs that are guessed partially correctly the type is correct but wrong position. Note that yellow balloons are only awarded for pegs that are not awarded with orange balloons.
To help you understand the rules, refer to the following example. The secret is wde.

Notice that, in the example above at row 6, only 1 yellow balloon has been awarded for the elephant peg for its correct
type (but wrong position). Even tho there are 2 elephant pegs in the guess, there is only 1 elephant in the secret.
61()play area Note: The orange balloons always appear before (i.e. on the left-hand side of) the yellow balloons, and all balloons have to be left-aligned in the balloon area just like what the Judge does in part 1.
:()
To make your task easier, you may follow the algorithm below for counting how many yellow balloons and orange balloons should be placed. However, you are welcome to use your own algorithm if you want.

2. 1.

O
2. 3.
Y. 1. getnumberofyellow(Y)
Count the number of yellow balloons that we should give out, assuming we do not give out any orange balloon at all. Simply use the getNumberOfYellowBalloons method that we provided, and store the result to a variable, say,
Count the number of orange balloons that we should give out. Store the result to a variable, say, O.
Update Y with Y = Y O, because a yellow balloon is only awarded to a peg when the peg wasnt awarded with
an orange balloon already. Y = Y OY Now, O and Y respectively store the number of orange balloons and the number of yellow balloons that you need
to place. OY
4.
In the FriendJudge class:
It is the third judge at the bottom. It inherits from Judge, that means you can use all the public methods that are defined
It should be the same as the one in NiceJudge class except for one difference the orange balloons are always placed at the exact positions of the pegs that are guessed completely correctly. That is, by looking at the position of the orange balloons, the player would know which particular pegs are guessed completely correctly. The yellow balloons can be placed anywhere that is available (i.e. anywhere that is not already occupied by other balloons) and the balloons do not have to be left-aligned this time.
To help you understand the rules, refer to the following example. The secret is wde.
NiceJudge ()
there.
Judge public void judgeRow(int row)

You can see that in the last row (row 7), two orange balloons were given at the last and the second last position. That means the dolphin peg (at the second last position) and the elephant peg (at the last position) are completely correctly guessed. ()
()()
In the second row (row 2), it shows that the last elephant peg is completely correctly guessed according to the orange balloon. There are also 2 yellow balloons at the beginning which means the other 2 pegs (dolphin and wombat) have the correct types but the positions of them are incorrect.
The player has to first move (drag and drop it with the mouse) the NaughtyGuy object from the top to the location where he/she wants the correct peg to reveal (in the play area), then run the cheat method. The procedure is illustrated below. Assume the secret is wde.
()NaughtyGuy/peg(play area) cheatwde
In the NaughtyGuy class:
The player can use the NaughtyGuy to cheat.
() ()
public void cheat()

Note: You can assume that the NaughtyGuy is always dragged to a valid (empty) position in the play area when cheat is run. :cheatNaughtyGuyplay()
Note: After the cheating is done, the NaughtyGuy should move itself back to its original location at the bottom as shown in the last screenshot. :cheatNaughtyGuy
Hint: Use the Actor methods getX, getY, and setLocation as NaughtyGuy is an Actor. See the documentation of those methods here.
:ActorgetXgetYsetLocationNaughtyGuyActor public void supercheat()
supercheat is similar to cheat, but it shows even more. It reveals the whole row where the NaughtyGuy is at. The procedure is illustrated below. Assume the secret is wde.
supercheatcheatwde

Note: You can assume that the NaughtyGuy is always dragged to a valid (empty) position in the play area when supercheat is run. :supercheatNaughtyGuy()
Note: After the reveal is done, the NaughtyGuy should move itself back to its original location at the bottom.
In the MastermindWorld class:
:NaughtyGuy

public void saveGame() throws Exception
Save the secret and the current game board to the file save.txt (which is located right under the project directory).
Save.txt()
The first line is the secret string. The remaining 56 lines store what to be placed on each of the 56 cells on the 87 game board (including the judges, naughty guy, pegs, and balloons; but blocks are not saved). The format of those 56 lines is always a character that represents the object (or x for nothing) that has to be placed at the specified position, followed by a space, then the x-position, followed by a space, then the y-position. For example, the line p 0 2 indicates that there is a pig at the position (0, 2) and the line x 4 3 indicates that there is nothing at the position (4, 3). The characters used are the ones listed as constants in the MastermindWorld like MastermindWorld.PIG (p) and MastermindWorld.NOTHING (x). Blocks (i.e., b) should NOT be saved. If a location only has a Block, then save x instead of b for that location. If a location has both a Block and a Judge/NaughtyGuy, save the Judge/NaughtyGuy only.
)
Note: You can use the getObjectChar method to get the character representing the object or nothing (x) at the specified location. If the specified location has both a Judge/NaughtyGuy and a Block, the Judge/NaughtyGuy character will be returned by getObjectChar. This is desirable because you do not need to save the Block objects in save.txt.
:getObjectChar(x)Judge/NaughtyGuyBlock, Judge/NaughtyGuygetObjectCharsave.txt
public void loadGame() throws Exception
Load the secret and the game board from the file save.txt. The game board has to be cleared first using the removeAllNonBlockObjects method. Then, create and place the objects according to the data loaded from save.txt
using the addObject method. save.txtremoveAllNonBlockObjects saveaddObject
For the file format, see save.txt. save.txt(2)
Thesave.txt 5re6presentsthefoll8oxw7ing board:56(judgenaughtGuy; 56(x)xy ,p 0 2(0,2)x 4 3(4,3)MastermindWorldMastermindWorld.Pig(p) MastermindWorld.NOTHING(x)Blocks(b)xb BlockJudge/NaughtyGuyJudge/NaughtyGuySave.txt :

public static int calculateRowScore(int row)
It calculates and returns the score of the specified row according to the current board.
The formula for the score is (numberOfOrangeBalloons*3 + numberOfYellowBalloons)
(numberoforangeballoon *3 + numberofyellowballoon) numberOfOrangeBalloons and numberOfYellowBalloons are the counts of the orange/yellow balloons in the specified
row.
If row is outside of the valid range [1,7], then it simply returns 0 as the score.
row[1,7]0 For examples, with the following board:
calculateRowScore(0) should return 0. calculateRowScore(1) should return 9. calculateRowScore(2) should return 5. calculateRowScore(3) should return 5. calculateRowScore(4) should return 0. calculateRowScore(5) should return 2. calculateRowScore(6) should return 1.
numberoforangenumberofyellowballoon/

calculateRowScore(7) should return 6.
public static int calculateMaxScore()
It returns the maximum score of all rows. For the same example we used above, the calculateMaxScore() will return 9. If there is no balloon at all on the broad, then it simply returns 0.
calculateMaxScore()90 public static void showScore()
It shows the players current score (using calculateMaxScore()) together with a comment at the top-right corner.
(calculateMaxScore())
The comment should be Get good! for score within [0,3], or Good! for score within [4,6], or Excellent! for score within [7,9].
[0,3]Get good![4,6]good![7,9]Excellent! For example, with the following board, the score is 6 according to calculateMaxScore(): calculateMaxScore()6:
Running the showScore() method shows the message at the top-right corner:
showScore():

You may use the provided showMessage() method to display a message at the top-right corner.
The message should always be in the format You scored (SCORE)! (COMMENT) as shown above.
showMessage() You scored (SCORE)!(COMMENT)
public static void updateHighscores() throws Exception (optional bonus part; see here for explanation)
There is a highscore.txt under the project directory. Here is an example highscore.tx:t. 6 3 2 highscore.txt
The file always contains just three numbers that are separated by single spaces. The first number is the highest score, the second number is the second highest score, and the last number is the third highest score.

When the method updateHighscores is ran, the following should happen:
updateHighscores:
1. Use calculateMaxScore to calculate the current players score. 1. calculateMaxScore
updated scores to the highscore.txt file. The file should always store the top 3 scores, in descending order, and nothing else. highscore.txt
3
Example 1: if the highscore.txt originally stores 6 3 2 and the players current score is 9, then the highscore.txt should store 9 6 3 after the method is ran.
1:highscore.txt6 3 29highscore.txt9 6 3
Example 2: if the highscore.txt originally stores 6 3 2 and the players current score is 4, then the highscore.txt should store 6 4 3 after the method is ran.
2. Load the 3 highest scores from the highscore.txt file.
3. If the current score is higher than any one of the existing high scores, update the high scores and save the
2:highscore.txt6 3 24txt6 4 3
2. highscore.txt3

Example 3: if the highscore.txt originally stores 6 3 2 and the players current score is 1, then the highscore.txt should store 6 3 2 after the method is ran. (no change)
3:highscore.txt6 3 21txt6 3 2()

Introduction to Computing with Java COMP1022P [2-0-2:3]
Menu
Home
Course Information Teaching staff
Grading and Bonus scheme Lecture notes and schedule Labs and schedule
About Final Exam
About Midterm Exam Assignments
Greenfoot resources Self-learning center Downloads
1:
Greenfoot resources Greenfoot installation
Greenfoot setup program for Microsoft Windows, Download 3.1.0 (includes JDK)
Greenfoot setup program for Microsoft Windows, Portable Version Download 3.1.0 (includes JDK) Greenfoot setup program for Mac OS X, for 10.8.3 or later Download 3.1.0 (includes JDK)
Greenfoot troubleshooting:
About new versions of Greenfoot: there is a newer version of Greenfoot available on the official website https://www.greenfoot.org/. If you use that instead to open our samples, you may be asked if you want to update your code. Just choose Yes, update my code..
About terminal not showing up:: if you cannot see the console or terminal, hold down the shift button, then right-click the Greenfoot Terminal on the taskbar, try maximize or move. Alternatively, you may use the latest version downloaded from the official website. Link can be found in the previous paragraph.
COMP1022P_GreenfootStartUpProject.zip
Greenfoot tutorials
A step-by-step tutorial to Install and use Greenfoot (if JDK is needed, please follow from step 1; otherwise, start from step 2)
Using Greenfoot in CS Labs (Room 4213)
Using Greenfoot in ITSC Barns (Barn A, B and C)
Greenfoot start up project
COMP1022P_GreenfootStartUpProject.zip

Greenfoot API documentation
In this course, students are only required to learn a selected number of methods defined in the Greenfoot APIs. The list of API methods is summarized in the following table:
Class Name
Method Name
int getRotation();
void setRotation(int angle);
void act();
void setImage(String fileName);
int getX();
int getY();
void setLocation(int x, int y);
void setDirection( int direction );
int getDirection();
boolean canMove(int numOfSteps);
void move(int numOfSteps);
Constants:
Creature.EAST = 0; Creature.WEST = 1; Creature.NORTH = 2; Creature.SOUTH = 3;
int width() int height()
Description
Get the angle of rotation Set the angle of rotation
The act method is called by the Greenfoot framework to give actors a chance to perform some useful actions
Set the image of the actor.
Example: setImage(wombat.jpg);
Get the x-coordinate of the current actor
Get the y-coordinate of the current actor
Assign a new location for this actor
Set the current direction of the creature object
Get the current direction of the creature object
Return true if the move can be completed successfully. Otherwise, return false
Move the object using the current direction by the given number of steps
Pre-requesite: canMove(numOfSteps) returns true
Example
api_rotation.zip
A simple Greenfoot example to demonstrate getRotation, setRotation and act methods
api_location.zip
A simple Greenfoot example to demonstrate getX, getY and setLocation methods
Actor
Creature (extends Actor)
api_creature.zip
An example to program rotating picobot along the boundary of the world. It uses a combination of methods/constants defined in the Creature class
GWorld
Get the width of the world Get the height of the world
A simple Greenfoot example to change the width and the height of the world to 12 (the default value is 8)
api_gworld_width_height.zip

void removeOneObject(Actor obj)
void addOneObject (Actor obj, int x, int y)
Actor getOneObjectAt(int x, int y, String actorClassName)
int random(int lowerLimit, int upperLimit)
Actor[] getAllObjects(String actorClassName)
void removeObjectsFromWorld(Actor[] objArray)
Remove one actor object from the world
Add one actor object to the world
Get one object at the location specified by x and y coordinates and its class name
Return null if the actor object cannot be located at the given position
An example to illustrate removeOneObject, addOneObject and getOneObjectAt methods
Generate a random number
definied by the upper and
the lower limits (both limits
are inclusive) api_random_picobots.zip
Get all objects and store them to an array
An example to create a random number of picobots and demonstrate how to remove all picobots from the
Remove all objects from the world world
api_add_remove_objects.zip
Last modified on 09/19/2019 12:29:03
Maintained by COMP1022P Teaching Team
(Best viewed with resolution 1024768)

wde j00 w01 d02 w03 p04 d05 e06 e07 n10 d11 w12 e13 p14 w15 e16 d17 f20 e21 e22 d23 p24 p25 p26 e27 c30 x31 x32 x33 x34 x35 x36 x37 x40 o41 o42 o43 x44 y45 y46 o47 x50 o51 y52 y53 x54 y55 x56 o57 x60 o61 y62 y63 x64 x65 x66 x67
2:

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] algorithm Scheme game Java graph software Go COMP1022P Assignment:
$25