Esempio n. 1
0
  // we use this code to get server messages
  public void listen() throws SlickException {

    Message_Decorder decode = new Message_Decorder(map, grid);

    while (true) {

      // get server message
      String server_message = conn.getUpdates();
      if (server_message != null) {
        System.out.println(server_message + "\n");

        // update map
        map.Update();
        if (grid != null) {
          grid.update(map);
        }

        // decode the message and update the map

        decode.setMap(map);
        decode.setGrid(grid);
        map = decode.process(server_message);

        map.Update();
        if (grid != null) {
          grid.update(map);
        }

        messagelist.add(server_message);
        if (map.getTanks().size() > 0) {}
      }
    }
  }
Esempio n. 2
0
  public static int distroyTank(Tank mytank, int[][] memory, Map map) {
    if (mytank != null) {

      // get mytank coordinates
      int xMy = mytank.getX();
      int yMy = mytank.getY();
      int direction = mytank.getDirection();

      // check all tanks
      l1:
      for (Tank tank : map.getTanks()) {
        // to identify enemy tank and who has more than 0 health
        if (tank.getId() != map.getClientID() && tank.getHealth() > 0) {

          int x = tank.getX();
          int y = tank.getY();

          // if enemy situated same x axis with me and right side
          if (xMy < x && y == yMy) {
            for (int i = xMy + 1; i < x; i++) {
              if (memory[i][yMy] != 0) {
                continue l1;
              }
            }
            if (direction == 1) {
              return 5;
            } else {
              return 3;
            }
          }
          // if enemy situated same x axis with me and left side

          else if (xMy > x && y == yMy) {

            for (int i = x + 1; i < xMy; i++) {
              if (memory[i][yMy] != 0) {
                continue l1;
              }
            }

            if (direction == 3) {
              return 5;
            } else {
              return 4;
            }
            //// if enemy situated same y axis with me and up to me
          } else if (yMy < y && x == xMy) {
            for (int i = yMy + 1; i < y; i++) {
              if (memory[xMy][i] != 0) {
                continue l1;
              }
            }

            if (direction == 2) {
              return 5;
            } else {
              return 2;
            }

            // if enemy situated same y axis with me and down to me
          } else if (yMy > y && x == xMy) {
            for (int i = y + 1; i < yMy; i++) {
              if (memory[xMy][i] != 0) {
                continue l1;
              }
            }
            if (direction == 0) {
              return 5;
            } else {
              return 1;
            }
          }
        }
      }

      return 0;
    }
    return 0;
  }