C#中如何調(diào)用Cards.dll實(shí)現(xiàn)圖形化發(fā)牌功能-創(chuàng)新互聯(lián)

小編給大家分享一下C#中如何調(diào)用Cards.dll實(shí)現(xiàn)圖形化發(fā)牌功能,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

創(chuàng)新互聯(lián)專注于清澗網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供清澗營(yíng)銷型網(wǎng)站建設(shè),清澗網(wǎng)站制作、清澗網(wǎng)頁(yè)設(shè)計(jì)、清澗網(wǎng)站官網(wǎng)定制、重慶小程序開(kāi)發(fā)服務(wù),打造清澗網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供清澗網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。

具體如下:

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試了很多,好象沒(méi)顏色改變
    //[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;         //原來(lái)52張牌是編了號(hào)的
           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的截尾,相當(dāng)于豎排
         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) //第一種方法實(shí)現(xiàn)隨機(jī)交換牌
     {
      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次隨機(jī)交換兩張牌
       {
        int a = r.Next(52); //生成0--->51的隨機(jī)數(shù)
        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) //第一種方法實(shí)現(xiàn)隨機(jī)交換牌
     {
      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依次隨機(jī)向前交換獲得最終值
       {
        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);
       }
     }
   }
}

界面設(shè)計(jì)的話截圖比貼Designer.cs省事多了:

C#中如何調(diào)用Cards.dll實(shí)現(xiàn)圖形化發(fā)牌功能

C#中如何調(diào)用Cards.dll實(shí)現(xiàn)圖形化發(fā)牌功能

以上是“C#中如何調(diào)用Cards.dll實(shí)現(xiàn)圖形化發(fā)牌功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站muchs.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

標(biāo)題名稱:C#中如何調(diào)用Cards.dll實(shí)現(xiàn)圖形化發(fā)牌功能-創(chuàng)新互聯(lián)
URL標(biāo)題:http://muchs.cn/article18/dchggp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、手機(jī)網(wǎng)站建設(shè)服務(wù)器托管、標(biāo)簽優(yōu)化自適應(yīng)網(wǎng)站、微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)