SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
DO NOT USE THE ANSWERS ON OTHER CHEGG ANSWERS TO ANSWER THIS QUESTION.
THEY ARE INCORRECT.
ITSC 1212 Module 8 Lab - the Turtle Games!
In this lab, we will be combining two of the concepts from your prepwork (number finding and
Turtle drawing) to create a sort of game. If you havent completed that work yet, it would be a
good idea to take a few minutes and review those tasks before starting the lab.
Concepts covered in this lab:
For and While loops
Method calling
Booleans
Required files or links
ITSC1212Lab8.java
visualizeGuess.txt
Part A: Designing the base game
1. The goal of the game were going to create in the lab is to create a World and drop an
invisible Turtle somewhere in that World. The players goal is to guess numbers until
they have successfully located the invisible Turtle.
2. Start by opening the ITSC1212Lab8.java file. Take a moment and review the contents of
this file. Notice that above the main method were creating two random numbers,
randomX and randomY, and then creating a World object. Were creating those variables
outside of the main method so that we can access those variables in additional methods
well be adding later in the lab. This is related to what is known as variable scope. Scope
refers to the visibility of variables. That is, which parts of your programs/methods can
see a variable and refer to or use it? This topic will be covered in more detail in a later
unit. For now, remember the basic rule that variables are known within the block where
theyre defined and any blocks defined inside that block.
3. Also notice that both of our random number variables are being initialized to 0. These
are the variables that will determine the random position of the Turtle, and will be
different each time the game is played. Its important to consider that the play space of
this World is 500x500, meaning there are 250,000 possible positions for our invisible
Turtle. To make things easier, lets limit these possible positions to only multiples of 5
and we want to limit it to a value of starting at 5 and ending at 495 so the turtle is not on
the edge. Take some time to think about how you might use Math.random() as you have
in past assignments to generate a random multiple of 5 from 5-495. If you get stuck here
for more than a few minutes, skip to the bottom of this document for the solution (please
do actually attempt this though, its really good practice ).
4. Now that we have our World and our random positions, we can advance to the main
method and actually create our game.
5. The first thing we need to do here is actually create the Turtle were going to be working
with. Start by creating a Turtle, as well as a Scanner object with which we can take user
input.
6. Use the Turtle method .setVisible() to set your Turtles visibility to false.
7. We now have an invisible Turtle at some unknown location inside our World with
possible values for its X and Y coordinates between 5 - 495. The next step is going to be
collecting the user guess for X and Y. To do so we need a couple of variables to keep
track of the user's guess. We will use the values of those variables and compare them to
the random values generated so it would be a good idea to initialize them to values our
program will never generate randomly (i.e., any integer that is less than 5 or greater than
495)
Lets take a moment and evaluate all the different pieces we have. We have a World, a
Turtle at an unknown location inside that world, two variables that contain the X/Y
position of the Turtle, and the users guesses for that X/Y.
In order to collect user guesses we need to utilize the Scanner class to capture what
they enter. Add the following lines to create an object that can help us accomplish this:
8. The next bit is up to you, and will be a good challenge to your ability to write both a while
loop, as well as your understanding of boolean expressions. Take your time thinking
through this process and the outcomes as you develop this logic.
9. Translate the following pseudocode into Java (the indentation of this is a hint to the
necessary structure).
While guessX does not equal randomX OR guessY does not equal randomY
If guessX does not equal randomX
Prompt the user for a guess of the X value
Save that to guessX
If guessX was too high
Inform the player of that
Alternatively, if it was too low
Inform the player of that.
If guessX is correct
Inform the player of that
If guessY does not equal randomY
Prompt the user for a guess of the Y value
Save that to guessY
If guessY was too high
Inform the player of that.
Alternatively, if it was too low
Inform the player of that.
If guessY is correct
Inform the player of that
Notice that this logic makes sense since we initialized the guess variables to values
where both parts of the compound conditional of the while loop will always be false
everytime the program starts. If this wasnt the case we might run into scenarios where
the user does not get the prompt to enter a guess and start playing.
As a reminder heres how you would use the Scanner object to capture the user input:
When you are satisfied with how your loop is written (we will test it later), continue on.
10. The beauty of structuring our code this way is that it will continue to ask the user for
guesses until both the X and Y are correct, and once one is correct it will only ask for
new input for the value that is still incorrect. This while loop will ONLY break once the
Turtle has been found.
11. Two important things to think about:
Why is a while loop more appropriate here than a for loop?
Why are we using an OR in the while loop instead of AND?
We are using a while loop because we know that once the while loop has broken that the
Turtle has been found. A while loop is more appropriate here since we do not need to
loop a specific number of times.
We are using an OR because the logic that is controlled by the loop condition is
responsible for determining that both of the x and y positions are guessed correctly. If we
use an AND we will break out of the loop once one value is guessed correctly (i.e., no
longer incorrect).
12. After the loop is done the user has guessed both x and y positions of our turtle and we
can add our win code. Specifically, what we want to have happen is the User be
notified of their correct guesses, and the invisible Turtle should appear. Add the following
lines to do this.
Feel free to add any kind of formatting or additional print statements to really jazz up this
win message.
13. Now that the basic pieces of this code are all in place, we need to test it so we can tell if
your while loop and the statements within it were written correctly.
14. Before you run the code, add two print statements to the beginning of your code that will
print the correct coordinates of the Turtle (i.e., the randomly generated values). This
must happen before your while loop and NOT inside or after it. Its important to know the
correct location of the Turtle during this testing phase so we can test different scenarios.
15. Now run your program and test the following scenarios:
Guess is too low (is the user instructed to guess higher next time?)
Guess too high (is the user instructed to guess lower next time?)
Make one correct guess (is that value skipped next round?)
Make both correct guesses (is the win message displayed?)
Remember that you can click the Open Desktop button
to view the World and Turtle.
16. When you are satisfied that this game is working correctly, show your code to a TA or
instructor to receive credit for this section.
Part B: Add in color blocks
1. One of the issues with this game is that it doesnt feel very responsive. Part of the
problem is that we have this World object but were not really doing anything with it.
What we could do in this situation is use the World to visually block off areas where we
know the Turtle cant be anymore based on previous guesses. For example, if a guess
for X was 300 and that was determined to be too high then it doesnt help the user to
guess a number that is between 300-495 so we block that area..
2. Open the file visualizeGuess.txt and copy its contents (the method) into the
ITSC1212Lab8 class file after ((i.e. below not inside) the main method. This is an
important step so pay extra attention and make sure the class structure is correct.
3. Most of this code is already written for you, but you have 4 for loops that must be
corrected. Before you jump into that, take a moment and make sure you understand
what this code is attempting to do. Note that any time you need to use the Color class
you need to import it. That is why we have added the import for the Color class at the
start of the file.
In a nutshell, what this code does is block off areas where the hidden Turtle cannot be
by using a second invisible Turtle to draw a series of black lines in those areas. Heres a
visual breakdown of this process describing what happens when an X guess is too high.
Here are some screenshots of sample testing:
4. The last thing to add after youve written the logic for the for loops is to call these
methods so we can test them and see them in action. You will want to add these method
calls back in the main method below or above each print statement telling the user of
their incorrect guess. For example, the condition block that determines guessX was too
low would look like so:
5. Writing the correct for loops to make this process work will likely take some trial and
error. Test your code frequently, making sure that the correct areas are blocked off each
time.
**Important note**
The point 0,0 in the World is the top left corner of the box. Intuitively, we want to
place that at the bottom left, because were used to that from math classes
Bonus: Add a new game mode
1. In this section, what you will do is give the player the option to play in a
Close-enough/Easy mode. The goal of this mode is:
a. Allow the user to select their desired game mode
b. If the user has selected the Easy mode:
i. Any guesses within 20 pixels of the correct X or Y position will be counted
as correct
2. Think about the flow of the game, and what, if anything, would need to change at each
step if the Easy mode were to be selected. We want you to think about how these two
modes could live side by side, rather than just copy and pasting the first version and
altering it.
3. Here are some helpful hints we think will be helpful for how to make this work:
Add boolean variables to track whether or not a guess is correct.
The reason you may find this helpful is because the two game modes have different
criteria for what a correct guess is. Your code, at this stage, is likely using a
guessX == randomX to test correctness, and obviously this doesnt work for the Easy
mode. By using boolean variables, you can have two distinct ways of establishing what a
correct answer is and store that result based on which game mode is being played. You
can also use these booleans to control your while loop, which vastly simplifies the way
that loop looks.
Leave the code that says a guess was too high or too low alone.
Altering the logic of this part of the loop is... A lot. Focus on the aspects that determine if
an answer was right or not.
Think about how you can alter the logic where a correct guess was established.
Consider this partial section of the pseudocode from Part A:
If guessY does not equal randomY
Prompt the user for a guess of the Y value
Save that to guessY
If guessY is correct
Inform the player of that
Or, If guessY was too high
Inform the player of that.
Alternatively, if it was too low
Inform the player of that.
You could alter it so it functions like this:
If guessY does not equal randomY
Prompt the user for a guess of the Y value
Save that to guessY
If guessY is correct Or if Easy Mode is on and guessY is within 20
pixels of the correct location
Inform the player of that
Update the value of the boolean correctY
Or, If guessY was too high
Inform the player of that.
Alternatively, if it was too low
Inform the player of that.
Once this works, consider other rearrangements you could make.
4. Once youre satisfied with your Easy mode, show your work to an instructor or TA to
receive credit.
Solution for Part A step # 3
// generate random X and Y for the turtle limit to multiples of 5
randomX = ((int)(Math.random() * 99) + 1) * 5;
randomY = ((int)(Math.random() * 99) + 1) * 5;

Contenu connexe

Similaire à DO NOT USE THE ANSWERS ON OTHER CHEGG ANSWERS TO ANSWER THIS.pdf

Vpet sd-1.25.18
Vpet sd-1.25.18Vpet sd-1.25.18
Vpet sd-1.25.18Thinkful
 
Accord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
Accord.Net: Looking for a Bug that Could Help Machines Conquer HumankindAccord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
Accord.Net: Looking for a Bug that Could Help Machines Conquer HumankindPVS-Studio
 
Coding in Disaster Relief - Worksheet (Advanced)
Coding in Disaster Relief - Worksheet (Advanced)Coding in Disaster Relief - Worksheet (Advanced)
Coding in Disaster Relief - Worksheet (Advanced)Charling Li
 
Basics of Programming - A Review Guide
Basics of Programming - A Review GuideBasics of Programming - A Review Guide
Basics of Programming - A Review GuideBenjamin Kissinger
 
Lab Assignment 17 - Working with Object ArraysIn the old days we w.pdf
Lab Assignment 17 - Working with Object ArraysIn the old days we w.pdfLab Assignment 17 - Working with Object ArraysIn the old days we w.pdf
Lab Assignment 17 - Working with Object ArraysIn the old days we w.pdfeyewaregallery
 
Hasktut
HasktutHasktut
Hasktutkv33
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsRuth Marvin
 
Explain the concept of two types of network intrusions What devic.docx
Explain the concept of two types of network intrusions What devic.docxExplain the concept of two types of network intrusions What devic.docx
Explain the concept of two types of network intrusions What devic.docxSANSKAR20
 
Copy of repast javagettingstarted
Copy of repast javagettingstartedCopy of repast javagettingstarted
Copy of repast javagettingstartedNimish Verma
 
Counting (Notes)
Counting (Notes)Counting (Notes)
Counting (Notes)roshmat
 
How tomakea gameinunity3d
How tomakea gameinunity3dHow tomakea gameinunity3d
How tomakea gameinunity3dDao Tung
 
C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1Mohamed Ahmed
 
Undefined behavior is closer than you think
Undefined behavior is closer than you thinkUndefined behavior is closer than you think
Undefined behavior is closer than you thinkAndrey Karpov
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number TutorialOXUS 20
 
Mastering python lesson2
Mastering python lesson2Mastering python lesson2
Mastering python lesson2Ruth Marvin
 
A 64-bit horse that can count
A 64-bit horse that can countA 64-bit horse that can count
A 64-bit horse that can countAndrey Karpov
 
The article is a report about testing of portability of Loki library with 64-...
The article is a report about testing of portability of Loki library with 64-...The article is a report about testing of portability of Loki library with 64-...
The article is a report about testing of portability of Loki library with 64-...PVS-Studio
 
What Deep Learning Means for Artificial Intelligence
What Deep Learning Means for Artificial IntelligenceWhat Deep Learning Means for Artificial Intelligence
What Deep Learning Means for Artificial IntelligenceJonathan Mugan
 

Similaire à DO NOT USE THE ANSWERS ON OTHER CHEGG ANSWERS TO ANSWER THIS.pdf (20)

Vpet sd-1.25.18
Vpet sd-1.25.18Vpet sd-1.25.18
Vpet sd-1.25.18
 
Accord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
Accord.Net: Looking for a Bug that Could Help Machines Conquer HumankindAccord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
Accord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
 
Coding in Disaster Relief - Worksheet (Advanced)
Coding in Disaster Relief - Worksheet (Advanced)Coding in Disaster Relief - Worksheet (Advanced)
Coding in Disaster Relief - Worksheet (Advanced)
 
Basics of Programming - A Review Guide
Basics of Programming - A Review GuideBasics of Programming - A Review Guide
Basics of Programming - A Review Guide
 
Lab Assignment 17 - Working with Object ArraysIn the old days we w.pdf
Lab Assignment 17 - Working with Object ArraysIn the old days we w.pdfLab Assignment 17 - Working with Object ArraysIn the old days we w.pdf
Lab Assignment 17 - Working with Object ArraysIn the old days we w.pdf
 
Hasktut
HasktutHasktut
Hasktut
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
 
Explain the concept of two types of network intrusions What devic.docx
Explain the concept of two types of network intrusions What devic.docxExplain the concept of two types of network intrusions What devic.docx
Explain the concept of two types of network intrusions What devic.docx
 
Grounded Pointers
Grounded PointersGrounded Pointers
Grounded Pointers
 
Copy of repast javagettingstarted
Copy of repast javagettingstartedCopy of repast javagettingstarted
Copy of repast javagettingstarted
 
Counting (Notes)
Counting (Notes)Counting (Notes)
Counting (Notes)
 
How tomakea gameinunity3d
How tomakea gameinunity3dHow tomakea gameinunity3d
How tomakea gameinunity3d
 
C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1
 
Undefined behavior is closer than you think
Undefined behavior is closer than you thinkUndefined behavior is closer than you think
Undefined behavior is closer than you think
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
 
Lets build a neural network
Lets build a neural networkLets build a neural network
Lets build a neural network
 
Mastering python lesson2
Mastering python lesson2Mastering python lesson2
Mastering python lesson2
 
A 64-bit horse that can count
A 64-bit horse that can countA 64-bit horse that can count
A 64-bit horse that can count
 
The article is a report about testing of portability of Loki library with 64-...
The article is a report about testing of portability of Loki library with 64-...The article is a report about testing of portability of Loki library with 64-...
The article is a report about testing of portability of Loki library with 64-...
 
What Deep Learning Means for Artificial Intelligence
What Deep Learning Means for Artificial IntelligenceWhat Deep Learning Means for Artificial Intelligence
What Deep Learning Means for Artificial Intelligence
 

Plus de adamsapparelsformen

Doctors Diaries is a 1990s documentary following a group of.pdf
Doctors Diaries is a 1990s documentary following a group of.pdfDoctors Diaries is a 1990s documentary following a group of.pdf
Doctors Diaries is a 1990s documentary following a group of.pdfadamsapparelsformen
 
Dont respond to this questionGive only the references Bib.pdf
Dont respond to this questionGive only the references Bib.pdfDont respond to this questionGive only the references Bib.pdf
Dont respond to this questionGive only the references Bib.pdfadamsapparelsformen
 
dogh dogcpp maincpp For the code above How many MyCo Cop.pdf
dogh dogcpp maincpp For the code above How many MyCo Cop.pdfdogh dogcpp maincpp For the code above How many MyCo Cop.pdf
dogh dogcpp maincpp For the code above How many MyCo Cop.pdfadamsapparelsformen
 
Donald Lyles 52year old male was admitted yesterday eveni.pdf
Donald Lyles 52year old male was admitted yesterday eveni.pdfDonald Lyles 52year old male was admitted yesterday eveni.pdf
Donald Lyles 52year old male was admitted yesterday eveni.pdfadamsapparelsformen
 
Domes and basins In some folds Inliers and outliersFigur.pdf
Domes and basins  In some folds Inliers and outliersFigur.pdfDomes and basins  In some folds Inliers and outliersFigur.pdf
Domes and basins In some folds Inliers and outliersFigur.pdfadamsapparelsformen
 
Dolce is an Italian company selling highend turnkey kitchen.pdf
Dolce is an Italian company selling highend turnkey kitchen.pdfDolce is an Italian company selling highend turnkey kitchen.pdf
Dolce is an Italian company selling highend turnkey kitchen.pdfadamsapparelsformen
 
Do This Consider the partial class declarations below A co.pdf
Do This Consider the partial class declarations below A co.pdfDo This Consider the partial class declarations below A co.pdf
Do This Consider the partial class declarations below A co.pdfadamsapparelsformen
 
Doede Corporation uses activitybased costing to compute pro.pdf
Doede Corporation uses activitybased costing to compute pro.pdfDoede Corporation uses activitybased costing to compute pro.pdf
Doede Corporation uses activitybased costing to compute pro.pdfadamsapparelsformen
 
Does anyone have a photo of the completed moon map I need t.pdf
Does anyone have a photo of the completed moon map I need t.pdfDoes anyone have a photo of the completed moon map I need t.pdf
Does anyone have a photo of the completed moon map I need t.pdfadamsapparelsformen
 
Document your result for H influenzae below 1 What is the.pdf
Document your result for H influenzae below 1 What is the.pdfDocument your result for H influenzae below 1 What is the.pdf
Document your result for H influenzae below 1 What is the.pdfadamsapparelsformen
 
Doal gaz doru bir ekilde tanmlayan ifadeyi sein Fracking.pdf
Doal gaz doru bir ekilde tanmlayan ifadeyi sein  Fracking.pdfDoal gaz doru bir ekilde tanmlayan ifadeyi sein  Fracking.pdf
Doal gaz doru bir ekilde tanmlayan ifadeyi sein Fracking.pdfadamsapparelsformen
 
Do it in Java Problem4 Natural Language Processing Writ.pdf
Do it in Java Problem4 Natural Language Processing Writ.pdfDo it in Java Problem4 Natural Language Processing Writ.pdf
Do it in Java Problem4 Natural Language Processing Writ.pdfadamsapparelsformen
 
Diyelim ki mevcut d politikann aksine ABD ve Meksika farkl .pdf
Diyelim ki mevcut d politikann aksine ABD ve Meksika farkl .pdfDiyelim ki mevcut d politikann aksine ABD ve Meksika farkl .pdf
Diyelim ki mevcut d politikann aksine ABD ve Meksika farkl .pdfadamsapparelsformen
 
Do it in Java Please ExamPrep4_Spring2023 Source Packages lo.pdf
Do it in Java Please ExamPrep4_Spring2023 Source Packages lo.pdfDo it in Java Please ExamPrep4_Spring2023 Source Packages lo.pdf
Do it in Java Please ExamPrep4_Spring2023 Source Packages lo.pdfadamsapparelsformen
 
DNA replikasyonundan geen bakterileri moleklleri izlemeni.pdf
DNA replikasyonundan geen bakterileri moleklleri izlemeni.pdfDNA replikasyonundan geen bakterileri moleklleri izlemeni.pdf
DNA replikasyonundan geen bakterileri moleklleri izlemeni.pdfadamsapparelsformen
 
DNA exits mostly as a double stranded molecule Because of .pdf
DNA exits mostly as a double stranded molecule Because of .pdfDNA exits mostly as a double stranded molecule Because of .pdf
DNA exits mostly as a double stranded molecule Because of .pdfadamsapparelsformen
 
Dk bir gerileme R2 u anlama gelir A sol taraftaki d.pdf
Dk bir gerileme  R2  u anlama gelir   A  sol taraftaki d.pdfDk bir gerileme  R2  u anlama gelir   A  sol taraftaki d.pdf
Dk bir gerileme R2 u anlama gelir A sol taraftaki d.pdfadamsapparelsformen
 
Divisional Income Statements and Retum on fnvestment Analysi.pdf
Divisional Income Statements and Retum on fnvestment Analysi.pdfDivisional Income Statements and Retum on fnvestment Analysi.pdf
Divisional Income Statements and Retum on fnvestment Analysi.pdfadamsapparelsformen
 
discussing Monopolies and Externalities Positive and Negati.pdf
discussing Monopolies and Externalities Positive and Negati.pdfdiscussing Monopolies and Externalities Positive and Negati.pdf
discussing Monopolies and Externalities Positive and Negati.pdfadamsapparelsformen
 
Distinguish time clauses from conditions and name the types .pdf
Distinguish time clauses from conditions and name the types .pdfDistinguish time clauses from conditions and name the types .pdf
Distinguish time clauses from conditions and name the types .pdfadamsapparelsformen
 

Plus de adamsapparelsformen (20)

Doctors Diaries is a 1990s documentary following a group of.pdf
Doctors Diaries is a 1990s documentary following a group of.pdfDoctors Diaries is a 1990s documentary following a group of.pdf
Doctors Diaries is a 1990s documentary following a group of.pdf
 
Dont respond to this questionGive only the references Bib.pdf
Dont respond to this questionGive only the references Bib.pdfDont respond to this questionGive only the references Bib.pdf
Dont respond to this questionGive only the references Bib.pdf
 
dogh dogcpp maincpp For the code above How many MyCo Cop.pdf
dogh dogcpp maincpp For the code above How many MyCo Cop.pdfdogh dogcpp maincpp For the code above How many MyCo Cop.pdf
dogh dogcpp maincpp For the code above How many MyCo Cop.pdf
 
Donald Lyles 52year old male was admitted yesterday eveni.pdf
Donald Lyles 52year old male was admitted yesterday eveni.pdfDonald Lyles 52year old male was admitted yesterday eveni.pdf
Donald Lyles 52year old male was admitted yesterday eveni.pdf
 
Domes and basins In some folds Inliers and outliersFigur.pdf
Domes and basins  In some folds Inliers and outliersFigur.pdfDomes and basins  In some folds Inliers and outliersFigur.pdf
Domes and basins In some folds Inliers and outliersFigur.pdf
 
Dolce is an Italian company selling highend turnkey kitchen.pdf
Dolce is an Italian company selling highend turnkey kitchen.pdfDolce is an Italian company selling highend turnkey kitchen.pdf
Dolce is an Italian company selling highend turnkey kitchen.pdf
 
Do This Consider the partial class declarations below A co.pdf
Do This Consider the partial class declarations below A co.pdfDo This Consider the partial class declarations below A co.pdf
Do This Consider the partial class declarations below A co.pdf
 
Doede Corporation uses activitybased costing to compute pro.pdf
Doede Corporation uses activitybased costing to compute pro.pdfDoede Corporation uses activitybased costing to compute pro.pdf
Doede Corporation uses activitybased costing to compute pro.pdf
 
Does anyone have a photo of the completed moon map I need t.pdf
Does anyone have a photo of the completed moon map I need t.pdfDoes anyone have a photo of the completed moon map I need t.pdf
Does anyone have a photo of the completed moon map I need t.pdf
 
Document your result for H influenzae below 1 What is the.pdf
Document your result for H influenzae below 1 What is the.pdfDocument your result for H influenzae below 1 What is the.pdf
Document your result for H influenzae below 1 What is the.pdf
 
Doal gaz doru bir ekilde tanmlayan ifadeyi sein Fracking.pdf
Doal gaz doru bir ekilde tanmlayan ifadeyi sein  Fracking.pdfDoal gaz doru bir ekilde tanmlayan ifadeyi sein  Fracking.pdf
Doal gaz doru bir ekilde tanmlayan ifadeyi sein Fracking.pdf
 
Do it in Java Problem4 Natural Language Processing Writ.pdf
Do it in Java Problem4 Natural Language Processing Writ.pdfDo it in Java Problem4 Natural Language Processing Writ.pdf
Do it in Java Problem4 Natural Language Processing Writ.pdf
 
Diyelim ki mevcut d politikann aksine ABD ve Meksika farkl .pdf
Diyelim ki mevcut d politikann aksine ABD ve Meksika farkl .pdfDiyelim ki mevcut d politikann aksine ABD ve Meksika farkl .pdf
Diyelim ki mevcut d politikann aksine ABD ve Meksika farkl .pdf
 
Do it in Java Please ExamPrep4_Spring2023 Source Packages lo.pdf
Do it in Java Please ExamPrep4_Spring2023 Source Packages lo.pdfDo it in Java Please ExamPrep4_Spring2023 Source Packages lo.pdf
Do it in Java Please ExamPrep4_Spring2023 Source Packages lo.pdf
 
DNA replikasyonundan geen bakterileri moleklleri izlemeni.pdf
DNA replikasyonundan geen bakterileri moleklleri izlemeni.pdfDNA replikasyonundan geen bakterileri moleklleri izlemeni.pdf
DNA replikasyonundan geen bakterileri moleklleri izlemeni.pdf
 
DNA exits mostly as a double stranded molecule Because of .pdf
DNA exits mostly as a double stranded molecule Because of .pdfDNA exits mostly as a double stranded molecule Because of .pdf
DNA exits mostly as a double stranded molecule Because of .pdf
 
Dk bir gerileme R2 u anlama gelir A sol taraftaki d.pdf
Dk bir gerileme  R2  u anlama gelir   A  sol taraftaki d.pdfDk bir gerileme  R2  u anlama gelir   A  sol taraftaki d.pdf
Dk bir gerileme R2 u anlama gelir A sol taraftaki d.pdf
 
Divisional Income Statements and Retum on fnvestment Analysi.pdf
Divisional Income Statements and Retum on fnvestment Analysi.pdfDivisional Income Statements and Retum on fnvestment Analysi.pdf
Divisional Income Statements and Retum on fnvestment Analysi.pdf
 
discussing Monopolies and Externalities Positive and Negati.pdf
discussing Monopolies and Externalities Positive and Negati.pdfdiscussing Monopolies and Externalities Positive and Negati.pdf
discussing Monopolies and Externalities Positive and Negati.pdf
 
Distinguish time clauses from conditions and name the types .pdf
Distinguish time clauses from conditions and name the types .pdfDistinguish time clauses from conditions and name the types .pdf
Distinguish time clauses from conditions and name the types .pdf
 

Dernier

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Dernier (20)

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

DO NOT USE THE ANSWERS ON OTHER CHEGG ANSWERS TO ANSWER THIS.pdf

  • 1. DO NOT USE THE ANSWERS ON OTHER CHEGG ANSWERS TO ANSWER THIS QUESTION. THEY ARE INCORRECT. ITSC 1212 Module 8 Lab - the Turtle Games! In this lab, we will be combining two of the concepts from your prepwork (number finding and Turtle drawing) to create a sort of game. If you havent completed that work yet, it would be a good idea to take a few minutes and review those tasks before starting the lab. Concepts covered in this lab: For and While loops Method calling Booleans Required files or links ITSC1212Lab8.java visualizeGuess.txt Part A: Designing the base game 1. The goal of the game were going to create in the lab is to create a World and drop an invisible Turtle somewhere in that World. The players goal is to guess numbers until they have successfully located the invisible Turtle. 2. Start by opening the ITSC1212Lab8.java file. Take a moment and review the contents of this file. Notice that above the main method were creating two random numbers, randomX and randomY, and then creating a World object. Were creating those variables outside of the main method so that we can access those variables in additional methods well be adding later in the lab. This is related to what is known as variable scope. Scope refers to the visibility of variables. That is, which parts of your programs/methods can see a variable and refer to or use it? This topic will be covered in more detail in a later unit. For now, remember the basic rule that variables are known within the block where theyre defined and any blocks defined inside that block. 3. Also notice that both of our random number variables are being initialized to 0. These are the variables that will determine the random position of the Turtle, and will be different each time the game is played. Its important to consider that the play space of this World is 500x500, meaning there are 250,000 possible positions for our invisible Turtle. To make things easier, lets limit these possible positions to only multiples of 5 and we want to limit it to a value of starting at 5 and ending at 495 so the turtle is not on the edge. Take some time to think about how you might use Math.random() as you have in past assignments to generate a random multiple of 5 from 5-495. If you get stuck here for more than a few minutes, skip to the bottom of this document for the solution (please do actually attempt this though, its really good practice ). 4. Now that we have our World and our random positions, we can advance to the main method and actually create our game. 5. The first thing we need to do here is actually create the Turtle were going to be working with. Start by creating a Turtle, as well as a Scanner object with which we can take user input. 6. Use the Turtle method .setVisible() to set your Turtles visibility to false.
  • 2. 7. We now have an invisible Turtle at some unknown location inside our World with possible values for its X and Y coordinates between 5 - 495. The next step is going to be collecting the user guess for X and Y. To do so we need a couple of variables to keep track of the user's guess. We will use the values of those variables and compare them to the random values generated so it would be a good idea to initialize them to values our program will never generate randomly (i.e., any integer that is less than 5 or greater than 495) Lets take a moment and evaluate all the different pieces we have. We have a World, a Turtle at an unknown location inside that world, two variables that contain the X/Y position of the Turtle, and the users guesses for that X/Y. In order to collect user guesses we need to utilize the Scanner class to capture what they enter. Add the following lines to create an object that can help us accomplish this: 8. The next bit is up to you, and will be a good challenge to your ability to write both a while loop, as well as your understanding of boolean expressions. Take your time thinking through this process and the outcomes as you develop this logic. 9. Translate the following pseudocode into Java (the indentation of this is a hint to the necessary structure). While guessX does not equal randomX OR guessY does not equal randomY If guessX does not equal randomX Prompt the user for a guess of the X value Save that to guessX If guessX was too high Inform the player of that Alternatively, if it was too low Inform the player of that. If guessX is correct Inform the player of that If guessY does not equal randomY Prompt the user for a guess of the Y value Save that to guessY If guessY was too high Inform the player of that. Alternatively, if it was too low Inform the player of that. If guessY is correct Inform the player of that Notice that this logic makes sense since we initialized the guess variables to values where both parts of the compound conditional of the while loop will always be false everytime the program starts. If this wasnt the case we might run into scenarios where the user does not get the prompt to enter a guess and start playing. As a reminder heres how you would use the Scanner object to capture the user input: When you are satisfied with how your loop is written (we will test it later), continue on.
  • 3. 10. The beauty of structuring our code this way is that it will continue to ask the user for guesses until both the X and Y are correct, and once one is correct it will only ask for new input for the value that is still incorrect. This while loop will ONLY break once the Turtle has been found. 11. Two important things to think about: Why is a while loop more appropriate here than a for loop? Why are we using an OR in the while loop instead of AND? We are using a while loop because we know that once the while loop has broken that the Turtle has been found. A while loop is more appropriate here since we do not need to loop a specific number of times. We are using an OR because the logic that is controlled by the loop condition is responsible for determining that both of the x and y positions are guessed correctly. If we use an AND we will break out of the loop once one value is guessed correctly (i.e., no longer incorrect). 12. After the loop is done the user has guessed both x and y positions of our turtle and we can add our win code. Specifically, what we want to have happen is the User be notified of their correct guesses, and the invisible Turtle should appear. Add the following lines to do this. Feel free to add any kind of formatting or additional print statements to really jazz up this win message. 13. Now that the basic pieces of this code are all in place, we need to test it so we can tell if your while loop and the statements within it were written correctly. 14. Before you run the code, add two print statements to the beginning of your code that will print the correct coordinates of the Turtle (i.e., the randomly generated values). This must happen before your while loop and NOT inside or after it. Its important to know the correct location of the Turtle during this testing phase so we can test different scenarios. 15. Now run your program and test the following scenarios: Guess is too low (is the user instructed to guess higher next time?) Guess too high (is the user instructed to guess lower next time?) Make one correct guess (is that value skipped next round?) Make both correct guesses (is the win message displayed?) Remember that you can click the Open Desktop button to view the World and Turtle. 16. When you are satisfied that this game is working correctly, show your code to a TA or instructor to receive credit for this section. Part B: Add in color blocks 1. One of the issues with this game is that it doesnt feel very responsive. Part of the problem is that we have this World object but were not really doing anything with it. What we could do in this situation is use the World to visually block off areas where we know the Turtle cant be anymore based on previous guesses. For example, if a guess for X was 300 and that was determined to be too high then it doesnt help the user to
  • 4. guess a number that is between 300-495 so we block that area.. 2. Open the file visualizeGuess.txt and copy its contents (the method) into the ITSC1212Lab8 class file after ((i.e. below not inside) the main method. This is an important step so pay extra attention and make sure the class structure is correct. 3. Most of this code is already written for you, but you have 4 for loops that must be corrected. Before you jump into that, take a moment and make sure you understand what this code is attempting to do. Note that any time you need to use the Color class you need to import it. That is why we have added the import for the Color class at the start of the file. In a nutshell, what this code does is block off areas where the hidden Turtle cannot be by using a second invisible Turtle to draw a series of black lines in those areas. Heres a visual breakdown of this process describing what happens when an X guess is too high. Here are some screenshots of sample testing: 4. The last thing to add after youve written the logic for the for loops is to call these methods so we can test them and see them in action. You will want to add these method calls back in the main method below or above each print statement telling the user of their incorrect guess. For example, the condition block that determines guessX was too low would look like so: 5. Writing the correct for loops to make this process work will likely take some trial and error. Test your code frequently, making sure that the correct areas are blocked off each time. **Important note** The point 0,0 in the World is the top left corner of the box. Intuitively, we want to place that at the bottom left, because were used to that from math classes Bonus: Add a new game mode 1. In this section, what you will do is give the player the option to play in a Close-enough/Easy mode. The goal of this mode is: a. Allow the user to select their desired game mode b. If the user has selected the Easy mode: i. Any guesses within 20 pixels of the correct X or Y position will be counted as correct 2. Think about the flow of the game, and what, if anything, would need to change at each step if the Easy mode were to be selected. We want you to think about how these two modes could live side by side, rather than just copy and pasting the first version and altering it. 3. Here are some helpful hints we think will be helpful for how to make this work: Add boolean variables to track whether or not a guess is correct. The reason you may find this helpful is because the two game modes have different criteria for what a correct guess is. Your code, at this stage, is likely using a guessX == randomX to test correctness, and obviously this doesnt work for the Easy mode. By using boolean variables, you can have two distinct ways of establishing what a correct answer is and store that result based on which game mode is being played. You
  • 5. can also use these booleans to control your while loop, which vastly simplifies the way that loop looks. Leave the code that says a guess was too high or too low alone. Altering the logic of this part of the loop is... A lot. Focus on the aspects that determine if an answer was right or not. Think about how you can alter the logic where a correct guess was established. Consider this partial section of the pseudocode from Part A: If guessY does not equal randomY Prompt the user for a guess of the Y value Save that to guessY If guessY is correct Inform the player of that Or, If guessY was too high Inform the player of that. Alternatively, if it was too low Inform the player of that. You could alter it so it functions like this: If guessY does not equal randomY Prompt the user for a guess of the Y value Save that to guessY If guessY is correct Or if Easy Mode is on and guessY is within 20 pixels of the correct location Inform the player of that Update the value of the boolean correctY Or, If guessY was too high Inform the player of that. Alternatively, if it was too low Inform the player of that. Once this works, consider other rearrangements you could make. 4. Once youre satisfied with your Easy mode, show your work to an instructor or TA to receive credit. Solution for Part A step # 3 // generate random X and Y for the turtle limit to multiples of 5 randomX = ((int)(Math.random() * 99) + 1) * 5; randomY = ((int)(Math.random() * 99) + 1) * 5;