Beispiel #1
0
 public ArrayList<Move> generatePossibleMoves() {
   ArrayList<Move> ans = new ArrayList<>();
   for (Piece pc : pieces) {
     if (pc.isFinalized()) continue;
     for (int x = 0; x < 20; x++) {
       for (int y = 0; y < 20; y++) {
         Point place = new Point(x, y);
         Piece p = pc.getCopy();
         p.place(x, y);
         for (int i = 0; i < p.data.rotations; i++) {
           if (game.getBoard().canPlace(p)) {
             ans.add(new Move(p, place, this));
           }
           p.rotateCW();
         }
         p.resetRotation();
         if (p.data.flip) {
           p.flipHorizontal();
           for (int i = 0; i < p.data.rotations; i++) {
             if (game.getBoard().canPlace(p)) {
               ans.add(new Move(p, place, this));
             }
             p.rotateCW();
           }
           p.resetRotation();
         }
       }
     }
   }
   possibleMoves = ans;
   return ans;
 }
Beispiel #2
0
 @Override
 public void onScroll(
     MotionEvent downEvent, MotionEvent moveEvent, float distanceX, float distanceY) {
   if (mModel.getCurrentState() == GameModel.STATE_RUNNING) {
     mModel.movePlayer(-distanceX, -distanceY);
   }
 }
Beispiel #3
0
 public static void sellItem() {
   if (selectedItem != -1 && items[selectedItem] != null) {
     if (items[selectedItem] instanceof StoreItem) {
       GameModel.earnMoney((int) Math.round(((StoreItem) items[selectedItem]).getPrice() * 0.6f));
     } else if (items[selectedItem] instanceof Robot) {
       GameModel.earnMoney((int) (((Robot) items[selectedItem]).approximateValue() * 0.6f));
     }
     items[selectedItem] = null;
   }
 }
Beispiel #4
0
  private void setModel(GameModel gameModel) {
    m_model = gameModel;
    m_header = gameModel.getHeaderModel();
    m_moves = gameModel.getMoveModel();

    String fen = m_header.getTag(PGN.TAG_FEN);
    if (fen != null) {
      setPosition(new Position(fen, false));
    } else {
      setPosition(Position.createInitialPosition());
    }
  }
Beispiel #5
0
 /*
  * @param t1, time bonus button is pressed
  * @param t2, time actual stop signal
  */
 public synchronized void calculatePercent(long t1, long t2) {
   if (t2 == 0) {
     gameModel.addPercentScore(0.3);
   }
   long[] timestamps = realValue(t1, t2);
   t1 = timestamps[0];
   t2 = timestamps[1];
   if (t1 < t2) {
     gameModel.addPercentScore(Math.abs(((double) t1 / (double) t2) + 1));
   } else {
     gameModel.addPercentScore(Math.abs(((double) t2 / (double) t1) + 1));
   }
 }
Beispiel #6
0
  private String rtsNewScope(GameModel gameModel) {
    List<VariableDescriptor> variableDescriptors = gameModel.getVariableDescriptors();
    StringBuilder sb = new StringBuilder();
    sb.append("[");

    for (Iterator<VariableDescriptor> it = variableDescriptors.iterator(); it.hasNext(); ) {
      VariableDescriptor vd = it.next();
      if ("question".equals(vd.getLabel().toLowerCase())) {
        if (!(vd.getScope() instanceof GameModelScope)) {
          sb.append(this.newScope(gameModel, vd));
        }
      } else if ("toolbar".equals(vd.getLabel().toLowerCase())
          || "moves".equals(vd.getLabel().toLowerCase())
          || "dialogues".equals(vd.getLabel().toLowerCase())) {
        if (vd instanceof ListDescriptor) {
          ListDescriptor list = (ListDescriptor) vd;
          for (VariableDescriptor child : list.getItems()) {
            if (child instanceof StringDescriptor) {
              sb.append(this.newScope(gameModel, child));
            }
          }
        }
      }
    }
    sb.append("]");

    return sb.toString();
  }
Beispiel #7
0
  private String rtsUpdateScope(GameModel gameModel) {
    List<VariableDescriptor> variableDescriptors = gameModel.getVariableDescriptors();
    StringBuilder sb = new StringBuilder();
    sb.append("[");

    for (VariableDescriptor vd : variableDescriptors) {

      if ("question".equals(vd.getLabel().toLowerCase())) {
        this.updateScope(vd);
      } else if ("toolbar".equals(vd.getLabel().toLowerCase())
          || "moves".equals(vd.getLabel().toLowerCase())
          || "dialogues".equals(vd.getLabel().toLowerCase())) {
        if (vd instanceof ListDescriptor) {
          ListDescriptor list = (ListDescriptor) vd;
          for (VariableDescriptor child : list.getItems()) {
            if (child instanceof StringDescriptor) {
              this.updateScope(child);
            }
          }
        }
      }
    }
    sb.append("]");

    return sb.toString();
  }
Beispiel #8
0
  private String addVariable(GameModel gm, String json, String varName, String parentName) {
    ObjectMapper mapper = JacksonMapperProvider.getMapper();
    logger.error("Going to add " + parentName + "/" + varName + " variable");

    try {
      // Does the variable already exists ?
      descriptorFacade.find(gm, varName);
      logger.error("  -> variable " + varName + " exists : SKIP");
      return "already exists";
    } catch (WegasNoResultException ex) {
      logger.error("  -> variable " + varName + " not found : PROCEED");
    }

    try {
      // assert the parent already exists ?
      descriptorFacade.find(gm, parentName);
      logger.error("  -> variable " + parentName + " exists : PROCEED");
    } catch (WegasNoResultException ex) {
      logger.error("  -> variable " + parentName + " not found : FAILED");
      return "parent not found";
    }
    try {
      VariableDescriptor vd = mapper.readValue(json, VariableDescriptor.class);
      descriptorController.createChild(gm.getId(), parentName, vd);
      descriptorFacade.flush();
      return "OK";
    } catch (WegasNotFoundException ex) {
      logger.error("Error white adding the variable : parent " + parentName + " not found", ex);
      return "Parent (2) not found";
    } catch (IOException ex) {
      logger.error("Error While Reading JSON: " + json, ex);
      return "JSON Error";
    }
  }
Beispiel #9
0
 public void processCommands() {
   System.out.println(
       "All commands received! Sending to model! Numcommands = "
           + turnCommands.getCommands().size());
   myModel.performCommands(turnCommands);
   turnCommands.clear();
   commandsReceived = 0;
 }
Beispiel #10
0
  private void updateListDescriptorScope(GameModel gameModel) {
    List<VariableDescriptor> variableDescriptors = gameModel.getVariableDescriptors();

    for (VariableDescriptor vd : variableDescriptors) {
      if (vd instanceof ListDescriptor) {
        this.updateScope(vd);
      }
    }
  }
Beispiel #11
0
  @GET
  @Path("PMG_UPGRADE")
  public String pmg_upgrade() {
    List<GameModel> PMGs = this.findPMGs(false);
    StringBuilder ret = new StringBuilder();
    String status;

    ret.append("<ul>");

    for (GameModel pmg : PMGs) {
      ret.append("<li>");
      ret.append(pmg.getName());
      ret.append("/");
      ret.append(pmg.getId());
      status =
          addVariable(
              pmg,
              "{\"@class\":\"BooleanDescriptor\",\"comments\":\"\",\"defaultInstance\":{\"@class\":\"BooleanInstance\",\"value\":false},\"label\":\"burndownEnabled\",\"scope\":{\"@class\":\"GameScope\",\"broadcastScope\":\"TeamScope\"},\"title\":null,\"name\":\"burndownEnabled\"}",
              "burndownEnabled",
              "properties");
      ret.append(" burndownEnabled: ");
      ret.append(status);

      ret.append("</li>");

      ret.append("<li>");
      ret.append(pmg.getName());
      ret.append("/");
      ret.append(pmg.getId());
      status =
          addVariable(
              pmg,
              "{\"@class\":\"BurndownDescriptor\",\"comments\":\"\",\"defaultInstance\":{\"@class\":\"BurndownInstance\",\"iterations\":[]},\"label\":\"burndown\",\"scope\":{\"@class\":\"TeamScope\",\"broadcastScope\":\"TeamScope\"},\"title\":\"\",\"name\":\"burndown\",\"description\":\"\"}",
              "burndown",
              "pageUtilities");
      ret.append(" burndown: ");
      ret.append(status);

      ret.append("</li>");
    }
    ret.append("</ul>");
    return ret.toString();
  }
Beispiel #12
0
  public void calScore(long timeStep) {
    // infrequent check on score. check status of game
    // increase or decrease increment for score(Never zero || < 0)
    // check is on game objects and delta of game objects

    if (model.getVirusCount() == 0 && tempVirusCount > 0) this.regEvent(GameScore.VIRUS_CLEAR);

    long hisTime = scoreStack[readScore].getTimeStamp();
    while ((runTime - hisTime) < MAX_TIME_FRAME) {
      if (readScore == curIndex) break;
      // this loops is crashing sometimes!
      hisTime = scoreStack[readScore].getTimeStamp();
      count[scoreStack[readScore].getEvent()] += 1;
      if (--readScore < 0) readScore = MAX_EVENTS - 1;
    }

    if (count[GameScore.VIRUS_CLEAR] > 0) scoreVel += (count[GameScore.VIRUS_CLEAR] * 0.4);
    else {
      scoreVel *= (0.4 * colFib(tempVirusCount));
    }
    if (count[GameScore.VIRUS_HIT] > 0) {
      scoreVel += (count[GameScore.VIRUS_HIT] * 0.4);
    }
    if (count[GameScore.ORGAN_HIT] > 0) {
      scoreVel += (count[GameScore.ORGAN_HIT] * 0.4);
    }
    if (count[GameScore.RED_BOUNDS] > 0) {
      scoreVel *= 0.7;
    }
    if (count[GameScore.FAT_BUST] > 0) {
      if (count[GameScore.FAT_BUST] > 6) scoreVel += (count[GameScore.VIRUS_HIT] * 1.4);
      else scoreVel += (count[GameScore.VIRUS_HIT] * 0.4);
    }
    if (count[GameScore.FAT_BUST_RICH] > 0) scoreVel += (count[GameScore.VIRUS_HIT] * 0.7);
    tempVirusCount = model.getVirusCount();

    resetCount();

    this.notifyObservers();
  }
Beispiel #13
0
  public void setLastLetter(String letter, boolean correct) {

    if (correct) {
      lastLetterBox.setBackground(Color.GREEN);
      correctLetters.setText(correctLetters.getText().replaceFirst("_", letter));

    } else {
      lastLetterBox.setBackground(Color.RED);
      // wrongLetters.setText(wrongLetters.getText() + " " + letter);
      wrongLetters.setText(String.valueOf(model.getWrongGuesses()));
    }

    lastLetter.setText(letter);
  }
Beispiel #14
0
  private String listDescriptorScope(GameModel gameModel) {
    List<VariableDescriptor> variableDescriptors = gameModel.getVariableDescriptors();
    StringBuilder sb = new StringBuilder();
    sb.append("[");

    for (VariableDescriptor vd : variableDescriptors) {
      if (vd instanceof ListDescriptor) {
        this.updateScope(vd);
      }
    }
    sb.append("]");

    return sb.toString();
  }
 private void paintStone(Graphics g) {
   int player = GameModel.getInstance().playerAt(position);
   if (player > 0) {
     BufferedImage stone = stonz[player];
     g.drawImage(
         stone,
         0,
         0,
         this.getWidth(),
         this.getHeight(),
         0,
         0,
         stone.getWidth(),
         stone.getHeight(),
         this);
   }
 }
Beispiel #16
0
 /**
  * Returns a string represention of the game. Implemented as the string represention of the header
  * plus the move model.
  *
  * @return a string represention of the game
  */
 public String toString() {
   return m_model.toString();
 }
Beispiel #17
0
 public void intializeWord(int wordLength) {
   lastLetterBox.setBackground(Color.WHITE);
   setCorrectLetters(wordLength);
   lastLetter.setText("");
   wrongLetters.setText(String.valueOf(model.getWrongGuesses()));
 }
Beispiel #18
0
 public void changeTrayForm(Shape shape) {
   model.changeTrayForm(shape);
 }
Beispiel #19
0
 public void setGraphicGameSize(int width, int height) {
   if (width > 0 && height > 0) {
     model.setGraphicSize(width, height);
   }
 }
Beispiel #20
0
 public void newGame(int size) throws BadTraySizeException, GameRunningException {
   model.newGame(size);
 }
Beispiel #21
0
 //    public void load(DataInput in, int headerMode, int movesMode) throws IOException
 //    {
 //        m_header = new ChGameHeaderModel(in, headerMode);
 //        m_moves = new ChGameMoveModel(in, movesMode);
 //    }
 //
 public void save(DataOutput out, int headerMode, int movesMode) throws IOException {
   m_model.save(out, headerMode, movesMode);
 }
Beispiel #22
0
 @Override
 public void makegame(String name) {
   GameModel game = new GameModel(this);
   game.setName(name);
   api.getModuleForClass(GameManager.class).registerGame(game);
 }
 public double getPaddlePosition() {
   return isAI ? game.getStage().ball.getPosition().y : paddlePosition;
 }
Beispiel #24
0
 public void makeMove(Move m) {
   game.makeMove(m);
 }