ArthurDn

Untitled

Sep 26th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.30 KB | None | 0 0
  1.  
  2.     package tetris;
  3.  
  4.     import java.awt.Color;
  5.  
  6. import java.awt.Graphics;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.KeyAdapter;
  10. import java.awt.event.KeyEvent;
  11.  
  12. import javax.swing.JLabel;
  13. import javax.swing.JPanel;
  14. import javax.swing.Timer;
  15.  
  16. import tetris.Z;
  17.  
  18.     public class Board extends JPanel implements ActionListener {
  19.         Timer timer;
  20.         static int [][] board=new int [10][20];
  21.        static int i=4;
  22.        static int j=1;
  23.         boolean isFallingFinished = false;
  24.         boolean isStarted = false;
  25.         boolean isPaused = false;
  26.         int numLinesRemoved = 0;
  27.    
  28.         JLabel statusbar;
  29.         Shape curPiece;
  30.        
  31.         public Board(Tetris parent) {
  32.  
  33.            setFocusable(true);
  34.            curPiece = new Z(30, i, j, "Red", "Z" );
  35.            timer = new Timer(4000, this);
  36.            timer.start();
  37.  
  38.            statusbar =  parent.getStatusBar();
  39.          
  40.            addKeyListener(new TAdapter());
  41.            clearBoard();  
  42.         }
  43.  
  44.         public void start()
  45.         {
  46.             if (isPaused)
  47.                 return;
  48.  
  49.             isStarted = true;
  50.             isFallingFinished = false;
  51.             numLinesRemoved = 0;
  52.             clearBoard();
  53.  
  54.             newPiece();
  55.             timer.start();
  56.         }
  57.         public void actionPerformed(ActionEvent e) {
  58.          
  59.                 newPiece();
  60.            
  61.         }
  62.  
  63.  
  64.         public void paint(Graphics g)
  65.         {
  66.             super.paint(g);
  67.             for ( ; i < 5; ++i) {
  68.                 for (; j < 18; ++j) {
  69.                   if (curPiece.color.equals("Red"))
  70.                       System.out.println("1");
  71.                      
  72.                       g.setColor(Color.red);
  73.                     if (curPiece.name.equals("Z"))
  74.                           System.out.println("2");
  75.                        g.fillRect(i*30, j*30, Z.size, Z.size);
  76.                 }
  77.             }
  78.  
  79.         }
  80.  
  81.         private void dropDown()
  82.         {
  83.            
  84.         }
  85.  
  86.         private void oneLineDown()
  87.         {
  88.            
  89.         }
  90.  
  91.  
  92.         private void clearBoard()
  93.         {
  94.            
  95.         }
  96.  
  97.         private void pieceDropped()
  98.         {
  99.          
  100.          
  101.         }
  102.  
  103.         private void newPiece()
  104.         {
  105.           repaint();
  106.         }
  107.  
  108.         private boolean tryMove(Shape newPiece, int newX, int newY)
  109.         {
  110.             return isFallingFinished;
  111.            
  112.            
  113.         }
  114.  
  115.         private void removeFullLines()
  116.         {
  117.          
  118.          }
  119.  
  120.      
  121.  
  122.         class TAdapter extends KeyAdapter {
  123.              public void keyPressed(KeyEvent e) {
  124.  
  125.            
  126.  
  127.                  int keycode = e.getKeyCode();
  128.  
  129.                  if (keycode == 'p' || keycode == 'P') {
  130.                    
  131.                      return;
  132.                  }
  133.  
  134.                  if (isPaused)
  135.                      return;
  136.  
  137.                  switch (keycode) {
  138.                  case KeyEvent.VK_LEFT:
  139.                      i=i-1;
  140.                      break;
  141.                  case KeyEvent.VK_RIGHT:
  142.                      i=i+1;
  143.                      break;
  144.                  case KeyEvent.VK_DOWN:
  145.                    
  146.                      break;
  147.                  case KeyEvent.VK_UP:
  148.                
  149.                      break;
  150.                  case KeyEvent.VK_SPACE:
  151.                      dropDown();
  152.                      break;
  153.                  case 'd':
  154.                      oneLineDown();
  155.                      break;
  156.                  case 'D':
  157.                      oneLineDown();
  158.                      break;
  159.                  }
  160.  
  161.              }
  162.          }
  163.     }
Advertisement
Add Comment
Please, Sign In to add comment