版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
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("藍(lán)方勝利!點擊任意處重新開局"); clickswitch = false;
8、 if (currentside = player.red) currentside = player.blue; label1.Text = "藍(lán)方" 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.藍(lán)車; Matrix01.container.Image = global:象棋.Properties.Resources.藍(lán)馬; Matrix02.container.Image = glob
11、al:象棋.Properties.Resources.藍(lán)象; Matrix03.container.Image = global:象棋.Properties.Resources.藍(lán)士; Matrix04.container.Image = global:象棋.Properties.Resources.藍(lán)將; Matrix05.container.Image = global:象棋.Properties.Resources.藍(lán)士; Matrix06.container.Image = global:象棋.Properties.Resources.藍(lán)象; Matrix07.container.Im
12、age = global:象棋.Properties.Resources.藍(lán)馬; Matrix08.container.Image = global:象棋.Properties.Resources.藍(lán)車; Matrix21.container.Image = global:象棋.Properties.Resources.藍(lán)炮; Matrix27.container.Image = global:象棋.Properties.Resources.藍(lán)炮; Matrix30.container.Image = global:象棋.Properties.Resources.藍(lán)卒; Matrix32.co
13、ntainer.Image = global:象棋.Properties.Resources.藍(lán)卒; Matrix34.container.Image = global:象棋.Properties.Resources.藍(lán)卒; Matrix36.container.Image = global:象棋.Properties.Resources.藍(lán)卒; Matrix38.container.Image = global:象棋.Properties.Resources.藍(lán)卒; 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)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024新能源研發(fā)團(tuán)隊人員股權(quán)激勵合同
- 2024年甲乙雙方關(guān)于城市燃?xì)夤艿烙盟芰瞎懿墓?yīng)合同
- 2024青島購房合同范文
- 2024年知識產(chǎn)權(quán)許可合同:授權(quán)乙方使用甲方專利技術(shù)生產(chǎn)產(chǎn)品
- 《真核表達(dá)系統(tǒng)》課件
- 2智能穿戴設(shè)備研發(fā)生產(chǎn)與分包合同2024
- 中國醫(yī)科大學(xué)《綠色建筑概論》2023-2024學(xué)年第一學(xué)期期末試卷
- 鄭州工業(yè)應(yīng)用技術(shù)學(xué)院《經(jīng)濟(jì)學(xué)論文寫作》2023-2024學(xué)年第一學(xué)期期末試卷
- 專業(yè)商標(biāo)權(quán)訴訟服務(wù)協(xié)議2024版A版
- 2025年度離婚協(xié)議書范本:養(yǎng)老保障及醫(yī)療費用分擔(dān)協(xié)議3篇
- 加油站涉恐風(fēng)險評估報告
- 醫(yī)療設(shè)備、器械項目實施方案、服務(wù)實施方案
- 2 汽車維修檔案管理制度范文精簡處理
- 工貿(mào)企業(yè)重大事故隱患判定標(biāo)準(zhǔn)培訓(xùn)PPT
- 2023年外交學(xué)院招考聘用筆試題庫含答案解析
- 農(nóng)學(xué)技能高考【種植類】復(fù)習(xí)題庫大全-2、《植物生產(chǎn)與環(huán)境》-上(單選多選題)
- 員工信息安全意識培訓(xùn)v
- GST200主機(jī)說明書內(nèi)容
- 審計工作底稿(模板)
- GB/T 6422-2009用能設(shè)備能量測試導(dǎo)則
- GB/T 36490-2018風(fēng)力發(fā)電機(jī)組防雷裝置檢測技術(shù)規(guī)范
評論
0/150
提交評論