软讯网络 > 编程语言 > .NET > C#.NET > 我开发的四国军旗(两人对下版),可以与我交流?
【标 题】:我开发的四国军旗(两人对下版),可以与我交流?
【关键字】:
【来 源】:http://blog.csdn.net/xiamin/archive/2007/01/18/1487081.aspx
我开发的四国军旗(两人对下版),可以与我交流?
四国军旗3.0版
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace 四国军旗

...{

/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form

...{

/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.PictureBox qi_pan;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
//在类class Form1中声明私有的数据成员变量
private PictureBox[] Qizi_Pic;
private int Pic_Width;
private int [ ]Q;
private int [ , ]Map;
bool _isDragging = false;
bool Layout_Flag=true;//布阵标志
bool first=true;//布阵时第一次单击标志
int mouse_x, mouse_y;
int old_x,old_y; //棋盘坐标
int old_Left,old_Top;
int tempx,tempy;//布阵时第一次单击坐标
bool IsMyTurn;

enum PlayerColor...{Red,Black,Green,Glue};
PlayerColor player;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.Button button3;//棋子原始位置(像素)
int r;//兵站间隔距离
public Form1()

...{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}


/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )

...{
if( disposing )

...{
if (components != null)

...{
components.Dispose();
}
}
base.Dispose( disposing );
}


Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()

...{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.qi_pan = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// qi_pan
//
this.qi_pan.Image = ((System.Drawing.Image)(resources.GetObject("qi_pan.Image")));
this.qi_pan.Location = new System.Drawing.Point(32, 0);
this.qi_pan.Name = "qi_pan";
this.qi_pan.Size = new System.Drawing.Size(447, 446);
this.qi_pan.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.qi_pan.TabIndex = 1;
this.qi_pan.TabStop = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(488, 48);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(42, 17);
this.label1.TabIndex = 2;
this.label1.Text = "label1";
//
// label2
//
this.label2.Location = new System.Drawing.Point(488, 88);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 32);
this.label2.TabIndex = 3;
this.label2.Text = "label2";
//
// button1
//
this.button1.Location = new System.Drawing.Point(344, 320);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 24);
this.button1.TabIndex = 4;
this.button1.Text = "保存布阵";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(344, 360);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 24);
this.button2.TabIndex = 5;
this.button2.Text = "读取布阵";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(488, 136);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 184);
this.listBox1.TabIndex = 6;
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 464);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(640, 22);
this.statusBar1.TabIndex = 7;
this.statusBar1.Text = "欢迎使用快乐军旗1.0";
//
// button3
//
this.button3.Location = new System.Drawing.Point(344, 408);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(64, 24);
this.button3.TabIndex = 8;
this.button3.Text = "开始对战";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(640, 486);
this.Controls.Add(this.button3);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.qi_pan);
this.Name = "Form1";
this.Text = "军旗2.1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion


/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()

...{
Application.Run(new Form1());
}

//添加处理棋子起始位置方法
private void begin_pos(int m)

...{
String filename="", path;
path = System.Windows.Forms.Application.StartupPath;// bin路径
Qizi_Pic=new PictureBox[25*m];
int i;
int n=1;
for( i = 0;i<25*m;i++)//添加25*m个棋子

...{
Qizi_Pic[i] = new PictureBox();
this.Controls.Add(Qizi_Pic[i]);
Qizi_Pic[i].Width = 22;
Qizi_Pic[i].Height = 22;
Qizi_Pic[i].Name = "R" +i.ToString();
Qizi_Pic[i].Tag = i.ToString();
Qizi_Pic[i].Parent = qi_pan;
if(i<25)

...{
filename = path + "\..\..\bmp\" + Q[i].ToString() + ".bmp";}
if(i<50&&i>=25)

...{
filename = path + "\..\..\bmp\G" + Q[i%25].ToString() + ".bmp";
//暗棋filename = path + "\..\..\bmp\G.bmp";
}
Qizi_Pic[i].Image = Image.FromFile(filename);
Qizi_Pic[i].Click+=new System.EventHandler(bt_Click);
Qizi_Pic[i].MouseDown+=new System.Windows.Forms.MouseEventHandler(bt_MouseDown);
Qizi_Pic[i].MouseMove+=new System.Windows.Forms.MouseEventHandler(bt_MouseMove);
Qizi_Pic[i].MouseUp+=new System.Windows.Forms.MouseEventHandler(bt_MouseUp);
if(i%5==0)n++;
Qizi_Pic[i].Top = 250+n*24;Qizi_Pic[i].Left = 10 + 23 *(i%5);
Qizi_Pic[i].Visible=false;

}
}
private void bt_Click(object sender, System.EventArgs e) //这里处理单击事件过程

...{
int x1,y1;
PictureBox picBox1=(PictureBox)sender;
int i=Convert.ToInt16(picBox1.Tag);
//转换成棋盘坐标(x1,y1)
x1=(picBox1.Left -10+picBox1.Width/2)/r+1;
y1=(picBox1.Top -10+picBox1.Width/2)/r+1;
if(Layout_Flag==true) //是否布局

...{

if(first==true)...{tempx=x1;tempy=y1;first=false;return; }

else...{old_x=tempx;old_y=tempy;first=true;}
if(Layout_Juge(old_x,old_y,x1,y1))//是否可以改变布局
if(Map[x1,y1]==101)//没有棋子

...{
MoveChess(Map[old_x,old_y],x1,y1);
Map[old_x,old_y]=101;
}
else //对调棋子

...{ MoveChess(Map[old_x,old_y],x1,y1); MoveChess(i,old_x,old_y);}
else
//statusBar1.Text="不能改变原有布局";
MessageBox.Show("第一排不允许放置炸弹,放置地雷在后两排,军旗只能在大本营",
"违反军旗布局规则");
}
}
private void bt_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)

...{
PictureBox picBox1=(PictureBox)sender;//将被击的赋给定义的picBox1变量
int i=Convert.ToInt16(picBox1.Tag);
if(Q[i%25]==30||Q[i%25]==29)return; //地雷不能动
if(IsBigHome(old_x,old_y))return; //大本营中棋子不能动
if (_isDragging)

...{
picBox1.Left = picBox1.Left - mouse_x + e.X;
picBox1.Top = picBox1.Top - mouse_y + e.Y;
}
}
private bool IsBigHome(int old_x,int old_y) //判断是否大本营

...{
if(old_x==8&& old_y==17)return true;
if(old_x==8&& old_y==10)return true;
if(old_x==8&& old_y==1)return true;
if(old_x==10&&old_y==17)return true;
if(old_y==8&& old_x==17)return true;
if(old_y==8&& old_x==10)return true;
if(old_y==8&& old_x==1)return true;
if(old_y==10&&old_x==17)return true;
return false;
}
private void bt_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)

...{
_isDragging = false;
int x,y;
string path = System.Windows.Forms.Application.StartupPath;// bin路径
path += "\..\..\wav\";
PictureBox picBox1=(PictureBox)sender;
int idx=Convert.ToInt16(picBox1.Tag);
//转换成棋盘坐标(x1,y1)
x=(picBox1.Left -10+picBox1.Width/2)/r+1;
y=(picBox1.Top -10+picBox1.Width/2)/r+1;
if(Layout_Flag==true) //是否布局

