Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tetris;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.Timer;
- import tetris.Z;
- public class Board extends JPanel implements ActionListener {
- Timer timer;
- static int [][] board=new int [10][20];
- static int i=4;
- static int j=1;
- boolean isFallingFinished = false;
- boolean isStarted = false;
- boolean isPaused = false;
- int numLinesRemoved = 0;
- JLabel statusbar;
- Shape curPiece;
- public Board(Tetris parent) {
- setFocusable(true);
- curPiece = new Z(30, i, j, "Red", "Z" );
- timer = new Timer(4000, this);
- timer.start();
- statusbar = parent.getStatusBar();
- addKeyListener(new TAdapter());
- clearBoard();
- }
- public void start()
- {
- if (isPaused)
- return;
- isStarted = true;
- isFallingFinished = false;
- numLinesRemoved = 0;
- clearBoard();
- newPiece();
- timer.start();
- }
- public void actionPerformed(ActionEvent e) {
- newPiece();
- }
- public void paint(Graphics g)
- {
- super.paint(g);
- for ( ; i < 5; ++i) {
- for (; j < 18; ++j) {
- if (curPiece.color.equals("Red"))
- System.out.println("1");
- g.setColor(Color.red);
- if (curPiece.name.equals("Z"))
- System.out.println("2");
- g.fillRect(i*30, j*30, Z.size, Z.size);
- }
- }
- }
- private void dropDown()
- {
- }
- private void oneLineDown()
- {
- }
- private void clearBoard()
- {
- }
- private void pieceDropped()
- {
- }
- private void newPiece()
- {
- repaint();
- }
- private boolean tryMove(Shape newPiece, int newX, int newY)
- {
- return isFallingFinished;
- }
- private void removeFullLines()
- {
- }
- class TAdapter extends KeyAdapter {
- public void keyPressed(KeyEvent e) {
- int keycode = e.getKeyCode();
- if (keycode == 'p' || keycode == 'P') {
- return;
- }
- if (isPaused)
- return;
- switch (keycode) {
- case KeyEvent.VK_LEFT:
- i=i-1;
- break;
- case KeyEvent.VK_RIGHT:
- i=i+1;
- break;
- case KeyEvent.VK_DOWN:
- break;
- case KeyEvent.VK_UP:
- break;
- case KeyEvent.VK_SPACE:
- dropDown();
- break;
- case 'd':
- oneLineDown();
- break;
- case 'D':
- oneLineDown();
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment