public bool math(chess a, sbyte value, sbyte x, sbyte y) { value = (sbyte)(value % 10); int t = 12; if (a.x == x) { t = (a.y > y) ? (a.y - y) : (y - a.y); //Cung hang } if (a.y == y) { t = (a.x > x) ? (a.x - x) : (x - a.x); //Cung cot } if ((a.x - a.y) == (x - y)) { t = (a.x > x) ? (a.x - x) : (x - a.x); //Cung duong cheo chinh } if ((a.x + a.y) == (x + y)) { t = (a.x > x) ? (a.x - x) : (x - a.x); //Cung duong cheo phu } if (t == 12) { return(false); } for (int i = 0; i <= 4; i++) { if (fire[a.value, value, i] == t - 1) { return(true); } } return(false); }
public bool teammate(Board b, chess c, int x2, int y2) { if (b.getInfo(x2, y2) == -1) { return(false); } if (((b.getInfo(c.x, c.y) < 10) && (b.getInfo(x2, y2) < 10)) || ((b.getInfo(c.x, c.y) > 9) && (b.getInfo(x2, y2) > 9))) { return(true); } return(false); }
private void Form1_Load(object sender, EventArgs e) { int num = 8; int cellheight, cellwidth; cellheight = cellwidth = (pictureBox1.Width / num) + 1; cells = new Button[num, num]; for (int row = 0; row < num; row++) { for (int col = 0; col < num; col++) { cells[row, col] = new Button(); if (row == 7) { char c = (char)(col + 65); cells[row, col].Text = c.ToString(); } if (col == 0) { cells[row, col].Text += (8 - row).ToString(); } cells[row, col].TextAlign = ContentAlignment.TopRight; cells[row, col].Top = row * cellheight; cells[row, col].Left = col * cellwidth; cells[row, col].Width = cellwidth; cells[row, col].Height = cellheight; cells[row, col].FlatStyle = FlatStyle.Popup; cells[row, col].Font = new Font(cells[row, col].Font.FontFamily, 8); cells[row, col].Name = "Button_" + row.ToString() + "_" + col.ToString(); if ((row + col) % 2 == 1) { cells[row, col].BackColor = Color.Gray; } else { cells[row, col].BackColor = Color.White; } pictureBox1.Controls.Add(cells[row, col]); cells[row, col].Click += new System.EventHandler(b_Click); } } c1 = new chess(pictureBox1.CreateGraphics(), pictureBox1.Width, pictureBox1.Height); c1.passform(this); updatebuttons = new updateButtonsDelegate(udb); updatestat = new updategamestatDelegate(uds); promote = new promoteDelegate(promo); promoteDelete = new promoteDelDelegate(promoBegone); captured = new capturedDelegate(dc); delCaptured = new capturedDelegate(clearCaptured); }
public state() { for (sbyte j = 1; j <= 9; j++) { for (sbyte k = 0; k <= 9; k++) { if (j == k) { continue; } fire[j, k, 0] = (sbyte)((j + k) % 10); // cong fire[j, k, 2] = (sbyte)((j * k) % 10); // nhan if (j > k) { fire[j, k, 1] = (sbyte)(j - k); // tru if (k != 0) { fire[j, k, 3] = (sbyte)(j / k); // thuong } else { fire[j, k, 3] = 0; } if (k != 0) { fire[j, k, 4] = (sbyte)(j % k); // du } else { fire[j, k, 4] = 0; } } else { fire[j, k, 1] = fire[j, k, 3] = fire[j, k, 4] = 0; } } } for (int i = 0; i < 10; i++) { QuanDo[i] = new chess(); QuanXanh[i] = new chess(); QuanDo[i].value = QuanDo[i].x = QuanDo[i].y = -1; QuanXanh[i].value = QuanXanh[i].x = QuanXanh[i].y = -1; } }
/* Creates a promotion selection form which lists the pieces which the player may select for upgrading their high ranked pawn. The constructor of the form takes the moving pawn as mvPawn in order to determine the colour of the upgraded piece to display and use. */ public PromotionSelection(chess.Model.Piece mvPawn) { InitializeComponent(); PictureBox queen, knight, rook, bishop; if (mvPawn.Val == Model.EGamePieces.WhitePawn) { queen = View.Display.getGuiPiece(Model.EGamePieces.WhiteQueen); knight = View.Display.getGuiPiece(Model.EGamePieces.WhiteKnight); rook = View.Display.getGuiPiece(Model.EGamePieces.WhiteRook); bishop = View.Display.getGuiPiece(Model.EGamePieces.WhiteBishop); queen.Tag = Model.EGamePieces.WhiteQueen; knight.Tag = Model.EGamePieces.WhiteKnight; rook.Tag = Model.EGamePieces.WhiteRook; bishop.Tag = Model.EGamePieces.WhiteBishop; this.defaultPiece = Model.EGamePieces.WhiteQueen; } else { queen = View.Display.getGuiPiece(Model.EGamePieces.BlackQueen); knight = View.Display.getGuiPiece(Model.EGamePieces.BlackKnight); rook = View.Display.getGuiPiece(Model.EGamePieces.BlackRook); bishop = View.Display.getGuiPiece(Model.EGamePieces.BlackBishop); queen.Tag = Model.EGamePieces.BlackQueen; knight.Tag = Model.EGamePieces.BlackKnight; rook.Tag = Model.EGamePieces.BlackRook; bishop.Tag = Model.EGamePieces.BlackBishop; this.defaultPiece = Model.EGamePieces.BlackQueen; } // register the click handler to the selection pieces queen.Click += promotionPieceSelect_Click; knight.Click += promotionPieceSelect_Click; rook.Click += promotionPieceSelect_Click; bishop.Click += promotionPieceSelect_Click; this.panelQueen.Controls.Add(queen); this.panelKnight.Controls.Add(knight); this.panelRook.Controls.Add(rook); this.panelBishop.Controls.Add(bishop); this.DialogResult = DialogResult.None; }
// 绘制旗子 private void drawChess(int posH, int posW, ChessType type) { if (type == ChessType.empty) { return; } GameObject chessObj = Instantiate(templetChess); chess chessScript = chessObj.GetComponent <chess>(); chessScript.type = type; chessScript.Pos = new chessPos(); chessScript.Pos.hIndex = posH; chessScript.Pos.wIndex = posW; chessScript.draw(); string key = string.Format("{0}_{1}_{2}", posH, posW, type); if (_typeToChessObj.ContainsKey(key) == false) { _typeToChessObj.Add(key, chessObj); } }
Color color2; //文本颜色 //↓初始化相应变量 void Start() { IsOrNo = GameObject.Find("IsOrNo"); UIM_chess = GameObject.Find("Plane").GetComponent <chess>(); CloseText = GameObject.Find("CloseText").GetComponent <Text>(); RestartText = GameObject.Find("RestartText").GetComponent <Text>(); WithDrawText = GameObject.Find("WithDrawText").GetComponent <Text>(); WinRestartText = GameObject.Find("WRText").GetComponent <Text>(); //↓关闭UI界面 IsOrNo.transform.DOScale(0, 0); SettingPanel.transform.DOScale(0, 0); NoChessImage.transform.DOScale(0, 0); WinImage.transform.DOScale(0, 0); //↑ EventTriggerListener.Get(CloseImage.gameObject).onEnter = GetEnterGameObject; EventTriggerListener.Get(RestartImage.gameObject).onEnter = GetEnterGameObject; EventTriggerListener.Get(WithDrawImage.gameObject).onEnter = GetEnterGameObject; EventTriggerListener.Get(WinRestartImage.gameObject).onEnter = GetEnterGameObject; EventTriggerListener.Get(CloseImage.gameObject).onExit = GetExitGameObject; EventTriggerListener.Get(RestartImage.gameObject).onExit = GetExitGameObject; EventTriggerListener.Get(WithDrawImage.gameObject).onExit = GetExitGameObject; EventTriggerListener.Get(WinRestartImage.gameObject).onExit = GetExitGameObject; }
// 处理用户对棋盘位置的点击事件 private void onClickPos(int posH, int posW, Collider2D chessPosCollider) { // 判断是否轮到玩家操作 if (PlayerGroup != CurrentGroup) { return; } ChessType selectChessType = _dataArr[posH, posW]; // 判断是选子 还是 落子 if (_currentSelectChess == null) { if (selectChessType == ChessType.empty) { return; } if (getGroupType(selectChessType) != PlayerGroup) { return; } string key = string.Format("{0}_{1}_{2}", posH, posW, selectChessType); if (_typeToChessObj.ContainsKey(key) == false) { Debug.Log("chessObj is not exist when selectChess!!!"); return; } _currentSelectChess = _typeToChessObj[key]; } else { chess chessScript = _currentSelectChess.GetComponent <chess>(); if (chessScript == null) { Debug.Log("chessScript is null when luo zi"); return; } // 落到己方的子上了 if (selectChessType != ChessType.empty && getGroupType(selectChessType) == PlayerGroup) { return; } // 判断棋子行走规则 if (_typeToRule[chessScript.type](_dataArr, chessScript.Pos.hIndex, chessScript.Pos.wIndex, posH, posW) == false) { return; } _dataArr[chessScript.Pos.hIndex, chessScript.Pos.wIndex] = ChessType.empty; _dataArr[posH, posW] = chessScript.type; string oldKey = string.Format("{0}_{1}_{2}", chessScript.Pos.hIndex, chessScript.Pos.wIndex, chessScript.type); _typeToChessObj.Remove(oldKey); chessScript.Pos.hIndex = posH; chessScript.Pos.wIndex = posW; string newKey = string.Format("{0}_{1}_{2}", chessScript.Pos.hIndex, chessScript.Pos.wIndex, chessScript.type); _typeToChessObj.Add(newKey, _currentSelectChess); // 移动棋子 _currentSelectChess.GetComponent <Transform>().position = chessPosCollider.GetComponent <Transform>().position; _currentSelectChess = null; // 如果是吃棋 删除吃掉的棋子对象 if (selectChessType != ChessType.empty) { string eattedKey = string.Format("{0}_{1}_{2}", posH, posW, selectChessType); if (_typeToChessObj.ContainsKey(eattedKey)) { GameObject eattedChess = _typeToChessObj[eattedKey]; _typeToChessObj.Remove(eattedKey); GameObject.Destroy(eattedChess); } } } }
public void set(ref chess c, int value) { c.value = (sbyte)value; }
public void set(ref chess c, int x, int y) { c.x = (sbyte)x; c.y = (sbyte)y; }
public void set(ref chess c, int x, int y, int value) { c.x = (sbyte)x; c.y = (sbyte)y; c.value = (sbyte)value; }
public bool capture(Board b, chess c, int x1, int y1) { sbyte x2, y2; x2 = (sbyte)x1; y2 = (sbyte)y1; //kiem tra xem co quan co nao o vi tri x2, y2 khong //neu o o x2,y2 trong if ((b.getInfo(x2, y2) == -1)) { return(false); } //neu o o x2,y2 la quan co cung mau if (((b.getInfo(c.x, c.y) < 10) && (b.getInfo(x2, y2) < 10)) || ((b.getInfo(c.x, c.y) > 9) && (b.getInfo(x2, y2) > 9))) { return(false); } //neu o o x2,y2 la quan co doi phuong //khi nao an duoc? //neu khong cung hang hoac cung cot hoac cung duong cheo if ((c.x != x2) && (c.y != y2) && ((c.x + c.y) != (x2 + y2)) && ((c.x - c.y) != (x2 - y2))) { return(false); } //cung hang if (c.y == y2) { if (c.x < x2) { //kiem tra vi tri (x+1, y) co quan minh khong? if (!this.teammate(b, c, c.x + 1, c.y)) { return(false); } //neu co quan minh dung canh, kiem tra xem co an duoc khong for (int j = c.x + 2; j < x2; j++) { if (b.getInfo(j, c.y) != -1) { return(false); } } if (math(c, b.getInfo(c.x + 1, c.y), x2, y2)) { //op = pheptoan; return(true); } } //x>x2 else { //kiem tra vi tri (x-1,y) co quan minh khong if (!this.teammate(b, c, c.x - 1, c.y)) { return(false); } //neu co, kiem tra xem co an duoc khong for (int j = c.x - 2; j > x2; j--) { if (b.getInfo(j, c.y) != -1) { return(false); } } //if ((khoang_cach == (value + quan_canh) % 10) || (khoang_cach == Math.Abs(value - quan_canh)) || (khoang_cach == (value * quan_canh) % 10) || (khoang_cach == (value / quan_canh)) || (khoang_cach == (quan_canh / value)) || (khoang_cach == (value % quan_canh)) || (khoang_cach == (quan_canh % value))) if (math(c, b.getInfo(c.x - 1, c.y), x2, y2)) { return(true); } } } //cung cot if (c.x == x2) { if (c.y < y2) { //kiem tra vi tri (x, y+1) co quan minh khong? if (!this.teammate(b, c, c.x, c.y + 1)) { return(false); } //neu co quan minh dung canh, kiem tra xem co an duoc khong for (int j = c.y + 2; j < y2; j++) { if (b.getInfo(c.x, j) != -1) { return(false); } } //if ((khoang_cach == (value + quan_canh) % 10) || (khoang_cach == (value - quan_canh)) || (khoang_cach == (value * quan_canh) % 10) || (khoang_cach == (value / quan_canh)) || (khoang_cach == (quan_canh / value)) || (khoang_cach == (value % quan_canh)) || (khoang_cach == (quan_canh % value))) if (math(c, b.getInfo(c.x, c.y + 1), x2, y2)) { return(true); } } //y>y2 else { //kiem tra vi tri (x,y-1) co quan minh khong if (!this.teammate(b, c, c.x, c.y - 1)) { return(false); } //neu co, kiem tra xem co an duoc khong for (int j = c.y - 2; j > y2; j--) { if (b.getInfo(c.x, j) != -1) { return(false); } } //if ((khoang_cach == (value + quan_canh) % 10) || (khoang_cach == Math.Abs(value - quan_canh)) || (khoang_cach == (value * quan_canh) % 10) || (khoang_cach == (value / quan_canh)) || (khoang_cach == (quan_canh / value)) || (khoang_cach == (value % quan_canh)) || (khoang_cach == (quan_canh % value))) if (math(c, b.getInfo(c.x, c.y - 1), x2, y2)) { return(true); } } } //cung duong cheo chinh if (c.x - c.y == x2 - y2) { if (c.x < x2) { //kiem tra vi tri (x+1, y+1) co quan minh khong? if (!this.teammate(b, c, c.x + 1, c.y + 1)) { return(false); } //neu co quan minh dung canh, kiem tra xem co an duoc khong for (int j = 2; j < x2 - c.x; j++) { if (b.getInfo(c.x + j, c.y + j) != -1) { return(false); } } //if ((khoang_cach == (value + quan_canh) % 10) || (khoang_cach == (value - quan_canh)) || (khoang_cach == (value * quan_canh) % 10) || (khoang_cach == (value / quan_canh)) || (khoang_cach == (quan_canh / value)) || (khoang_cach == (value % quan_canh)) || (khoang_cach == (quan_canh % value))) if (math(c, b.getInfo(c.x + 1, c.y + 1), x2, y2)) { return(true); } } //x>x2 else { //kiem tra vi tri (x-1,y-1) co quan minh khong if (!this.teammate(b, c, c.x - 1, c.y - 1)) { return(false); } //neu co, kiem tra xem co an duoc khong for (int j = c.x - x2 - 1; j >= 2; j--) { if (b.getInfo(c.x - j, c.y - j) != -1) { return(false); } } //if ((khoang_cach == (value + quan_canh) % 10) || (khoang_cach == Math.Abs(value - quan_canh)) || (khoang_cach == (value * quan_canh) % 10) || (khoang_cach == (value / quan_canh)) || (khoang_cach == (quan_canh / value)) || (khoang_cach == (value % quan_canh)) || (khoang_cach == (quan_canh % value))) if (math(c, b.getInfo(c.x - 1, c.y - 1), x2, y2)) { return(true); } } } //cung duong cheo phu if (c.x + c.y == x2 + y2) { if (c.x < x2) { //kiem tra vi tri (x+1, y-1) co quan minh khong? if (!this.teammate(b, c, c.x + 1, c.y - 1)) { return(false); } //neu co quan minh dung canh, kiem tra xem co an duoc khong for (int j = 2; j < x2 - c.x; j++) { if (b.getInfo(c.x + j, c.y - j) != -1) { return(false); } } //if ((khoang_cach == (value + quan_canh) % 10) || (khoang_cach == (value - quan_canh)) || (khoang_cach == (value * quan_canh) % 10) || (khoang_cach == (value / quan_canh)) || (khoang_cach == (quan_canh / value)) || (khoang_cach == (value % quan_canh)) || (khoang_cach == (quan_canh % value))) if (math(c, b.getInfo(c.x + 1, c.y - 1), x2, y2)) { return(true); } } //x>x2 else { //kiem tra vi tri (x-1,y+1) co quan minh khong if (!this.teammate(b, c, c.x - 1, c.y + 1)) { return(false); } //neu co, kiem tra xem co an duoc khong for (int j = c.x - x2 - 1; j >= 2; j--) { if (b.getInfo(c.x - j, c.y + j) != -1) { return(false); } } //if ((khoang_cach == (value + quan_canh) % 10) || (khoang_cach == Math.Abs(value - quan_canh)) || (khoang_cach == (value * quan_canh) % 10) || (khoang_cach == (value / quan_canh)) || (khoang_cach == (quan_canh / value)) || (khoang_cach == (value % quan_canh)) || (khoang_cach == (quan_canh % value))) if (math(c, b.getInfo(c.x - 1, c.y + 1), x2, y2)) { return(true); } } } return(false); }
public bool move(Board b, chess c, int x, int y) { sbyte x2, y2; x2 = (sbyte)x; y2 = (sbyte)y; Point X = new Point(c.x, c.y); if (X.distance(x2, y2) <= 0) { return(false); } if (X.distance(x2, y2) > c.value) { return(false); } //neu o x2, y2 khong trong if (b.getInfo(x2, y2) != -1) { return(false); } //cung hang, cung cot hoac cung duong cheo va trong tam kiem soat //cung cot if (c.x == x2)//sua { if (c.y < y2) { for (sbyte i = 1; i <= (y2 - c.y); i++) { if (b.getInfo(c.x, c.y + i) > -1) { return(false); } } } else { for (sbyte i = 1; i <= (c.y - y2); i++) { if (b.getInfo(c.x, c.y - i) > -1) { return(false); } } } } //cung hang if (c.y == y2)//sua { if (c.x < x2) { for (sbyte i = 1; i <= (x2 - c.x); i++) { if (b.getInfo(c.x + i, c.y) > -1) { return(false); } } } else { for (sbyte i = 1; i <= (c.x - x2); i++) { if (b.getInfo(c.x - i, c.y) > -1) { return(false); } } } } //cung duong cheo if ((c.x + c.y) == (x2 + y2)) { if (c.x < x2) { for (sbyte i = 1; i <= (x2 - c.x); i++) { if (b.getInfo(c.x + i, c.y - i) > -1) { return(false); } } } else { for (sbyte i = 1; i <= (c.x - x2); i++) { if (b.getInfo(c.x - i, c.y + i) > -1) { return(false); } } } } if ((x2 - y2) == (c.x - c.y)) { if (c.x < x2) { for (sbyte i = 1; i <= (x2 - c.x); i++) { if (b.getInfo(c.x + i, c.y + i) > -1) { return(false); } } } else { for (sbyte i = 1; i <= (c.x - x2); i++) { if (b.getInfo(c.x - i, c.y - i) > -1) { return(false); } } } } return(true); }