扑克游戏林林总总,同一种游戏各地玩法亦不尽相同。编程爱好者多喜欢编写一些本地玩法的扑克游戏。那么,编写自己的扑克游戏该从何处入手呢?
扑克游戏编程关键有两点:一是扑克牌面的绘制;二是扑克游戏规则的算法实现。初学扑克游戏编程的爱好者可从一些简单的游戏、借用一些现有资源开始。本文拟借用windows自带的cards.dll和简单的21点游戏为例,介绍扑克游戏编程的初步方法。
一、 扑克牌面绘制
cards.dll支持windows自带的游戏,如solitaire(纸牌游戏)。如果我们知道如何使用cards.dll中的api函数,那么,我们就能像windows自带的游戏一样绘制扑克牌面。我们需要使用其中三个基本函数:cdtinit, cdtdrawext,和 cdtterm。并且需要两个变量:width和height用于初始化函数cdtinit进行初始化。下面给出这些接口函数的声明及参数说明。
private width as integer = 0
private height as integer = 0
declare function cdtinit lib "cards.dll" (byref width as integer, _
byref height as integer) as boolean
参数说明:width,height返回牌默认宽和高,单位为pixels。
declare function cdtdrawext lib "cards.dll" (byval hdc as intptr, _
byval x as integer, byval y as integer, byval dx as integer, _
byval dy as integer, byval card as integer, _
byval mode as integer, byval color as long) as boolean
参数说明:hdc(handle to a device context)句柄;
x,y指定牌左上角坐标位;
dx,dy指定牌宽和高;
card需要绘制的牌,0-51[a(草花、方块、红桃、黑桃),2,…,k];53-65牌背面;
mode 指定绘制方式,牌面向上为0,牌面向下为1;
color 指定背景色。
declare sub cdtterm lib "cards.dll" ()
无参数。
我们需要在游戏开始时调用cdtinit对cards.dll进行初始化,这样我们才能使用cards.dll中的cdtdrawex等函数;每绘制一张牌,我们都要调一次cdtdrawext函数;当我们结束游戏时,调用一次cdtterm以结束cards.dll的使用。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器