Gameover
This commit is contained in:
parent
8949a699ef
commit
744c17517b
@ -1,7 +1,6 @@
|
||||
package Tetris;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
@ -11,8 +10,7 @@ import javax.swing.JPanel;
|
||||
import javax.swing.Timer;
|
||||
|
||||
//Ewen Kerbs,Zhe Wang-Holkenbrink
|
||||
public class Board extends JPanel implements KeyListener
|
||||
{
|
||||
public class Board extends JPanel implements KeyListener {
|
||||
private static int FPS = 60;
|
||||
private static int delay = FPS / 1000;
|
||||
|
||||
@ -26,6 +24,7 @@ public class Board extends JPanel implements KeyListener
|
||||
private Stein[] steine = new Stein[7];
|
||||
private Stein currenStein;
|
||||
private Random ran;
|
||||
private boolean gameOver = false;
|
||||
|
||||
// Steinfarben
|
||||
private Color[] colors = {Color.decode("#ff00bf"), Color.decode("#0000ff"), Color.decode("#00ff80"), Color.decode("#ff8000"), Color.decode("#ffb3b3"),
|
||||
@ -81,9 +80,28 @@ public class Board extends JPanel implements KeyListener
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if (spielbeenden()) {
|
||||
loop.stop();
|
||||
return;
|
||||
}
|
||||
currenStein.update();
|
||||
}
|
||||
|
||||
private boolean spielbeenden() {
|
||||
if (!gameOver) {
|
||||
for (int i = 0; i < currenStein.getCoords().length; i++) {
|
||||
for (int j = 0; j < currenStein.getCoords()[0].length; j++) {
|
||||
if (currenStein.getCoords()[i][j] != 0) {
|
||||
if (board[currenStein.getY() + i][currenStein.getX() + j] != null) {
|
||||
gameOver = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void setCurrenStein() {
|
||||
currenStein = steine[ran.nextInt(steine.length)];
|
||||
@ -123,44 +141,40 @@ public class Board extends JPanel implements KeyListener
|
||||
g.drawLine(0, BLOCK_SIZE * row, BLOCK_SIZE * BOARD_WIDTH, BLOCK_SIZE * row);
|
||||
}
|
||||
for (int col = 0; col < BOARD_WIDTH + 1; col++) {
|
||||
g.drawLine(col * BLOCK_SIZE, 0, col * BLOCK_SIZE, BLOCK_SIZE * BOARD_HEIGHT);
|
||||
g.drawLine(col * BLOCK_SIZE, 0, col * BLOCK_SIZE, BLOCK_SIZE * BOARD_HEIGHT);}
|
||||
if (gameOver) {
|
||||
String gameOverString = "GAME OVER";
|
||||
g.setColor(Color.GREEN);
|
||||
g.setFont(new Font("SANS_SERIF", Font.BOLD, 30));
|
||||
g.drawString(gameOverString, 50, GameGui.height / 2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Bewegen die Steine mit Taste, Taste-Space : nach unten, Taste d : nach rechts, Taste a : nach links, leider klappt nicht.
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
// switch(e.getKeyChar()) {
|
||||
// case KeyEvent.VK_SPACE:
|
||||
// currenStein.speedup();
|
||||
// break;
|
||||
// case KeyEvent.VK_A:
|
||||
// currenStein.moveLeft();
|
||||
// break;
|
||||
// case KeyEvent.VK_D:
|
||||
// currenStein.moveRight();
|
||||
// break;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Bewegen die Steine mit Taste, Taste-Space : nach unten, Taste Enter : nach rechts, Taste Escape : nach links
|
||||
//Tastatur eingabe zur steinbewegung
|
||||
//wang/kerbs
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(e.getKeyChar() == KeyEvent.VK_SPACE){
|
||||
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
currenStein.speedup();
|
||||
}else if(e.getKeyChar() == KeyEvent.VK_ENTER){
|
||||
} else if (e.getKeyCode() == KeyEvent.VK_D) {
|
||||
currenStein.moveRight();
|
||||
}
|
||||
else if(e.getKeyChar() == KeyEvent.VK_ESCAPE){
|
||||
} else if (e.getKeyCode() == KeyEvent.VK_A) {
|
||||
currenStein.moveLeft();
|
||||
} else if (e.getKeyCode() == KeyEvent.VK_W) {
|
||||
currenStein.steinRotiert();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if(e.getKeyChar() == KeyEvent.VK_SPACE){
|
||||
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
currenStein.speedDown();
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Stein {
|
||||
|
||||
|
||||
//SteineTyp Block;
|
||||
private int x = 4, y = 0;
|
||||
private int normal = 850;
|
||||
@ -201,4 +203,14 @@ public void moveRight(){
|
||||
public void moveLeft(){
|
||||
deltax = -1;
|
||||
}
|
||||
public int[][] getCoords() {
|
||||
return coords;
|
||||
}
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user