首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .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 窗体设计器生成的代码

  
/// <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//是否布局