Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA CODE can you help to change this code to ( do not make a new one, need to u

ID: 3776636 • Letter: J

Question

JAVA CODE

can you help to change this code to ( do not make a new one, need to use this old code )

Running of the Bulls game.

In our version of the Running of the Bulls, one fool runs through Pamplona trying to avoid some number of bulls. If the fool makes it to the exit square without being gored, he wins; if a bull catches him first, he loses. When one of these events occurs, a message should appear next to the Run button.

The fool's movement must be controlled by the four scroll keys (use an event handler that handles a KeyEvent and find the key strokes using the the KeyCode enum). Make sure he cannot move through walls. Use a Coordinate variable to track the fool's location. I did not use a Fool class, but you may use one if you like.

You will need a Bull class. Among other things, it will contain a method to determine the bull's next step. If he can see the fool, he moves towards him. If the bull cannot see the fool, he moves toward the fool's last known location if possible, otherwise he moves randomly. Like the fool, the bulls cannot move through walls.

The bulls should move faster than the fool. The best way to implement this is for the bulls to take more than one move for each fool move. You can code this by writing a method in StreetMap that calls each bull's move method, and calling the StreetMap method some number of times from inside the fool move event handler (the one that responds to the scroll keys.) Since the bulls move faster, the fool should get a few free moves before the Bulls begin moving.

Use css to make it obvious at all times where the bulls and the fool are.

Create an event handler for the run button which returns both the fool and the bulls to the starting point. You may also have the button also create a new map.

Experiment with the game to make it difficult, but still possible, for the fool to escape unharmed. Design Main so that you can set parameters there for the number of turns in the head start, the number of bulls, and the number of bull moves per fool move. If you want more practice with GUI building, provide a way to set these parameters with user input.

///////////////////////////////////////////////////////////////

MazeGuiPane.java

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class MazeGuiPane extends Application {
private GridPane grid = new GridPane();
private BorderPane border = new BorderPane();
private Scene sc = new Scene(border);
public Label[][] labelGridArray = new Label[20][20];
private StreetMap map = new StreetMap();
int col;
int row;

public void start(Stage primary) {

sc.getStylesheets().add("style.css");
grid.getStyleClass().add("grid-style");
border.getStyleClass().add("border-style");
Label mainTitle = new Label("Map Of Pamplona");
mainTitle.getStyleClass().add("white-text");
Button butt = new Button("RUN!");
VBox vBox = new VBox();
HBox buttHBox = new HBox();
HBox titleBox = new HBox();
VBox titleVBox = new VBox();
VBox buttVBox = new VBox();

map.makeGrid();

for (col = 0; col < 20; col++) {
for (row = 0; row < 20; row++) {
Label square = new Label();
if (map.gridArray[col][row].getValue() == ' '){
square.getStyleClass().add("default-box");
}
else if(map.gridArray[col][row].getValue() == 'S') {
square.setText("Start");
square.getStyleClass().add("start-end");
}
else if(map.gridArray[col][row].getValue() == 'E') {
square.setText("End");
square.getStyleClass().add("start-end");
}
else {
square.getStyleClass().add("wall");
}
// System.out.println(map.gridArray[col][row]);
// System.out.println("label: " + labelGridArray[col][row] );

square.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
row = grid.getRowIndex(square);
col = grid.getColumnIndex(square);
if(map.gridArray[col][row].getValue() == 'W'){
square.getStyleClass().removeAll("wall");
square.getStyleClass().add("default-box");
map.gridArray[col][row].setTier(row); map.gridArray[col][row].setColumn(col); map.gridArray[col][row].setValue(' ');
}
else {
square.getStyleClass().removeAll("default-box");
square.getStyleClass().add("wall");
map.gridArray[col][row].setTier(row); map.gridArray[col][row].setColumn(col); map.gridArray[col][row].setValue('W');
}
}
});

labelGridArray[col][row] = square;
grid.add(square, col, row);
}
}
titleBox.getStyleClass().add("title");
titleBox.getChildren().add(mainTitle);
titleVBox.getChildren().add(titleBox);

buttHBox.getStyleClass().add("button-style");
buttHBox.getChildren().add(butt);
buttVBox.getChildren().add(buttHBox);

vBox.getChildren().add(grid);

border.setTop((titleBox));
border.setCenter(vBox);
border.setBottom(buttVBox);


primary.setScene(sc);
primary.show();
}


public static void main (String[] args) {
launch(args);
}}

=========================================================

Coordinate.java

==================================================================

StreetMap.java

==================================================================

style.css

Explanation / Answer

//this code is used to find fools location using mouse events when mouse is moved //

import java.awt.*;

import java.awt.event.*;

import java.applet.Appet;

class findFoolloc extendsApplet implements MouseListener MouseMotionListener{

int xco,yco;

string event="";

public void init()

{

addMouseListener(this);

addMouseMotionListener(this);

}

public void mousePressed(MouseEvent me)

{

xco=me.getxco();

yco=me.getyco();

event="location of fool";

}

//controlling fools movement by scroll keys

import java.applet.Applet;

import java.awt.Graphics;

import java.awt.event.KeyListener;

import java.awt.event.KyEvent;

public class foolsMovement extends Applet implements KeyListener

{

int xco,yco;

string loc="";

public void init()

{

addKeyListener(this);

}

public void keyPressed(keyEvent k)

public void keyReleased(keyEvent k)

public string keyTyped(KeyEvent k)

{

loc=k.getchar();

if(loc=='up')

str="moving up";

xco=k.getx();

yco=k.gety();

return xco,yco;

elseif(loc='down')

str="moving down";

xco=k.getx();

yco=k.gety();

return xco,yco;

elseif(loc='right')

str="moving right";

xco=k.getx();

yco=k.gety();

return xco,yco;

else

str="moving left";

xco=k.getx();

yco=k.gety();

return xco,yco;

repaint();

}

public void paint(Graphics g)

{

show status("bull is "+loc);

}

///method for movement of bull:-

public class bullsMovement extends Applet implements KeyListener

{

string loc="";

int xco,yco;

public void init()

{

addKeyListener(this);

}

public void keyPressed(keyEvent k)

public void keyReleased(keyEvent k)

public int keyTyped(KeyEvent k)

{

loc=k.getchar();

if(loc=='up')

str="moving up";

xco=k.getxco();

yco=k.getyco();

return xco,yco;

elseif(loc='down')

str="moving down";

xco=k.getxco();

yco=k.getyco();

return xco,yco;

elseif(loc='right')

str="moving right";

xco=k.getxco();

yco=k.getyco();

return xco,yco;

else

str="moving left";

xco=getxco();

yco=getyco();

return xco,yco;

repaint();

}

public void paint(Graphics g)

{

show status("bull is "+loc);

}

}

public class compareBullsFools extends foolsMovement bullsMovement{

foolsMovement obj1=new foolsMovement();

bullsMovement obj2=new bullsMovement();

obj1.foolsMovement();

obj2.bullsMovement();

if(obj1.foolsMovement() .equals(obj2.bullsMovement )

{

System.out.printl("crash the fool");

}

else{

{

system.out.println("move random");

}

//method to implement bulls moving fater than fools:-

int foolsxco= obj1.getxco();

int foolsyco=obj1.getyco();

int bullsxco=obj2.getxco();

int bullsyco=obj2.getyco();

if(foolsxco==bullsxco&&foolsyco==bullsyco)

{

system.out.println("crash");

}

for(int i=0;i<foolsxco;i++)

{

bullsxco++;}

for(int j=0;j<foolsyco;j++)

{

bullsyco++;

}

}

//if both bulls and fool crash then following should be done:

if(foolsxco==bullsxco&&foolsyco==bullsyco)

{

system.out.pritnln("move to start game over");

button b=new button();

b.addActionListener(this);

system.out.println("press the button");

public void actionPerformed(ActionEvent e){

streetmap ob3=new streetmap();

ob3.streetmap();

k.setbullxco=0;

k.setbullyco=0;

k.setfoolsxco=2;//since they are provided with 2 xtra moves

s.setfoolsyco=2;

}