Skip to content

Commit

Permalink
Add gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
salif committed Jul 15, 2024
1 parent abb61d8 commit 6fde82a
Show file tree
Hide file tree
Showing 19 changed files with 502 additions and 106 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

16 changes: 4 additions & 12 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: salif # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
patreon: salifm
ko_fi: salif
liberapay: salif
custom: ['https://salif.eu/sponsor-me']
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.class
.gradle/
build/
.idea/
Tetris.iml
*.class
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Tetris

Fun & Simple Original tetris

## Download
[Tetris.jar](https://github.com/salifm/Tetris/raw/master/out/Tetris.jar)

Download [Tetris.jar](https://github.com/salifm/Tetris/raw/master/out/Tetris.jar)

See releases [on Github](https://github.com/salif/Tetris/releases).

## How to play

Expand All @@ -15,15 +18,17 @@ Fun & Simple Original tetris

### on Linux

![on linux](https://i.imgur.com/5zC5MkV.png)

![on Linux](https://i.imgur.com/96jMEXf.png)
![Tetris screenshot on Linux](https://i.imgur.com/96jMEXf.png)

### on Window

![on window](https://i.imgur.com/THAGnd7.png)
![Tetris screenshot on Windows](https://i.imgur.com/zp9uXmk.png)

## Links

- [Homepage](https://salif.github.io/Tetris/)
- [Source code](https://github.com/salif/Tetris)

![on Windows](https://i.imgur.com/zp9uXmk.png)
### Forked from:

## Forked from:
[github.com/ChihoWon/Tetris](https://github.com/ChihoWon/Tetris)
10 changes: 9 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
theme: jekyll-theme-cayman
theme: jekyll-theme-cayman

title: "Tetris"
description: "Fun & Simple Original tetris"
show_downloads: false

author:
name: Salif Mehmed
url: https://salif.eu
1 change: 1 addition & 0 deletions _includes/head-custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script data-goatcounter="https://sgi.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script>
35 changes: 35 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.5.1/userguide/building_java_projects.html
*/

plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'

// This dependency is used by the application.
implementation 'com.google.guava:guava:31.0.1-jre'
}

application {
// Define the main class for the application.
mainClass = 'com.github.salif.tetris.App'
}

tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.salifm.tetris;

public class Main {
package com.github.salif.tetris;

public class App {
public static void main(String[] args) {
new GameWindow();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.salifm.tetris;
package com.github.salif.tetris;

import java.awt.Color;
import java.awt.Dimension;
Expand All @@ -8,18 +8,17 @@
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.*;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

import com.salifm.tetris.Tetromino.Tetrominoes;
import com.github.salif.tetris.Tetromino.Tetrominoes;

public class GameBoardPanel extends JPanel implements ActionListener {
private static final int BoardWidth = 10; // game board x size
private static final int BoardHeight = 22; // game board y size
private static final long serialVersionUID = 6802492405004738658L;
private static final int BoardWidth = 10; // game board x size
private static final int BoardHeight = 22; // game board y size

// game status & timer
private Timer timer;
Expand All @@ -44,26 +43,27 @@ public class GameBoardPanel extends JPanel implements ActionListener {
private String currentLevel;
private int currentTimerResolution;

private GameWindow tetrisFrameD;


public GameBoardPanel(GameWindow tetrisFrame, int timerResolution) {

setFocusable(true);
setBackground(new Color(0, 30, 30));
curBlock = new Tetromino();
timer = new Timer(timerResolution, this);
timer.start(); // activate timer
timer.start(); // activate timer
currentTimerResolution = timerResolution;

gameBoard = new Tetrominoes[BoardWidth * BoardHeight];

// colour of tetrominoes
colorTable = new Color[]{
new Color(0, 0, 0), new Color(164, 135, 255),
new Color(255, 128, 0), new Color(255, 0, 0),
new Color(32, 128, 255), new Color(255, 0, 255),
new Color(255, 255, 0), new Color(0, 255, 0)
colorTable = new Color[] {
new Color(0, 0, 0),
new Color(164, 135, 255),
new Color(255, 128, 0),
new Color(255, 0, 0),
new Color(32, 128, 255),
new Color(255, 0, 255),
new Color(255, 255, 0),
new Color(0, 255, 0)
};

// keyboard listener
Expand Down Expand Up @@ -118,7 +118,6 @@ public void keyPressed(KeyEvent e) {
}
});

tetrisFrameD = tetrisFrame;
initBoard();
}

Expand Down Expand Up @@ -157,9 +156,6 @@ private void setResolution() {
case 1:
currentTimerResolution = 370;
break;
case 0:
currentTimerResolution = 370;
break;
}

timer.setDelay(currentTimerResolution);
Expand Down Expand Up @@ -241,7 +237,7 @@ public void paint(Graphics g) {
}

g.setColor(Color.WHITE);
g.setFont(new Font("Consolas", Font.PLAIN, 28));
g.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 28));
g.drawString(currentStatus, 15, 35);
g.drawString(currentLevel, 15, 70);

Expand All @@ -258,7 +254,8 @@ public void paint(Graphics g) {
for (int i = 0; i < 4; i++) {
int x = curX + curBlock.getX(i);
int y = tempY - curBlock.getY(i);
drawTetromino(g, 0 + x * blockWidth(), boardTop + (BoardHeight - y - 1) * blockHeight(), curBlock.getShape(),
drawTetromino(g, 0 + x * blockWidth(), boardTop + (BoardHeight - y - 1) * blockHeight(),
curBlock.getShape(),
true);
}

Expand All @@ -271,7 +268,6 @@ public void paint(Graphics g) {
}
}


// rendering - current tetromino
if (curBlock.getShape() != Tetrominoes.NO_BLOCK) {
for (int i = 0; i < 4; i++) {
Expand Down Expand Up @@ -364,7 +360,7 @@ private void newTetromino() {
curBlock.setShape(Tetrominoes.NO_BLOCK);
timer.stop();
isStarted = false;
GameOver(currentScore);
gameOver(currentScore);
}
}

Expand Down Expand Up @@ -398,48 +394,8 @@ private void advanceToEnd() {
tetrominoFixed();
}

private void GameOver(int dbScore) {
int maxScore = readDB();
String showD = "";
if (dbScore > maxScore) {
writeDB(dbScore);
showD = String.format("%nCongratulations! %nNew max score: %d", dbScore);
} else {
showD = String.format("Score: %d %nMax score: %d", dbScore, maxScore);
}
UIManager.put("OptionPane.okButtonText", "new game");
JOptionPane.showMessageDialog(null, showD, "Game Over!", JOptionPane.OK_OPTION);
setResolution();
start();
}

private int readDB() {
try {
BufferedReader inputStream = new BufferedReader(new FileReader("Tetris.score"));
String dbMaxScore = inputStream.readLine();
inputStream.close();
return Integer.parseInt(dbMaxScore);
} catch (IOException e) {
return -1;
} catch (NumberFormatException e) {
return -1;
}
private void gameOver(int score) {
JOptionPane.showMessageDialog(null, "", "Game Over!", JOptionPane.OK_OPTION);
}

private void writeDB(int dbScore) {
try {
File UIFile = new File("Tetris.score");
if (!UIFile.exists()) {
UIFile.createNewFile();
}
FileWriter filewriter = new FileWriter(UIFile.getAbsoluteFile());
BufferedWriter outputStream = new BufferedWriter(filewriter);
outputStream.write(String.valueOf(dbScore));
outputStream.newLine();
outputStream.write("This is database for Tetris game - https://github.com/salifm/Tetris");
outputStream.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.salifm.tetris;
package com.github.salif.tetris;

import java.awt.GridLayout;
import javax.swing.JFrame;

public class GameWindow extends JFrame {

private static final long serialVersionUID = 8737819995837542594L;

public GameWindow() {
setTitle("Tetris :D");
setSize(400, 814);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package com.salifm.tetris;
package com.github.salif.tetris;

import java.util.Random;

public class Tetromino {
enum Tetrominoes {
NO_BLOCK, Z_SHAPE, S_SHAPE, I_SHAPE, T_SHAPE, O_SHAPE, L_SHAPE, J_SHAPE
}

;
};

private Tetrominoes tetrominoes;
private int coords[][]; // current shape of a tetromino
private int coords[][]; // current shape of a tetromino
private int tetrominoTable[][][];

public Tetromino() {
coords = new int[4][2];
tetrominoTable = new int[][][]{
{{0, 0}, {0, 0}, {0, 0}, {0, 0}}, // NO_BLOCK
{{0, -1}, {0, 0}, {-1, 0}, {-1, 1}}, // Z_SHAPE
{{0, -1}, {0, 0}, {1, 0}, {1, 1}}, // S_SHAPE
{{0, -1}, {0, 0}, {0, 1}, {0, 2}}, // I_SHAPE
{{-1, 0}, {0, 0}, {1, 0}, {0, 1}}, // T_SHAPE
{{0, 0}, {1, 0}, {0, 1}, {1, 1}}, // O_SHAPE
{{-1, -1}, {0, -1}, {0, 0}, {0, 1}}, // L_SHAPE
{{1, -1}, {0, -1}, {0, 0}, {0, 1}} // J_SHAPE
tetrominoTable = new int[][][] {
{ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }, // NO_BLOCK
{ { 0, -1 }, { 0, 0 }, { -1, 0 }, { -1, 1 } }, // Z_SHAPE
{ { 0, -1 }, { 0, 0 }, { 1, 0 }, { 1, 1 } }, // S_SHAPE
{ { 0, -1 }, { 0, 0 }, { 0, 1 }, { 0, 2 } }, // I_SHAPE
{ { -1, 0 }, { 0, 0 }, { 1, 0 }, { 0, 1 } }, // T_SHAPE
{ { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } }, // O_SHAPE
{ { -1, -1 }, { 0, -1 }, { 0, 0 }, { 0, 1 } }, // L_SHAPE
{ { 1, -1 }, { 0, -1 }, { 0, 0 }, { 0, 1 } } // J_SHAPE
};

setShape(Tetrominoes.NO_BLOCK);
Expand Down
14 changes: 14 additions & 0 deletions app/src/test/java/com/github/salif/tetris/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package com.github.salif.tetris;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class AppTest {
@Test void appHasAGreeting() {
App classUnderTest = new App();
// assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 6fde82a

Please sign in to comment.