public void moveLayerThree(Graphics g) {
   backy += (int) (player1.getVelocity() * 0.1);
   midy += (int) (player1.getVelocity() * 0.5);
   drawEnemy(g);
   drawCoin(g);
   drawBox(g);
   drawPoof(g);
   drawStar(g);
   drawJumper(g);
   drawSpike(g);
   drawPup(g);
   if (backy <= dieHeight) {
     // System.out.println(die);
     g.drawImage(player1.move(2), player1.getX(), player1.getY(), this);
     if (player1.animationComplete()) {
       die = true;
     }
   } else {
     if (backy <= dieHeight) {
       player1.resetCounter();
     }
     if (keys[KeyEvent.VK_RIGHT]) {
       g.drawImage(player1.move(1), player1.getX(), player1.getY(), this);
     } else if (keys[KeyEvent.VK_LEFT]) {
       g.drawImage(player1.move(-1), player1.getX(), player1.getY(), this);
     } else {
       g.drawImage(player1.move(0), player1.getX(), player1.getY(), this);
     }
   }
 }
Beispiel #2
0
  public void movePlayer(PositionSwitcher movement) {
    Position newPlayerPos = movement.change(player.getPosition());
    Box box = boxIn(newPlayerPos);
    if (canMoveBoxAt(movement, box)) {
      box.move(movement);
      player.move(movement);

    } else if (isEmpty(newPlayerPos)) {
      player.move(movement);
    }
  }
Beispiel #3
0
  private void processKeyboard() {
    if (Gdx.input.isKeyPressed(Keys.LEFT)) {
      player.move(-1, 0);
    }
    if (Gdx.input.isKeyPressed(Keys.RIGHT)) {
      player.move(1, 0);
    }
    if (Gdx.input.isKeyPressed(Keys.UP)) {
      player.move(0, 1);
    }
    if (Gdx.input.isKeyPressed(Keys.DOWN)) {
      player.move(0, -1);
    }

    if (Gdx.input.isKeyPressed(Keys.SPACE)) {
      player.useShield();
    }
  }
Beispiel #4
0
 public void tick(GameControls gc, GameTimer time) {
   dt = time.GetDeltaTime();
   boolean hasMoved =
       player.move(
           level, (int) (player.getX() + gc.GetAxis(0)), (int) (player.getY() - gc.GetAxis(1)));
   if (hasMoved) {
     level.tick();
   }
 }
  public static void handleBanishment(Player player) {
    System.out.println("You're banished on the Moon.");

    // make sure the player is on a banish space
    while (!(board.getSpaces()[player.getBoardPosition()] instanceof MoonSpace)) {
      player.setPosition((player.getBoardPosition() + 1) % Board.BOARDSPACES, board);
    }

    if (player.getBanishmentAvoidChances() > 0) {
      System.out.println(
          "You can leave the Moon by using a "
              + "banishment avoid chance. Would you like to do "
              + "this? Y/N");
      if (Util.getResponse()) {
        player.changeBanishmentAvoidChances(-1);
        player.setBanished(0);
        System.out.println(
            "You're no longer banished. "
                + "You have "
                + player.getBanishmentAvoidChances()
                + " banishment avoid chances left");
        return;
      }
    }

    if (player.getCash() >= 50) {
      System.out.println(
          "You can leave the Moon now by " + "paying 50 bits. Would you like to pay? Y/N");
      if (Util.getResponse()) {
        player.changeCash(-50);
        player.setBanished(0);
        System.out.println("You're no longer banished");
        return;
      }
    }

    System.out.println(
        "You can escape from the Moon if you roll "
            + "a double. Press Enter when you want to roll");

    // wait for Enter key to be pressed
    input.nextLine();

    rollDice(player);

    int[] lastRolls = player.getLastRolls();
    if (lastRolls[0] == lastRolls[1]) {
      System.out.println("You escaped!");
      player.setBanished(0);
      player.move();
    } else {
      System.out.println("You remain on the Moon until at least " + "your next turn");
      player.setBanished(player.getBanished() - 1);
    }
  }
Beispiel #6
0
  private void processGamepad() {
    for (Controller controller : Controllers.getControllers()) {
      final float MOV_THRESHOLD = 0.25f;
      float xaxis = controller.getAxis(1);
      float yaxis = -controller.getAxis(0);
      if (Math.abs(xaxis) < MOV_THRESHOLD) xaxis = 0f;
      if (Math.abs(yaxis) < MOV_THRESHOLD) yaxis = 0f;
      player.move(xaxis, 0);
      player.move(0, yaxis);

      if (controller.getButton(0)) player.useShield();
    }
  }
Beispiel #7
0
 public void playerMove(String command) {
   char direction = command.charAt(0);
   Entity enemy = collision.collisionCheck(player.getX(), player.getY(), direction, entities);
   if (enemy != null) {
     collision.combat(player, enemy);
     // 4 testing
     System.out.println("COMBAT");
   } else {
     player.move(direction);
     // 4 testing
     System.out.println("MOVEMENT");
   }
 }
 /**
  * Disconnects this session from the server by canceling the registered key and closing the socket
  * channel.
  *
  * @param forced if the session must be disconnected because of an IO issue.
  */
 public void disconnect(boolean forced) {
   try {
     if (!forced && player.getCombatBuilder().inCombat()) {
       combatLogout = true;
       key.attach(null);
       key.cancel();
       channel.close();
       World.submit(
           new Task(150, false) {
             @Override
             public void execute() {
               if (!player.getCombatBuilder().inCombat()) {
                 disconnect(true);
                 this.cancel();
               }
             }
           });
       return;
     }
     packetDisconnect = forced;
     if (state == IOState.LOGGED_IN) {
       if (player.getOpenShop() != null)
         Shop.SHOPS.get(player.getOpenShop()).getPlayers().remove(player);
       World.getTaskQueue().cancel(player.getCombatBuilder());
       World.getTaskQueue().cancel(player);
       player.setSkillAction(false);
       World.getPlayers().remove(player);
       MinigameHandler.execute(player, m -> m.onLogout(player));
       player.getTradeSession().reset(false);
       player.getPrivateMessage().updateOtherList(false);
       if (FightCavesHandler.remove(player)) player.move(new Position(2399, 5177));
       player.save();
     }
     key.attach(null);
     key.cancel();
     channel.close();
     ConnectionHandler.remove(host);
     logger.info(
         state == IOState.LOGGED_IN
             ? player + " has logged " + "out."
             : this + " has logged out.");
     state = IOState.LOGGED_OUT;
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public static void movePlayer(Player player) {
   rollDice(player);
   player.move();
 }
Beispiel #10
0
 public void update(float dt) {
   player.move(dt);
 }
Beispiel #11
0
  public void checkInput(String input) {
    if (currentConvo != null) {
      if (input.equalsIgnoreCase("cancel")) {
        currentConvo = null;
        player.currentLoc.look();
      } else {
        currentConvo.talk(input);
      }
      return;
    }
    System.out.println(input);
    Pattern lookPattern = Pattern.compile("^look(\\s|$)");
    Pattern getPattern = Pattern.compile("^get(\\s|$)");
    Pattern dropPattern = Pattern.compile("^drop(\\s|$)");
    Pattern usePattern = Pattern.compile("^use(\\s|$)");
    Pattern movePattern = Pattern.compile("^move(\\s|$)");
    Pattern talkPattern = Pattern.compile("^talk(\\s|$)");
    Pattern argumentPattern = Pattern.compile("\\s\\w+($|\\s)");
    Pattern twoArgumentPattern =
        Pattern.compile(
            "\\s(\\w+|\\w+\\s\\w+)\\son\\s(\\w+|\\w+\\s\\w+)($|\\s)"); // makes UseOn work
    Pattern savePattern = Pattern.compile("^save(\\s|$)");
    Pattern loadPattern = Pattern.compile("^load(\\s|$)");
    Matcher argumentMatcher = argumentPattern.matcher(input);
    Matcher twoArgumentMatcher = twoArgumentPattern.matcher(input);

    // LOOK
    if (lookPattern.matcher(input).find()) {
      if (argumentMatcher.find()) {
        player.look(input.substring(argumentMatcher.start() + 1, input.length()));
      } else {
        player.look("");
      }
      return;
    }
    // END LOOK

    // TALK
    if (talkPattern.matcher(input).find()) {
      if (argumentMatcher.find()) {
        player.talk(input.substring(argumentMatcher.start() + 1, input.length()));
      } else {
        Gui.setOutputText("You talk to yourself for a while, it was a rivetting conversation");
      }
      return;
    }

    // GET/PICK UP
    if (getPattern.matcher(input).find()) {
      if (argumentMatcher.find()) {
        System.out.println("found argument");
        player.pickUp(input.substring(argumentMatcher.start() + 1, input.length()));
        return;
      } else {
        Gui.setOutputText("You can't pick up nothing, f****t.");
        return;
      }
    }
    // END GET

    // USE ON
    if (twoArgumentMatcher
        .find()) { // checks for two arguments so "use cat picture on joint" should call useOn?
      input = input.substring(twoArgumentMatcher.start() + 1, input.length());
      Pattern findOnPattern = Pattern.compile("\\son\\s");
      Matcher findOnMatcher = findOnPattern.matcher(input);
      findOnMatcher.find();
      String firstArg = input.substring(0, findOnMatcher.start()); // item 1
      String secondArg = input.substring(findOnMatcher.end(), input.length()); // item 2
      player.useOn(firstArg, secondArg);
      return;
    }
    // END USE ON

    // USE
    if (usePattern.matcher(input).find()) {
      if (argumentMatcher.find()) {
        player.use(input.substring(argumentMatcher.start() + 1, input.length()));
        return;
      } else {
        Gui.setOutputText("There's nothing like that to use.");
        return;
      }
    }
    // END USE

    // DROP
    if (dropPattern.matcher(input).find()) {
      if (argumentMatcher.find()) {
        player.drop(input.substring(argumentMatcher.start() + 1, input.length()));
        return;
      } else {
        Gui.setOutputText("You have dropped nothing.");
        return;
      }
    }
    // END DROP

    // MOVE
    if (movePattern.matcher(input).find()) {
      if (argumentMatcher.find()) {
        String destination = input.substring(argumentMatcher.start() + 1, input.length());
        for (Location l : player.currentLoc.getLinks()) {
          if (destination.equalsIgnoreCase(l.getName()) && l.isDiscovered()) {
            player.move(l);
            return;
          }
        }
        Gui.setOutputText("Invalid location");
        return;
      } else {
        Gui.setOutputText("You shuffled around a little bit");
        return;
      }
    }
    // END MOVE

    // SAVE
    if (savePattern.matcher(input).find()) {
      Gui.setOutputText(TextAdventure.saveWorld());
    }
    // END SAVE

    // LOAD
    if (loadPattern.matcher(input).find()) {
      Gui.setOutputText(TextAdventure.loadWorld());
    }
    // END LOAD

    // NONE OF THE ABOVE
    Gui.setOutputText(
        (String) TextAdventure.pick(TextAdventure.invalidVerb)); // prints out invalid verb
    return;
  }
 // test the move method
 void testMove(Tester t) {
   player.move(500, 30);
   t.checkExpect(player.loc, new Posn(500, 350));
 }
Beispiel #13
0
  public void handleInput() {

    // handle movement keys

    if (!editorMode) {

      if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
        player.move(Player.LEFT);
      } else if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
        player.move(Player.RIGHT);
      } else if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
        player.move(Player.DOWN);
      } else if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
        player.move(Player.UP);
      }

    } else {

      if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
        editorTag.getPosition().add(new Coord(-1f, 0f));
      } else if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
        editorTag.getPosition().add(new Coord(1f, 0f));
      } else if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
        editorTag.getPosition().add(new Coord(0f, -1f));
      } else if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
        editorTag.getPosition().add(new Coord(0f, 1f));
      }
    }

    // handle other keys

    while (Keyboard.next()) {

      char k = Keyboard.getEventCharacter();

      // the ` key toggles the console

      if (k == '`') {
        if (console.isEnabled()) {
          console.disable();
        } else {
          console.enable();
        }
      } else if (console.isEnabled()) {

        if (Keyboard.getEventKeyState()) {
          console.nextChar(k);
        }
      }

      // editor specific commands

      if (editorMode && !console.isEnabled()) {

        if (k == ' ') {
          map.setTile(editorTag.getPosition(), currentEditorTile);
        } else if (k == 'n') {
          currentEditorTile = (currentEditorTile + 1) % map.getNumTypes();
        }
      }
    }
  }
Beispiel #14
0
  private void parseCommand(String message) throws IOException {
    if (message.length() == 0) return;

    // Get the command (first word)
    String comm;
    String arguments = null;

    if (message.indexOf(' ') != -1) {
      comm = message.substring(0, message.indexOf(' '));
      arguments = message.substring(message.indexOf(' ') + 1);
    } else {
      comm = message;
    }

    switch (comm.toLowerCase()) {
      case "say":
        say(arguments);
        break;

      case "tell":
        tell(arguments);
        break;

      case "north":
      case "n":
        player.move(Direction.N);
        break;

      case "northeast":
      case "ne":
        player.move(Direction.NE);
        break;

      case "east":
      case "e":
        player.move(Direction.E);
        break;

      case "southeast":
      case "se":
        player.move(Direction.SE);
        break;

      case "south":
      case "s":
        player.move(Direction.S);
        break;

      case "southwest":
      case "sw":
        player.move(Direction.SW);
        break;

      case "west":
      case "w":
        player.move(Direction.W);
        break;

      case "northwest":
      case "nw":
        player.move(Direction.NW);
        break;

      case "in":
        player.move(Direction.IN);
        break;

      case "out":
        player.move(Direction.OUT);
        break;

      case "look":
      case "l":
        player.look();
        break;

      default:
        Telnet.writeLine(cs, "Your meaning is unclear\n");
    }
  }
 /*
  * commandInput(String given){...}
  * This is where the commands input by the player
  * are handled. You will need to add more if() checks
  * as you add more commands to the game. This is also
  * where login and signup are handled.
  */
 public void commandInput(String given) {
   // No empty strings.
   if (given.length() == 0) {
     return;
   }
   // Have the user login to their account.
   if (!login && !signup && username.length() == 0) {
     username = given;
     if (find(given, "name", file)) {
       prompt = true;
       commandOutput("Log into account " + given + "? [Y/N]\n");
     } else {
       signup = true;
       commandOutput("User not found. Would you like to make an account? [Y/N]\n");
     }
     return;
   }
   // Prompt for accepting login attempt
   if (prompt) {
     if (given.toUpperCase().equals("Y")) {
       newPass = false;
       commandOutput("Password: "******"N")) {
       username = "";
       commandOutput("Please reenter the account name you wish to log into.\n");
       prompt = false;
       return;
     } else {
       return;
     }
   }
   // Prompt for making a new account;
   if (signup) {
     if (given.toUpperCase().equals("Y")) {
       newPass = true;
       commandOutput("Please enter a password for this account:\n");
       signup = false;
       return;
     } else if (given.toUpperCase().equals("N")) {
       username = "";
       commandOutput("Please reenter the account name you wish to log into.\n");
       signup = false;
       return;
     } else {
       return;
     }
   }
   // Unidentified user with no password.
   if (newPass) {
     // Write the new player's information to the file.
     try {
       FileWriter writer = new FileWriter("players.txt", true);
       writer.write(username + " {");
       writer.write(System.lineSeparator());
       writer.write(username);
       writer.write(System.lineSeparator());
       writer.write("Password: "******"100");
       writer.write(System.lineSeparator());
       writer.write("100");
       writer.write(System.lineSeparator());
       writer.write("0");
       writer.write(System.lineSeparator());
       writer.write("0");
       writer.write(System.lineSeparator());
       writer.write("0");
       writer.write(System.lineSeparator());
       writer.write("[]");
       writer.write(System.lineSeparator());
       writer.write("None");
       writer.write(System.lineSeparator());
       writer.write("None");
       writer.write(System.lineSeparator());
       writer.write("None");
       writer.write(System.lineSeparator());
       writer.write("None");
       writer.write(System.lineSeparator());
       writer.write("None");
       writer.write(System.lineSeparator());
       writer.write("None");
       writer.write(System.lineSeparator());
       writer.write("None");
       writer.write(System.lineSeparator());
       writer.write("None");
       writer.write(System.lineSeparator());
       writer.write("}");
       writer.write(System.lineSeparator());
       writer.close();
       try {
         outgoing = new PrintWriter(socket.getOutputStream(), true);
       } catch (IOException ex) {
       }
       commandOutput(
           "Thank you! Please log into your new account by reentering this username!\n");
       username = "";
       newPass = false;
     } catch (IOException e) {
       username = "";
       newPass = false;
       commandOutput("Unexpected error occured. Please try again!\n");
     }
     return;
   }
   if (!login && username.length() > 0) {
     if (getPass(username, given, file)) {
       player = constructPlayer(username, file);
       login = true;
       commandOutput("Welcome back " + username + ".\n");
     } else {
       commandOutput("Incorrect password. Please reenter username.\n");
       username = "";
     }
     return;
   }
   String input = given.toUpperCase();
   if (input.equals("QUIT") || input.equals("DISCONNECT")) {
     try {
       // #Save_Player;
       commandOutput("Thank you and goodbye!\n");
       savePlayer(player);
       socket.close();
     } catch (IOException ex) {
     }
   } else if (input.contains("CON") || input.contains("CONDITION") || input.contains("STATUS")) {
     player.cond();
   } else if ((input.contains("MOVE ") && input.length() > 5)
       || (input.contains("M ") && input.length() > 2)
       || (movable.contains(input))) {
     player.move(input);
   } else if (input.contains("LOOK")
       || input.equals("L")
       || (input.contains("L ") && movable.contains(input.substring(input.indexOf(" ") + 1)))) {
     player.look(input);
   } else if (input.contains("GET") || input.contains("PICK UP")) {
     player.get(input);
   } else if ((input.contains("EQ ") && input.substring(0, input.indexOf(" ")).length() < 4)
       || (input.contains("EQUIP ") && input.substring(0, input.indexOf(" ")).length() < 7)
       || (input.contains("WEAR ") && input.substring(0, input.indexOf(" ")).length() < 5)) {
     player.equip(input);
   } else if (input.contains("UNEQ ") || input.contains("UNEQUIP ")) {
     player.unequip(input);
   } else if (input.equals("I") || input.equals("INVENTORY") || input.equals("INV")) {
     player.inventory();
   } else if (input.equals("EQ") || input.equals("EQUIPMENT")) {
     player.equipment();
   } else if (input.contains("DROP ")) {
     player.drop(input);
   } else if (input.equals("STAT") || input.equals("ST") || input.equals("STATS")) {
     player.stats();
   } else if (input.equals("")) {
     player.cond();
   } else if (input.contains("FLEE") || input.contains("F ") || input.equals("F")) {
     // player.flee(input);
   }
   while (player.drawText.size() > 0) {
     commandOutput(player.drawText.get(0));
     player.drawText.remove(0);
   }
 }
  /**
   * This starts the main game loop. This is the guts of the game. When the loop starts it checks to
   * see if the player has any lives left, if not, it prints "Game Over" and resets the game. If
   * there are lives left, it decides what the ghosts next move will be, detects any collisions, and
   * acts accordingly, and also gets input from the player
   */
  public void start() {
    Globals.state = ENEMY_HUNTER_STATE;
    Globals.game.setPlayer(new Player());
    player = Globals.game.getPlayer();
    player.setCenter(board.getPlayerStartPoint());
    newGame();
    paused = false;
    waiting = true;
    Point regenDoorPoint = board.getRegenDoor();
    Point regenPoint = board.getRegenPoint();
    Point playerPoint = player.getCenter();
    while ((this.isVisible()) && (player.getLives() >= 0)) {
      if (paused) {
        paintPauseScreen();
      }
      while (paused || stopped || waiting) {
        Thread.yield();
      }

      if (Globals.blipsLeft <= 0) {
        Globals.speed *= SPEED_MOD;
        resetCanvas();
        board.reset();
        Globals.blipsLeft = board.getBlipCount();
      }
      // now we need to see if the current state is enemy hunted
      if (Globals.state == ENEMY_HUNTED_STATE) {
        // now we need to see if we should go out of it
        if (Globals.timeUntilLeaveingHuntedState <= 0) {
          Globals.state = ENEMY_HUNTER_STATE;
          Globals.timeUntilLeaveingHuntedState = TIME_IN_HUNTED_STATE;
        } else {
          // we shouldn't, so we decrement the counter
          Globals.timeUntilLeaveingHuntedState -= Globals.speed;
        }
      }
      // move the player
      player.move(board.getMoveOptions(player), playerChoice);
      if (Globals.aiMode == FSA_AI_MODE) {
        // now updated the enemy movements
        for (int i = 0; i < enemies.length; i++) {
          // these are put here to reduce program jumping and cache misses as well
          Enemy enemy = enemies[i];
          int moveOptions = board.getMoveOptions(enemy);
          // first, we need to take apporpriate actions if we're on a regen tile
          if (board.getCurrentTile(enemy).isRegen()) {
            // first check to see if the enemy is alive
            if (!enemy.isAlive()) {
              // it's not, so we make it alive
              enemy.setAlive(true);
            }
            // now we tell the enemy to move towards the the door
            enemy.move(moveOptions, regenDoorPoint, true);
          } else {
            // We're not in the regen pen, so now we check if the enemy is alive
            if (!enemy.isAlive()) {
              // it's not, so we want to go towards the regen point
              enemy.move(moveOptions, regenPoint, false);
            } else {
              // the enemy is alive, so we tell it towards/away from the player
              enemy.move(moveOptions, playerPoint, false);
            }
          }
        }
      } else if (Globals.aiMode == ANN_AI_MODE) {
        // Globals.game.getNet().process(ANNTools.getBoardCondition(board, enemies, player));
        player.setInputValues(board);
        for (Enemy enemy : enemies) {
          enemy.setInputValues(board);
        }
        Globals.game.getNet().generateActivations();
        for (int i = 0; i < enemies.length; i++) {
          // Last 2 values don't matter here
          enemies[i].move(
              board.getMoveOptions(enemies[i]),
              board.getRegenDoor(),
              board.getCurrentTile(enemies[i]).isRegen());
        }
      }

      // no we check for collisions and act appropriately
      checkCollision();
      // check to see if we should notify the game that we have stepped
      if (Globals.trainingMode != TRAINING_MODE_OFF) {
        // we should, so we do.
        Globals.game.step();
      }
      // And now we sleep. The sleep time is the current speed
      try {
        Thread.sleep(Globals.speed);
      } catch (InterruptedException e) {
        break;
      }
      // no update the screen
      update();
    }
    if (player.getLives() <= 0) {
      paintGameOver();
      try {
        Thread.sleep(2500);
      } catch (InterruptedException e) {
        // DO nothing
      }
      newGame();
      start();
    }
  }
Beispiel #17
0
 @Override
 public void move() {
   move(direction);
 }
Beispiel #18
0
 public void actionPerformed(ActionEvent e) {
   p.move();
   repaint();
 }