C#编程调用Cards.dll实现图形化发牌功能示例
作者:songkexin 发布时间:2022-10-24 12:02:54
标签:C#,图形
本文实例讲述了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 x,int y,int dx,int dy,int card,int type,long color);
//[DllImport("cards.dll")]
//public static extern bool cdtAnimate(IntPtr hdc,int cardback,int x,int y,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(), left_x, top_y, CardId, 0,9);
}
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
cdtTerm();
}
private void btn_PaintBack_Click(object sender, EventArgs e)
{
int i, left_x, top_y, 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(), left_x, top_y, 54 + BackId, 1, 9);
}
}
private void btn_Random1_Click(object sender, EventArgs e) //第一种方法实现随机交换牌
{
int ii, k, left_x, top_y, 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(), left_x, top_y, CardId, 0, 9);
}
}
private void btn_Random2_Click(object sender, EventArgs e) //第一种方法实现随机交换牌
{
int ii, k, left_x, top_y, 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(), left_x, top_y, CardId, 0, 9);
}
}
}
}
界面设计的话截图比贴Designer.cs省事多了:
希望本文所述对大家C#程序设计有所帮助。


猜你喜欢
- 本文实例为大家分享了Android实现密码明密文切换的具体代码,供大家参考,具体内容如下小眼睛在密码栏右边!奉上我使用的素材:添加图片到re
- 注解实现自动装配@Autowire注解@Autowire注解,自动装配通过类型,名字如果Autowire不能唯一自动装配上属性,则需要通过@
- BufferedInputStream 介绍BufferedInputStream 是缓冲输入流。它继承于FilterInputStream
- 一个很常用的功能,一个ViewPager会自动滚动,并且有一排小圆点黑和白来指示当前的滚动进度首先写一个ViewPager的适配器,这里这个
- 环境说明:Android Studio 2.0V7包版本:com.android.support:appcompat-v7:23.4.0co
- C#处理猜拳问题的简单实例(非窗体)//猜拳,5局3胜,要求使用公用变量。namespace 结构体复习_公用变量{class Progra
- 本文实例为大家分享了Java操作MongoDB模糊查询和分页查询,供大家参考,具体内容如下模糊查询条件:1、完全匹配Pattern patt
- 场景既然要搞懂Redis分布式锁,那肯定要有一个需要它的场景。高并发售票问题就是一个经典案例。搭建环境准备redis服务,设置redis的键
- 一、内部类介绍1.定义:一个类内部又嵌套了一个类,被嵌套的类就是内部类(inner class),嵌套其他类的称为外部类(outer cla
- 一、之前旧的写法class Singleton{ private Singleton() {} &nb
- ⛳️ 基本类型做形式参数(零散参数的数据接收)1、基本数据类型要求前台页面的表单输入框的name属性值与对应控制器方法中的形式参数名称与类型
- 前言记得去年做一个聊天项目需要实现类似QQ的下拉刷新并且有侧滑删除的功能,在网上找了很久都没有QQ的完美,多多少少存在各种的问题,最后把下拉
- 首先定义一个加在方法上的注解import java.lang.annotation.*;/** * 开启自动参数填充 */@Retentio
- 介绍线段树(又名区间树)也是一种二叉树,每个节点的值等于左右孩子节点值的和,线段树示例图如下以求和为例,根节点表示区间0-5的和,左孩子表示
- 首先描述一下问题,spring boot 使用的是内嵌的tomcat, 所以不清楚文件上传到哪里去了, 而且spring boot 把静态的
- 在日常工作中,经常需要不同格式的图片,有时还需要进行图片格式的相互转换,本文以一个简单的小例子,简述图片格式转换的常见方法,仅供学习分享使用
- 问题现象今天在做一个需求:将存入数据库中的数据读到后解析成list遍历分析数据格式:"[1677660600000, 167766
- 我只给出比较有效的,方便的打印方法,有些WEB打印是调用ActiveX控件的,这样就需要用户去修改自己IE浏览器的Interne
- 上帝之火本系列讲述的是开源实时监控告警解决方案Prometheus,这个单词很牛逼。每次我都能联想到带来上帝之火的希腊之神,普罗米修斯。而这
- Java基础 Servlet * 详解 1 概念:Servlet * ,用来监听web容器的一些对象状态的变化,主要是Servle