private void SelectChessman(int x, int y) { if (Chessmans [x, y] == null) { return; } if (Chessmans [x, y].isWhite != isWhiteTurn) { return; } bool hasAtLeastOneMove = false; allowedMoves = Chessmans [x, y].PossibleMove(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (allowedMoves [i, j]) { hasAtLeastOneMove = true; } } } if (!hasAtLeastOneMove) { return; } selectedChessman = Chessmans [x, y]; // previousMat = selectedChessman.GetComponent<MeshRenderer>().material; // selectedMat.mainTexture = previousMat.mainTexture; // selectedChessman.GetComponent<MeshRenderer>().material = selectedMat; BoardHighlights.Instance.HighlightAllowedMoves(allowedMoves); }
public void Promote_AI(string move) { // Prima rimuovo il pedone Chessman c = Chessmans[pendingX, pendingY]; activeChessman.Remove(c.gameObject); Destroy(c.gameObject); // Scelta pezzo da cambiare int index = -1; switch (move[4]) { case 'n': index = 10; break; case 'q': index = 7; break; case 'b': index = 9; break; case 'r': index = 8; break; } // Faccio spawnare il pezzo nuovo SpawnChessman(index, pendingX, pendingY); }
private void SelectChessman(int x, int y) { // Se seleziono una casa vuota if (Chessmans[x, y] == null) { return; } // Se non è un pezzo bianco if (Chessmans[x, y].isWhite != isWhiteTurn) { return; } // Calcolo mosse possibili allowedMoves = Chessmans[x, y].PossibleMove(); // Aggiornamento pezzo selezionato selectedChessman = Chessmans[x, y]; // Cambio materiale previousMat = selectedChessman.GetComponent <MeshRenderer>().material; selectedMat.mainTexture = previousMat.mainTexture; selectedChessman.GetComponent <MeshRenderer>().material = selectedMat; // Illumina le case BoardHighlights.Instance.HighlightAllowedMoves(allowedMoves); }
protected override void OnClick(EventArgs e) { try { Chessman selected = null; if (_CurrMouseOverPos.HasValue) { selected = _Game.Chessboard.GetChessmanByPos(_CurrMouseOverPos.Value); } if (_CurrSelectedChessman == null) { if (selected != null) { _CurrSelectedChessman = selected; Invalidate(); } } else if (_CurrSelectedChessman != selected) { _Game.Chessboard.PushMove(new ChessMove(_CurrSelectedChessman.Camp, _CurrSelectedChessman.Type, selected?.Type, _CurrSelectedChessman.Position, _CurrMouseOverPos.Value, string.Empty)); _CurrSelectedChessman = null; Invalidate(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } base.OnClick(e); }
public void RemoveChessmanFromList(Chessman toRemove) { if ((toRemove.isWhite ? WhiteChessmen : BlackChessmen) != null) { (toRemove.isWhite ? WhiteChessmen : BlackChessmen).Remove(toRemove); } }
private void MoveChessman(int x, int y) { if (allowedMoves[x, y]) { Chessman c = Chessmans [x, y]; if (c != null && c.isWhite != isWhiteTurn) { if (c.GetType() == typeof(King)) { EndGame(); return; } activeChessman.Remove(c.gameObject); Destroy(c.gameObject); } // Выбор шахматной фигуры Chessmans [selectedChessman.CurrentX, selectedChessman.CurrentY] = null; selectedChessman.transform.position = GetTileCenter(x, y); selectedChessman.SetPosition(x, y); Chessmans [x, y] = selectedChessman; isWhiteTurn = !isWhiteTurn; } selectedChessman.GetComponent <MeshRenderer> ().material = previousMat; BoardHighLights.Instance.Hidehighlights(); selectedChessman = null; }
public void PointMovePlate(int x, int y, string name) { GameObject objeto = GameObject.Find(name); Chessman chesspiece = objeto.GetComponent <Chessman>(); GameObject Controller = GameObject.FindGameObjectWithTag("GameController"); Game sc = Controller.GetComponent <Game>(); //se a posição existir if (sc.PositionOnBoard(x, y)) { //recebemos a posição GameObject cp = sc.GetPosition(x, y); //se a posição for nula if (cp == null) { //colocamos uma moveplate movePlateSpawner.MovePlateSpawn(x, y, Tipos.Normal, name); } //se a peça na posição for do jogador inimigo else if (cp.GetComponent <Chessman>().GetPlayer() != chesspiece.GetPlayer()) { //Coloca uma moveplate de ataque movePlateSpawner.MovePlateSpawn(x, y, Tipos.Attack, name); } } }
public void PerformPlay(Position origin, Position destiny) { Chessman caughtChessman = ExecuteMovement(origin, destiny); if (IsXequeMate(CurrentPlayer)) { UndoMovement(origin, destiny, caughtChessman); throw new ChessBoardException("Você não pode se colocar em xeque!"); } if (IsXequeMate(Enemy(CurrentPlayer))) { Xeque = true; } else { Xeque = false; } if (TestXequeMate(Enemy(CurrentPlayer))) { End = true; } else { Round++; ChangePlayer(); } }
private void KnightMove(int x, int y, ref bool[,] moves) { if (x >= 0 && y >= 0 && x <= 7 && y <= 7) { Chessman piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { if (!this.KingInDanger(x, y)) { moves[x, y] = true; } } // If the piece is not from same team else if (piece.isWhite != isWhite) { if (!this.KingInDanger(x, y)) { moves[x, y] = true; } } // else if the piece is from same team, don't include it } }
//Spawns all the pieces on board, positioning private void SpawnAllChessmans() { activeChessman = new List <GameObject>(); Chessmans = new Chessman[8, 8]; EnPassantMove = new int[2] { -1, -1 }; //spawn the white team //king SpawnChessman(0, 3, 0); //Queen SpawnChessman(1, 4, 0); //Rooks SpawnChessman(2, 0, 0); SpawnChessman(2, 7, 0); //Bishop SpawnChessman(3, 2, 0); SpawnChessman(3, 5, 0); //Knights SpawnChessman(4, 1, 0); SpawnChessman(4, 6, 0); //Pawn for (int i = 0; i < 8; i++) { SpawnChessman(5, i, 1); } //spawn Black team //spawn the white team //king SpawnChessman(6, 4, 7); //Queen SpawnChessman(7, 3, 7); //Rooks SpawnChessman(8, 0, 7); SpawnChessman(8, 7, 7); //Bishop SpawnChessman(9, 2, 7); SpawnChessman(9, 5, 7); //Knights SpawnChessman(10, 1, 7); SpawnChessman(10, 6, 7); //Pawn for (int i = 0; i < 8; i++) { SpawnChessman(11, i, 6); } }
public void playerAttack() { print("playerAttack"); Chessman enemy = BoardManager.Instance.playerHitChessman; if (gameView.instance.hitEnemyParticle) { Instantiate(gameView.instance.hitEnemyParticle, enemy.gameObject.transform.position, Quaternion.identity); } gameController.instance.DamageChassman(enemy, BoardManager.Instance.selectedChessman.damage); if (enemy.health <= 0) { BoardManager.Instance.inAttack = false; } /* * if (gameView.instance.hitEnemyParticle) { * Instantiate(gameView.instance.hitEnemyParticle, target.gameObject.transform.position, Quaternion.identity); * } */ //enemy.GetComponentInChildren<animotionEvent>().hit(); //damageDisplay.instance.spawnDamageDisplay(BoardManager.Instance.selectedChessman.damage, 0, enemy.gameObject.transform); BoardManager.Instance.OnPlayerFinishAttack(); } //玩家打人
public Board() { GDevice = LightFireCS.Graphics.GDevice.Get(); Cam = new LightFireCS.Graphics.Camera(); TexMan = LightFireCS.Graphics.TextureManager.Get(); ModelLoader = LightFireCS.Graphics.ModelLoader.Get(); InputDevice = LightFireCS.Input.IDevice.Get(); TexMan.LoadTextureFromFile(@"g:\Programmieren\Chess\Models\WHITE.TGA"); TexMan.LoadTextureFromFile(@"g:\Programmieren\Chess\Models\BLACK.TGA"); TexMan.LoadTextureFromFile(@"g:\Programmieren\Chess\Models\BOARD.TGA"); Cam.SetPosition(0, 20, 30); Cam.SetRotation(0, 0, 45); Cam.SetPosition(0, 30, 30); Cam.SetRotation(0, 0, 120); HomePosition(); arrow = new Arrow(1, 1, true); /*ParseFen("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"); * Render(); * ParseFen("rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2"); * Render(); * ParseFen("rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2"); * Render();*/ //MoveFigure(1, 7, 2, 5); /*MoveFigure(2, 6, 2, 4); * MoveFigure(1, 1, 1, 3); * MoveFigure(1, 3, 2, 4); * RenderAscii();*/ }
public void HomePosition() { ParseFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq _ 0 1"); chessmanInHand = null; chessman = new Chessman[32]; chessman[0] = new King(5, 1, true); chessman[1] = new King(5, 8, false); chessman[2] = new Queen(4, 1, true); chessman[3] = new Queen(4, 8, false); chessman[4] = new Bishop(3, 1, true); chessman[5] = new Bishop(6, 1, true); chessman[6] = new Bishop(3, 8, false); chessman[7] = new Bishop(6, 8, false); chessman[8] = new Knight(2, 1, true); chessman[9] = new Knight(7, 1, true); chessman[10] = new Knight(2, 8, false); chessman[11] = new Knight(7, 8, false); chessman[12] = new Rock(1, 1, true); chessman[13] = new Rock(8, 1, true); chessman[14] = new Rock(1, 8, false); chessman[15] = new Rock(8, 8, false); for (int i = 16; i < 24; i++) { chessman[i] = new Pawn(i - 15, 2, true); chessman[i + 8] = new Pawn(i - 15, 7, false); } foreach (Chessman cmBuild in chessman) { cmBuild.BuildMoveList(ref board); } }
public bool KnightThreat(int x, int y) { if (x >= 0 && y >= 0 && x <= 7 && y <= 7) { Chessman piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { return(false); } // If the piece is from same team if (piece.isWhite == isWhite) { return(false); } // The piece is from Opponent team // If the opponent piece is Knight if (piece.GetType() == typeof(Knight)) { Debug.Log("Threat from Knight"); return(true); // Yes, there is a Knight threat } } return(false); }
public void SelectChessman(int x, int y) { if (Chessmans[x, y] == null) { return; } if (Chessmans[x, y].isWhite != isWhiteTurn) { return; } print("Select"); audioSource.PlayOneShot(pickSound, 0.2f); selectedChessman = Chessmans[x, y]; Vector3 pos = selectedChessman.transform.position; Quaternion rot = selectedChessman.transform.rotation; pos.y = .6f; selectedChessman.transform.position = pos; selectedChessman.transform.rotation = Quaternion.Euler(12f, rot.eulerAngles.y, 0f); this.allowedMoves = selectedChessman.PossibleMoves(); BoardHighlightsOffline.Instace.HighlightAllowedMoves(allowedMoves); }
public override void SpawnAllChessmans() { activeChessman = new List <GameObject>(); Chessmans = new Chessman[8, 8]; EnPassantMove = new int[2] { -1, -1 }; SpawnChessman(0, 6, 0); SpawnChessman(2, 3, 0); SpawnChessman(3, 3, 6); SpawnChessman(3, 0, 2); SpawnChessman(5, 0, 1); SpawnChessman(5, 2, 2); SpawnChessman(5, 5, 1); SpawnChessman(5, 5, 5); SpawnChessman(5, 6, 1); SpawnChessman(5, 7, 1); SpawnChessman(6, 5, 7); SpawnChessman(7, 5, 2); SpawnChessman(8, 1, 7); SpawnChessman(8, 6, 7); SpawnChessman(9, 1, 5); SpawnChessman(9, 1, 6); SpawnChessman(10, 4, 6); SpawnChessman(11, 0, 6); SpawnChessman(11, 2, 6); SpawnChessman(11, 5, 6); SpawnChessman(11, 7, 6); }
// Displays red, blue and green boxes whenever the player clicks on chessman. public void DisplayHighlighters(List <Move> possibleMoves) { if (possibleMoves.Count() == 0) { Debug.Log("No Possible moves"); return; } foreach (var p in possibleMoves) { int objectIndex; float height_Y = 1; if (p.isCastle) { objectIndex = 2; } else if (p.isKill) { Chessman chessman = GetComponentInChessman <Chessman>(p.z, p.x); //Getting the height of Red Cube above the figure to kill. //My figures will be replaced anyway, this should be fixed. switch (chessman.tag) { case "Pawn": height_Y = 11; break; case "Rook": height_Y = 10; break; case "Knight": height_Y = 13; break; case "Bishop": height_Y = 14; break; case "Queen": height_Y = 13.5f; break; case "King": Debug.LogError("DisplayValidMoves:: Entered King tag in switch chessman.tag"); break; default: Debug.LogError("DisplayValidMoves:: Wrong tag"); break; } objectIndex = 1; } else { objectIndex = 0; } //Sets the highlighter at correct place GameObject highlighter = ObjectPooler.Instance.GetPooledObject(objectIndex); Vector3 newPos = new Vector3(GetWorldPos(p.x), height_Y, GetWorldPos(p.z)); highlighter.transform.position = newPos; highlighter.SetActive(true); } }
private void MoveChessman(int x, int y) { //Debug.Log("MoveChessman , " + x + " " + y+" , "+Chessmans[x, y]+ " "+ selectedChessman); //Debug.Log("allowedMove"+allowedMoves[x,y]); if (allowedMoves[x, y]) { Chessman c = Chessmans[x, y]; if (c != null && c.isWhite != isWhiteTurn) { //Capture a piece //If it is the king if (c.GetType() == typeof(King)) { EndGame(); return; } activechessman.Remove(c.gameObject); Destroy(c.gameObject); } //Debug.Log("MoveChessman , " + x + " " + y+" , "+Chessmans[x, y]+ " "+ selectedChessman); Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null; selectedChessman.transform.position = GetTileCenter(x, y); selectedChessman.SetPosition(x, y); Chessmans[x, y] = selectedChessman; isWhiteTurn = !isWhiteTurn; } BoardHighlights.Instance.HideHighlights(); selectedChessman = null; }
public bool TestXequeMate(Color color) { if (!IsXequeMate(color)) { return(false); } foreach (Chessman piece in InGameChessmans(color)) { bool[,] possibleMovements = piece.PossibleMovements(); for (int row = 0; row < Board.Rows; row++) { for (int column = 0; column < Board.Columns; column++) { if (possibleMovements[row, column]) { Position origin = piece.PiecePosition; Position destiny = new Position(row, column); Chessman capturedChessman = ExecuteMovement(origin, destiny); bool testXeque = IsXequeMate(color); UndoMovement(origin, destiny, capturedChessman); if (!testXeque) { return(false); } } } } } return(true); }
private void SelectChessman(int x, int y) { if (Chessmans[x, y] == null) { return; } if (Chessmans[x, y].isWhite != isWhiteTurn) { return; } bool hasAtleastOneMove = false; allowedMoves = Chessmans[x, y].PossibleMove(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (allowedMoves[i, j]) { hasAtleastOneMove = true; } } } if (!hasAtleastOneMove) { return; } //Check (allowedMoves); selectedChessman = Chessmans[x, y]; //Debug.Log ("SelectChessman , " + x + " " + y + " , " + Chessmans[x, y] + " " + selectedChessman); BoardHighlights.Instance.HighlightAllowedMoves(allowedMoves); }
private void ProcessIfPawnStepOnFinalLine(int x, int y) { if (selectedChessman.GetType() == typeof(Pawn)) { // check if pawn steps on final line, it becomes Queen if (y == 7) // white team { int currentX = selectedChessman.CurrentX, currentY = selectedChessman.CurrentY; // remove selected chessman activeChessmans.Remove(selectedChessman.gameObject); Destroy(selectedChessman.gameObject); // spawn new chessman SpawnChessman(1, currentX, currentY); selectedChessman = Chessmans[currentX, currentY]; // rotate the chessman selectedChessman.RotateEach(ROTATE_TIME); } else if (y == 0) // black team { int currentX = selectedChessman.CurrentX, currentY = selectedChessman.CurrentY; // remove selected chessman activeChessmans.Remove(selectedChessman.gameObject); Destroy(selectedChessman.gameObject); // spawn new chessman SpawnChessman(7, currentX, currentY); selectedChessman = Chessmans[currentX, currentY]; // rotate the chessman // selectedChessman.RotateEach(ROTATE_TIME); } } }
private void MoveChessman(int x, int y) { //if (selectedChessman.PossibleMove (x, y)) { if (allowedMoves[x, y]) { Chessman c = Chessmans [x, y]; if (c != null && c.isWhite != isWhiteTurn) { if (c.GetType() == typeof(King)) { EndGame(); return; } activeChessman.Remove(c.gameObject); Destroy(c.gameObject); } Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null; selectedChessman.transform.position = GetTileCenter(x, y); selectedChessman.SetPosition(x, y); Chessmans [x, y] = selectedChessman; isWhiteTurn = !isWhiteTurn; } BoardHighlights.Instance.HideHighlights(); selectedChessman = null; }
private void SelectedChessman(int x, int y) { if (Chessmans [x, y] == null) { return; } if (Chessmans [x, y].isWhite != isWhiteTurn) { return; } //Pour q'une piece bloquer par un adversaire ne soit plus selectionnable bool hasAtleastOneMove = false; allowedMoves = Chessmans [x, y].PossibleMove(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (allowedMoves [i, j]) { hasAtleastOneMove = true; } } } selectedChessman = Chessmans [x, y]; BoardHighlights.Instance.HighlightAllowedMoves(allowedMoves); }
private void SelectChessman(int x, int y) { if (Chessmans[x, y] == null) { return; // return } if (Chessmans[x, y].isWhite != isWhiteTurn) { return; //trying pick piece is black piec } bool hasAtleastOneMove = false; allowedMoves = Chessmans[x, y].PossibleMove(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (allowedMoves[i, j]) { hasAtleastOneMove = true; } } } if (!hasAtleastOneMove) { return; } selectedChessman = Chessmans[x, y]; BoardHighlights.Instance.HighLightAllowedMoves(allowedMoves); }
private bool QueenMove(int x, int y, ref bool[,] moves) { Chessman piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { if (!this.KingInDanger(x, y)) { moves[x, y] = true; } return(true); // Keep on looping } // If the piece is from opponent team else if (piece.isWhite != isWhite) { if (!this.KingInDanger(x, y)) { moves[x, y] = true; } } // Else if the piece is from same team, do nothing return(false); // Stop the looping }
private void MoveChessman(int x, int y) { if (allowedMoves[x, y]) { Chessman c = Chessmans[x, y]; if (c != null && c.isWhite != isWhiteTurn) { // Capture a piece // If it is the king end the game if (c.GetType() == typeof(King)) { EndGame(); return; } activeChessMan.Remove(c.gameObject); Destroy(c.gameObject); } Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null; //we move selectedChessman.transform.position = GetTileCenter(x, y + 1); selectedChessman.SetPosition(x, y); Chessmans[x, y] = selectedChessman; isWhiteTurn = !isWhiteTurn; // swap to other value, only } BoardHighlights.Instance.Hidehighlights(); selectedChessman = null; // unselect if click on place doesnt make sense }
public void LineMovePlate(int xIncrement, int yIncrement, string name) { GameObject objeto = GameObject.Find(name); Chessman chesspiece = objeto.GetComponent <Chessman>(); GameObject Controller = GameObject.FindGameObjectWithTag("GameController"); /*A variavel do tipo game "sc" vai receber um componente * do objeto Controller,sendo esse componente o script Game*/ Game sc = Controller.GetComponent <Game>(); /*recebemos o x e o y da peça no tabuleiro e icrementamos * de acordo com os argumentos do método*/ int x = chesspiece.GetXBoard() + xIncrement; int y = chesspiece.GetYBoard() + yIncrement; /*enquanto a posição no tabuleiro existir,e não ouver nada * nessa posição*/ while (sc.PositionOnBoard(x, y) && sc.GetPosition(x, y) == null) { //Coloca um moveplate no tabuleiro na posição x e y movePlateSpawner.MovePlateSpawn(x, y, Tipos.Normal, chesspiece.name); x += xIncrement; y += yIncrement; } /*se a posição existir e a posição for de um jogador que * não é o jogador atual*/ if (sc.PositionOnBoard(x, y) && sc.GetPosition(x, y).GetComponent <Chessman>().GetPlayer() != chesspiece.GetPlayer()) { //Cria um moveplate de ataque movePlateSpawner.MovePlateSpawn(x, y, Tipos.Attack, chesspiece.name); } }
private void MoveChessman(int x, int y) { //if (selectedChessman.PossibleMove (x, y)) if (allowedMoves[x, y]) { Chessman c = Chessmans [x, y]; if (c != null && c.isWhite != isWhiteTurn) { // Capture a piece // If it is the king if (c.GetType() == typeof(King)) { //End the game EndGame(); return; } activeChessman.Remove(c.gameObject); Destroy(c.gameObject); } Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null; selectedChessman.transform.position = GetTileCenter(x, y); selectedChessman.SetPosition(x, y); Chessmans [x, y] = selectedChessman; isWhiteTurn = !isWhiteTurn; } // selectedChessman.GetComponent<MeshRenderer> ().material = previousMat; BoardHighlights.Instance.HideHighlights(); selectedChessman = null; }
private void SpawnAllChessmans() { activeChessman = new List <GameObject>(); Chessmans = new Chessman[8, 8]; EnPassantMove = new int[2] { -1, -1 }; // SPAWN THE WHITE TEAM // KING SpawnChessman(0, 4, 0); // QUEEN SpawnChessman(1, 3, 0); // ROOKS SpawnChessman(2, 0, 0); SpawnChessman(2, 7, 0); // BISHOPS SpawnChessman(3, 2, 0); SpawnChessman(3, 5, 0); // KNIGHTS SpawnChessman(4, 1, 0); SpawnChessman(4, 6, 0); // PAWNS for (int i = 0; i < 8; i++) { SpawnChessman(5, i, 1); } // SPAWN THE BLACK TEAM // KING SpawnChessman(6, 3, 7); // QUEEN SpawnChessman(7, 4, 7); // ROOKS SpawnChessman(8, 0, 7); SpawnChessman(8, 7, 7); // BISHOPS SpawnChessman(9, 2, 7); SpawnChessman(9, 5, 7); // KNIGHTS SpawnChessman(10, 1, 7, false); SpawnChessman(10, 6, 7, false); // PAWNS for (int i = 0; i < 8; i++) { SpawnChessman(11, i, 6); } }
private void OnTriggerEnter(Collider other) { if (other.tag == "ChessPiece") { Chessman otherChessman = other.GetComponent <Chessman>(); if ((this.transform.parent.GetComponent <Chessman>().isWhite != otherChessman.isWhite) && (otherChessman.isTarget)) { BoardManager.Instance.activeChessMan.Remove(otherChessman.gameObject); Destroy(otherChessman.gameObject); if (this.transform.parent.GetComponent <Chessman>().isWhite) { GameManager.WhitePlayerAddScore(GameManager.GetPieceWorth(otherChessman.GetType().ToString())); GameManager.BlackPlayerRemovePiece(otherChessman.GetType().ToString()); } else { GameManager.BlackPlayerAddScore(GameManager.GetPieceWorth(otherChessman.GetType().ToString())); GameManager.WhitePlayerRemovePiece(otherChessman.GetType().ToString()); } if (otherChessman.GetType() == typeof(King)) { BoardManager.Instance.EndGame(); return; } } else { return; } } }
public Board() { CurrTurn = String.Empty; PlayerWhiteId = String.Empty; PlayerBlackId = String.Empty; WinnerId = String.Empty; chessboard = new Chessman[Configure.ROWS, Configure.COLS]; for (int i = 0; i < Configure.ROWS; i++) { for (int j = 0; j < Configure.COLS; j++) { chessboard[i, j] = new Chessman(); } } Id = Guid.NewGuid().ToString(); Players = 0; Viewers = 0; IsGameOver = true; }
public void NewGameStartInit() { IsGameOver = false; WinnerId = String.Empty; CurrTurn = PlayerWhiteId; chessboard = new Chessman[Configure.ROWS, Configure.COLS]; for (int i = 0; i < Configure.ROWS; i++) { for (int j = 0; j < Configure.COLS; j++) { chessboard[i, j] = new Chessman(); } } }
//for selecting/clicking public void ClickOnChessboard(int mouseX, int mouseY, Players player) { int horizontal, vertical; horizontal = mouseX / sizeOfCell; vertical = mouseY / sizeOfCell; //if cell exists if (((horizontal > 0) && (horizontal < 9) && (vertical > 0) && (vertical < 9)) || //special corners (((horizontal == 9) && (vertical == 8)) || ((horizontal == 0) && (vertical == 1)) || ((horizontal == 8) && (vertical == 0)) || ((horizontal == 1) && (vertical == 9)))) { bool wasAttack = false; if (GetChessmanOnCoordinates(horizontal, vertical) != null) { if (GetChessmanOnCoordinates(horizontal, vertical) != selectedChessman) { //attack method if enemy if (selectedChessman != null) { selectedChessman.ShowPossibleMovements(true); selectedChessman.ShowPossibleAttacks(true); if (selectedChessman.IsThatPossibleAttack(horizontal, vertical)) { selectedChessman.AttackChessmanOnCoordinates(horizontal, vertical); selectedChessmanStr = ""; selectedChessman = null; wasAttack = true; TurnAnalyse(); //turn happened game.ToggleTurn(); } } //is rightfully select if ((!wasAttack) && (player == GetChessmanOnCoordinates(horizontal, vertical).GetChessmanOwner())) { //is check and could king move if (game.GetPlayerObject(player).GetCheckState()) { if (!(game.GetPlayerObject(player).CanKingMove())) { if (GetChessmanOnCoordinates(horizontal, vertical).GetChessmanName() != ChessmenNames.King) { selectedChessman = GetChessmanOnCoordinates(horizontal, vertical); selectedChessmanStr = selectedChessman.GetNameOfChessmanRussianNominative() + ' '; selectedChessman.ShowPossibleMovements(false); selectedChessman.ShowPossibleAttacks(false); } else { MessageBox.Show("Вам объявлен шах, но король не может двигаться.", "Внимание"); } } else { if (GetChessmanOnCoordinates(horizontal, vertical).GetChessmanName() != ChessmenNames.King) { MessageBox.Show("Вам объявлен шах. Ходить может только король.", "Внимание"); } else { selectedChessman = GetChessmanOnCoordinates(horizontal, vertical); selectedChessmanStr = selectedChessman.GetNameOfChessmanRussianNominative() + ' '; selectedChessman.ShowPossibleMovements(false); selectedChessman.ShowPossibleAttacks(false); } } } else { //if (GetChessmanOnCoordinates(horizontal, vertical).CanMoveOrAttack()) //{ selectedChessman = GetChessmanOnCoordinates(horizontal, vertical); selectedChessmanStr = selectedChessman.GetNameOfChessmanRussianNominative() + ' '; selectedChessman.ShowPossibleMovements(false); selectedChessman.ShowPossibleAttacks(false); //} } } } else { //if repeat click then deselect chessman selectedChessman.ShowPossibleMovements(true); selectedChessman.ShowPossibleAttacks(true); selectedChessmanStr = ""; selectedChessman = null; } } else { //move method if possible move if (selectedChessman != null) { selectedChessmanStr = ""; selectedChessman.ShowPossibleMovements(true); selectedChessman.ShowPossibleAttacks(true); if (selectedChessman.IsThatPossibleMove(horizontal, vertical)) { selectedChessman.MoveChessman(horizontal, vertical, true); TurnAnalyse(); //turn happened game.ToggleTurn(); } selectedChessman = null; } } chessboardPicturebox.Refresh(); } }
public void DrawChessman(Chessman chessman) { chessman.DrawChessmanOnChessboard(ref chessboardBitmap, x, y, sizeOfCell); }