中国象棋游戏源代码资料_第1页
中国象棋游戏源代码资料_第2页
中国象棋游戏源代码资料_第3页
中国象棋游戏源代码资料_第4页
中国象棋游戏源代码资料_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论