Beispiel #1
0
 // Add a random tetris shape to the arraylist
 // Add the shape to the tool bar
 // Also find the ai command when ai is enabled
 public void addShape() {
   shapeTrack = new ArrayList<Integer>();
   int n = (int) (Math.random() * 7);
   switch (n) {
     case (0):
       shapes.add(new Block(THA.WIDTH / 2 - 40, -80, new Color(0, 0, 128)));
       break;
     case (1):
       shapes.add(new Line(THA.WIDTH / 2 - 40, -80, new Color(75, 0, 130)));
       break;
     case (2):
       shapes.add(new LeftZ(THA.WIDTH / 2 - 40, -80, new Color(255, 215, 0)));
       break;
     case (3):
       shapes.add(new RightZ(THA.WIDTH / 2 - 40, -80, new Color(255, 20, 147)));
       break;
     case (4):
       shapes.add(new T(THA.WIDTH / 2 - 40, -80, new Color(205, 0, 0)));
       break;
     case (5):
       shapes.add(new LeftL(THA.WIDTH / 2 - 40, -80, new Color(255, 165, 0)));
       break;
     case (6):
       shapes.add(new RightL(THA.WIDTH / 2 - 40, -80, new Color(0, 128, 0)));
       break;
     default:
       System.out.println("Impossible Error!!!");
       break;
   }
   ns.clear();
   ns.addShape(shapes);
   if (shapeAI.getAI()) {
     aiCommand = shapeAI.initAI(map, shapes.get(0));
   }
 }
Beispiel #2
0
 /** Controls the movements and actions of character and tetris pieces */
 public void keyPressed(KeyEvent key) {
   String keyText = KeyEvent.getKeyText(key.getKeyCode());
   if (!pause) {
     if (!shapeAI.getAI()) {
       if (keyText.equalsIgnoreCase("a")) {
         shapes.get(0).moveLeft(map);
         shapeTrack.add(1);
       }
       if (keyText.equalsIgnoreCase("d")) {
         shapes.get(0).moveRight(map);
         shapeTrack.add(2);
       }
       if (keyText.equalsIgnoreCase("w")) {
         shapes.get(0).turn(map, shapeTrack);
       }
     }
     if (keyText.equalsIgnoreCase("left")) {
       character.moveLeft();
     }
     if (keyText.equalsIgnoreCase("right")) {
       character.moveRight();
     }
     if (keyText.equalsIgnoreCase("up")) {
       character.jump();
     }
     if (keyText.equalsIgnoreCase("Slash")) {
       guntrack += 1;
       if (guntrack > weapons.length - 1) {
         guntrack = 0;
       }
     }
   }
   repaint();
 }
Beispiel #3
0
 public void unPause() {
   pause = false;
   moveTime.start();
   fallTime.start();
   bulletMoveTime.start();
   waterTime.start();
   bulletTime.start();
   grenadeTime.start();
   laserTime.start();
   shotgunTime.start();
   if (shapeAI.getAI()) {
     aiMove.start();
   }
 }
Beispiel #4
0
 public void pause() {
   pause = true;
   moveTime.stop();
   fallTime.stop();
   bulletMoveTime.stop();
   waterTime.stop();
   bulletTime.stop();
   grenadeTime.stop();
   laserTime.stop();
   shotgunTime.stop();
   if (shapeAI.getAI()) {
     aiMove.stop();
   }
 }