




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 象棋 enum player blank, red, blue, ; enum chesstype blank, jiang, che, ma, pao, xiang, zu, shi ; struct chess public
2、 player side; public chesstype type; ; /下載于 struct block public PictureBox container; public chess item; ; public partial class Form1 : Form public Form1() InitializeComponent(); pictureboxlist = new List<PictureBox>(81); Matrix=new block10; int i,j; for (i = 0; i < 10;i+ ) Matrixi = new bl
3、ock9; for(i=0;i<10;i+) for(j=0;j<9;j+) Control col = this.Controls.Find("pictureBox" + (i*9+j+1), false); Matrixij.container=col0 as PictureBox; Matrixij.container.Location = new Point(60 * j, 60 * i); redcoll = new collecter(); bluecool = new collecter(); for (i = 91; i < 107;i+
4、) Control col = this.Controls.Find("pictureBox" + i, false); bluecool.add(col0 as PictureBox); for (i = 107; i < 123;i+ ) Control col = this.Controls.Find("pictureBox" + i, false); redcoll.add(col0 as PictureBox); resetground(); List<PictureBox> pictureboxlist; block Mat
5、rix; collecter redcoll; collecter bluecool; int chozenX; int chozenY; player currentside; bool beenchozen; bool clickswitch; private void click1(object sender, EventArgs e) if(!clickswitch) resetground(); return; string name = (sender as PictureBox).Name; string number = name.Substring(10); int inde
6、x = Convert.ToInt32(number); int i,j; bool flag = false; i=(index-1)/9; j=(index-1)%9; /下載于 if (beenchozen) MatrixchozenXchozenY.container.BorderStyle = BorderStyle.None; MatrixchozenXchozenY.container.BackColor = Color.Transparent; beenchozen = false; if(MatrixchozenXchozenY.item.side=Matrixij.item
7、.side) return; if (MatrixchozenXchozenY.item.side != player.blank) if(Matrixij.item.type= chesstype.jiang) flag=true; if(!movechess(i, j) return; if(flag) if (currentside = player.red) MessageBox.Show("紅方勝利!點擊任意處重新開局"); else MessageBox.Show("藍方勝利!點擊任意處重新開局"); clickswitch = false;
8、 if (currentside = player.red) currentside = player.blue; label1.Text = "藍方" label1.ForeColor = Color.Blue; else currentside = player.red; label1.Text = "紅方" label1.ForeColor = Color.Red; else if(Matrixij.item.side= currentside) Matrixij.container.BorderStyle = BorderStyle.FixedS
9、ingle; Matrixij.container.BackColor = Color.Brown; chozenX = i; chozenY = j; beenchozen = true; private void resetground() int i, j; for (i = 0; i < 10;i+ ) for(j=0;j<9;j+) Matrixij.container.Image = null; Matrixij.item.side = player.blank; Matrixij.item.type = chesstype.blank; beenchozen = fa
10、lse; clickswitch = true; currentside = player.red; label1.Text = "紅方" label1.ForeColor = Color.Red; redcoll.clear(); bluecool.clear(); Matrix00.container.Image = global:象棋.Properties.Resources.藍車; Matrix01.container.Image = global:象棋.Properties.Resources.藍馬; Matrix02.container.Image = glob
11、al:象棋.Properties.Resources.藍象; Matrix03.container.Image = global:象棋.Properties.Resources.藍士; Matrix04.container.Image = global:象棋.Properties.Resources.藍將; Matrix05.container.Image = global:象棋.Properties.Resources.藍士; Matrix06.container.Image = global:象棋.Properties.Resources.藍象; Matrix07.container.Im
12、age = global:象棋.Properties.Resources.藍馬; Matrix08.container.Image = global:象棋.Properties.Resources.藍車; Matrix21.container.Image = global:象棋.Properties.Resources.藍炮; Matrix27.container.Image = global:象棋.Properties.Resources.藍炮; Matrix30.container.Image = global:象棋.Properties.Resources.藍卒; Matrix32.co
13、ntainer.Image = global:象棋.Properties.Resources.藍卒; Matrix34.container.Image = global:象棋.Properties.Resources.藍卒; Matrix36.container.Image = global:象棋.Properties.Resources.藍卒; Matrix38.container.Image = global:象棋.Properties.Resources.藍卒; Matrix60.container.Image = global:象棋.Properties.Resources.紅卒; M
14、atrix62.container.Image = global:象棋.Properties.Resources.紅卒; Matrix64.container.Image = global:象棋.Properties.Resources.紅卒; Matrix66.container.Image = global:象棋.Properties.Resources.紅卒; Matrix68.container.Image = global:象棋.Properties.Resources.紅卒; Matrix71.container.Image = global:象棋.Properties.Resou
15、rces.紅炮; Matrix77.container.Image = global:象棋.Properties.Resources.紅炮; Matrix90.container.Image = global:象棋.Properties.Resources.紅車; Matrix91.container.Image = global:象棋.Properties.Resources.紅馬; Matrix92.container.Image = global:象棋.Properties.Resources.紅象; Matrix93.container.Image = global:象棋.Proper
16、ties.Resources.紅士; Matrix94.container.Image = global:象棋.Properties.Resources.紅將; Matrix95.container.Image = global:象棋.Properties.Resources.紅士; Matrix96.container.Image = global:象棋.Properties.Resources.紅象; Matrix97.container.Image = global:象棋.Properties.Resources.紅馬; Matrix98.container.Image = global
17、:象棋.Properties.Resources.紅車; /下載于 Matrix00.item.side = player.blue; Matrix01.item.side = player.blue; Matrix02.item.side = player.blue; Matrix03.item.side = player.blue; Matrix04.item.side = player.blue; Matrix05.item.side = player.blue; Matrix06.item.side = player.blue; Matrix07.item.side = player.
18、blue; Matrix08.item.side = player.blue; Matrix21.item.side = player.blue; Matrix27.item.side = player.blue; Matrix30.item.side = player.blue; Matrix32.item.side = player.blue; Matrix34.item.side = player.blue; Matrix36.item.side = player.blue; Matrix38.item.side = player.blue; Matrix60.item.side = p
19、layer.red; Matrix62.item.side = player.red; Matrix64.item.side = player.red; Matrix66.item.side = player.red; Matrix68.item.side = player.red; Matrix71.item.side = player.red; Matrix77.item.side = player.red; Matrix90.item.side = player.red; Matrix91.item.side = player.red; Matrix92.item.side = play
20、er.red; Matrix93.item.side = player.red; Matrix94.item.side = player.red; Matrix95.item.side = player.red; Matrix96.item.side = player.red; Matrix97.item.side = player.red; Matrix98.item.side = player.red; Matrix00.item.type = chesstype.che; Matrix01.item.type = chesstype.ma; Matrix02.item.type = ch
21、esstype.xiang; Matrix03.item.type = chesstype.shi; Matrix04.item.type = chesstype.jiang; Matrix05.item.type = chesstype.shi; Matrix06.item.type = chesstype.xiang; Matrix07.item.type = chesstype.ma; Matrix08.item.type = chesstype.che; Matrix21.item.type = chesstype.pao; Matrix27.item.type = chesstype
22、.pao; Matrix30.item.type = chesstype.zu; Matrix32.item.type = chesstype.zu; Matrix34.item.type = chesstype.zu; Matrix36.item.type = chesstype.zu; Matrix38.item.type = chesstype.zu; Matrix60.item.type = chesstype.zu; Matrix62.item.type = chesstype.zu; Matrix64.item.type = chesstype.zu; Matrix66.item.
23、type = chesstype.zu; Matrix68.item.type = chesstype.zu; Matrix71.item.type = chesstype.pao; Matrix77.item.type = chesstype.pao; Matrix90.item.type = chesstype.che; Matrix91.item.type = chesstype.ma; Matrix92.item.type = chesstype.xiang; Matrix93.item.type = chesstype.shi; Matrix94.item.type = chesst
24、ype.jiang; Matrix95.item.type = chesstype.shi; Matrix96.item.type = chesstype.xiang; Matrix97.item.type = chesstype.ma; Matrix98.item.type = chesstype.che; private bool movechess(int X,int Y) int i, j, k, n=0; switch(MatrixchozenXchozenY.item.type) case chesstype.che: if(chozenX=X) i = chozenY <
25、Y ? chozenY : Y; j = chozenY > Y ? chozenY : Y; for(k=i+1;k<j;k+) if(MatrixXk.item.side!= player.blank) return false; if (chozenY = Y) i = chozenX < X ? chozenX : X; j = chozenX > X ? chozenX : X; for (k = i + 1; k < j; k+) if (MatrixkY.item.side != player.blank) return false; setmove
26、(X, Y); return true; case chesstype.jiang: if(MatrixXY.item.type= chesstype.jiang&&chozenY=Y) i = chozenX < X ? chozenX : X; j = chozenX > X ? chozenX : X; for (k = i + 1; k < j; k+) if (MatrixkY.item.side != player.blank) return false; setmove(X, Y); return true; if (MatrixchozenXc
27、hozenY.item.side= player.blue) if(Y<3|Y>5|X>2) return false; else if(Y<3|Y>5|X<7) return false; if(chozenX-X)*(chozenX-X)+(chozenY-Y)*(chozenY-Y)!=1) return false; setmove(X, Y); return true; case chesstype.ma: if (Math.Abs(chozenX - X) = 1 && Math.Abs(chozenY - Y) = 2) if
28、(MatrixchozenXchozenY + (Y - chozenY) / Math.Abs(Y - chozenY).item.side!= player.blank) return false; else if (Math.Abs(chozenX - X) = 2 && Math.Abs(chozenY - Y) = 1) if (MatrixchozenX + (X - chozenX) / Math.Abs(X - chozenX)chozenY.item.side != player.blank) return false; else return false;
29、setmove(X, Y); return true; case chesstype.pao: n = 0; if(chozenX=X) i = chozenY < Y ? chozenY : Y; j = chozenY > Y ? chozenY : Y; n = 0; for(k=i+1;k<j;k+) if(MatrixXk.item.side!= player.blank) n+; if(n>1) return false; else if (chozenY = Y) i = chozenX < X ? chozenX : X; j = chozenX
30、> X ? chozenX : X; n = 0; for (k = i + 1; k < j; k+) if (MatrixkY.item.side != player.blank) n+; if (n > 1) return false; else return false; if(n=0&&MatrixXY.item.side!= player.blank) return false; if(n=1&&MatrixXY.item.side= player.blank) return false; setmove(X, Y); return true; case chesstype.shi: if (MatrixchozenXchozenY.item.side= player.
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 質量管理體系在注塑工業(yè)的商業(yè)價值
- 跨境電商平臺在旅游商品銷售中的角色
- 零售行業(yè)中的財務成本控制方案
- 浙江鴨2025版高中生物考前特訓選擇題快練考點5遺傳的分子基礎含解析
- 高中語文情感美文第156張票根
- 貴州2025年02月貴州出入境邊防檢查總站所屬事業(yè)單位公開招考1名工作人員筆試歷年典型考題(歷年真題考點)解題思路附帶答案詳解
- 高中語文情感美文最美麗的你在路上
- 小學數(shù)學教研學習培養(yǎng)學生數(shù)學的創(chuàng)新意識五六年級上
- 跨境電商平臺物流優(yōu)化策略
- 財商教育與財務知識庫的建設
- 2025年中央一號文件高頻重點考試題庫150題(含答案解析)
- 接觸隔離標準操作流程
- 港股基礎知識
- 2025年溫州市甌海旅游投資集團有限公司下屬子公司招聘筆試參考題庫附帶答案詳解
- 2025年天津三源電力集團有限公司招聘筆試參考題庫含答案解析
- 2025年上半年浙江嘉興桐鄉(xiāng)市水務集團限公司招聘10人易考易錯模擬試題(共500題)試卷后附參考答案
- 2025年腹腔穿刺術課件 (1)2
- (八省聯(lián)考)2025年高考綜合改革適應性演練 物理試卷合集(含答案逐題解析)
- 2024年干式電力電容器項目可行性研究報告
- 河南12系列建筑設計圖集一(12YJ1)
- 2025年度智能倉儲管理系統(tǒng)軟件開發(fā)合同6篇
評論
0/150
提交評論