Change the following code so that it checks the following 3 conditions:
1. there is no space between each cells (imgs)
2. even if it is resized, the components wouldn't disappear
3. The GameGUI JPanel takes all the JFrame space, so that there shouldn't be extra space appearing in the frame other than the game.
Main():
Labyrinth labyrinth = new Labyrinth(10);
Player player = new Player(9, 0);
Dragon dragon = new Dragon(9, 9);
JFrame frame = new JFrame("Labyrinth Game");
GameGUI gui = new GameGUI(labyrinth, player, dragon);
frame.add(gui);
frame.setSize(600, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
public class GameGUI extends JPanel {
private final Labyrinth labyrinth;
private final Player player;
private final Dragon dragon; //labyrinth, player, dragon are just public classes
private final ImageIcon playerIcon = new ImageIcon("data/images/player.png");
private final ImageIcon dragonIcon = new ImageIcon("data/images/dragon.png");
private final ImageIcon wallIcon = new ImageIcon("data/images/wall.png");
private final ImageIcon emptyIcon = new ImageIcon("data/images/empty.png");
public GameGUI(Labyrinth labyrinth, Player player, Dragon dragon) {
this.labyrinth = labyrinth;
this.player = player;
this.dragon = dragon;
setFocusable(true);
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
char move = switch (e.getKeyCode()) {
case KeyEvent.VK_W -> 'W';
case KeyEvent.VK_S -> 'S';
case KeyEvent.VK_A -> 'A';
case KeyEvent.VK_D -> 'D';
default -> ' ';
};
if (move != ' ') {
player.move(move, labyrinth);
dragon.move(labyrinth);
repaint();
checkGameState();
}
}
});
}
private void checkGameState() {
if (player.getX() == labyrinth.getSize() - 1 && player.getY() == labyrinth.getSize() - 1) {
JOptionPane.showMessageDialog(this, "You escaped! Congratulations!");
System.exit(0);
}
if (Math.abs(player.getX() - dragon.getX()) <= 1 &&
Math.abs(player.getY() - dragon.getY()) <= 1) {
JOptionPane.showMessageDialog(this, "The dragon caught you! Game Over.");
System.exit(0);
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int cellSize = 50;
for (int i = 0; i < labyrinth.getSize(); i++) {
for (int j = 0; j < labyrinth.getSize(); j++) {
if (labyrinth.getCell(i, j).isWall()) {
wallIcon.paintIcon(this, g, j * cellSize, i * cellSize);
} else if(!labyrinth.getCell(i, j).isWall()){
emptyIcon.paintIcon(this, g, j * cellSize, i * cellSize);
}
}
}
playerIcon.paintIcon(this, g, player.getY() * cellSize, player.getX() * cellSize);
dragonIcon.paintIcon(this, g, dragon.getY() * cellSize, dragon.getX() * cellSize);
}
}

to generate a solution
a solution
- Programming languages such as C#, Java, and Visual Basic are ___________ languages. machine high-level low-level uninterpretedarrow_forward(Practice) You’re given the job of planting a vegetable garden. Determine a set of subtasks to accomplish this task. (Hint: One subtask is planning the garden’s layout.)arrow_forward(Practice) You’re given the job of preparing a complete meal for five people next weekend. Determine a set of subtasks to accomplish this task. (Hint: One subtask, not necessarily the first, is buying the food.)arrow_forward
- In the game Rock paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: Rock beats scissors, because a rock can break a pair of scissors. Scissors beats paper, because scissors can cut paper. Paper beats rock, because a piece of paper can cover a rock. Create a game in which the computer randomly chooses rock, paper, or scissors. Let the user enter a character, r, p, or s, each representing one of the three choices. Then, determine the winner. Save the application as RockPaperScissors.cs.arrow_forwardThe grammar and spelling rules of a programming language constitute its _________. logic variables class syntaxarrow_forwardOf the following languages, which is least similar to C#? a. Java b. Visual Basic c. C++ d. machine languagearrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageCOMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE LMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT



