Advertisement
Guest User

Noah smokes cock

a guest
Dec 18th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.96 KB | None | 0 0
  1. import java.awt.event.KeyEvent;
  2. import java.awt.*;
  3. import java.io.PrintStream;
  4. import kareltherobot.*;
  5. import javax.swing.KeyStroke;
  6.  
  7. public class Pacman extends SuperKarel implements Runnable
  8. {
  9.    public int up;
  10.    public int down;
  11.    public int left;
  12.    public int right;
  13.    public int beeperCount;
  14.    public static int atAvenue;
  15.    public static int atStreet;
  16.    public boolean isKill;
  17.    public int isSuper;
  18.    public int lives = 3;
  19.  
  20.    public Pacman(int street, int avenue, Direction direction, int beepers)
  21.    {
  22.       super(street, avenue, direction, beepers);
  23.       World.setupThread(this);
  24.       atAvenue = avenue;
  25.       atStreet = street;
  26.    }
  27.    
  28.    public void run()
  29.    {
  30.       startPacman();
  31.       wakawaka = new EasySound("wakawaka.wav");
  32.       movepacman();
  33.    }
  34.    
  35.    private void movepacman()
  36.    {
  37.       while (true)
  38.       {
  39.          if (left > 1)
  40.          {
  41.             faceWest();
  42.             if (frontIsClear())
  43.             {
  44.                grabBeeper();
  45.                left--;
  46.                atAvenue--;
  47.                superTimer();
  48.                move();
  49.             }
  50.          
  51.          }
  52.          else if (right > 1)
  53.          {
  54.             faceEast();
  55.             if (frontIsClear())
  56.             {
  57.                grabBeeper();
  58.                right--;
  59.                atAvenue++;
  60.                superTimer();
  61.                move();
  62.             }
  63.          }
  64.          else if (up > 1)
  65.          {
  66.             faceNorth();
  67.             if (frontIsClear())
  68.             {
  69.                grabBeeper();
  70.                up--;
  71.                atStreet++;
  72.                superTimer();
  73.                move();
  74.             }
  75.          }
  76.          else if (down > 1)
  77.          {
  78.             faceSouth();
  79.             if (frontIsClear())
  80.             {
  81.                grabBeeper();
  82.                down--;
  83.                atStreet--;
  84.                superTimer();
  85.                move();
  86.             }
  87.          }
  88.          if ((nextToARobot()) && isSuper<1)
  89.          {
  90.             if (lives > 0) {
  91.                lives--;
  92.                turnOff();
  93.                //teleports back
  94.             }
  95.             else
  96.             {
  97.                System.out.println("You lose.");
  98.                turnOff();
  99.             }
  100.          }
  101.          System.out.println("" + atStreet + " " +atAvenue + " " + beeperCount);
  102.          
  103.          if (beeperCount > 338)
  104.             break;
  105.       }
  106.    }
  107.  
  108.    private void superTimer()
  109.    {
  110.       if(isSuper>0)
  111.       {
  112.          isSuper--;
  113.       }
  114.    }
  115.  
  116.    private void grabBeeper()
  117.    {
  118.       World.setDelay(0);
  119.       if (nextToABeeper())
  120.       {
  121.          
  122.          pickBeeper();
  123.          eatingSound();
  124.          beeperCount++;
  125.          if (nextToABeeper())
  126.          {
  127.             pickBeeper();
  128.             isSuper = 300; //Number of moves Pacman is invincible for
  129.          }
  130.          //No witches detected
  131.       }
  132.       World.setDelay(5);
  133.    }
  134.    
  135.    private void eatingSound()
  136.    {
  137.      
  138.       wakawaka.play();
  139.    }
  140. /*
  141.      
  142.    public void warp()
  143.    {
  144.       if(atAvenue==26 && atStreet==17)
  145.       {
  146.          turnOff();
  147.          Pacman = new Pacman(17, 2, East, beeperCount);
  148.          Pacman.setVisible(true);
  149.       }
  150.       else if(atAvenue==2 && atStreet==17)
  151.       {
  152.          turnOff();
  153.          Pacman = new Pacman(17, 26, West, beeperCount);
  154.          Pacman.setVisible(true);
  155.       }
  156.    }
  157.    */
  158.  
  159.    
  160.    public void startPacman()
  161.    {
  162.        KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
  163.       focusManager.addKeyEventDispatcher(
  164.             new KeyEventDispatcher()
  165.             {
  166.                @Override
  167.                public boolean dispatchKeyEvent(KeyEvent e)
  168.                {
  169.                   {
  170.                   if (e.getKeyCode() == 38) {
  171.                      up = 25;
  172.                      left = 0;
  173.                      down = 0;
  174.                      right = 0;
  175.                   }
  176.                   else if (e.getKeyCode() == 37) {
  177.                      up = 0;
  178.                      left = 25;
  179.                      down = 0;
  180.                      right = 0;
  181.                   }
  182.                   else if (e.getKeyCode() == 40) {
  183.                      up = 0;
  184.                      left = 0;
  185.                      down = 25;
  186.                      right = 0;
  187.                   }
  188.                   else if (e.getKeyCode() == 39) {
  189.                      up = 0;
  190.                      left = 0;
  191.                      down = 0;
  192.                      right = 25;
  193.                   }
  194.                
  195.                   return false;
  196.                }
  197.                }
  198.                  
  199.            
  200.             });
  201.    
  202.    }
  203.    
  204.  
  205.    public static void main(String[] args)
  206.    {
  207.       World.readWorld("pacworldfixedv2.kwld");
  208.       World.setDelay(5);
  209.       World.setTrace(false);
  210.       World.showSpeedControl(true);
  211.       World.setVisible(true);
  212.       Pacman first = new Pacman(11, 14, North, 0);
  213.    }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement