版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
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壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030年中國智能公交行業(yè)商業(yè)模式創(chuàng)新戰(zhàn)略制定與實施研究報告
- 新形勢下餐飲食材配送行業(yè)可持續(xù)發(fā)展戰(zhàn)略制定與實施研究報告
- 2025-2030年中國有色金屬礦產(chǎn)采選行業(yè)開拓第二增長曲線戰(zhàn)略制定與實施研究報告
- 高層領導戰(zhàn)略管理培訓課件
- 四川省綿陽市2024屆高三下學期第三次診斷性考試(三模)英語試題
- 中國錄音復制行業(yè)競爭格局分析及投資戰(zhàn)略咨詢報告
- 一年級數(shù)學(上)計算題專項練習匯編
- 實驗小學學年第一學期班主任參考計劃二年級3班
- 疫情防控視角下的社區(qū)多元主體協(xié)同治理研究
- 關愛殘疾兒童呵護折翼天使
- 2024年危險化學品生產(chǎn)經(jīng)營單位其他從業(yè)人員考試題庫附答案
- 信號分析與處理課程設計課程教學大綱基本要求及規(guī)范(集中實踐環(huán)節(jié))
- 2024年中考物理真題及分類匯編-考點25:磁現(xiàn)象-電生磁
- 2024年更新版:精準農(nóng)業(yè)無人機植保服務合同
- 2024年度中國醫(yī)院人力資源現(xiàn)狀調(diào)研報告
- 【MOOC】有機化學-華中農(nóng)業(yè)大學 中國大學慕課MOOC答案
- 二水石膏轉(zhuǎn)化為半水石膏的研究
- 中醫(yī)特色治療進修匯報
- 闌尾炎內(nèi)鏡治療
- 《2025年日歷》電子版模板年歷月歷工作學習計劃橫版整年帶農(nóng)歷
- 2023-2024學年廣東省廣州市白云區(qū)九年級(上)期末語文試卷
評論
0/150
提交評論