资源简介
C#版24点扑克游戏源代码 其中关联相关类 (排列组合类,计算器类,24点计算类)
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace AppMain
{
public partial class MainForm : Form
{
#region 声明扑克牌API
// cards.dll文件位于System32目录下
[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);
private IntPtr m_HDC = new IntPtr();
#endregion
#region 定义变量
///
/// 四个数
///
private int[] m_FourNumber = new int[4];
///
/// 四种花色
///
private int[] m_CardsColor = new int[4];
///
/// 计算结果
///
private string m_Result = string.Empty;
#endregion
#region 自定义方法
///
/// 初始化
///
private void Init()
{
//清除结果
this.txt_Result.Text = string.Empty;
//随机生成四个数,直至有解
Random rand = new Random();
m_Result = string.Empty;
while (m_Result == string.Empty)
{
for (int i = 0; i < m_FourNumber.Length; i++)
{
m_FourNumber[i] = rand.Next(10) + 1;
}
m_Result = Arithmetic.TwentyFourPoint.GetResultString(m_FourNumber);
}
//随机生成扑克牌的花色
for (int i = 0; i < m_FourNumber.Length; i++)
{
m_CardsColor[i] = rand.Next(4);
}
//重绘以正确显示扑克牌
this.Refresh();
}
///
/// 绘制四张扑克牌
///
private void DrawCards()
{
for (int i = 0; i < this.m_FourNumber.Length; i++)
{
if (m_FourNumber[i] > 0)
{
cdtDraw(m_HDC 25 + i * 90 70 m_FourNumber[i] * 4 - 4 + m_CardsColor[i] 0 1);
}
}
}
#endregion
#region 事件处理
public MainForm()
{
InitializeComponent();
int width height;
width = 0; height = 0;
cdtInit(ref width ref height); // 初始化扑克牌
}
private void MainForm_Load(object sender EventArgs e)
{
this.Icon = Properties.Resources.App;
Init();
}
private void TwentyFourPointForm_FormClosing(object sender FormClosingEventArgs e)
{
cdtTerm();
}
// 重写窗体的OnPaint方法
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
m_HDC = g.GetHdc();
g.ReleaseHdc(m_HDC);
DrawCards();
}
private void btn_Build_Click(object sender EventArgs e)
{
Init();
}
private void btn_Setup_Click(object sender EventArgs e)
{
SetupForm form = new SetupForm();
form.FourNumber = m_FourNumber;
if (form.ShowDialog() == DialogResult.OK)
{
m_FourNumber = form.FourNumber;
m_Result = Arithmetic.TwentyFourPoint.GetResultString(m_FourNumber);
this.txt_Result.Text = m_Result;
this.Refresh();
if (m_Result == str
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5551 2010-01-21 10:55 24点\TwentyFourPoint\AppMain\AppMain.csproj
文件 512 2010-01-21 10:55 24点\TwentyFourPoint\AppMain\AppMain.csproj.user
文件 9728 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\bin\Debug\Arithmetic.dll
文件 24064 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\bin\Debug\Arithmetic.pdb
文件 210944 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\bin\Debug\TwentyFourPoint.exe
文件 30208 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\bin\Debug\TwentyFourPoint.pdb
文件 14328 2010-01-21 11:25 24点\TwentyFourPoint\AppMain\bin\Debug\TwentyFourPoint.vshost.exe
文件 490 2007-07-21 01:33 24点\TwentyFourPoint\AppMain\bin\Debug\TwentyFourPoint.vshost.exe.manifest
文件 3567 2010-01-21 08:23 24点\TwentyFourPoint\AppMain\ex
文件 3294 2010-01-21 10:58 24点\TwentyFourPoint\AppMain\MainForm.cs
文件 3630 2010-01-21 10:58 24点\TwentyFourPoint\AppMain\MainForm.Designer.cs
文件 5814 2010-01-21 10:58 24点\TwentyFourPoint\AppMain\MainForm.resx
文件 856 2010-01-21 11:25 24点\TwentyFourPoint\AppMain\obj\Debug\AppMain.csproj.FileListAbsolute.txt
文件 949 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\obj\Debug\AppMain.csproj.GenerateResource.Cache
文件 180 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\obj\Debug\AppMain.MainForm.resources
文件 98118 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\obj\Debug\AppMain.Properties.Resources.resources
文件 180 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\obj\Debug\AppMain.SetupForm.resources
文件 3185 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\obj\Debug\ResolveAssemblyReference.cache
文件 4608 2010-01-21 10:55 24点\TwentyFourPoint\AppMain\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
文件 210944 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\obj\Debug\TwentyFourPoint.exe
文件 30208 2010-01-21 11:08 24点\TwentyFourPoint\AppMain\obj\Debug\TwentyFourPoint.pdb
文件 477 2010-01-21 08:32 24点\TwentyFourPoint\AppMain\Program.cs
文件 1458 2010-01-21 09:15 24点\TwentyFourPoint\AppMain\Properties\AssemblyInfo.cs
文件 3082 2010-01-21 10:55 24点\TwentyFourPoint\AppMain\Properties\Resources.Designer.cs
文件 6191 2010-01-21 10:55 24点\TwentyFourPoint\AppMain\Properties\Resources.resx
文件 1088 2010-01-21 08:31 24点\TwentyFourPoint\AppMain\Properties\Settings.Designer.cs
文件 249 2010-01-21 08:29 24点\TwentyFourPoint\AppMain\Properties\Settings.settings
文件 97566 2010-01-21 10:55 24点\TwentyFourPoint\AppMain\Resources\App.ico
文件 1188 2010-01-21 10:12 24点\TwentyFourPoint\AppMain\SetupForm.cs
文件 9875 2010-01-21 09:35 24点\TwentyFourPoint\AppMain\SetupForm.Designer.cs
............此处省略36个文件信息
评论
共有 条评论