Add Simon Light Game

This commit is contained in:
Marcel Schwarz 2019-08-09 06:40:32 +02:00
parent 4b0a539906
commit 4ca3dcabe6
14 changed files with 433 additions and 4 deletions

View File

@ -1,4 +1,4 @@
#Fri, 09 Aug 2019 06:29:16 +0200
#Fri, 09 Aug 2019 06:39:47 +0200
D\:\\Git-Repos\\java-fx-8-samples=

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.shape.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="simonlightgame.LayoutController">
<center>
<GridPane BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="TOP" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Circle fx:id="cirGreen" fill="#25ff1f" radius="38.0" stroke="BLACK" strokeType="INSIDE" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Circle fx:id="cirRed" fill="#ff1f1f" radius="38.0" stroke="BLACK" strokeType="INSIDE" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Circle fx:id="cirYellow" fill="#e8ff1f" radius="38.0" stroke="BLACK" strokeType="INSIDE" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Circle fx:id="cirBlue" fill="#0010ff" radius="38.0" stroke="BLACK" strokeType="INSIDE" GridPane.rowIndex="2" />
<Label text="Simon Game" GridPane.columnIndex="1">
<opaqueInsets>
<Insets />
</opaqueInsets>
<GridPane.margin>
<Insets top="20.0" />
</GridPane.margin>
<font>
<Font size="23.0" />
</font>
</Label>
<Label fx:id="lblPoints" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Points: 00" GridPane.rowIndex="4">
<padding>
<Insets left="10.0" />
</padding>
</Label>
<GridPane GridPane.columnIndex="2" GridPane.rowIndex="4">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="btnNewGame" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNewGame" text="New Game" />
<Button fx:id="btnExit" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleExit" text="Exit" GridPane.rowIndex="1" />
</children>
</GridPane>
</children>
</GridPane>
</center>
</BorderPane>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -4,7 +4,7 @@
function launchApplication(jnlpfile) {
dtjava.launch( {
url : 'java-fx-8-samples.jnlp',
jnlp_content : 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxqbmxwIHNwZWM9IjEuMCIgeG1s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8+DQogIDwvaW5mb3JtYXRpb24+DQogIDxyZXNvdXJjZXM+DQogICAgPGoyc2UgdmVyc2lvbj0iMS42KyIgaHJlZj0iaHR0cDovL2phdmEuc3VuLmNvbS9wcm9kdWN0cy9hdXRvZGwvajJzZSIvPg0KICAgIDxqYXIgaHJlZj0iamF2YS1meC04LXNhbXBsZXMuamFyIiBzaXplPSIyMTQ1OTEiIGRvd25sb2FkPSJlYWdlciIgLz4NCiAgPC9yZXNvdXJjZXM+DQogIDxqZng6amF2YWZ4LWRlc2MgIHdpZHRoPSI4MDAiIGhlaWdodD0iNjAwIiBtYWluLWNsYXNzPSJ1dGlscy5SdW5uZXIiICBuYW1lPSJqYXZhLWZ4LTgtc2FtcGxlcyIgLz4NCiAgPHVwZGF0ZSBjaGVjaz0iYWx3YXlzIi8+DQo8L2pubHA+DQo='
},
{
javafx : '8.0+'
@ -24,7 +24,7 @@
placeholder : 'javafx-app-placeholder',
width : '800',
height : '600',
jnlp_content : 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxqbmxwIHNwZWM9IjEuMCIgeG1sbnM6amZ4PSJodHRwOi8vamF2YWZ4LmNvbSIgaHJlZj0iamF2YS1meC04LXNhbXBsZXMuam5scCI+DQogIDxpbmZvcm1hdGlvbj4NCiAgICA8dGl0bGU+amF2YS1meC04LXNhbXBsZXM8L3RpdGxlPg0KICAgIDx2ZW5kb3I+bXNjaHc8L3ZlbmRvcj4NCiAgICA8ZGVzY3JpcHRpb24+bnVsbDwvZGVzY3JpcHRpb24+DQogICAgPG9mZmxpbmUtYWxsb3dlZC8+DQogIDwvaW5mb3JtYXRpb24+DQogIDxyZXNvdXJjZXM+DQogICAgPGoyc2UgdmVyc2lvbj0iMS42KyIgaHJlZj0iaHR0cDovL2phdmEuc3VuLmNvbS9wcm9kdWN0cy9hdXRvZGwvajJzZSIvPg0KICAgIDxqYXIgaHJlZj0iamF2YS1meC04LXNhbXBsZXMuamFyIiBzaX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: '8.0+'

Binary file not shown.

View File

@ -8,7 +8,7 @@
</information>
<resources>
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="java-fx-8-samples.jar" size="207882" download="eager" />
<jar href="java-fx-8-samples.jar" size="214591" download="eager" />
</resources>
<jfx:javafx-desc width="800" height="600" main-class="utils.Runner" name="java-fx-8-samples" />
<update check="always"/>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.shape.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="simonlightgame.LayoutController">
<center>
<GridPane BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="TOP" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Circle fx:id="cirGreen" fill="#25ff1f" radius="38.0" stroke="BLACK" strokeType="INSIDE" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Circle fx:id="cirRed" fill="#ff1f1f" radius="38.0" stroke="BLACK" strokeType="INSIDE" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Circle fx:id="cirYellow" fill="#e8ff1f" radius="38.0" stroke="BLACK" strokeType="INSIDE" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Circle fx:id="cirBlue" fill="#0010ff" radius="38.0" stroke="BLACK" strokeType="INSIDE" GridPane.rowIndex="2" />
<Label text="Simon Game" GridPane.columnIndex="1">
<opaqueInsets>
<Insets />
</opaqueInsets>
<GridPane.margin>
<Insets top="20.0" />
</GridPane.margin>
<font>
<Font size="23.0" />
</font>
</Label>
<Label fx:id="lblPoints" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Points: 00" GridPane.rowIndex="4">
<padding>
<Insets left="10.0" />
</padding>
</Label>
<GridPane GridPane.columnIndex="2" GridPane.rowIndex="4">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="btnNewGame" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNewGame" text="New Game" />
<Button fx:id="btnExit" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleExit" text="Exit" GridPane.rowIndex="1" />
</children>
</GridPane>
</children>
</GridPane>
</center>
</BorderPane>

View File

@ -0,0 +1,180 @@
/*
* 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 simonlightgame;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
/**
*
* @author mschw
*/
public class LayoutController implements Initializable {
@FXML
public Circle cirGreen;
@FXML
public Circle cirRed;
@FXML
public Circle cirYellow;
@FXML
public Circle cirBlue;
@FXML
private Label lblPoints;
@FXML
private Button btnNewGame;
@FXML
private Button btnExit;
public static ArrayList<Circle> sequence = new ArrayList<>();
Circle[] circles = {cirBlue,cirGreen,cirRed,cirYellow};
Timer timer = new Timer(this);
int stage = 0;
boolean isClickAllowed = true;
Thread animator;
@Override
public void initialize(URL url, ResourceBundle rb) {
cirBlue.setOnMouseClicked((event) -> {
this.isClickAllowed = false;
new Thread(() -> this.doAnimation("blue")).start();
this.processCircleClick("blue");
this.isClickAllowed = true;
});
cirGreen.setOnMouseClicked((event) -> {
this.processCircleClick("green");
});
cirRed.setOnMouseClicked((event) -> {
this.processCircleClick("red");
});
cirYellow.setOnMouseClicked((event) -> {
this.processCircleClick("yellow");
});
}
@FXML
private void handleNewGame(ActionEvent event) {
this.sequence = new ArrayList<>();
this.makeSequence();
//this.showSequence();
}
@FXML
private void handleExit(ActionEvent event) {
System.exit(0);
}
private void processCircleClick(String who) {
switch (who) {
case "blue":
break;
case "red":
break;
case "green":
break;
case "yellow":
break;
}
}
private void showSequence() {
timer.start();
}
private void makeSequence() {
Random rd = new Random();
for (int i = sequence.size(); i < 3 + stage; i++) {
sequence.add(circles[rd.nextInt(4)]);
}
printSequence();
}
private void doAnimation(String who) {
switch (who) {
case "blue":
Platform.runLater(() -> cirBlue.setFill(Color.LIGHTBLUE));
try {
Thread.sleep(400);
} catch (InterruptedException ex) {
}
Platform.runLater(() -> cirBlue.setFill(Color.BLUE));
break;
case "red":
Platform.runLater(() -> cirRed.setFill(Color.PINK));
try {
Thread.sleep(400);
} catch (InterruptedException ex) {
}
Platform.runLater(() -> cirRed.setFill(Color.RED));
break;
case "green":
Platform.runLater(() -> cirGreen.setFill(Color.LIGHTGREEN));
try {
Thread.sleep(400);
} catch (InterruptedException ex) {
}
Platform.runLater(() -> cirGreen.setFill(Color.GREEN));
break;
case "yellow":
Platform.runLater(() -> cirYellow.setFill(Color.CORNSILK));
try {
Thread.sleep(400);
} catch (InterruptedException ex) {
}
Platform.runLater(() -> cirYellow.setFill(Color.YELLOW));
break;
}
}
private void printSequence() {
System.out.println("Die aktuelle Sequenz ist: ");
String seq = new String();
for (Circle circle : sequence) {
if (circle.equals(cirBlue)) {
seq += "blue ";
}
if (circle.equals(cirGreen)) {
seq += "green ";
}
if (circle.equals(cirRed)) {
seq += "red ";
}
if (circle.equals(cirYellow)) {
seq += "yellow ";
}
}
System.out.println(seq);
}
}

View File

@ -0,0 +1,45 @@
/*
* 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 simonlightgame;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
*
* @author mschw
*/
public class Main extends Application {
@Override
public void start(Stage stage) {
Parent root = null;
try {
root = FXMLLoader.load(getClass().getResource("Layout.fxml"));
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}

View File

@ -0,0 +1,68 @@
/*
* 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 simonlightgame;
import java.util.ArrayList;
import javafx.animation.AnimationTimer;
import javafx.application.Platform;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
/**
*
* @author mschw
*/
public class Timer extends AnimationTimer {
private LayoutController controller;
Timer(LayoutController controller) {
controller = this.controller;
}
@Override
public void handle(long now) {
for (Circle circle : LayoutController.sequence) {
if (circle.equals(controller.cirBlue)) {
controller.cirBlue.setFill(Color.LIGHTBLUE);
try {
Thread.sleep(400);
} catch (InterruptedException ex) {
}
controller.cirBlue.setFill(Color.BLUE);
}
if (circle.equals(controller.cirGreen)) {
controller.cirGreen.setFill(Color.LIGHTGREEN);
try {
Thread.sleep(400);
} catch (InterruptedException ex) {
}
controller.cirGreen.setFill(Color.GREEN);
}
if (circle.equals(controller.cirRed)) {
controller.cirRed.setFill(Color.PINK);
try {
Thread.sleep(400);
} catch (InterruptedException ex) {
}
controller.cirRed.setFill(Color.RED);
}
if (circle.equals(controller.cirYellow)) {
controller.cirYellow.setFill(Color.CORNSILK);
try {
Thread.sleep(400);
} catch (InterruptedException ex) {
}
controller.cirYellow.setFill(Color.YELLOW);
}
}
}
}

View File

@ -144,6 +144,10 @@ public class Runner extends Application{
btn24.setOnAction(event -> new chatspammer.Main().start(new Stage()));
gridpane.add(btn24, 2, 9);
Button btn25 = new Button("Start Simon Light Game");
btn25.setOnAction(event -> new simonlightgame.Main().start(new Stage()));
gridpane.add(btn25, 0, 10);
ScrollPane root = new ScrollPane(gridpane);
Scene scene = new Scene(root, 600, 400);