Board Made of Rectangles
I don't know if this is the right way to do this but I seems looks like a good idea.
This commit is contained in:
parent
58f17472d8
commit
26d3bb5c05
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
@ -4,5 +4,5 @@
|
|||||||
<component name="FrameworkDetectionExcludesConfiguration">
|
<component name="FrameworkDetectionExcludesConfiguration">
|
||||||
<file type="web" url="file://$PROJECT_DIR$" />
|
<file type="web" url="file://$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" project-jdk-name="19" project-jdk-type="JavaSDK" />
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="19" project-jdk-type="JavaSDK" />
|
||||||
</project>
|
</project>
|
BIN
Current_Window.png
Normal file
BIN
Current_Window.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
15
README.md
15
README.md
@ -1,3 +1,16 @@
|
|||||||
# jchess
|
# jchess
|
||||||
|
|
||||||
Java chess game
|
A chess Board writen in Java
|
||||||
|
|
||||||
|
The goal of this project is to get used to javaFX. This might awefull code, don't loook to deeply!
|
||||||
|
|
||||||
|
## Build & Run
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ ./gradlew build
|
||||||
|
$ ./gradlew run
|
||||||
|
```
|
||||||
|
|
||||||
|
## Appearance
|
||||||
|
|
||||||
|
![Current Window](./Current_Window.png "Current Window")
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
// Apply the application plugin to add support for building a CLI application in Java.
|
// Apply the application plugin to add support for building a CLI application in Java.
|
||||||
id 'application'
|
id 'application'
|
||||||
|
id 'org.openjfx.javafxplugin' version '0.0.13'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@ -29,6 +30,11 @@ application {
|
|||||||
mainClass = 'jchess.App'
|
mainClass = 'jchess.App'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
javafx {
|
||||||
|
version = "20"
|
||||||
|
modules = [ 'javafx.controls']
|
||||||
|
}
|
||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
// Use JUnit Platform for unit tests.
|
// Use JUnit Platform for unit tests.
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
@ -1,14 +1,44 @@
|
|||||||
/*
|
|
||||||
* This Java source file was generated by the Gradle 'init' task.
|
|
||||||
*/
|
|
||||||
package jchess;
|
package jchess;
|
||||||
|
|
||||||
public class App {
|
|
||||||
public String getGreeting() {
|
import javafx.application.Application;
|
||||||
return "Hello World!";
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class App extends Application {
|
||||||
|
|
||||||
|
public final static int WIDTH = 500, HEIGHT = 500;
|
||||||
|
public final static String PROGRAM_NAME = "JChess";
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
@Override
|
||||||
System.out.println(new App().getGreeting());
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
BorderPane root = new BorderPane();
|
||||||
|
|
||||||
|
GridPane board = new GridPane();
|
||||||
|
|
||||||
|
Rectangle[][] cases = new Rectangle[8][8];
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
for (int j = 0; j < 8; j++) {
|
||||||
|
cases[i][j] = new Rectangle(WIDTH/8, HEIGHT/8);
|
||||||
|
cases[i][j].setFill((i + j) % 2 == 0 ? Color.WHITE : Color.LIGHTGRAY);
|
||||||
|
board.add(cases[i][j], i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
root.setCenter(board);
|
||||||
|
Scene scene = new Scene(root, WIDTH, HEIGHT);
|
||||||
|
scene.addEventHandler(KeyEvent.KEY_PRESSED, new KeyboardEvent());
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.setTitle(PROGRAM_NAME);
|
||||||
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
app/src/main/java/jchess/KeyboardEvent.java
Normal file
16
app/src/main/java/jchess/KeyboardEvent.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package jchess;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
|
|
||||||
|
public class KeyboardEvent implements EventHandler<KeyEvent> {
|
||||||
|
@Override
|
||||||
|
public void handle(KeyEvent event) {
|
||||||
|
System.out.println(event.getCharacter());
|
||||||
|
if(event.getCode() == KeyCode.Q){
|
||||||
|
Platform.exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user