Question: 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

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.

Modify the AlienDirection program in Listing 7.20 so that it displays 10

My code so far :

package alien;

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;

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:Small_alien.png"); imageView = new ImageView(alien); imageView.setX(20); imageView.setY(20); Group root = new Group(imageView);

Scene scene = new Scene(root, 400, 200, Color.BLUE); scene.setOnKeyPressed(this::processKeyPress);

primaryStage.setTitle("Alien Direction"); primaryStage.setScene(scene); primaryStage.show(); }

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; } } public static void main(String[] args) { launch(args); } }

Transcribed image text

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!