我开发扑克牌游戏---界面

界面
using  System;
using  System.Collections.Generic;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Text;
using  System.Windows.Forms;
using  System.Collections;             // ArrayList类 
using  System.Runtime.InteropServices; // 有限制鼠标移动区域的API函数,ClipCursor(nil)则取消限制
namespace  mycards
{
    
public partial class MainForm : Form
    
{

        
private PictureBox []pic;
        
private string path;
        
public MainForm()
        
{
            InitializeComponent();
        }


        
private void Btn_start_Click(object sender, EventArgs e)//开始按钮
        {
            Btn_SendCard.Enabled 
= true;
            Btn_start.Enabled 
= false;
            
//panel1.Invalidate(); 
            string filename;
            
for(int i=1;i<=52;i++)
            
{
                filename 
= path + "/../../bmp/" + i.ToString() + ".bmp";
                filename 
= path + "/../../bmp/" + "0.bmp";
                pic[i].Left 
= 80 + 8 *i; 
                pic[i].Top 
= 180 ;
                pic[i].Width 
= 71; pic[i].Height = 96;
                pic[i].Image 
= Image.FromFile(filename);
                pic[i].Visible 
= true;
                pic[i].BringToFront();               
            }

        }

        
private void bt_Click(object sender, System.EventArgs e) //这里处理单击事件过程
        {
            PictureBox picBox1 
= (PictureBox)sender;
            
int i = Convert.ToInt16(picBox1.Tag);
            picBox1.Top 
-= 10;

        }

        
private void Dbt_Click(object sender, System.EventArgs e) //这里处理双击事件过程
        {
            PictureBox picBox1 
= (PictureBox)sender;
            
int i = Convert.ToInt16(picBox1.Tag);
            picBox1.Top 
= 240;
            picBox1.Left 
= 300;
            picBox1.BringToFront(); 
        }


        
private void Form1_Load(object sender, EventArgs e)
        
{
            pic 
= new PictureBox[53];
            path 
= System.Windows.Forms.Application.StartupPath;// bin路径
            for (int i = 1; i <= 52; i++)
            
{                
                pic[i] 
= new PictureBox();
                pic[i].Left 
= 80 + 8 * i;  
                pic[i].Top 
= 180;
                pic[i].Width 
= 71; pic[i].Height = 96;
                
this.Controls.Add(pic[i]);
                pic[i].Visible 
=false;
                
//pic[i].Click += new System.EventHandler(bt_Click);
                
//pic[i].MouseDown += new System.Windows.Forms.MouseEventHandler(bt_MouseDown);
                
//pic[i].MouseMove += new System.Windows.Forms.MouseEventHandler(bt_MouseMove);
                
//pic[i].MouseUp += new System.Windows.Forms.MouseEventHandler(bt_MouseUp); 

            }


        }

        
private void button3_Click(object sender, EventArgs e)//产生20随机数组
        {
            
string ps = "";
            ArrayList list 
= new ArrayList();
            
int k = 0;
            
do
            
{
                Random random 
= new System.Random();
                k 
= random.Next(020);
                
if (!list.Contains(k))
                
{
                    list.Add(k);
                    
                }

            }

            
while (list.Count < 20);
            
int[] p = new int[20];      
            list.CopyTo(p);
            
for (int i = 0; i < 20; i++)
            
{
                ps 
= ps + "|" + p[i].ToString();
            }

            
this.Text = ps;
        }

        
//90度旋转纸牌
        private void Rotate_card(PictureBox picBox)
        
{
            
int w = picBox.Width;
            
int h = picBox.Height;
            picBox.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
            picBox.Height 
= w;
            picBox.Width 
= h;
            picBox.Refresh();
        }


        
private void Btn_SendCard_Click(object sender, EventArgs e)//随机给4人发牌
        {
            Btn_SendCard.Enabled 
= false;
            Btn_start.Enabled 
= true;
            
            一副牌 一副牌实例 
= new 一副牌();
            
int[] key = new int[13];// 一个人牌的序号在1--52中
            for (int i = 1; i <= 4; i++)
            
{
                Console.Write(
"{0}:", i);
                
for (int j = 1; j <= 13; j++)
                
{
                    card card实例 
= 一副牌实例.发牌();
                    
if (card实例 != null)
                    
{
                        key[j 
- 1= card实例.pic_order();
                    }

                }

                Array.Sort(key);
                
switch (i)
                
{
                    
case 1//牌手自己
                        for (int j = 1; j <= 13; j++)
                        
{
                            
int k = key[j - 1];
                            
string filename = path + "/../../bmp/" + k.ToString() + ".bmp";
                            pic[k].Image 
= Image.FromFile(filename);
                            pic[k].Left 
= 150 + 20 * j;
                            pic[k].Top 
= 350;
                            pic[k].BringToFront();
                            pic[k].Click 
+= new System.EventHandler(bt_Click);
                            pic[k].DoubleClick 
+= new System.EventHandler(Dbt_Click);
                        }

                        
break;
                    
case 2//牌手的下家
                        for (int j = 1; j <= 13; j++)
                        
{
                            
int k = key[j - 1];
                            
if (checkBox1.Checked)
                            
{
                                
string filename = path + "/../../bmp/" + k.ToString() + ".bmp";
                                pic[k].Image 
= Image.FromFile(filename);
                            }
                          
                            Rotate_card(pic[k]);
                            pic[k].Top 
= 50 + 20 * j;
                            pic[k].Left 
= 50;
                            pic[k].BringToFront();
                        }

                        
break;
                    
case 3//牌手的对家
                        for (int j = 1; j <= 13; j++)
                        
{
                            
int k = key[j - 1];
                            
if (checkBox1.Checked)
                            
{
                                
string filename = path + "/../../bmp/" + k.ToString() + ".bmp";
                                pic[k].Image 
= Image.FromFile(filename);
                            }
 
                            Rotate_card(pic[k]);
                            Rotate_card(pic[k]);
                            pic[k].Left 
= 150 + 20 * j;
                            pic[k].Top 
= 50;
                            pic[k].BringToFront();
                        }

                        
break;
                    
case 4//牌手的上家
                        for (int j = 1; j <= 13; j++)
                        
{
                            
int k = key[j - 1];
                            
if (checkBox1.Checked)
                            
{
                                
string filename = path + "/../../bmp/" + k.ToString() + ".bmp";
                                pic[k].Image 
= Image.FromFile(filename);
                            }
 
                            Rotate_card(pic[k]);
                            Rotate_card(pic[k]);
                            Rotate_card(pic[k]);
                            pic[k].Top 
= 310 - 20 * j;
                            pic[k].Left 
= 500;
                            pic[k].BringToFront();
                        }

                        
break;
                }

            }

        }
 

    }

}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值