private void selectChessPiece(int x, int y) { allowedMoves = chessMen[x, y].possibleMove(); selectedPiece = chessMen[x, y]; selectedPiece.GetComponent <Outline>().enabled = true; BoardHighlights.Instance.highlightAllowedMoves(allowedMoves); }
public void ParseFile(string fileName) { pieces = new ChessPieces(); var lines = File.ReadLines($"../../{fileName}"); foreach (var line in lines) { switch (line.Length) { case 4: Console.WriteLine(PlacePiece(line)); break; case 5: Console.WriteLine(MoveSinglePiece(line)); break; case 6: Console.WriteLine(CapturePiece(line)); break; case 11: Console.WriteLine(MoveTwoPieces(line)); break; } } ConsoleView consoleView = new ConsoleView(); consoleView.DisplayBoard(board); }
public void GetPopulateChessboard(string[,] chessBoardArray) { _chessPieces = new ChessPieces(); Console.WriteLine("WHITE: " + Input.WhitePieces); Console.WriteLine("BLACK: " + Input.BlackPieces); var whitePiece = _chessPieces.WhitePieces; var blackPiece = _chessPieces.BlackPieces; for (var row = 0; row < 8; row++) { for (var col = 0; col < 8; col++) { chessBoardArray[row, col] = " "; } } foreach (var item in whitePiece) { var charArray = item.ToCharArray(); var row = int.Parse(charArray[1].ToString()) - 1; var col = int.Parse(charArray[2].ToString()) - 1; chessBoardArray[row, col] = charArray[0].ToString().ToUpper(); } foreach (var item in blackPiece) { var charArray = item.ToCharArray(); var row = int.Parse(charArray[1].ToString()) - 1; var col = int.Parse(charArray[2].ToString()) - 1; chessBoardArray[row, col] = charArray[0].ToString().ToLower(); } }
static void Main(string[] args) { // Declare a new object var piece = new ChessPieces(); // GetPiece 12 times var get1 = (Piece)piece.GetPiece(); var get2 = (Piece)piece.GetPiece(); var get3 = (Piece)piece.GetPiece(); var get4 = (Piece)piece.GetPiece(); var get5 = (Piece)piece.GetPiece(); var get6 = (Piece)piece.GetPiece(); var get7 = (Piece)piece.GetPiece(); var get8 = (Piece)piece.GetPiece(); var get9 = (Piece)piece.GetPiece(); var get10 = (Piece)piece.GetPiece(); var get11 = (Piece)piece.GetPiece(); var get12 = (Piece)piece.GetPiece(); // Output all 12 of the pieces using ToString method Console.WriteLine(get1.ToString()); Console.WriteLine(get2.ToString()); Console.WriteLine(get3.ToString()); Console.WriteLine(get4.ToString()); Console.WriteLine(get5.ToString()); Console.WriteLine(get6.ToString()); Console.WriteLine(get7.ToString()); Console.WriteLine(get8.ToString()); Console.WriteLine(get9.ToString()); Console.WriteLine(get10.ToString()); Console.WriteLine(get11.ToString()); Console.WriteLine(get12.ToString()); }
private ChessBoardSim SimulateBoard(ChessPiece piece, int[] newPositionCoords) { ChessBoardSim simBoard = new ChessBoardSim(ChessPieces.GetBoardLayout(), turnNumber); simBoard.MovePiece(piece, newPositionCoords[0], newPositionCoords[1], true); return(simBoard); }
private void InitializePieces() { foreach (var item in Game.Pieces) { ChessPieces.Add(new ChessPieceViewModel(item)); } }
private void castlingMove(int x, int y, ChessPieces c) { if (y == 0) { if (x == 0) { moveChessPiece(x, y, 1, 0); } else if (x == 7) { moveChessPiece(x, y, 6, 0); } selectedPiece = chessMen[4, 0]; } else if (y == 7) { if (x == 0) { moveChessPiece(x, y, 1, 7); } else if (x == 7) { moveChessPiece(x, y, 6, 7); } selectedPiece = chessMen[4, 7]; } }
public void spellHighlight(string spellName) { BoardHighlights.Instance.hideHighlights(); if (selectedPiece) { selectedPiece.GetComponent <Outline>().enabled = false; selectedPiece = null; } if (isSpellMove) { isSpellMove = false; } else { isSpellMove = true; this.spellName = spellName; switch (spellName) { case "Upgrade": allowedMoves = spells.possibleUpgrade(); break; case "Stun": allowedMoves = spells.possibleStun(); break; case "Cover": allowedMoves = spells.possibleCover(); break; } BoardHighlights.Instance.highlightAllowedMoves(allowedMoves); } }
// ReSharper disable once InconsistentNaming public static void Main() { _chessPieces = new ChessPieces(); _allValidMoves = new AllValidMoves(); _chessBoardArray = new string[8, 8]; _chessBoard = new ChessBoard(); do { var allWhitePossibleMoves = _allValidMoves.GetWhiteValidMoves(); var allBlackPossibleMoves = _allValidMoves.GetBlackValidMoves(); _chessBoard.GetPopulateChessboard(_chessBoardArray); // Populate chessboard array with pieces' inputs from input.txt _chessBoard.GetDrawChessBoard(_chessBoardArray); // Draw up a chessboard Console.Write("enter piece location: "); var inputString = Console.ReadLine(); var checkedPiece = GetCheckAndGetPiece(inputString); if (!string.IsNullOrEmpty(checkedPiece)) { GetValidMoves(checkedPiece, allWhitePossibleMoves, allBlackPossibleMoves); } else { Console.WriteLine("There is no such piece"); } Console.WriteLine("Press Enter to Continue"); Console.ReadLine(); } while (true); // ReSharper disable once FunctionNeverReturns }
private void DisplayMovementOptions(ChessPiece piece) { foreach (int[] location in ChessPieces.GetAllMovementOptions()[ChessPieces.GetAlliedPiecesRemaining().IndexOf(piece)]) { InstantiateMovementBox("Movement", location[0], location[1]); } }
private void MovePiece(ChessPiece piece, int xpos, int ypos) { ChessPieces.MovePiece(piece, xpos, ypos, true); piece.transform.localPosition = TileToVector(xpos, ypos, 0.5f, PIECE_SCALING / 2.0f); //piece.SetPosition(new int[] { xpos, ypos }); //ChessPieces.SetPiece(xpos, ypos, piece); InstantiateAudioSource(xpos, ypos, movePieceSound); }
private void ExcuteMoveLAN(Form form) { if (form.InvokeRequired) { // this is worker thread updateExcuteLANDelegate del = new updateExcuteLANDelegate(ExcuteMoveLAN); form.Invoke(del, new object[] { form }); } else { // this is UI thread Point position = Mode1AndMode2.moveLAN; // x la diem dau- y la diem den ChessPieces piece = (ChessPieces)this.boardGui.boardLogic.GetCell(position.X).GetChessPieces().Clone(); // MessageBox.Show(piece.chessPieceType.chessPieceName); Cell cell = this.boardGui.boardLogic.GetCell(position.Y); Move move; if (cell.Occupied()) { move = new AttackMove(piece, position.Y, cell.GetChessPieces()); } else { move = new NormalMove(piece, position.Y); } CellGui cellG = this.boardGui.GetCellGui(position.X); // khong can thiet, cainay chi cap nhat game thoi ma, chi can hien ben nguoi choi duoc roi if (move.IsPromote()) { cellG.SetPromote(move); //set lai icon cho ben nay-ban chat la phia ben nay board logic khong co con nay //nhung chi co ben kia duoc di nen khong sao het- danh lua nguoi choi. } this.boardGui.boardLogic = move.ExcuteMove(this.boardGui.boardLogic); BoardGui.moveHistory.ListMoveHistory.Add(move); BoardGui.moveHistory.listRedo.Clear(); if (move.TheKingDie(this.boardGui.boardLogic)) { Mode1AndMode2.status_game = statusGame.EndGame; } //set lai icon tren ban co cho nguoi xem biet duoc da di.-> thay doi board gui this.boardGui.GetCellGui(position.X).SetImageIcon(); this.boardGui.GetCellGui(position.Y).SetImageIcon(); //reset thanh chua chon nuoc co nao va set nguoi choi tiep theo vi da danh xong nuoc co nay. this.boardGui.CellSelectedFirst = this.boardGui.CellSelectedSecond = null; this.boardGui.boardLogic.SetNextPlayer(); } }
public void Awake() { if (instance) { Debug.Log("Il y a déjà une instance de GameManager : " + name); Destroy(this.gameObject); } else { instance = this; } float scalingRatioX = Screen.width / 1440f; float scalingRatioY = Screen.height / 2960f; playerText.gameObject.GetComponent <RectTransform>().localScale = new Vector3(scalingRatioX, scalingRatioX, 1f); playerText.gameObject.GetComponent <RectTransform>().anchoredPosition = new Vector3(340f * scalingRatioX, -110f * scalingRatioY, 0f); popup.GetComponent <RectTransform>().localScale = new Vector3(scalingRatioX, scalingRatioX, 1f); popup.GetComponent <RectTransform>().anchoredPosition = new Vector3(0f, -620f * scalingRatioY, 0f); pauseButton.localScale = new Vector3(scalingRatioY, scalingRatioY, 1f); pauseButton.anchoredPosition = new Vector3(-150f * scalingRatioX, -150f * scalingRatioY, 0f); button1.transform.localScale = new Vector3(scalingRatioY, scalingRatioY, 1f); button1.GetComponent <RectTransform>().anchoredPosition = new Vector3(0f, 400f * scalingRatioY, 0f); button2.transform.localScale = new Vector3(scalingRatioY, scalingRatioY, 1f); button3.transform.localScale = new Vector3(scalingRatioY, scalingRatioY, 1f); button3.GetComponent <RectTransform>().anchoredPosition = new Vector3(0f, -400f * scalingRatioY, 0f); finalText.gameObject.GetComponent <RectTransform>().localScale = new Vector3(scalingRatioX, scalingRatioX, 1f); finalText.gameObject.GetComponent <RectTransform>().anchoredPosition = new Vector3(720 * scalingRatioX, -590f * scalingRatioY, 0f); playerPlaying = Player.White; playerText.text = "White to play"; currentBoard = new ChessPieces[8][]; currentBoard[0] = new ChessPieces[8] { ChessPieces.WhiteRook, ChessPieces.WhitePawn, 0, 0, 0, 0, ChessPieces.BlackPawn, ChessPieces.BlackRook }; currentBoard[1] = new ChessPieces[8] { ChessPieces.WhiteKnight, ChessPieces.WhitePawn, 0, 0, 0, 0, ChessPieces.BlackPawn, ChessPieces.BlackKnight }; currentBoard[2] = new ChessPieces[8] { ChessPieces.WhiteBishop, ChessPieces.WhitePawn, 0, 0, 0, 0, ChessPieces.BlackPawn, ChessPieces.BlackBishop }; currentBoard[3] = new ChessPieces[8] { ChessPieces.WhiteQueen, ChessPieces.WhitePawn, 0, 0, 0, 0, ChessPieces.BlackPawn, ChessPieces.BlackQueen }; currentBoard[4] = new ChessPieces[8] { ChessPieces.WhiteKing, ChessPieces.WhitePawn, 0, 0, 0, 0, ChessPieces.BlackPawn, ChessPieces.BlackKing }; currentBoard[5] = new ChessPieces[8] { ChessPieces.WhiteBishop, ChessPieces.WhitePawn, 0, 0, 0, 0, ChessPieces.BlackPawn, ChessPieces.BlackBishop }; currentBoard[6] = new ChessPieces[8] { ChessPieces.WhiteKnight, ChessPieces.WhitePawn, 0, 0, 0, 0, ChessPieces.BlackPawn, ChessPieces.BlackKnight }; currentBoard[7] = new ChessPieces[8] { ChessPieces.WhiteRook, ChessPieces.WhitePawn, 0, 0, 0, 0, ChessPieces.BlackPawn, ChessPieces.BlackRook }; }
public Knight(ChessPieces pieceType, PieceColors color, char currentXcoordinate, int currentYCoordinate, bool canMove, bool hasMoved) { this.PieceType = pieceType; this.Color = color; this.CurrentXCoordinate = currentXcoordinate; this.CurrentYCoordinate = currentYCoordinate; this.CanMove = canMove; this.HasMoved = hasMoved; }
private void SpawnChessPiece(int index, int xPos, int yPos) { GameObject piece = Instantiate(chessPiecesPrefabs[index], TileToVector(xPos, yPos, 0.5f, PIECE_SCALING / 2.0f), Quaternion.identity) as GameObject; piece.transform.localScale = Vector3.one * PIECE_SCALING; piece.transform.parent = chessBoard.transform; UnHighlightPiece(piece); ChessPieces.AddPiece(piece.GetComponent <ChessPiece>(), xPos, yPos); }
public King(ChessPieces pieceType, PieceColors color, char currentXCoordinate, char futureXCoordinate, int currentYCoordinate, int futureYCoordinate, bool canMove, bool hasMoved) { this.PieceType = pieceType; this.Color = color; this.CurrentXCoordinate = currentXCoordinate; this.FutureXCoordinate = futureXCoordinate; this.CurrentYCoordinate = currentYCoordinate; this.FutureYCoordinate = futureYCoordinate; this.CanMove = canMove; this.HasMoved = hasMoved; }
protected Piece(ChessPieces piece, PieceColors color, char x, int y, char fx, int fy, bool canMove, bool hasMoved) { this.PieceType = piece; this.Color = color; this.CurrentXCoordinate = x; this.CurrentYCoordinate = y; this.FutureXCoordinate = fx; this.FutureYCoordinate = fy; this.CanMove = canMove; this.HasMoved = hasMoved; }
public void pawnUpgrade(int currentX, int currentY, int upgrade) { //Black Upgrade if (currentY == 0) { upgrade += 6; } selectedPiece = chessMen[currentX, currentY]; activeChessmen.Remove(selectedPiece.gameObject); Destroy(selectedPiece.gameObject); spawnChessman(upgrade, currentX, currentY); swapTurn(); }
public Pawn(UnitColor unitColor, HashSet <int> protectEnemyKingMoves, HashSet <int> protectAllyKingMoves, HashSet <int> potentialMoves) { var chessPieces = new ChessPieces(); _iPawnMove = new PawnMove(); _allyCoord = UnitColor.White == unitColor ? chessPieces.WhiteChessPieces.Item2 : chessPieces.BlackChessPieces.Item2; _enemyCoord = UnitColor.White == unitColor ? chessPieces.BlackChessPieces.Item2 : chessPieces.WhiteChessPieces.Item2; _enemyKing = UnitColor.White == unitColor ? chessPieces.BlackChessPieces.Item3 : chessPieces.WhiteChessPieces.Item3; _protectEnemyKingMoves = protectEnemyKingMoves; _protectAllyKingMoves = protectAllyKingMoves; _potentialMoves = potentialMoves; _unitColor = unitColor; }
/// <summary> /// thang cap cho con tot khi di den cuoi ban co /// </summary> /// <param name="move"></param> public void SetPromote(Move move) { PromotionForm f = new PromotionForm(); f.SetIconImage(move.actionPiece.side); f.ShowDialog(); if (f.DialogResult == DialogResult.OK) { //set lai con tot vua di la con duoc chon tu bang phong chuc. ChessPieces p = f.GetChessPiece(move.actionPiece.side); p.chessPiecePosition = move.actionPiece.chessPiecePosition; move.actionPiece = p; } }
private void StartTurn() { ChessPieces.CalculateAllMovementOptions(); ChessPieces.GetAllMovementOptions(); if (ChessPieces.MovementOptionsAreAvailable()) { Debug.Log("Moves available"); } else { string winner = ChessPieces.IsWhiteTurn() ? "Black" : "White"; Debug.Log(winner + " wins!"); } }
public IEnumerator MoveToAnim(int x, int y) { Vector3 startPos = transform.position; float counter = 0; while (counter < AnimDur) { counter += Time.deltaTime; transform.position = Vector3.Lerp(startPos, Tile.Position(x, y), counter / AnimDur); transform.position = new Vector3(transform.position.x, 1 * ChessPieces.Arch(counter / AnimDur), transform.position.z); yield return(null); } transform.position = Tile.Position(x, y); }
private void DestroyPiece(ChessPiece piece) { InstantiateAudioSource(piece.GetPosition()[0], piece.GetPosition()[1], destroyPieceSound); //Move Piece to the graveyard, and remove it from active pieces/piece list. if (piece.isWhite) { piece.gameObject.transform.localPosition = new Vector3(graveyardWhite, 0, -1); graveyardWhite += 1.0f; } else { piece.gameObject.transform.localPosition = new Vector3(graveyardBlack, 0, TILE_SIZE * 8 + 1); graveyardBlack -= 1.0f; } ChessPieces.RemovePiece(piece); }
// public List<CellGui> listRelationCellGui = new List<CellGui>(); public void SetImageIcon() { //neu o dang co quan co chiem giu thi moi can set if (this.board.boardLogic.GetCell(this.IDCellGui).Occupied()) { ChessPieces piece = (ChessPieces)board.boardLogic.GetCell(this.IDCellGui).GetChessPieces().Clone(); string side = piece.side == ChessPieceSide.BLACK ? "black" : "white"; string name = piece.chessPieceType.chessPieceName; string imagePath = Application.StartupPath + "\\ChessPieceIcon\\" + side + name + ".png"; this.BackgroundImage = Image.FromFile(@imagePath); this.BackgroundImageLayout = ImageLayout.Center; } else { this.BackgroundImage = null; } }
public override bool Equals(object obj) { if (obj == null) { return(false); } ChessPieces objAsPart = obj as ChessPieces; if (objAsPart == null) { return(false); } else { return(this == (ChessPieces)obj); } }
public void actionSpell(string spellName, int x, int y) { spelledPiece sp = new spelledPiece(); sp.spellName = spellName; sp.newID = pieceID; if (spellName == "Upgrade") { selectedPiece = chessMen[x, y]; string type = selectedPiece.GetType().ToString(); switch (type) { case "Queen": sp.pieceType = 1; break; case "Rook": sp.pieceType = 2; break; case "Bishop": sp.pieceType = 3; break; case "Knight": sp.pieceType = 4; break; case "Pawn": sp.pieceType = 5; break; } if (!selectedPiece.isItWhite) { sp.pieceType += 6; } sp.endSpellTurn = turnCount + 4; activeChessmen.Remove(selectedPiece.gameObject); Destroy(selectedPiece.gameObject); } else if (spellName == "Stun") { chessMen[x, y].enabled = false; sp.endSpellTurn = turnCount + 3; } else if (spellName == "Cover") { sp.endSpellTurn = turnCount + 6; } spawnSpellMan(spellName, x, y); sp.x = x; sp.y = y; spelledPieces.Add(sp); BoardHighlights.Instance.hideHighlights(); isSpellMove = false; }
private void spawnAllChessmen() { activeChessmen = new List <GameObject>(); chessMen = new ChessPieces[8, 8]; passantMove = new int[2] { -1, -1 }; //WHITE TEAM //King spawnChessman(0, 4, 0); //Queen spawnChessman(1, 3, 0); //Rook spawnChessman(2, 0, 0); spawnChessman(2, 7, 0); //Bishop spawnChessman(3, 2, 0); spawnChessman(3, 5, 0); //Horse spawnChessman(4, 6, 0); spawnChessman(4, 1, 0); //BLACK TEAM //King spawnChessman(6, 4, 7); //Queen spawnChessman(7, 3, 7); //Rook spawnChessman(8, 0, 7); spawnChessman(8, 7, 7); //Bishop spawnChessman(9, 2, 7); spawnChessman(9, 5, 7); //Horse spawnChessman(10, 6, 7); spawnChessman(10, 1, 7); //Pawns for (int i = 0; i < 8; i++) { spawnChessman(5, i, 1); spawnChessman(11, i, 6); } }
private void CheckMouseDown() { if (Input.GetMouseButtonDown(0)) { if (selectionX >= 0 && selectionY >= 0) { //Check if a piece is currently selected if (selectedPiece == null) { ChessPiece targetPiece = ChessPieces.GetPiece(selectionX, selectionY); //Check for piece on selected tile, and if it belongs to the player if (targetPiece != null && targetPiece.isWhite == ChessPieces.IsWhiteTurn() && CanMove(targetPiece)) { //Display available movement options DisplayMovementOptions(targetPiece); HighlightPiece(targetPiece); selectedPiece = targetPiece; } } else { //Check if valid movement option if (MovementOptions[selectionX, selectionY]) { MovePiece(selectedPiece, selectionX, selectionY); //selectedPiece.SetHasMoved(true); //If pawn reached other side, upgrade!!! turnNumber += 1; StartTurn(); } //Deselect Piece UnHighlightPiece(selectedPiece); selectedPiece = null; MovementOptions = new bool[8, 8]; foreach (GameObject square in movementOptionTiles) { Destroy(square); } } } } }
private void enPassantMove(int x, int y, ChessPieces c) { if (x == passantMove[0] && y == passantMove[1]) { if (isWhiteTurn) { c = chessMen[x, y - 1]; } else { c = chessMen[x, y + 1]; } activeChessmen.Remove(c.gameObject); Destroy(c.gameObject); } for (int i = 0; i < passantMove.Length; i++) { passantMove[i] = -1; } }
public void Piece_should_have_name_and_initial_position_and_defined_colour(ChessPieces chessPiece) { var position = new Position("D5"); if (chessPiece == ChessPieces.Horse) { var horse = new Horse(position, PieceColours.White); horse.Name.Should().BeEquivalentTo(chessPiece.ToString()); horse.CurrentPosition.Equals(position); } if (chessPiece == ChessPieces.Pawn) { var pawn = new Pawn(position, PieceColours.White); pawn.Name.Should().BeEquivalentTo(chessPiece.ToString()); pawn.CurrentPosition.Equals(position); } if (chessPiece == ChessPieces.Rook) { var horse = new Rook(position, PieceColours.White); horse.Name.Should().BeEquivalentTo(chessPiece.ToString()); horse.CurrentPosition.Equals(position); } if (chessPiece == ChessPieces.Bishop) { var bishop = new Bishop(position, PieceColours.White); bishop.Name.Should().BeEquivalentTo(chessPiece.ToString()); bishop.CurrentPosition.Equals(position); } if (chessPiece == ChessPieces.King) { var king = new King(position, PieceColours.White); king.Name.Should().BeEquivalentTo(chessPiece.ToString()); king.CurrentPosition.Equals(position); } if (chessPiece == ChessPieces.Queen) { var queen = new Queen(position, PieceColours.Black); queen.Name.Should().BeEquivalentTo(chessPiece.ToString()); queen.CurrentPosition.Equals(position); } }