Beispiel #1
0
 /** Metod som aktiveras när man trycker på nyttspel knappen. */
 public void nyttSpel() {
   // om man trycker på nytt spel så resettas poängen och metoden newGame anropas i klassen viewer
   // och då resettas värdena i viewern. metoden enableButtons i userInput klassen anropas och
   // knapparna av dimmas.
   humPlayer.setScore(0);
   cpuPlayer.setScore(0);
   gameboard.newGame();
   gameboard.enableButtons();
 }
 @Test
 public void testGetScore_AfterScoreChange() {
   assertTrue(player1.getScore() == 0);
   assertTrue(player2.getScore() == 0);
   player1.setScore(100);
   player2.setScore(999);
   assertTrue(player1.getScore() == 100);
   assertTrue(player2.getScore() == 999);
 }
  /** Test of setScore method, of class Player. */
  @Test
  public void testSetScore() {
    assertTrue(player1.getScore() == 0);
    assertTrue(player2.getScore() == 0);

    player1.setScore(100);
    player2.setScore(999);
    assertTrue(player1.getScore() == 100);
    assertTrue(player2.getScore() == 999);

    player1.setScore(999);
    player2.setScore(100);
    assertTrue(player1.getScore() == 999);
    assertTrue(player2.getScore() == 100);
  }
  /**
   * Creates a new "game" from the current engine.Globals.game variable. While the ANN stays the
   * same, the speed, actor positions, score, et cetera, are all reset.
   */
  public void newGame() {
    stopped = true;
    player.setLives(STARTING_LIVES);
    player.setScore(0);
    Graphics g = strategy.getDrawGraphics();
    waiting = true;

    Globals.state = ENEMY_HUNTER_STATE;

    player.setCenter(board.getPlayerStartPoint());
    player.setDirection(Player.DEFAULT_STARTING_DIRECTION);

    board.reset();
    Globals.blipsLeft = Globals.game.getBoard().getBlipCount();

    for (Enemy enemy : enemies) {
      enemy.reset();
    }

    GamePainters.drawBoard(board, g, this);
    GamePainters.drawEnemies(enemies, g, this);
    GamePainters.drawPlayer(player, g, this);
    GamePainters.paintBottomBar(player, board, g, this);
    strategy.show();
  }
  public void protocolBall() {
    /* On met à jour la position de la balle */
    int positionBallX = Integer.parseInt(tab[1]);
    int positionBallY = Integer.parseInt(tab[2]);

    Ball ball = pong.getBall();

    /* Anti-cheat */
    if ((positionBallX > (ball.getPositionX() + ball.getSpeedX()) && ball.getSpeedX() > 0)
        || (positionBallX < (ball.getPositionX() + ball.getSpeedX()) && ball.getSpeedX() < 0)
        || (positionBallY > (ball.getPositionY() + ball.getSpeedY()) && ball.getSpeedY() > 0)
        || (positionBallY < (ball.getPositionY() + ball.getSpeedY()) && ball.getSpeedY() < 0)) {
      errorCheat("Balle avec coordonnées invalides (cheat)");
    }

    ball.setPosition(new Point(positionBallX, positionBallY));
    pong.setBall(ball);

    /* On met à jour les scores */
    for (int i = 3; i < tab.length; i++) {
      String[] curPlayer = tab[i].split(";");
      PlayerID playerID = PlayerID.valueOf(curPlayer[0]);
      int score = Integer.parseInt(curPlayer[1]);

      Iterator<Player> it = pong.setPlayers.iterator();
      while (it.hasNext()) {
        Player player = it.next();
        if (player.getPlayerID() == playerID) {
          player.setScore(score);
        }
      }
    }
  }
Beispiel #6
0
 public Player addPlayer(User user) {
   Player player = new Player();
   player.setUser(user);
   player.setScore(0);
   if (players != null) {
     player.setOrder(players.stream().mapToInt(p -> p.getOrder()).max().getAsInt() + 1);
   } else {
     player.setOrder(0);
   }
   getPlayers().add(player);
   return player;
 }
Beispiel #7
0
  public void init() {

    // LEVEL SPEED
    levelSpeed = 8;

    // AudioPlayer init
    AudioLoader.loadFromFile("nivel3_sonido.txt");

    // images loading
    ImagesLoader.loadFromFile("nivel3_imagenes.txt");
    ImagesLoader.loadFromFile("nivel_efectosvisuales_imagenes.txt");
    ImagesLoader.loadFromFile("food_imagenes.txt");

    // food appearance probability
    if (difficulty == OptionsState.EASY) foodprobability = 0.8;
    if (difficulty == OptionsState.NORMAL) foodprobability = 0.88;
    if (difficulty == OptionsState.HARD) foodprobability = 0.94;

    fooddelays = new int[6];
    fooddelays[0] = 100;
    fooddelays[1] = 600;
    fooddelays[2] = 100;
    fooddelays[3] = 500;
    fooddelays[4] = 100;
    fooddelays[5] = 400;

    // Events init
    eventIntro = true;
    eventClear = eventDead = eventCaught = false;

    txtAnimation = new TextAnimation();

    camera = new Camera();
    cameraPoint = new Camera();

    levelStart = false;
    levelIntroTimer = System.nanoTime();
    levelIntroDelay = 10000;

    foodTimer = System.nanoTime();
    foodDelay = 3000;

    // load fonts
    Text.loadFont("yummyFont.png");
    Text.loadFont("leishoFont.png");

    player = new Player();
    npc = new NPC(player);
    dishes = new ArrayList<>();
    hud = new HUD(player);

    // difficulty
    difficulty = OptionsData.getDifficulty();

    // rails init
    rails = new Rail[3];

    // title init
    titleIntroA = new Title(levelName, Title.INTROANIMATIONA);
    titleIntroB = new Title("EMPIEZA", Title.INTROANIMATIONB);
    titleClear = new Title("GANASTE", Title.CLEARANIMATION);
    titleDead = new Title("MORISTE", Title.CAUGHTANIMATION);
    titleCaught = new Title("ATRAPADO", Title.CAUGHTANIMATION);

    titleIntroA.start();

    // background creation
    // individual creation

    bgKitchen = new Background(0, 0, ImagesLoader.getImage("3_background"), Background.MOVELEFT);
    heartAttack =
        new BackgroundAnimation(
            ImagesLoader.getImage("heartsolo"), BackgroundAnimation.HEARTATTACK);
    warning =
        new BackgroundAnimation(ImagesLoader.getImage("warning"), BackgroundAnimation.WARNING);
    /*
    bgSky = new Background(0, 0, ImagesLoader.getImage("nivel1_clouds"));
    bgSoil = new Background(0, GamePanel.HEIGHT - (ImagesLoader.getHeight("nivel1_soil")),
            ImagesLoader.getImage("nivel1_soil"));
    */
    numbers = new ArrayList<>();
    explosions = new ArrayList<>();
    powerup = new ArrayList<>();
    player.init(dishes, numbers, explosions, powerup);

    // setting the score for the player
    player.setScore(PlayerData.getScore());

    foodValues = new HashMap<>();
    foodList = new ArrayList<>();
    powerList = new ArrayList<>();

    loadFoodFile("archivoComida.txt");

    powerList.add("FREEZEPOWER");
    powerList.add("DOUBLESCOREPOWER");
    powerList.add("DOUBLESPEEDPOWER");
    powerList.add("HALFSPEEDPOWER");

    // set position
    // debugging
    player.setPositionInRail(playerxscreen, player.getCurrentRail());
    cameraPoint.setPosition(playerxscreen, 0);

    // player.setVector(levelSpeed, 0);
    // parameters to be given: dx, dy, moveSpeed, jumpStart, fallSpeed
    player.setSpeed(levelSpeed, 0, 3.6, -28.8, 1.8);
    cameraPoint.setVector(levelSpeed, 0);

    npc.setPositionInRail(-npc.getWidth() / 2, npc.getCurrentRail());
    // npc.setVector(levelSpeed, 0);
    // parameters to be given: dx, dy, moveSpeed
    npc.setSpeed(levelSpeed, 0, 3.6);

    player.setCamera(camera);
    npc.setCamera(camera);

    // results stuff init
    squarewidth = 5;
    squareheight = 1;
    resultsDelay = 600;
    ticksResults = 0;

    // AudioPlayer volume setting
    // AudioPlayer.setVolume("musicFnm", -5.0f);
    AudioPlayer.setVolume("increasescore", -25.0f);

    // AudioPlayer bg play
    AudioPlayer.playAndLoop(musicFnm);
  }
Beispiel #8
0
  public void addPoints(Player player, int num) {

    player.setScore(player.getScore() + num);
  }
Beispiel #9
0
  public void serverWinScore() {
    //		System.out.println(server.getName() + " Score");
    if (!conditionEndGame()) {
      String scoreServerAndReciever = server.getScore() + reciever.getScore();
      switch (scoreServerAndReciever) {
        case "00":
          server.setScore("15");
          break;
        case "015":
          server.setScore("15");
          break;
        case "030":
          server.setScore("15");
          break;
        case "040":
          server.setScore("15");
          break;

        case "150":
          server.setScore("30");
          break;
        case "1515":
          server.setScore("30");
          break;
        case "1530":
          server.setScore("30");
          break;
        case "1540":
          server.setScore("30");
          break;

        case "300":
          server.setScore("40");
          break;
        case "3015":
          server.setScore("40");
          break;
        case "3030":
          server.setScore("40");
          break;
        case "3040":
          server.setScore("40");
          break;

        case "400":
          server.setScore("Win");
          server.setWin(true);
          winer = server;
          break;
        case "4015":
          server.setScore("Win");
          server.setWin(true);
          winer = server;
          break;
        case "4030":
          server.setScore("Win");
          server.setWin(true);
          winer = server;
          break;

        case "4040":
          server.setScore("A");
          break;

        case "A40":
          server.setScore("Win");
          server.setWin(true);
          winer = server;
          break;

        case "40A":
          reciever.setScore("40");
          break;
      }
    }
    printConsole();
  }
Beispiel #10
0
 public void setScoreServerAndRecieverInGame(String serverScore, String recieverScore) {
   server.setScore(serverScore);
   reciever.setScore(recieverScore);
 }