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 AddCellGuiAndCell() { // if(listCellGui!=null) listCellGui.Clear(); this.Controls.Clear(); if (listCellGui != null) { this.listCellGui.Clear(); } for (int i = 0; i < 64; i++) { CellGui cell = new CellGui(this, i); this.Controls.Add(cell, i % 8, i / 8); this.listCellGui.Add(cell); } this.Refresh(); }
/// <summary> /// them cac cellgui len boardgui /// </summary> /// <param name="isClient"></param> public void AddCellGuiAndCell(bool isClient) { // if(listCellGui!=null) listCellGui.Clear(); this.Controls.Clear(); if (listCellGui != null) { this.listCellGui.Clear(); } this.Visible = false; //Neu la client thi tao ban co dao nguoc if (isClient) { int position = 63; for (int i = 0; i < 64; i++) { CellGui cell = new CellGui(this, i); this.Controls.Add(cell, position % 8, position / 8); this.listCellGui.Add(cell); position--; } } else { for (int i = 0; i < 64; i++) { CellGui cell = new CellGui(this, i); this.Controls.Add(cell, i % 8, i / 8); this.listCellGui.Add(cell); } } this.Visible = true; this.Refresh(); }