Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
peterarsentev committed Jul 22, 2024
1 parent a3aa9fa commit 940b6a2
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 67 deletions.
40 changes: 29 additions & 11 deletions README.md
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!
1 change: 1 addition & 0 deletions packman/src/main/java/module-info.java
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;
}
34 changes: 34 additions & 0 deletions packman/src/main/java/ru/job4j/Rotate.java
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();
}
}
}
50 changes: 0 additions & 50 deletions packman/src/main/java/ru/job4j/packman/CatchBall.java

This file was deleted.

55 changes: 55 additions & 0 deletions packman/src/main/java/ru/job4j/packman/Tetris.java
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);
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>puzzle</module>
<module>packman</module>
<module>snake</module>
<module>tetris</module>
</modules>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions snake/src/main/java/module-info.java
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;
}
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) {
}
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.job4j.snake;
package ru.job4j.tetris;

import javafx.application.Application;
import javafx.application.Platform;
Expand Down Expand Up @@ -126,4 +126,9 @@ private void redrawSnake(Group group) {
group.getChildren().removeAll(snakePosition);
drawSnake(group);
}


public static void main(String[] args) {
Main.launch(args);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.job4j.snake;
package ru.job4j.tetris;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -28,6 +28,7 @@ boolean step() {
case UP -> new Cell(tail.x(), tail.y() - 1);
case DOWN -> new Cell(tail.x(), tail.y() + 1);
};

var eat = next.equals(apple);
if (!eat) {
body.remove(0);
Expand Down
15 changes: 15 additions & 0 deletions tetris/pom.xml
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>
7 changes: 7 additions & 0 deletions tetris/src/main/java/module-info.java
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;
}
4 changes: 4 additions & 0 deletions tetris/src/main/java/ru/job4j/tetris/Cell.java
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) {
}
31 changes: 31 additions & 0 deletions tetris/src/main/java/ru/job4j/tetris/Figure.java
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;
}
}
Loading

0 comments on commit 940b6a2

Please sign in to comment.