Ejemplo n.º 1
0
 /**
  * Adjust unit loyalty, create rebels, place rebels. Note: AFAIK in all mods Naval move units can
  * only move on oceans, and non-Naval units can move on land, so rebels are placed with this
  * feature in mind.
  */
 public void adjustUnitLoyalty() {
   List<Unit> units = game.getUnits();
   LinkedList<Unit> rebels = new LinkedList<>();
   for (Unit unit : units) {
     if (unit.owner == game.getTurn() && canRebel(unit)) {
       unit.loyalty = pay_rate * C.PAY_LOYALTY_HIT;
       if (!unit.in_space && unit.loyalty < C.LOYALTY_REBEL_LIMIT) {
         if (game.getRandom().nextFloat()
             < (1 - unit.loyalty / C.LOYALTY_REBEL_LIMIT) * C.LOYALTY_REBEL_HIGH_P) {
           rebels.add(unit);
         }
       }
     }
   }
   if (rebels.isEmpty()) {
     return;
   }
   rebels.sort(Comp.unit_xy);
   rebels.sort(Comp.unit_pidx);
   LinkedList<Unit> naval = new LinkedList<>();
   LinkedList<Unit> non_naval = new LinkedList<>();
   for (Unit rebel : rebels) {
     if (rebel.move_type == C.MoveType.NAVAL) {
       naval.add(rebel);
     } else {
       non_naval.add(rebel);
     }
   }
   placeRebels(naval, Util.FindHexesAround.Hextype.SEA);
   placeRebels(non_naval, Util.FindHexesAround.Hextype.LAND);
 }
Ejemplo n.º 2
0
  public static void main(String[] args) {

    Background bg = new Background();

    Player player = new Player(100, 100, 200, 1);

    LinkedList<GameObject> gameObjects = new LinkedList<>();

    gameObjects.sort(
        new Comparator<GameObject>() {
          @Override
          public int compare(GameObject t, GameObject t1) {
            if (t.getY() > t.getY()) {
              return 1;
            }
            if (t.getY() < t.getY()) {
              return -1;
            }
            return 0;
          }
        });

    gameObjects.add(player);

    GUI f = new GUI(bg, gameObjects);
    f.setVisible(true);
    f.setResizable(false);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(800, 600);
    f.setLocationRelativeTo(null);
    f.setTitle("EatGetRekt");
    f.makeStrat();

    long lastFrame = System.currentTimeMillis();
    while (true) {
      long thisFrame = System.currentTimeMillis();
      float tslf = (float) (thisFrame - lastFrame) / 1000;
      lastFrame = thisFrame;

      f.repaintScreen();

      bg.update(tslf);
      for (GameObject gameObject : gameObjects) {
        gameObject.update(tslf);
      }
      try {
        Thread.sleep(15);
      } catch (InterruptedException ex) {
        JOptionPane.showMessageDialog(
            null,
            "You can not travel backwards in time. " + "Error: " + ex.getMessage(),
            "ERROR",
            JOptionPane.ERROR_MESSAGE);
      }
      if (KL.keys[KeyEvent.VK_ESCAPE]) {
        System.exit(0);
      }
    }
  }
Ejemplo n.º 3
0
  @SuppressWarnings("unchecked")
  public JPanel view(String src_n, String dst_n) {
    List<JPanel> panels = new LinkedList<>();
    LinkedList<String> sorted = new LinkedList<>(data.keySet());
    sorted.sort(String::compareTo);
    for (String k : sorted) {
      Set<Pair<Object, Object>> xxx = data.get(k);
      List<Pair<Object, Object>> table = new LinkedList<>(xxx);

      Object[][] arr = new Object[table.size()][2];
      int i = 0;
      for (Pair<Object, Object> p : table) {
        arr[i][0] = p.first;
        arr[i][1] = p.second;
        i++;
      }
      @SuppressWarnings("serial")
      JTable t =
          new JTable(arr, new Object[] {src_n, dst_n}) {
            @Override
            public Dimension getPreferredScrollableViewportSize() {
              Dimension d = getPreferredSize();
              return new Dimension(d.width, d.height);
            }
          };
      // //t.setRowSelectionAllowed(false);
      // t.setColumnSelectionAllowed(false);
      // MouseListener[] listeners = t.getMouseListeners();
      // for (MouseListener l : listeners) {
      // t.removeMouseListener(l);
      // }
      TableRowSorter<?> sorter = new MyTableRowSorter(t.getModel());

      t.setRowSorter(sorter);
      sorter.allRowsChanged();
      sorter.toggleSortOrder(0);
      t.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
      JPanel p = new JPanel(new GridLayout(1, 1));
      p.add(new JScrollPane(t));
      p.setBorder(
          BorderFactory.createTitledBorder(
              BorderFactory.createEmptyBorder(2, 2, 2, 2), k + "  (" + xxx.size() + " rows)"));
      panels.add(p);
      //	p.setPreferredSize(new Dimension(60, 60));
    }

    /*int x = (int) Math.ceil(Math.sqrt(panels.size()));
    if (x == 0) {
    	return new JPanel();
    }
    JPanel panel = new JPanel(new GridLayout(x, x));
    for (JPanel p : panels) {
    	panel.add(p);
    }
    panel.setBorder(BorderFactory.createEtchedBorder()); */
    return FqlUtil.makeGrid(((List<JComponent>) ((Object) panels)));
  }
Ejemplo n.º 4
0
  /**
   * attempts to execute this goal
   *
   * @param player the player
   * @return if the goal is unable to be executed
   */
  public boolean execute(TTRPlayer player) {
    boolean consideringClaimedRoutes = true;
    ArrayList<ArrayList<Route>> neededRoutes = player.getPath(to, from, consideringClaimedRoutes);

    if (neededRoutes == null) {
      isCompleteable = false;
      return false;
    }
    for (ArrayList<Route> routes : neededRoutes) {
      System.out.println(
          "Route from "
              + routes.get(0).getDest1().name()
              + " to "
              + routes.get(0).getDest2().name()
              + " at cost "
              + routes.get(0).getCost());
      // System.out.print(routes.get(0).getDest1().name()+" ");
    }
    // order routes by the level of threat they face
    LinkedList<Threat> routesByThreat = new LinkedList<Threat>();
    for (ArrayList<Route> routeBundle : neededRoutes) {
      int totalThreat =
          calcTotalThreat(routeBundle.get(0).getDest1())
              + calcTotalThreat(routeBundle.get(0).getDest2());
      routesByThreat.add(new Threat(routeBundle, totalThreat));
    }
    routesByThreat.sort(new ThreatComparator());
    for (Threat threat : routesByThreat) {
      Destination dest1 = threat.getRoute().get(0).getDest1();
      Destination dest2 = threat.getRoute().get(0).getDest2();
      int threatAmount = threat.getThreat();
      System.out.print("Route from " + dest1 + " to " + dest2 + " has threat " + threatAmount);
    }
    // try to purchase route
    for (Threat threat : routesByThreat) {
      ArrayList<Route> routeBundle = threat.getRoute();
      for (Route route : routeBundle) {
        if (canPurchase(route, player.getHand(), player.getNumTrainPieces())) {
          System.out.println(
              "I think I can claim the route from " + route.getDest1() + " to " + route.getDest2());
          // if grey route
          if (route.getColor() == TrainCardColor.rainbow) {
            CardAmount maxColor = getColorOfMaxPieces(player.getHand());
            player.claimRoute(route, maxColor.getColor());
            return true;
          }
          // normal route
          player.claimRoute(route, route.getColor());
          return true;
        }
      }
    }
    // get cards for routes
    for (Threat threat : routesByThreat) {
      ArrayList<Route> routeBundle = threat.getRoute();
      for (Route route : routeBundle) {
        if (!canPurchase(route, player.getHand(), player.getNumTrainPieces())
            && route.getOwner() == null) {
          // if grey route
          if (route.getColor() == TrainCardColor.rainbow) {
            player.drawTrainCard(0); // get random card
            return true;
          }
          // normal route
          ArrayList<TrainCard> visibleCards = player.getFaceUpCards();
          for (int i = 0; i < visibleCards.size(); i++) {
            if (visibleCards.get(i).getColor() == route.getColor()) {
              player.drawTrainCard(i + 1);
              return true;
            }
          }
          // otherwise draw random card
          player.drawTrainCard(0);
          return true;
        }
      }
    }
    System.out.println("We have failed to execute");
    return false;
  }