Exemplo n.º 1
0
 /**
  * Insert Token reference to Board.
  *
  * @param b Board Object.
  * @param t Input Token reference.
  * @param row Insert position in Board.
  * @param col Insert position in Board.
  */
 public void insertToken2Board(Board b, Token t, int row, int col) {
   if (t instanceof PlayerToken) {
     PlayerToken ct = (PlayerToken) t;
     ct.setRow(row);
     ct.setCol(col);
   }
   int index = row * this.N + col;
   b.BoardTokens[index] = t;
 }
Exemplo n.º 2
0
 public void takeToken(Board board, PlayerToken tkn) {
   int tmpc = tkn.getCol();
   int tmpr = tkn.getRow();
   // if a token loses in an attack, move it away from board:
   tkn.setCol(-1);
   tkn.setRow(-1);
   // place in its place plain, ol' vanilla grass:
   this.insertToken2Board(board, StrategoBoard.grassToken, tmpr, tmpc);
 }
Exemplo n.º 3
0
 /**
  * Converts the input PlayerToken to the other side. The particular token can not be converted
  * back, till the end of the game.
  *
  * @param board
  * @param tkn PlayerToken to be converted.
  */
 public void convertToken(Board board, PlayerToken tkn) {
   // Check if PlayerToken is converted previously:
   boolean isconverted = board.isConverted(tkn);
   if (!isconverted) {
     // Come to the dark side, we have cookies..
     tkn.setOwn(this.getTurn().side());
     this.getTurn().side().tokens.add(tkn);
     board.convertedTokens.add(tkn);
   }
 }
Exemplo n.º 4
0
 public void attackToken(
     Board board, MovablePlayerToken src, PlayerToken trg, boolean specialPower) {
   // An attack happens only between PlayerTokens:
   // perform attack method of source token:
   String outcome = "";
   // No need for an extra attack method, just interpret differently the results.
   if (specialPower && (src instanceof SpecialMovablePlayerToken)) {
     SpecialMovablePlayerToken scltkn = (SpecialMovablePlayerToken) src;
     outcome = scltkn.specialAttackTo(trg);
   } else {
     outcome = src.attackTo(trg);
   }
   if (outcome.equals("won")) {
     // Save location:
     int tmpc = trg.getCol();
     int tmpr = trg.getRow();
     // Remove token that lost from the board:
     takeToken(board, trg);
     // move token that won to its place:
     this.moveToken(board, src, new Vector2D(tmpr, tmpc));
   } else if (outcome.equals("lost")) {
     // Remove token that lost from the board:
     takeToken(board, src);
   } else if (outcome.equals("tie")) {
     // remove both tokens from the board:
     takeToken(board, src);
     takeToken(board, trg);
   } else if (outcome.equals("wonNotMove")) {
     // Remove token that lost from the board:
     takeToken(board, trg);
   } else if (outcome.equals("nothing")) {
     // Nothing happens in the board.
   } else if (outcome.equals("convert")) {
     // Target Token is converted to the other side (probably
     // due to cookies)..
     convertToken(board, trg);
   }
 }