Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* So this is my program, I cannot make all the functions in it work. Can anyone copy paste it and see what i need

/* So this is my program, I cannot make all the functions in it work. Can anyone copy paste it and see what i need to do to make them work? */ package AlienTiles;

import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.StackPane; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; import javafx.scene.control.Label; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color;

/** * * @author rijanprajapati */ public class AlienTiles extends Application {

private int rows = 7; private int columns = 7; private Cell[][] cells = new Cell[rows][columns]; private Color[] colors = {Color.RED, Color.BLUE, Color.GREEN, Color.PURPLE}; private String[] strMenu = {"file", "Game", "Editing"}; private String[][] strMenuItems = {{"Save to file", "Load from File"}, {"New game: Same color", "New game: Random color"}, {"undo"}}; private MenuBar menuBar; private Menu[] menus; private MenuItem[][] menuItems; private final int CELL_LENGTH = 80;

@Override public void start(Stage primaryStage) { menuBar = new MenuBar(); menus = new Menu[strMenu.length]; menuItems = new MenuItem[strMenuItems.length][]; for (int i = 0; i < strMenu.length; i++) { menus[i] = new Menu(strMenu[i]); menuItems[i] = new MenuItem[strMenuItems[i].length]; for (int j = 0; j < strMenuItems[i].length; j++) { menuItems[i][j] = new MenuItem(strMenuItems[i][j]); } menus[i].getItems().addAll(menuItems[i]);

} menuBar.getMenus().addAll(menus); BorderPane borderPane = new BorderPane(); GridPane pane = new GridPane(); borderPane.setBottom(menuBar); borderPane.setCenter(pane); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { pane.add(cells[i][j] = new Cell(i, j, 0, CELL_LENGTH, CELL_LENGTH), j, i);

}

} for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { cells[i][j].setOnMouseClicked(e -> { Object src = e.getSource(); if (src instanceof MenuItem) { return; } Cell c = (Cell) src; for (int k = 0; k < columns; k++) { cells[c.row][k].forward(); } for (int k = 0; k < rows; k++) { if (k != c.row) { cells[k][c.column].forward(); } } }); } } Scene scene = new Scene(borderPane, CELL_LENGTH * rows + 5, CELL_LENGTH * columns + 40); primaryStage.setTitle("Aliengame"); primaryStage.setScene(scene); primaryStage.show();

}

public class Cell extends Rectangle {

public int row; public int column; public int colorIndex = 0;

public Cell(int rowIndex, int columnIndex, int colorIndex, int width, int height) { super(width, height); row = rowIndex; column = columnIndex; this.colorIndex = colorIndex % colors.length; setFill(colors[this.colorIndex]); super.setStroke(Color.BLACK);

}

public Cell(int rowIndex, int columnIndex, int colorIndex) { this(rowIndex, columnIndex, colorIndex, 40, 40); }

public Cell() { this(0, 0, 0); }

public void forward() { colorIndex = (colorIndex + 1) % colors.length; setFill(colors[this.colorIndex]); super.setStroke(Color.BLACK); }

public void backward() { colorIndex = (colorIndex + colors.length - 1) % colors.length; setFill(colors[this.colorIndex]); super.setStroke(Color.BLACK);

}

}

public static void main(String[] args) { launch(args);

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

Describe the punctuated-equilibrium model of group development.

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago