EssayGhost Assignment代写,Essay代写,网课代修,Quiz代考

EssayGhost-Essay代写,作业代写,网课代修代上,cs代写代考

一站式网课代修,论文代写

高质量的Assignment代写、Paper代写、Report代写服务

EG1hao
网课代修代上,cs代写代考
数据结构代写
您的位置: 主页 > 编程案例 > 数据结构代写 >
代做数据结构:java游戏编程代写 AVIANIGHTMARE代写 - 数据结构代做
发布时间:2021-07-25 14:01:01浏览次数:
Notes: A submission with no demonstration will not attract marks. It is fine if files are automatically renamed by Canvas.If you wish to organise special consideration, please follow the instructions below: https://www.rmit.edu.au/students/student-essentials/assessment-and-exams/assessment/special-consideration4. Existing code that you must use without making changes:For your convenience, the GameManager.java and Goal.java files can be found under Canvas→Assignments→Assignment 2. You must not modify these files (must not even add package fields). As a risk minimisation measure, periodically replace your GameManager.java and Goal.java code with the code that is provided.JAVA codeimport java.awt.Dimension;import java.awt.Graphics;import java.awt.Toolkit;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.image.BufferedImage;import java.awt.Font;import java.util.Random;import javax.swing.JFrame;import javax.swing.JOptionPane;public class GameManager extends JFrame implements KeyListener {private int canvasWidth;private int canvasHeight;private int borderLeft;private int borderTop;private BufferedImage canvas;private Stage stage;private Enemy[] enemies;private Player player;private Goal goal;private Graphics gameGraphics;private Graphics canvasGraphics;private int numEnemies;private boolean continueGame;public static void main(String[] args) {// During development, you can adjust the values provided in the brackets below// as needed. However, your code must work with different/valid combinations// of values.int choice;GameManager managerObj = new GameManager(1920, 1080);choice=JOptionPane.showConfirmDialog(null,"Play again?", "", JOptionPane.OK_CANCEL_OPTION);}while(choice==JOptionPane.OK_OPTION);System.exit(0);public GameManager(int preferredWidth, int preferredHeight) {int maxEnemies; maxEnemies=Integer.parseInt(JOptionPane.showInputDialog("How many enemies? (Default is 5)"));if (maxEnemies 0)maxEnemies=5;catch (Exception e){maxEnemies=5;this.borderLeft = getInsets().left;this.borderTop = getInsets().top;Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();if (screenSize.width preferredWidth)this.canvasWidth = screenSize.width - getInsets().left - getInsets().right;this.canvasWidth = preferredWidth - getInsets().left - getInsets().right;if (screenSize.height preferredHeight)this.canvasHeight = screenSize.height - getInsets().top - getInsets().bottom;this.canvasHeight = preferredHeight - getInsets().top - getInsets().bottom;setSize(this.canvasWidth, this.canvasHeight);setResizable(false);setDefaultCloseOperation(EXIT_ON_CLOSE);setVisible(true);addKeyListener(this);Random rng = new Random();this.canvas = new BufferedImage(this.canvasWidth, this.canvasHeight, BufferedImage.TYPE_INT_RGB);// Create a Stage object to hold the background imagesthis.stage = new Stage();// Create a Goal object with its initial x and y coordinatesthis.goal = new Goal((Math.abs(rng.nextInt()) % (this.canvasWidth)),(Math.abs(rng.nextInt()) % this.canvasHeight));// Create a Player object with its initial x and y coordinatesthis.player = new Player((Math.abs(rng.nextInt()) % (this.canvasWidth)),(Math.abs(rng.nextInt()) % this.canvasHeight));// Create the Enemy objects, each with a reference to this (GameManager) object// and their initial x and y coordinates.this.numEnemies = maxEnemies;this.enemies = new Enemy[this.numEnemies];for (int i = 0; i this.numEnemies; i++) {this.enemies[i] = new Enemy(this, Math.abs(rng.nextInt()) % (this.canvasWidth),Math.abs(rng.nextInt()) % this.canvasHeight);this.gameGraphics = getGraphics();this.canvasGraphics = this.canvas.getGraphics();this.continueGame = true;long gameStartTime=System.nanoTime();while (this.continueGame) {updateCanvas();this.stage.setGameOverBackground();double gameTime=(System.nanoTime()-gameStartTime)/1000000000.0;updateCanvas();this.gameGraphics.setFont(new Font(this.gameGraphics.getFont().getFontName(), Font.PLAIN, 50)); if (gameTime 1)this.gameGraphics.drawString("Oops! Better luck next time...", this.canvasWidth/3, this.canvasHeight/2 - 50);this.gameGraphics.drawString("You survived " + String.format("%.1f", gameTime)+ " seconds with "+this.numEnemies+" enemies!",this.canvasWidth/4, this.canvasHeight/2 - 50);return;public void updateCanvas() {long start = System.nanoTime();this.goal.performAction();// If the player is alive, this should move the player in the direction of the// key that has been pressed// Note: See keyPressed and keyReleased methods in the GameManager class.this.player.performAction();// If the enemy is alive, the enemy must move towards the Player. The Player object// is obtained via the GameManager object that is given at the time of creating an Enemy// object.// Note: The amount that the enemy moves by must be much smaller than that of// the player above or else the game becomes too hard to play.for (int i = 0; i this.numEnemies; i++) {this.enemies[i].performAction();if ((Math.abs(this.goal.getX() - this.player.getX()) (this.goal.getCurrentImage().getWidth() / 2)) (Math.abs(this.goal.getY() - this.player.getY()) (this.goal.getCurrentImage().getWidth() / 2))) {for (int i = 0; i this.numEnemies; i++) {// Sets the image of the enemy to the "dead" image and sets its status to// indicate deadthis.enemies[i].die();// Sets the background of the stage to the finished game background.this.stage.setGameOverBackground();this.continueGame = false;// If an enemy is close to the player or the goal, the player and goal dieint j = 0;while (j this.numEnemies) {if ((Math.abs(this.player.getX() - this.enemies[j].getX()) (this.player.getCurrentImage().getWidth() / 2)) (Math.abs(this.player.getY() - this.enemies[j].getY()) (this.player.getCurrentImage().getWidth()/ 2))) {this.player.die();this.goal.die();this.stage.setGameOverBackground();j = this.numEnemies;this.continueGame = false;else if ((Math.abs(this.goal.getX() - this.enemies[j].getX()) (this.goal.getCurrentImage().getWidth() / 2)) (Math.abs(this.goal.getY() - this.enemies[j].getY()) (this.goal.getCurrentImage().getWidth()/ 2))) {this.player.die();this.goal.die();this.stage.setGameOverBackground();j = this.numEnemies;this.continueGame = false;try {// Draw stagethis.canvasGraphics.drawImage(stage.getCurrentImage(), 0, 0, null);// Draw goalthis.canvasGraphics.drawImage(this.goal.getCurrentImage(),this.goal.getX() - (this.goal.getCurrentImage().getWidth() / 2),this.goal.getY() - (this.goal.getCurrentImage().getHeight() / 2), null);// Draw playerthis.canvasGraphics.drawImage(player.getCurrentImage(),this.player.getX() - (this.player.getCurrentImage().getWidth() / 2),this.player.getY() - (this.player.getCurrentImage().getHeight() / 2), null);// Draw enemiesfor (int i = 0; i this.numEnemies; i++) {this.canvasGraphics.drawImage(this.enemies[i].getCurrentImage(),this.enemies[i].getX() - (this.enemies[i].getCurrentImage().getWidth() / 2),this.enemies[i].getY() - (this.enemies[i].getCurrentImage().getHeight() / 2), null);} catch (Exception e) {System.err.println(e.getMessage());// Draw everything.this.gameGraphics.drawImage(this.canvas, this.borderLeft, this.borderTop, this);long end = System.nanoTime();this.gameGraphics.setFont(new Font(this.gameGraphics.getFont().getFontName(), Font.PLAIN, 15)); this.gameGraphics.drawString("FPS: " + String.format("%2d", (int) (1000000000.0 / (end - start))),this.borderLeft + 50, this.borderTop + 75);return;public Player getPlayer() {return this.player;public void keyPressed(KeyEvent ke) {// Below, the setKey method is used to tell the Player object which key is// currently pressed. // The Player object must keep track of the pressed key and use it for// determining the direction// to move.// Important: The setKey method in Player must not move the Player.if (ke.getKeyCode() == KeyEvent.VK_LEFT)this.player.setKey('L', true);if (ke.getKeyCode() == KeyEvent.VK_RIGHT)this.player.setKey('R', true);if (ke.getKeyCode() == KeyEvent.VK_UP)this.player.setKey('U', true);if (ke.getKeyCode() == KeyEvent.VK_DOWN)this.player.setKey('D', true);if (ke.getKeyCode() == KeyEvent.VK_ESCAPE)this.continueGame = false;return;@Overridepublic void keyReleased(KeyEvent ke) {// Below, the setKey method is used to tell the Player object which key is// currently released.// The Player object must keep track of the pressed key and use it for// determining the direction// to move.// Important: The setKey method in Player must not move the Player.if (ke.getKeyCode() == KeyEvent.VK_LEFT)this.player.setKey('L', false);if (ke.getKeyCode() == KeyEvent.VK_RIGHT)this.player.setKey('R', false);if (ke.getKeyCode() == KeyEvent.VK_UP)this.player.setKey('U', false);if (ke.getKeyCode() == KeyEvent.VK_DOWN)this.player.setKey('D', false);return;@Overridepublic void keyTyped(KeyEvent ke) {return;}import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;import java.util.*;public class Goal {private int x;private int y;private BufferedImage imageCurrent;private BufferedImage imageRunning;private BufferedImage imageOver;private int stepSize;private Random rng; // Tip: Code that students write must not use randomnesspublic Goal(int x, int y) { try {this.imageRunning = ImageIO.read(new File("goal-alive.png"));this.imageOver = ImageIO.read(new File("goal-dead.png"));} catch (IOException e) {e.printStackTrace();this.x=x;this.y=y;this.stepSize=10;this.rng=new Random(x+y); // Tip: Code that students write (elsewhere) must not use any randomness.this.imageCurrent = this.imageRunning;return;public void performAction() {// The code below shows how the Goal can be moved by manipulating its x and y coordinates.// Tip: Code that students write (elsewhere) must not use any randomness.this.x+= this.rng.nextInt()%stepSize;this.y+= this.rng.nextInt()%stepSize;return;

所有的编程代写范围:essayghost为美国、加拿大、英国、澳洲的留学生提供C语言代写、代写C语言、C语言代做、代做C语言、数据库代写、代写数据库、数据库代做、代做数据库、Web作业代写、代写Web作业、Web作业代做、代做Web作业、Java代写、代写Java、Java代做、代做Java、Python代写、代写Python、Python代做、代做Python、C/C++代写、代写C/C++、C/C++代做、代做C/C++、数据结构代写、代写数据结构、数据结构代做、代做数据结构等留学生编程作业代写服务。