Make the following game user friendly with GUI, with some simple graphics
The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units.
Cell Class:
public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return isWall; } public void setWall(boolean isWall) { this.isWall = isWall; } @Override public String toString() { return isWall ? "#" : "."; } }
Labyrinth Class:
import java.util.Random; public class Labyrinth { private final int size; private final Cell[][] grid; public Labyrinth(int size) { this.size = size; this.grid = new Cell[size][size]; generateLabyrinth(); } private void generateLabyrinth() { Random rand = new Random(); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { // Randomly create walls and paths grid[i][j] = new Cell(rand.nextBoolean()); } } // Ensure start and end are open paths grid[0][0].setWall(false); grid[size - 1][size - 1].setWall(false); } public Cell getCell(int x, int y) { return grid[x][y]; } public int getSize() { return size; } public void display(Player player, Dragon dragon) { for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (i == player.getX() && j == player.getY()) { System.out.print("P "); } else if (i == dragon.getX() && j == dragon.getY()) { System.out.print("D "); } else { System.out.print(grid[i][j] + " "); } } System.out.println(); } } }
Player Class:
public class Player { private int x; private int y; public Player(int startX, int startY) { this.x = startX; this.y = startY; } public int getX() { return x; } public int getY() { return y; } public void move(char direction, Labyrinth labyrinth) { int newX = x; int newY = y; switch (direction) { case 'W': newX--; break; // Move up case 'S': newX++; break; // Move down case 'A': newY--; break; // Move left case 'D': newY++; break; // Move right } if (newX >= 0 && newX < labyrinth.getSize() && newY >= 0 && newY < labyrinth.getSize() && !labyrinth.getCell(newX, newY).isWall()) { x = newX; y = newY; } } }
Dragon Class:
import java.util.Random; public class Dragon { private int x; private int y; private char direction; private final Random rand = new Random(); public Dragon(int startX, int startY) { this.x = startX; this.y = startY; chooseDirection(); } public int getX() { return x; } public int getY() { return y; } public void move(Labyrinth labyrinth) { int newX = x; int newY = y; switch (direction) { case 'W': newX--; break; case 'S': newX++; break; case 'A': newY--; break; case 'D': newY++; break; } if (newX >= 0 && newX < labyrinth.getSize() && newY >= 0 && newY < labyrinth.getSize() && !labyrinth.getCell(newX, newY).isWall()) { x = newX; y = newY; } else { chooseDirection(); // Choose a new direction if blocked } } private void chooseDirection() { char[] directions = {'W', 'S', 'A', 'D'}; direction = directions[rand.nextInt(directions.length)]; } }
Game Class:
import java.util.Scanner; public class Game { public static void main(String[] args) { int size = 10; // Example size Labyrinth labyrinth = new Labyrinth(size); Player player = new Player(0, 0); Dragon dragon = new Dragon(size - 1, size - 1); Scanner scanner = new Scanner(System.in); boolean running = true; while (running) { labyrinth.display(player, dragon); if (player.getX() == size - 1 && player.getY() == size - 1) { System.out.println("Congratulations! You escaped the labyrinth!"); break; } if (Math.abs(player.getX() - dragon.getX()) <= 1 && Math.abs(player.getY() - dragon.getY()) <= 1) { System.out.println("The dragon caught you! Game Over!"); break; } System.out.print("Move (W/A/S/D): "); char move = scanner.next().toUpperCase().charAt(0); player.move(move, labyrinth); dragon.move(labyrinth); } scanner.close(); } }
Step by stepSolved in 2 steps with 3 images
- The goal of Snake is to create a snake as long as possible. This is achieved by guiding the snake to an apple on the game board. The snake cannot stop moving, and dies whenever it hits something (excluding apples). Because the snake is growing longer and longer as the game progresses, it gets increasingly difficult to avoid collisions with the snake itself. The player can change the direction of the head of the snake by using the arrow keys. At step in the game, there is always an apple somewhere on the board. If the snake eats an apple, the snake becomes one cell longer. A new apple is placed on a random location, excluding all places covered by the snake. When the snake reaches a side of the game board, it re-emerges at the opposite end.arrow_forwardThe game is played in the magic maze, as shown below. The squares are flaming lava pools. If you try to cross them you will die. The grid lines are passageways and are safe to travel in. You can start at any location on the grid but must travel in the passageways. You may travel as far as you want in any direction, but once you turn, you must repeat that distance and you may only make left turns. You may not reverse direction inside the tight passageways. You must end up at the same spot you started at. If you successful, then you gain a magic coin, which automatically appears. You can start over again and again in a different or same starting spot and earn new magic coins, but the routes you take must differ somehow for each magic coin. That is, no magic coins for the exact same route as previously done. If the route varies in any way (perhaps it is the same starting location and ending location as a previous route, but longer), it will earn a new magic coin. Mad Madame Mim has…arrow_forwardRead this case study carefully ! A team of developers plans to make a game with the adventure genre . To play the game , the user is required to enter a name . The game description is as follows : 1. The player must choose a character ( from 3 optional characters ) at the beginning of the game 2. The character wears a war hat , has a sword weapon , armor , and the ability to attack the opponent strongly . 3. Each character can move forward , backward , left , and right . In addition , characters can perform shooting , hitting , or kicking actions . 4. Users are required to complete challenges in each level as a condition to proceed to the next level . 5. In each level , the character must kill all the monsters in front of or above with the actions he can do 6. As a reward , users can collect items , such as stars , weapons , and power - ups . 7. There are five levels in the game . Create a flowchart to model the gameplay ! *arrow_forward
- when coding a chess game, implement the following method: isInCheck(Side s): Returns true if the king of side s is attacked by any of the opponent’s pieces, i.e., if in the current board state, any of the opponents pieces can move to where the king is. Otherwise, it returns false. Note that this method is only used to warn the player when they are in check. You can use the GUI to test if this is working. public boolean isInCheck(Side side) { // TODO write this method return false; } public enum Side { BLACK, WHITE; public static Side negate(Side s) { return s == Side.BLACK ? Side.WHITE : Side.BLACK; } }arrow_forwardDescription: The game is a single player scenario, in which the player’s army needs to defeat the enemy’s (AI’s) army. There are 4 possible troops for an army: Archers, Spearman, Cavaliers, Footman. Each troop has some attributes and some actions. And to avoid excessive programming and calculation, we want to treat these troops as squadrons. The player always starts with 10 squadrons of their choices: they can choose any combinations of the 4 possible troop types. Each squadron should have 100 members of that troop type. Each turn, the player is allowed to choose one of their squadrons and perform an action which is allowed by that troop type. Player and the AI take turns to make actions. The game continues until either the player or the AI has no troops left. Troop Types and Descriptions: Archers: should be able to attack from range with no casualties, meaning the attack action should not cause any damage to themselves. They should be pretty fragile to anything themselves. They…arrow_forwardEmail me the answers to the following questions. If you are not familiar with Peg Solitaire, then look it up online. Peg Solitaire is a game consisting of a playing board with 33 holes together with 32 pegs. In the picture above, the hole in the center is empty and the remaining holes contain pegs. The goal is to remove all the pieces except one, which should be in the center. A piece can be removed by jumping an adjacent piece over it into an empty hole. Jumps are permitted horizontally or vertically, but not diagonally. Your assignment consists of one required part, plus one extra credit part: 1. Explain (in words) why Breadth First Search and Iterative Deepening are not good methods for this problem.arrow_forward
- Tic-Tac-Toe For this question, you will be implementing a simple Tic-Tac-Toe game without the graphics. Here is how it works: • First, it is randomly determined if the user starts the game or the computer and this information is shown to the user. The player who starts always starts as "X". • The players (computer and the user) will then take turns in playing. The computer will choose a random empty spot on its turn. The user enters its choice in the console. • Each of the empty spots have a corresponding number that the players choose on their turn. If the user enters anything other than the number of an empty spot (not yet filled with "X" or "O"), it will not be accepted, and they will be prompted to enter a correct number. 2 4 7 8 • After each turn, two things need to be done: 1) displaying the updated board 2) checking if anyone has won (it should be printed who has won – the user or the computer). The game goes on until someone wins or until all the 9 empty spots are filled and no…arrow_forwardMinecraft is an open-world video game based on placing and interacting with 3D textured blocks. If you are not familiar with the game, each player has a personal inventory which can hold a limited number of blocks and items. Specific blocks and items can be combined on a crafting table to form new items. For example, three wheats arranged in a horizontal line on a crafting table gives the player one loaf of bread. These combinations are known as crafting recipes and the game has hundreds of them. This question deals with the recipe for making a cake. One cake requires 1 egg. 2 sugars, 3 wheats and 3 buckets of milk. Your job is to build a program to help the player determine how many cakes they can make based on the number of ingredients that they have. Crafting Figure 2: A screenshot from Minecraft showing a crafting table showing the recipe for making a cake. Your program won't make this picture, this is just showing you the rules for making a cake! Most items in the player's…arrow_forwardAVA code OVERVI EW This is a review exercise, so the primary goal of the exercise is to get your mind working and in the correct space.In this activity you will create a imaginary grid of locations that goes from −?≤?≤?, −?≤?≤?, with the coordinate (0,0) being "home". On this grid you will keep track of various animal objects as they move around the grid. Make sure that all animals stay within that grid at all timesincluding when they are created. Zwill be the map size and will control the highest number allowed on themap before wraping around. Using Java, create the following classes and primary program that uses the classes that you developed. INS T RUCT IONS Create the following classes. A N I MA L C LA SS Create an Animal class. Each animal has a name, an x and y integer coordinate. The Animal class should have at minimum the following methodsbelowbut you may want to add more if necessary: Also note, everyanimal will need to have to have “z”passed to it so that it knows how big the…arrow_forward
- Pls make the layout of the game! it is gui based! you do not neet to make the code all the way just what ever you can to get started! In java pls thank you!arrow_forwardUsing java card Graphic GUI, create a card game with a card layout in which 13 cards are displayed and if that card has the king of heart, then lose if not the player winsarrow_forwardHumans vs Goblin with objects: Land/goblins/humans. game uses a grid and has a turn based move of north, south, east, west. Comarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,