Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Alien Direction Path Game The Alien Direction Game System Modify the AlienDirection program in Listing 7.20 so that it displays 10 random numbers between 1
Alien Direction Path Game
The Alien Direction Game System
Modify the AlienDirection program in Listing 7.20 so that it displays 10 random numbers between 1 and 100 in random locations and as the alien moves, it eats the numbers and as the numbers are consumed, it shows the total. When a number is consumed, the consumed number disappears, while other numbers remain the same. When all the numbers are consumed, the game starts over.
Deliverables
The program and screenshots of the final execution.
Source code:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package aliendirection; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyEvent; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.stage.Stage; /** * * @author dhrgam */ public class AlienDirection extends Application { public final static int JUMP = 10; private ImageView imageView; @Override public void start(Stage primaryStage) { Image alien = new Image("file:alien.png"); imageView = new ImageView(alien); //imageView.setScaleX(0.5); //imageView.setScaleY(0.5); imageView.setX(20); imageView.setY(20); Group root = new Group(imageView); Scene scene = new Scene(root, 400, 200, Color.BLACK); scene.setOnKeyPressed(this::processKeyPress); primaryStage.setTitle("Alien Direction"); primaryStage.setScene(scene); primaryStage.show(); } //-------------------------------------------------------------------- // Modifies the position of the image view when an arrow key is // pressed. //-------------------------------------------------------------------- public void processKeyPress(KeyEvent event) { switch (event.getCode()) { case UP: imageView.setY(imageView.getY() - JUMP); break; case DOWN: imageView.setY(imageView.getY() + JUMP); break; case RIGHT: imageView.setX(imageView.getX() + JUMP); break; case LEFT: imageView.setX(imageView.getX() - JUMP); break; default: break; // do nothing if it's not an arrow key } } public static void main(String[] args) { launch(args); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started