Question: Java program. I am trying to find a way to restart the mainscript, if the player crashes. So it would say You crashed. Press space

Java program.

I am trying to find a way to restart the mainscript, if the player crashes. So it would say "You crashed. Press space to return to menu." When I try to insert it, the loop causes it to reload the menu infinitely.

Java program. I am trying to find a way to restart the

public static void main(String[] args) throws InterruptedException { 25e 26 // Checkpoint has not been crossed from start middleCrossed = false; reverse = false restart = false pos(X) = (int)(n/2.0); pos[] = n-4; distance]0; distance1]0; Assume clockwise movement Implements start position // Implements distance of zero 28 29 Menu) while(!StdDraw.mousePressed) /Runs menu 35 36 Waits for mouse click int corK = (int)Math.round(StdDraw. mouseX()); int corV = (int)Math. round(StdDraw. mousey()); // Read position of mouse Implements track 1, if first button is pressed if (StdDraw. mousePressed() && (coPX >= n/4-3 && corK = n/2-1 && corV n/2+1)) { 41 42 Tracki: if (Crashi(pos[XI,posLYM)) Adds loop for new input if position is within the track Keys); if (!middleCrossed && pos[X) 45 > n/4 && pos(X) n-n/4 && pos[] n-n/4) { // Checks IS checkpoint is crossed 0 / Checks if moves are counterclockwise else if ((middleCrossed && !reverse && posLn/2 && pos[M > n-n/4) I1 (middleCrossed && reverse && posn/2 && posLM n-n/4)) Penoption(6); StdDraw. text(n/2, n/2, "You Finished!"); Penoption(7); StdDraw. text(n/2, n/3, "You used " moves"moves."; break; / Breaks loop and shows the number of moves used for // completing the track 51 53 56 else StdDraw.text(n/2, n/2, "You crashed"); // Breaks loop if position hits or passes the outline of the track 58 } while (true); 61 63 65 Implements track 1, if second button is pressed else if Track2); } (StdDraw . mousePressed&L (corK >-n-n/4-3 && corK -n/2-1 && corV n/2+1)) { e if (Crash2(posL,pos[M)) 1 Adds loop for new input if position is within the track Keys); if (!middleCrossed && posLXIn/4 && posL %; // Checks if moves are counterclockwise } ((middleCrossed && ! reverse && pos[X) >-n/2 && pos[Y) n-n/4) (middleCrossed && reverse && pos[X) II > // Breaks loop and shows the number of moves used for // completing the track 74 75 76 else 79 81 83 85 PenOption(6); StdDraw. text(n/2, n/2, "You crashed!"); // Breaks loop if position hits or passes the outline of the track ! while (true)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!