Skip to content

Commit 68c589c

Browse files
author
hasnat163
committed
general improvements
1 parent df7e590 commit 68c589c

File tree

11 files changed

+81
-27
lines changed

11 files changed

+81
-27
lines changed

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Tetris_Game.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Ensure you have Java Development Kit (JDK) installed on your machine to run and
6161
- **Rotate:** Up arrow key / W
6262
- **Drop:** Down arrow key / S
6363
- **Pause/Resume Game:** Press 'SpaceBar'
64+
- **Music:** Press 'M' to toggle music
6465

6566
The objective is to place the tetrominoes to create complete lines, which will then be cleared from the board. The game ends when the Tetris playfield is filled.
6667

@@ -71,8 +72,11 @@ The objective is to place the tetrominoes to create complete lines, which will t
7172

7273
## Authors
7374

74-
- Muhammad Hasnat Rasool - *Initial work* - [YourGitHub](https://github.com/hasnatrasool163)
75+
- Muhammad Hasnat Rasool - *Initial work* - [GitHubLink](https://github.com/hasnatrasool163)
7576

77+
## Top Contributors
78+
79+
- Digi-Bomb -[GitHubLink](https://github.com/Digi-Bomb)
7680

7781
## Acknowledgments
7882

Tetris-in-Java.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

tetris/GamePanel.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void run() {
5151
// we perform 2 task
5252
// update + draw
5353
// in update we update position x and y
54-
double drawInterval = 1000000000/FPS;
54+
double drawInterval = (double) 1000000000 /FPS;
5555
double delta =0;
5656

5757
long lastTime = System.nanoTime();
@@ -88,23 +88,23 @@ public void run() {
8888
poweruptimedelta--;
8989

9090
//This logic takes care of the power up being on cooldown
91-
if(powerupused == true && powerupCounter >= 20){
91+
if(powerupused && powerupCounter >= 20){
9292
powerupused = false;
9393
powerupCounter = 0;
9494
System.out.println("Powerup Rest: " + powerupCounter);
9595
}
96-
else if(powerupused == true && powerupCounter < 20){
96+
else if(powerupused && powerupCounter < 20){
9797
powerupCounter++;
9898
System.out.println("Powerup Counter: " + powerupCounter);
9999
}
100100

101101
//this makes it so that when the power up is used and in progress it keeps track of the time
102-
if(powerupused == true && powerupInProgress == true){
102+
if(powerupused && powerupInProgress){
103103
powerupInProgressCounter++;
104104
}
105105

106106
//this resets the power up
107-
if(powerupInProgress == true && powerupInProgressCounter >= 10){
107+
if(powerupInProgress && powerupInProgressCounter >= 10){
108108
powerupInProgress = false;
109109
PlayManager.dropInterval -= 40;
110110
powerupInProgressCounter = 0;
@@ -117,14 +117,14 @@ else if(powerupused == true && powerupCounter < 20){
117117

118118
private void update() {
119119

120-
if (KeyHandler.gamestart == false) {
120+
if (!KeyHandler.gamestart) {
121121
mh.update();
122122
}
123-
if (KeyHandler.gamequit == true)
123+
if (KeyHandler.gamequit)
124124
{
125125
System.exit(0);
126126
}
127-
else if(KeyHandler.pausePressed == false && pm.gameOver == false)
127+
else if(!KeyHandler.pausePressed && !pm.gameOver)
128128
{
129129
pm.update();
130130
}
@@ -134,7 +134,7 @@ public void paintComponent(Graphics g) {
134134
super.paintComponent(g);
135135

136136
Graphics2D g2 = (Graphics2D) g;
137-
if (KeyHandler.gamestart == false)
137+
if (!KeyHandler.gamestart)
138138
{
139139
mh.draw(g2);
140140
}
@@ -147,14 +147,14 @@ public void paintComponent(Graphics g) {
147147

148148
@Override
149149
public void PowerUpUpdate() {
150-
if(powerupused == false){
150+
if(!powerupused){
151151
PlayManager.dropInterval += 40;
152152
System.out.println(PlayManager.dropInterval);
153153
powerupused = true;
154154
powerupInProgress = true;
155155
PowerupCounter = 0;
156156
}
157-
else if(powerupused == true){
157+
else if(powerupused){
158158
System.out.println("the power up is on cooldown");
159159
}
160160
}

tetris/MenuHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public void draw(Graphics2D g2){
4343
String instructions = "Press 1 to Start, Press 2 to Quit";
4444
int instrWidth = g2.getFontMetrics().stringWidth(instructions);
4545
g2.drawString(instructions, (WIDTH - instrWidth) / 2, HEIGHT / 2);
46+
47+
instructions = "Press M to turn On the Music";
48+
instrWidth = g2.getFontMetrics().stringWidth(instructions);
49+
g2.drawString(instructions, (WIDTH - instrWidth) / 2, (int) (HEIGHT / (1.5)));
4650
}
4751

4852
public void update()

tetris/PlayManager.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ private Mino minoPicker() {
109109

110110
public void update() {
111111
// check if the current is active
112-
if(KeyHandler.gamestart == false)
112+
if(!KeyHandler.gamestart)
113113
{
114114

115115
}
116116
else{
117-
if (currentMino.active == false) {
117+
if (!currentMino.active) {
118118
// if not active add that in static block
119119
staticBlocks.add(currentMino.b[0]);
120120
staticBlocks.add(currentMino.b[1]);
@@ -199,12 +199,12 @@ private void checkDelete() {
199199
}
200200

201201
// a line has deleted so need to move down blocks
202-
for (int i = 0; i < staticBlocks.size(); i++) {
202+
for (Block staticBlock : staticBlocks) {
203203

204204
// if a block is above the current y , move it down by the block size
205205

206-
if (staticBlocks.get(i).y < y) {
207-
staticBlocks.get(i).y += Block.SIZE;
206+
if (staticBlock.y < y) {
207+
staticBlock.y += Block.SIZE;
208208
}
209209
}
210210
}
@@ -258,16 +258,16 @@ public void draw(Graphics2D g2) {
258258
currentMino.draw(g2);
259259
}
260260
nextMino.draw(g2);
261-
for (int i = 0; i < staticBlocks.size(); i++) {
262-
staticBlocks.get(i).draw(g2);
261+
for (Block staticBlock : staticBlocks) {
262+
staticBlock.draw(g2);
263263
}
264264

265265
// Draw any effects (line deletion, etc.) using a subtle style
266266
if (effectsCounterOn) {
267267
effectCounter++;
268268
g2.setColor(Color.RED);
269-
for (int i = 0; i < effectY.size(); i++) {
270-
g2.fillRect(left_x, effectY.get(i), WIDTH, Block.SIZE);
269+
for (Integer integer : effectY) {
270+
g2.fillRect(left_x, integer, WIDTH, Block.SIZE);
271271
}
272272
if (effectCounter == 10) {
273273
effectsCounterOn = false;

0 commit comments

Comments
 (0)