// attTile[0] = left tile, attTile[1] = right tile public ITile[] getCrossTiles(ITile tile, int direction) { ITile[] attTiles = new ITile[2]; attTiles[0] = tile.GetX() > 0 ? getTile(tile.GetX() - 1, tile.GetY() - direction) : null; attTiles[1] = tile.GetX() < tiles.GetLength(1) ? getTile(tile.GetX() + 1, tile.GetY() - direction) : null; return(attTiles); }
public void setTile(ITile tile) { tiles[tile.GetY(), tile.GetX()] = tile; Button btn = getUiButton(tile.GetX(), tile.GetY()); if (Program.mainForm != null) { if (tile.GetTileType() == TileType.None) { btn.Image = null; } else if (tile.GetTileType() == TileType.Black) { btn.Image = blackImg; } else if (tile.GetTileType() == TileType.Red) { btn.Image = redImg; } } }
public void removeChecker(ITile tile) { setTile(new EmptyTile(tile.GetX(), tile.GetY())); }
public ITile getTile(ITile tile) { ITile t = tiles[tile.GetY(), tile.GetX()]; return(t); }
internal void processMove(ITile firstTile, ITile nextTile) { firstTile = map.getTile(firstTile); nextTile = map.getTile(nextTile); bool extraTurn = false, failedTurn = true, mustAttack = isAttackAvailable(currentTurn); Console.WriteLine($"From:{firstTile.GetX()},{firstTile.GetY()} to:{nextTile.GetX()},{nextTile.GetY()}"); //Checks if it's correct turn if (firstTile.GetTileType() == currentTurn) { int direction = getTileDirection(currentTurn); //If direction down and y delta is 1 or 2 if (direction != 0 && firstTile.GetY() == nextTile.GetY() + direction || firstTile.GetY() == nextTile.GetY() + direction * 2) { var deltaX = Math.Abs(firstTile.GetX() - nextTile.GetX()); if (deltaX == 1 && !mustAttack) { if (nextTile.GetTileType() == TileType.None) { //Move map.removeChecker(firstTile); map.setTile(currentTurn, nextTile.GetX(), nextTile.GetY()); failedTurn = false; } } else if (deltaX == 2) { //Get available attack moves var attackTiles = getAttackTiles(firstTile, direction); foreach (var attTile in attackTiles) { if (attTile.Key != null && attTile.Value != null && attTile.Value == nextTile) { map.removeChecker(firstTile); map.removeChecker(attTile.Key); var tile = map.setTile(currentTurn, attTile.Value.GetX(), attTile.Value.GetY()); failedTurn = false; //Should give extra turn? if (getAttackTiles(tile, direction).Count > 0) { extraTurn = true; } } } } } } //Check if game over var counts = map.getTileCounts(); if (counts.ContainsKey(TileType.Black) && counts[TileType.Black] == 0) { Program.mainForm.setTurnLabel(getTurnLabel(TileType.Black, true)); } else if (counts.ContainsKey(TileType.Red) && counts[TileType.Red] == 0) { Program.mainForm.setTurnLabel(getTurnLabel(TileType.Red, true)); } //next turn if (!failedTurn && !extraTurn) { currentTurn = getOpositeTeam(currentTurn); Program.mainForm.setTurnLabel(getTurnLabel(currentTurn, false)); if (isAttackAvailable(currentTurn)) { Program.mainForm.setTurnLabel(getTurnLabel(currentTurn, false) + " must attack"); } } }