diff --git a/build/built-jar.properties b/build/built-jar.properties index 60614ec..61cdadb 100644 --- a/build/built-jar.properties +++ b/build/built-jar.properties @@ -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= diff --git a/build/classes/simonlightgame/Layout.fxml b/build/classes/simonlightgame/Layout.fxml new file mode 100644 index 0000000..f372c81 --- /dev/null +++ b/build/classes/simonlightgame/Layout.fxml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/build/classes/simonlightgame/LayoutController.class b/build/classes/simonlightgame/LayoutController.class new file mode 100644 index 0000000..fd96bd9 Binary files /dev/null and b/build/classes/simonlightgame/LayoutController.class differ diff --git a/build/classes/simonlightgame/Main.class b/build/classes/simonlightgame/Main.class new file mode 100644 index 0000000..af8d038 Binary files /dev/null and b/build/classes/simonlightgame/Main.class differ diff --git a/build/classes/simonlightgame/Timer.class b/build/classes/simonlightgame/Timer.class new file mode 100644 index 0000000..3231f3f Binary files /dev/null and b/build/classes/simonlightgame/Timer.class differ diff --git a/build/classes/utils/Runner.class b/build/classes/utils/Runner.class index 1fbbdb9..3f9757f 100644 Binary files a/build/classes/utils/Runner.class and b/build/classes/utils/Runner.class differ diff --git a/dist/java-fx-8-samples.html b/dist/java-fx-8-samples.html index 12b19cd..a0b294d 100644 --- a/dist/java-fx-8-samples.html +++ b/dist/java-fx-8-samples.html @@ -4,7 +4,7 @@ function launchApplication(jnlpfile) { dtjava.launch( { url : 'java-fx-8-samples.jnlp', - jnlp_content : 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxqbmxwIHNwZWM9IjEuMCIgeG1sbnM6amZ4PSJodHRwOi8vamF2YWZ4LmNvbSIgaHJlZj0iamF2YS1meC04LXNhbXBsZXMuam5scCI+DQogIDxpbmZvcm1hdGlvbj4NCi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dmEuc3VuLmNvbS9wcm9kdWN0cy9hdXRvZGwvajJzZSIvPg0KICAgIDxqYXIgaHJlZj0iamF2YS1meC04LXNhbXBsZXMuamFyIiBzaXplPSIyMTQ1OTEiIGRvd25sb2FkPSJlYWdlciIgLz4NCiAgPC9yZXNvdXJjZXM+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+DQogICAgPGoyc2UgdmVyc2lvbj0iMS42KyIgaHJlZj0iaHR0cDovL2phdmEuc3VuLmNvbS9wcm9kdWN0cy9hdXRvZGwvajJzZSIvPg0KICAgIDxqYXIgaHJlZj0iamF2YS1meC04LXNhbXBsZXMuamFyIiBzaXplPSIyMDc4ODIiIGRvd25sb2FkPSJlYWdlciIgLz4NCiAgPC9yZXNvdXJjZXM+DQogIDxqZng6amF2YWZ4LWRlc2MgIHdpZHRoPSI4MDAiIGhlaWdodD0iNjAwIiBtYWluLWNsYXNzPSJ1dGlscy5SdW5uZXIiICBuYW1lPSJqYXZhLWZ4LTgtc2FtcGxlcyIgLz4NCiAgPHVwZGF0ZSBjaGVjaz0iYWx3YXlzIi8+DQo8L2pubHA+DQo=' + jnlp_content : 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxqbmxwIHNwZWM9IjEuMCIgeG1sbnM6amZ4PSJodHRwOi8vamF2YWZ4LmNvbSIgaHJlZj0iamF2YS1meC04LXNhbXBsZXMuam5scCI+DQogIDxpbmZvcm1hdGlvbj4NCiAgICA8dGl0bGU+amF2YS1meC04LXNhbXBsZXM8L3RpdGxlPg0KICAgIDx2ZW5kb3I+bXNjaHc8L3ZlbmRvcj4NCiAgICA8ZGVzY3JpcHRpb24+bnVsbDwvZGVzY3JpcHRpb24+DQogICAgPG9mZmxpbmUtYWxsb3dlZC8+DQogIDwvaW5mb3JtYXRpb24+DQogIDxyZXNvdXJjZXM+DQogICAgPGoyc2UgdmVyc2lvbj0iMS42KyIgaHJlZj0iaHR0cDovL2phdmEuc3VuLmNvbS9wcm9kdWN0cy9hdXRvZGwvajJzZSIvPg0KICAgIDxqYXIgaHJlZj0iamF2YS1meC04LXNhbXBsZXMuamFyIiBzaXplPSIyMTQ1OTEiIGRvd25sb2FkPSJlYWdlciIgLz4NCiAgPC9yZXNvdXJjZXM+DQogIDxqZng6amF2YWZ4LWRlc2MgIHdpZHRoPSI4MDAiIGhlaWdodD0iNjAwIiBtYWluLWNsYXNzPSJ1dGlscy5SdW5uZXIiICBuYW1lPSJqYXZhLWZ4LTgtc2FtcGxlcyIgLz4NCiAgPHVwZGF0ZSBjaGVjaz0iYWx3YXlzIi8+DQo8L2pubHA+DQo=' }, { javafx : '8.0+' diff --git a/dist/java-fx-8-samples.jar b/dist/java-fx-8-samples.jar index e8567db..c63f73a 100644 Binary files a/dist/java-fx-8-samples.jar and b/dist/java-fx-8-samples.jar differ diff --git a/dist/java-fx-8-samples.jnlp b/dist/java-fx-8-samples.jnlp index 03cc518..9be5021 100644 --- a/dist/java-fx-8-samples.jnlp +++ b/dist/java-fx-8-samples.jnlp @@ -8,7 +8,7 @@ - + diff --git a/src/simonlightgame/Layout.fxml b/src/simonlightgame/Layout.fxml new file mode 100644 index 0000000..f372c81 --- /dev/null +++ b/src/simonlightgame/Layout.fxml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/src/simonlightgame/LayoutController.java b/src/simonlightgame/LayoutController.java new file mode 100644 index 0000000..bb70de7 --- /dev/null +++ b/src/simonlightgame/LayoutController.java @@ -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 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); + } + +} diff --git a/src/simonlightgame/Main.java b/src/simonlightgame/Main.java new file mode 100644 index 0000000..81dc702 --- /dev/null +++ b/src/simonlightgame/Main.java @@ -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); + } + +} diff --git a/src/simonlightgame/Timer.java b/src/simonlightgame/Timer.java new file mode 100644 index 0000000..cbaf063 --- /dev/null +++ b/src/simonlightgame/Timer.java @@ -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); + + } + + } + } +} \ No newline at end of file diff --git a/src/utils/Runner.java b/src/utils/Runner.java index ad53d5e..af47762 100644 --- a/src/utils/Runner.java +++ b/src/utils/Runner.java @@ -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);