-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3aa9fa
commit 940b6a2
Showing
16 changed files
with
300 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
This project demonstrates how to use Java Fx in OOP Style. | ||
All examples are popular games. (Snake, Chess, TicTacToe, SeeBattle and etc) | ||
Sure, here's the updated README with the chat link at the beginning: | ||
|
||
If you have any suggestions about this project, please, creating a new GitHub issue https://github.com/peterarsentev/games_oop_javafx/issues | ||
--- | ||
|
||
# Welcome to Java Mastery! | ||
|
||
## Snake | ||
[Join our chat on Telegram!](https://t.me/job4j_java_mastery) | ||
|
||
![ScreenShot](images/Snake.png) | ||
Welcome to "Java Mastery" – your ultimate chat for mastering Java programming! Whether you're a beginner starting from scratch or an experienced developer looking to deepen your knowledge, our chat community has you covered. Join us for in-depth discussions, coding challenges, best practices, and the latest updates in the world of Java. Let's code, learn, and grow together! | ||
|
||
## TicTacToe | ||
## About This Project | ||
|
||
![ScreenShot](images/TicTacToe.png) | ||
This project showcases how to use JavaFX in an object-oriented programming (OOP) style through a series of popular game examples. Dive into the code for classic games such as Snake, Chess, and Tic-Tac-Toe, and see how JavaFX can bring these games to life. | ||
|
||
## Chess | ||
If you have any suggestions or encounter any issues with this project, please create a new GitHub issue [here](https://github.com/peterarsentev/games_oop_javafx/issues). | ||
|
||
![ScreenShot](images/Chess.png) | ||
## Game Examples | ||
|
||
## TODO | ||
### Snake | ||
|
||
![Snake](images/Snake.png) | ||
|
||
### Tic-Tac-Toe | ||
|
||
![TicTacToe](images/TicTacToe.png) | ||
|
||
### Chess | ||
|
||
![Chess](images/Chess.png) | ||
|
||
## Upcoming Features | ||
|
||
- SeaBattle | ||
- PackMan | ||
- Pac-Man | ||
- Tetris | ||
|
||
Stay tuned for more updates and improvements! | ||
|
||
--- | ||
|
||
Let me know if there are any other changes you'd like to make! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module puzzle { | ||
requires javafx.fxml; | ||
requires javafx.controls; | ||
requires javafx.graphics; | ||
opens ru.job4j.packman to javafx.fxml; | ||
exports ru.job4j.packman; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ru.job4j; | ||
|
||
public class Rotate { | ||
public static void rotate(int[][] array) { | ||
int n = array.length; | ||
for (int i = 0; i < n / 2; i++) { | ||
for (int j = i; j < n - i - 1; j++) { | ||
int temp = array[i][j]; | ||
array[i][j] = array[j][n - i - 1]; | ||
array[j][n - i - 1] = array[n - i - 1][n - j - 1]; | ||
array[n - i - 1][n - j - 1] = array[n - j - 1][i]; | ||
array[n - j - 1][i] = temp; | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
int[][] array = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; | ||
System.out.println("Original Array:"); | ||
for (int i = 0; i < array.length; i++) { | ||
for (int j = 0; j < array[i].length; j++) { | ||
System.out.print(array[i][j] + " "); | ||
} | ||
System.out.println(); | ||
} | ||
rotate(array); | ||
for (int i = 0; i < array.length; i++) { | ||
for (int j = 0; j < array[i].length; j++) { | ||
System.out.print(array[i][j] + " "); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package ru.job4j.packman; | ||
|
||
import javafx.application.Application; | ||
import javafx.event.Event; | ||
import javafx.scene.Scene; | ||
import javafx.scene.input.KeyEvent; | ||
import javafx.scene.layout.BorderPane; | ||
import javafx.scene.layout.Pane; | ||
import javafx.scene.paint.Color; | ||
import javafx.scene.shape.Circle; | ||
import javafx.stage.Stage; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
import javafx.scene.shape.Rectangle; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.shape.Line; | ||
|
||
|
||
public class Tetris extends Application { | ||
|
||
@Override | ||
public void start(Stage stage) { | ||
BorderPane canvas = new BorderPane(); | ||
Scene scene = new Scene(canvas, 500, 500); | ||
stage.setScene(scene); | ||
stage.show(); | ||
stage.setTitle("Tetris"); | ||
// Control panel | ||
Pane controlPanel = new Pane(); | ||
controlPanel.setPrefSize(500, 100); | ||
controlPanel.setStyle("-fx-background-color: #f0f0f0;"); | ||
canvas.setBottom(controlPanel); | ||
Button rotateButton = new Button("Rotate"); | ||
controlPanel.getChildren().add(rotateButton); | ||
Pane mainPanel = new Pane(); | ||
mainPanel.setPrefSize(500, 400); | ||
mainPanel.setStyle("-fx-background-color: #ffffff;"); | ||
canvas.setCenter(mainPanel); | ||
for (int i = 0; i < 500; i += 50) { | ||
Line line = new Line(i, 0, i, 500); | ||
line.setStroke(Color.BLACK); | ||
mainPanel.getChildren().add(line); | ||
} | ||
for (int i = 0; i < 500; i += 50) { | ||
Line line = new Line(0, i, 500, i); | ||
line.setStroke(Color.BLACK); | ||
mainPanel.getChildren().add(line); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
Tetris.launch(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module tictactoe { | ||
requires javafx.fxml; | ||
requires javafx.controls; | ||
opens ru.job4j.snake to javafx.fxml; | ||
exports ru.job4j.snake; | ||
opens ru.job4j.tetris to javafx.fxml; | ||
exports ru.job4j.tetris; | ||
} |
2 changes: 1 addition & 1 deletion
2
snake/src/main/java/ru/job4j/snake/Cell.java → ...e/src/main/java/ru/job4j/tetris/Cell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ru.job4j.snake; | ||
package ru.job4j.tetris; | ||
|
||
public record Cell(int x, int y) { | ||
} |
2 changes: 1 addition & 1 deletion
2
...c/main/java/ru/job4j/snake/Direction.java → .../main/java/ru/job4j/tetris/Direction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ru.job4j.snake; | ||
package ru.job4j.tetris; | ||
|
||
enum Direction { | ||
LEFT, RIGHT, UP, DOWN | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>games</artifactId> | ||
<groupId>ru.job4j</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>tetris</artifactId> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module tictactoe { | ||
requires javafx.fxml; | ||
requires javafx.controls; | ||
requires javafx.graphics; | ||
opens ru.job4j.tetris to javafx.fxml; | ||
exports ru.job4j.tetris; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ru.job4j.tetris; | ||
|
||
public record Cell(int x, int y) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ru.job4j.tetris; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
public class Figure { | ||
private List<Cell> body; | ||
|
||
public Figure(List<Cell> cells) { | ||
this.body = new ArrayList<>(cells); | ||
} | ||
|
||
public void rotate() { | ||
|
||
} | ||
|
||
public void move() { | ||
List<Cell> newBody = new ArrayList<>(); | ||
for (Cell cell : body) { | ||
newBody.add(new Cell(cell.x(), cell.y() + 1)); | ||
} | ||
body = newBody; | ||
} | ||
|
||
|
||
List<Cell> asCells() { | ||
return body; | ||
} | ||
} |
Oops, something went wrong.