C#编程调用Cards.dll实现图形化发牌功能示例

C#编程调用Cards.dll实现图形化发牌功能示例,第1张

概述本文实例讲述了C#编程调用Cards.dll实现图形化发牌功能。分享给大家供大家参考,具体如下:

本文实例讲述了C#编程调用Cards.dll实现图形化发牌功能。分享给大家供大家参考,具体如下:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.windows.Forms;using System.Runtime.InteropServices;using System.windows.Forms.Design;namespace GetCards{  public partial class Form1 : Form   {     [Dllimport("cards.dll")]    public static extern bool cdtinit(ref int wIDth,ref int height);     [Dllimport("cards.dll")]    public static extern voID cdtTerm();     [Dllimport("cards.dll")]    public static extern bool cdtDraw(IntPtr hdc,int x,int y,int card,int mode,long color);    //mode=0表正面,1表反面,color我从0-0xFF000试了很多,好象没颜色改变    //[Dllimport("cards.dll")]    //public static extern bool cdtDrawExt(IntPtr hdc,int dx,int dy,int type,long color);    //[Dllimport("cards.dll")]    //public static extern bool cdtAnimate(IntPtr hdc,int cardback,int frame);    int[] bb = new int[100];    public Form1()     {       InitializeComponent();     }    private voID Form1_Load(object sender,EventArgs e)     {      int wIDth,height;       wIDth = 0; height = 0;       cdtinit(ref wIDth,ref height);     }    private voID btn_PaintCard_Click(object sender,EventArgs e)     {      int i,k,left_x,top_y,CardID;      for (k = 0; k <= 3; k++)       {        for (i = 1; i <= 13; i++)         {           left_x = 20 + (i - 1) * 15;        //牌的重叠后的宽度是15           top_y = 20 + k * 100;           //每行13张牌.高度是20           CardID = (i - 1) * 4 + k;         //原来52张牌是编了号的           cdtDraw(this.CreateGraphics().GetHdc(),CardID,9);         }       }     }    private voID Form1_FormClosed(object sender,FormClosedEventArgs e)     {       cdtTerm();     }    private voID btn_PaintBack_Click(object sender,BackID;      for (i = 0; i <= 11; i++)              //12张牌背面图       {         BackID = i;         top_y = 20 + (i & 3) * 100;           //小于等于3的不变,>3的截尾,相当于竖排         left_x = 20 + (i >> 2) * 80 + 180 + 80;     //左边牌占15*12+80=260,也就是和最右张牌20(隐含了牌大小=80)         cdtDraw(this.CreateGraphics().GetHdc(),54 + BackID,1,9);       }     }    private voID btn_Random1_Click(object sender,EventArgs e) //第一种方法实现随机交换牌     {      int ii,CardID;      int[] theArray = new int[52];       Random r = new Random();       ListBox1.Items.Clear();      for (int i = 0; i < 52; i++)       {         theArray[i] = i + 1;       }      for (int i = 0; i < 52; i++) //就是做52次随机交换两张牌       {        int a = r.Next(52); //生成0--->51的随机数        int b = r.Next(52);        int tmp = theArray[a];         theArray[a] = theArray[b];         theArray[b] = tmp;       }      for (int i = 0; i < 52; i++)       {         ListBox1.Items.Add(theArray[i]);         k = (int)(i / 13);         ii = i % 13 + 1;         left_x = 20 + (ii - 1) * 15;         top_y = 20 + k * 100;         CardID = theArray[i] - 1;         cdtDraw(this.CreateGraphics().GetHdc(),9);       }     }    private voID btn_Random2_Click(object sender,CardID;      int[] theArray = new int[52];      int i = 0;      while (i < theArray.Length)       {         theArray[i] = ++i;       }       Random r = new Random();       ListBox1.Items.Clear();      while (i > 1) //从51-->1依次随机向前交换获得最终值       {        int j = r.Next(i);        int t = theArray[--i];         theArray[i] = theArray[j];         theArray[j] = t;       }      for (i = 0; i < theArray.Length; ++i)       {         ListBox1.Items.Add(theArray[i].ToString());         k = (int)(i / 13);         ii = i % 13 + 1;         left_x = 20 + (ii - 1) * 15;         top_y = 20 + k * 100;         CardID = theArray[i] - 1;         cdtDraw(this.CreateGraphics().GetHdc(),9);       }     }   }}

界面设计的话截图比贴Designer.cs省事多了:

更多关于C#相关内容感兴趣的读者可查看本站专题:《C#图片 *** 作技巧汇总》、《C#常见控件用法教程》、《WinForm控件用法总结》、《C#数据结构与算法教程》、《C#面向对象程序设计入门教程》及《C#程序设计之线程使用技巧总结》

希望本文所述对大家C#程序设计有所帮助。

总结

以上是内存溢出为你收集整理的C#编程调用Cards.dll实现图形化发牌功能示例全部内容,希望文章能够帮你解决C#编程调用Cards.dll实现图形化发牌功能示例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1255669.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存