红心网络游戏:纸牌游戏设计制作(C语言)

纸牌游戏设计制作 (C语言)

我是编程爱好者。早期使用windows时就被扫雷游戏,钻石棋游戏,红心大战游戏迷住。相信大家也都玩过吧。在学习VB6编程时就编制过钻石棋和红心大战那样的纸牌游戏。都是标准Windows图形界面的。感兴趣的同好可参考我在同站上传的资源《纸牌游戏设计(VB6源码)》,其中有纸牌卡座制作和博眼子游戏。

今天再与大家共享C语言的纸牌游戏《博眼子》。此游戏是由牌九演变过来的纸牌游戏,它与《争上游》(俗称大怪路子或八十分)、《红心大战》(俗称攻猪),《二十一点》(黑杰克)等都曾风靡上海滩。今试编此游戏程序介绍一些界面设计方法和游戏设计各个功能的算法。代码中加了注释,也展示了算法的设计要点和算法检验以及程序调试方法与过程。

算法设计:52张牌面制作显示。洗牌,随机显示52张牌。牌序数 0-51 转换为 A234...JQK 。界面显示圆角牌背牌面。界面提示文字显示。程序主要介绍了一些测试调试方法。

程序提供了一个框架,VB , VC,  VS 或 JAVA  改写可作为参考。

MySpringC是一个简化的C语言编译器。主要用于科学计算、个人娱乐和个性化的设备控制等场合。当前运行在Android平台上,是Android平台的一款应用。使用MySpringC可以书写简单的C语言程序,编写完成后可以编译、运行并获得 结果。还可以做出安卓手机桌面app应用。SpringC支持的C与普通的C非常类似,程序从main开始,支持全局变量和局部变量,支持各种数据类型和常用的控制流。MySpringC它没有复杂、庞大的编程环境,只要你了解一点C或java,只需要一部手机,在家里、在地铁上任何方便的时候,就可以编写满足自己特定需求的小程序。 MySpringC不仅可以编写简单的C语言程序,而且它能读取手机中各种传感器的数值,控制各种多媒体设备,从而实现让普通用户用C语言控制手机,编写出意想不到的、适合自己使用的应用。

 

v.2.7是目前的完善版本。下面的游戏代码就是用它在安卓手机上编写的,可制作成安卓手机桌面app应用程序。此样例可复制黏贴到编译器直接使用,亦可用 VB6 ,C++ ,  java  改写。

 

以下是源码:
//****************************************
//*   纸牌游戏-博眼子  Version   1.1.0      *
//*   制作:张纯叔  ( micelu@126.com )   *
//****************************************
Canvas cs ;
string sBarDes[10];
int nBarId[10];
string sMenu[50];
int nMenu[50];
float src[4];  //ClearDraw (cls) clear screen
string s,ss,ss1,ss2,ss3;
int sx,sy,dx,dy,px,py;
int i,j,n,t,k;    //t = times
int cardp;    //card picture 54 p
int num;      //select card number
int pnum[54];    //洗牌后的牌序列
int cardnum,cardstyle;  //牌点牌花色
string cas1,cas2;           //牌点牌花色$
string cas3;         //牌背花色
double Rn;    //random number
string t$;     //提示文字
int tsize;      //textsize
int users1,users2,users3;  //东北西玩家分数
int bankers ;      //庄家分数 score
float bs,us1,us2,us3 ;   //计算分数 banker & users
int c1,c2 ;  
float gscore ;    //输入c1c2计算各家分数
int isdo;    //1 翻牌可计算分,0 不计

main(){
setDisplay(1);
  cs.SetBackground(205,205,205);
  cs.Active();

   sBarDes[0]="重新开始";
   nBarId[0]=100;
   sBarDes[1]="  洗  牌 ";
   nBarId[1]=101;
   sBarDes[2]="  发  牌 ";
   nBarId[2]=102;
   sBarDes[3]="  翻  牌";
   nBarId[3]=103;
   sBarDes[4]="退出程序";
   nBarId[4]=104;
   sBarDes[5]="V.";
   nBarId[5]=105;
   setToolBarHeight(6);
   setButtonTextSize(13);
   setToolBarBackgroundColor(255,192,192,192);
   setButtonColor(255,0,0,240);
   setButtonTextColor(255,255,255,0);
   setToolBar(100,myToolBarProc,sBarDes,nBarId,6);

   sMenu[0]="重新开始";
   nMenu[0]=200;
   sMenu[1]="洗牌" ;
   nMenu[1]=201;
   sMenu[2]="发牌";
   nMenu[2]=202;
   sMenu[3]="翻牌";
   nMenu[3]=203;
   sMenu[4]="测试 => 洗牌验牌";
   nMenu[4]=204;
   sMenu[5]="测试 => 查看计分";
   nMenu[5]=205;
   sMenu[6]="显示游戏主屏幕";
   nMenu[6]=206;
   sMenu[7]="退出";
   nMenu[7]=207;
   setMenu(200,myMenuProc,sMenu,nMenu,8);
  setTitle("纸牌游戏-博眼子   ");
//**********
      cas3="🐵";        //预设牌背图案,采用微信那样的表情符号图案猴脸
      bankers=500;    //预定分数
      users1=500;
      users2=500;
      users3=500;
  drawcover ();
 while (){}
  }//main ()

drawcover (){     // 画封面版本号
    cs.SetColor (255,0,120,0);
     cs.DrawRect (2,2,718,720);
     t$="🐒" ;      //表情符号图案猴子
     sx=420;   sy=230;    tsize=120;
     print_t ();
     t$="纸牌游戏" ;
     sx=130;   sy=160;   tsize=60;
     print_t ();
    t$="博眼子" ;
     sx=135;   sy=260;   tsize=80;
     print_t ();
     t$="欢迎加入纸牌游戏团" ;
     sx=135;   sy=400;   tsize=50;
     print_t ();
     ss="Copyright  v.1.1.0   micelu@126.com ";
     cs.SetTextSize (22);
     cs.SetColor (255,250,250,250);
     cs.DrawText (ss,20,700);      
     cs.Update ();
}//drawcover ()

drawcards (){  //预制54张牌,验牌测试
//设计制作显示52张牌,调试
    cs.SetColor (255,0,120,0);
    cs.DrawRect (2,2,718,720);
      cs.SetTextStyle (1);
     cs.SetTextSize (28);
   for (i=0;i<=51;i++){
        px=(i-i/13*13)*50+30;
        py=i/13*120+120;
    //**** draw cards 圆角 ****
      cs.SetColor (255,0,0,0);  //黑色框线
      cs.DrawRect (px+13,py-30,px+57,py+75);
      cs.DrawRect (px,py-20,px+68,py+63);
      cs.DrawCircle (px+10,py-20,9);
      cs.DrawCircle (px+10,py+65,9);
      cs.DrawCircle (px+59,py+65,9);
      cs.DrawCircle (px+59,py-20,9);
      cs.SetColor (255,250,250,250);  //牌面白色
      cs.DrawRect (px+13,py-28,px+55,py+73);
      cs.DrawRect (px+2,py-20,px+66,py+63);
      cs.DrawCircle (px+12,py-19,9);
      cs.DrawCircle (px+12,py+63,9);
      cs.DrawCircle (px+57,py+63,9);
      cs.DrawCircle (px+57,py-19,9);
    //牌号 0 => 51 转为4花色 A 1234...JQK ****
        cardnum=(i-i/13*13)+1;
        cardstyle=i/13;
        cas1=intToString(cardnum);
        if(cardnum==1) cas1="A";
        if(cardnum==11) cas1="J";
        if(cardnum==12) cas1="Q";
        if(cardnum==13) cas1="K";
   if (cardstyle==0) cas2="♠";    //黑桃图案表情符号
        if (cardstyle==1) cas2="❤️ ";   //红心图案
        if (cardstyle==2) cas2=" ♣";  //梅花图案
        if (cardstyle==3) cas2="  ";   //方块图案
       // print i," , ",cardnum," , ",cardstyle;   
       // print cas1+" "+ cas2;    //*** test ***
     if(cardstyle==0||cardstyle==2) {
            cs.SetColor (255,0,0,0);     }
     if(cardstyle==1||cardstyle==3) {
            cs.SetColor (255,250,0,0);      }
     n=0;
     if (cardnum==10) n=8;           
     cs.DrawText (cas1,px+12-n,py);
     cs.DrawText (cas2,px+5,py+30);      
        ss=intToString(i);
       // cs.DrawText (ss,px+15,py+63);      
          }
      cs.Update ();
      setDisplay(1);
}//drawcards ()

 

showcard (){  //验牌测试,洗牌显示
//设计过程:画牌验牌洗牌测试用
    cs.SetColor (255,0,120,0);  //backcolor
    cs.DrawRect (2,2,718,720);
     cs.Update ();
   cs.SetFillMode (1);//0不填色,1填色
      cs.SetTextStyle (1);
     cs.SetTextSize (28);
    for (k=0;k<=51;k++){
        i=pnum[k];
        px=(k-k/13*13)*50+35;
        py=k/13*120+120;
    //**** draw cards 圆角 ****
      cs.SetColor (255,0,0,0);  //黑色框线
      cs.DrawRect (px+13,py-30,px+57,py+75);
      cs.DrawRect (px,py-20,px+68,py+63);
      cs.DrawCircle (px+10,py-20,9);
      cs.DrawCircle (px+10,py+65,9);
      cs.DrawCircle (px+59,py+65,9);
      cs.DrawCircle (px+59,py-20,9);
      cs.SetColor (255,250,250,250);  //牌面白色
      cs.DrawRect (px+13,py-28,px+55,py+73);
      cs.DrawRect (px+2,py-20,px+66,py+63);
      cs.DrawCircle (px+12,py-19,9);
      cs.DrawCircle (px+12,py+63,9);
      cs.DrawCircle (px+57,py+63,9);
      cs.DrawCircle (px+57,py-19,9);
    //牌号 0 => 51 转为4花色 A 1234...JQK ****
        cardnum=(i-i/13*13)+1;
        cardstyle=i/13;
        cas1=intToString(cardnum);
        if(cardnum==1) cas1="A";
        if(cardnum==11) cas1="J";
        if(cardnum==12) cas1="Q";
        if(cardnum==13) cas1="K";
  if (cardstyle==0) cas2="♠";   //黑桃图案表情符号
  if (cardstyle==1) cas2=" ❤️";   //红心图案
        if (cardstyle==2) cas2="♣";   //梅花图案
        if (cardstyle==3) cas2="  ";   //方块图案
       // print i," , ",cardnum," , ",cardstyle;   
       // print cas1+" "+ cas2;   //test 牌点牌花色**
     if(cardstyle==0||cardstyle==2) {  //show cards
            cs.SetColor (255,0,0,0);     }
     if(cardstyle==1||cardstyle==3) {
            cs.SetColor (255,250,0,0);      }
     n=0;
     if (cardnum==10) n=8;           
     cs.DrawText (cas1,px+12-n,py);
     cs.DrawText (cas2,px+5,py+30);      
  // ss=intToString(i);  //test > print card's number
  // cs.DrawText (ss,px+10,py+60);      
         }
      cs.Update ();
 }//showcard ()

//纸牌序列:
//cardP num   0 to 12 黑桃 A234..JQK
//cardP num 13 to 25 红心 A234..JQK
//cardP num 26 to 38 梅花 A234..JQK
//cardP num 39 to 51 方块 A234..JQK
// VB6,VS2007 编程:设picturebox: 
// cardP(54)图片数组
// 图片高宽为单张纸牌图大小
// 预制扑克牌序列图片底图,程序启动时按序将
// 每单张图片BitBlt..SRCCOPY到图片数组,
// cardP (0-53)就是整付牌的图片,洗牌发牌都要用到。
// 本程序简化用 num 序号表示54张牌
//********************

shuffle_cards (){    //洗牌设计
     cs.SetColor (255,0,120,0);   //backcolor
     cs.DrawRect (2,2,718,720);
     cs.Update ();
      for (i=0;i<=51;i++){ pnum[i]=-1 ;   }  //init
//** 洗牌 **********************
     t$="游戏开始 >>>       发牌" ;
     sx=50;   sy=50;    tsize=30;
     print_t ();
  for (i=0;i<=51;i++){
      ResetPiece:
      Rn=random()*52;       //随机洗牌
             num=(int )(Rn);
             pnum[i]=num ;
         for (k=0;k<i; k++){       //已有则重新选列
         if (num==pnum[k]) goto ResetPiece ;        }
                    }
   for (k=0;k<=51;k++){  //显示牌背面图案
        px=(k-k/13*13)*50+30;
        py=k/13*120+120;
        cardback ();     //draw cards back picture
                }
      cs.Update ();     //刷新

  // showcard();  //用于洗牌查验测试,游戏时注释掉
 }//shuffle_cards ()

cardback (){   //draw cards back picture
//发牌时隐藏牌面显示牌背图案
    //**** draw cards 圆角 ****
      cs.SetColor (255,0,0,0);  //黑色框线
      cs.DrawRect (px+13,py-30,px+57,py+75);
      cs.DrawRect (px,py-20,px+68,py+63);
      cs.DrawCircle (px+10,py-20,9);
      cs.DrawCircle (px+10,py+65,9);
      cs.DrawCircle (px+59,py+65,9);
      cs.DrawCircle (px+59,py-20,9);
      cs.SetColor (255,20,140,240);  //牌背底色
      cs.DrawRect (px+13,py-28,px+55,py+73);
      cs.DrawRect (px+2,py-20,px+66,py+63);
      cs.DrawCircle (px+12,py-19,9);
      cs.DrawCircle (px+12,py+63,9);
      cs.DrawCircle (px+57,py+63,9);
      cs.DrawCircle (px+57,py-19,9);
      cs.SetTextSize(44);
     cs.DrawText (cas3,px+8,py+40);  //show 背花图案
    
      cs.Update ();
}//cardback ()

redeal (){    //发牌,重新发牌
      bankers=500;
      users1=500;
      users2=500;
      users3=500;
     cs.SetColor (255,0,120,0);
     cs.DrawRect (2,2,718,720);
     cs.Update ();
     t$="游戏开始 >>>       洗牌" ;
     sx=50;   sy=50;    tsize=30;
     print_t ();
     cs.Update ();
}//redeal ()

transcards (){  //num 转换 cardnum, cardstyle
//牌序号转为牌点和牌花色,画出牌张
    //**** draw cards 圆角 ****
      cs.SetColor (255,0,0,0);  //黑色框线
      cs.DrawRect (px+13,py-30,px+57,py+75);
      cs.DrawRect (px,py-20,px+68,py+63);
      cs.DrawCircle (px+10,py-20,9);
      cs.DrawCircle (px+10,py+65,9);
      cs.DrawCircle (px+59,py+65,9);
      cs.DrawCircle (px+59,py-20,9);
      cs.SetColor (255,250,250,250);  //牌面白色
      cs.DrawRect (px+13,py-28,px+55,py+73);
      cs.DrawRect (px+2,py-20,px+66,py+63);
      cs.DrawCircle (px+12,py-19,9);
      cs.DrawCircle (px+12,py+63,9);
      cs.DrawCircle (px+57,py+63,9);
      cs.DrawCircle (px+57,py-19,9);
     //******* 画出牌面
        cardnum=(num-num/13*13)+1;
        cardstyle=num/13;
        cas1=intToString(cardnum);
        if(cardnum==1) cas1="A";
        if(cardnum==11) cas1="J";
        if(cardnum==12) cas1="Q";
        if(cardnum==13) cas1="K";
   if (cardstyle==0) cas2="♠";  //黑桃图案表情符号
   if (cardstyle==1) cas2="❤️ ";  //红心图案
   if (cardstyle==2) cas2="♣";   //梅花图案
   if (cardstyle==3) cas2=" ";  //方块图案
     if(cardstyle==0||cardstyle==2) {
            cs.SetColor (255,0,0,0);     }
     if(cardstyle==1||cardstyle==3) {
            cs.SetColor (255,250,0,0);      }
     cs.SetTextSize (30);
     n=0
     if (cardnum==10) n=8;           
     cs.DrawText (cas1,px+12-n,py);
     cs.DrawText (cas2,px+5,py+30);                
      cs.Update ();
}//transcards ()

game1(){   //游戏 ”博眼子”  >>> 发牌
     cs.SetColor (255,0,120,0);   //backcolor
     cs.DrawRect (2,2,718,720);
         cs.Update ();
  //*******显示"庄家"...文字及分数
     ss=intToString (bankers);
     t$="庄家 "+"  "+ss ;
     sx=270;   sy=660;   tsize=40;
     print_t ();
     ss=intToString (users2);
     t$="北家"+"  "+ss ;
     sx=290;   sy=100;    tsize=30;
     print_t ();
     ss=intToString (users1);
     t$=ss+"  "+"东家" ;
     sx=555;   sy=420;    tsize=30;
     print_t ();
     ss=intToString (users3);
     t$="西家"+"  "+ss ;
     sx=55;   sy=420;    tsize=30;
     print_t ();
//**** 发牌 >>>
    px=280;    py=530;   //南家
        num=pnum[3];     //发牌顺序东北西南
        cardback() ;           //发牌只显示牌背
    px=360;    py=530;    //南家
        num=pnum[7];
        cardback ();
    px=540;    py=300;   //东家
        num=pnum[0];
        cardback ();
    px=620;    py=300;   //东家
        num=pnum[4];
        cardback ();
     px=280;    py=160;   //北家
        num=pnum[1];
        cardback ();
    px=360;    py=160;   //北家
        num=pnum[5];
        cardback ();
    px=40;    py=300;   //西家
        num=pnum[2];
        cardback ();
    px=120;    py=300;   //西家
        num=pnum[6];
        cardback ();
     t$="Do >  翻牌" ;
     sx=250;   sy=350;    tsize=50;
     print_t ();
    cs.Update ();
    isdo=1;    //重新发牌可计分
         clearOutput();
}//game1 ()

result (){   //翻牌比大小
       if (isdo==0) return ;   //发牌后计分,不重复计分
    cs.SetColor (255,0,120,0);   //backcolor
    cs.DrawRect (2,2,718,720);  //擦除文字重新显示
         cs.Update ();
  //***********
    px=280;    py=530;   //南家
        num=pnum[3];    c1=num ;
        transcards ();
    px=360;    py=530;   //南家
        num=pnum[7];    c2=num ;
        transcards ();
            cal_score ();
            bs=gscore ;

    px=540;    py=300;   //东家
        num=pnum[0];      c1=num ;
        transcards ();
    px=620;    py=300;   //东家
        num=pnum[4];      c2=num ;
        transcards ();
           cal_score ();
           us1=gscore ;

    px=280;    py=160;   //北家
        num=pnum[1];    c1=num ;
        transcards ();
    px=360;    py=160;   //北家
        num=pnum[5];     c2=num ;
        transcards ();
           cal_score ();
           us2=gscore ;

    px=40;    py=300;   //西家
        num=pnum[2];   c1=num ;
        transcards ();
    px=120;    py=300;   //西家
        num=pnum[6];    c2=num ;
        transcards ();  
           cal_score ();
           us3=gscore ;

//****************
//比大小计算各家得分
     if (bs>=us1){
           bankers=bankers+10 ;
           users1=users1-10 ;    }
    if (bs<us1){
           bankers=bankers-10 ;
           users1=users1+10 ;    }
    if (bs>=us2){
           bankers=bankers+10 ;
           users2=users2-10 ;    }
    if (bs<us2){
           bankers=bankers-10 ;
           users2=users2+10 ;    }
    if (bs>=us3){
           bankers=bankers+10 ;
           users3=users3-10 ;    }
    if (bs<us3){
           bankers=bankers-10 ;
           users3=users3+10 ;    }
     t$="🐒" ;
     sx=300;   sy=410;    tsize=120;
     print_t ();

//更新计分
      ss=intToString (bankers);
     t$="庄家 "+"  "+ss ;
     sx=270;   sy=660;   tsize=40;
     print_t ();
     ss=intToString (users2);
     t$="北家"+"  "+ss ;
     sx=290;   sy=100;    tsize=30;
     print_t ();
     ss=intToString (users1);
     t$=ss+"  "+"东家" ;
     sx=555;   sy=420;    tsize=30;
     print_t ();
     ss=intToString (users3);
     t$="西家"+"  "+ss ;
     sx=55;   sy=420;    tsize=30;
     print_t ();
     cs.Update ();
     isdo=0;   //翻牌计分后不重复计分
}//result ()

 

 

//**** 计分规则:
// 至尊宝  红A 黑A 60分, 最大
// 宝为对:天宝KK 50,  地宝22 48, 人宝QQ  46,
// 鹅宝(和对)JJ 44, 人四 44 42分,
// 长十10 10  40, 长三 33 38, 九九 99 36,
// 梅花55 34,短六66 32, 杂八88 30,杂七77 28,
// 天九王K9 26,
// 天八杠K8 , KQ= 24 ,25, 地八杠2 8 , 2 Q= 22  ,  23,
// 杂牌计分:
// 同样分值按天地人鹅长短加权比大小
// K=2点, Q=8点, J=4点,10=10点
// 黑A  = 6点, 红A  =  3点,2=2点
// 9=9点  8=8点  7=7点 6=6点  5=5点  4=4点  3=3点

cal_score (){
//计算分数,输入为c1,c2,输出 gscore
float c1s,c2s ;
float c1sc,c2sc;
     //为计分:c1c2换算为 1 ->> 13 (A ->> K )序
    c1s=(c1-c1/13*13)+1;  //num> 1 -> 13 (A -> K)
    c2s=(c2-c2/13*13)+1;
           print "    c1 = ",c1, "      c2 = ",c2 ;        
    if (c1s==1&&c2s==1){   //黑A红A 为至尊宝
          if (c1==0||c1==26&&c2==13||c2==39) {
             gscore=60 ;  goto putout ;          }
          if (c1==13||c1==39&&c2==0||c2==26) {
             gscore=60 ;  goto putout ;          }
                }
     //** 天宝到77杂牌宝,到天王天地杠 ****
      if (c1s==13&&c2s==13) { gscore=50 ; 
              goto putout ;    }  //K天
      if (c1s==2&&c2s==2) { gscore=48 ; 
              goto putout ;  }  //2地
      if (c1s==12&&c2s==12) { gscore=46 ;  
              goto putout ; } //Q人
      if (c1s==11&&c2s==11) { gscore=44 ; 
              goto putout ;  } //J鹅
      if (c1s==5&&c2s==5) { gscore=40 ;  
              goto putout ;  } //5梅花 或等同杂宝    
      if (c1s==10&&c2s==10) { gscore=35 ;  
              goto putout ;  } //10长
      if (c1s==3&&c2s==3) { gscore=35 ; 
              goto putout ; } //3长
      if (c1s==9&&c2s==9) { gscore=35 ; 
              goto putout ; } //9长
      if (c1s==6&&c2s==6) { gscore=32 ; 
              goto putout ;  } //6短
      if (c1s==8&&c2s==8) { gscore=30 ; 
              goto putout ;  } //8杂
      if (c1s==7&&c2s==7) { gscore=30 ;  
              goto putout ;  } //7杂   
      if (c1s==4&&c2s==4) {  gscore=30;  
              goto putout ;  } //4杂  或有作长牌
     if (c1s==13&&c2s==9) { gscore=26 ; 
              goto putout ;    }  //K9天九王
     if (c1s==9&&c2s==13) { gscore=26 ; 
              goto putout ;    }  //K9天九王
     if (c1s==13&&c2s==12) { gscore=25 ; 
              goto putout ;    }  //KQ天杠
     if (c1s==12&&c2s==13) { gscore=25 ; 
              goto putout ;    }  //KQ天杠
     if (c1s==13&&c2s==8) { gscore=24 ; 
              goto putout ;    }  //K8天杠
     if (c1s==8&&c2s==13) { gscore=24 ; 
              goto putout ;    }  //K8天杠
     if (c1s==2&&c2s==12) { gscore=23 ; 
              goto putout ;    }  //2 Q地杠
     if (c1s==12&&c2s==2) { gscore=23 ; 
               goto putout ;    }  //2 Q地杠
      if (c1s==2&&c2s==8) { gscore=22 ; 
               goto putout ;    }  //2 8地杠
      if (c1s==8&&c2s==2) { gscore=22 ; 
               goto putout ;    }  //2 8地杠        

//杂牌计算点数
      if (c1==0||c1==26)  c1s=6 ;  //黑A
      if (c1==13||c1==39)  c1s=3 ;  //红A
      if (c2==0||c2==26)  c2s=6 ;  //黑A
      if (c2==13||c2==39)  c2s=3 ;  //红A
      if (c1s==13) c1sc=2.5 ;  //K
      if (c1s==2) c1sc=2.4 ;  //2
      if (c1s==12) c1sc=8.3 ;  //Q
      if (c1s==11) c1sc=4.2 ;  //J
      if (c1s==10) c1sc=10.2 ;  //10
      if (c1s==9) c1sc=9.2 ;  //9
      if (c1s==8) c1sc=8 ;  //8
      if (c1s==7) c1sc=7 ;  //7
      if (c1s==6) c1sc=6.2 ;  //6
      if (c1s==5) c1sc=5 ;  //5
      if (c1s==4) c1sc=4;  //4
      if (c1s==3) c1sc=3.2 ;  //3
      if (c2s==13) c2sc=2.5;  //K
      if (c2s==2) c2sc=2.4 ;  //2
      if (c2s==12) c2sc=8.3 ;  //Q
      if (c2s==11) c2sc=4.2;  //J
      if (c2s==10) c2sc=10.2 ;  //10
      if (c2s==9) c2sc=9.2 ;  //9
      if (c2s==8) c2sc=8 ;  //8
      if (c2s==7) c2sc=7 ;  //7
      if (c2s==6) c2sc=6.2 ;  //6
      if (c2s==5) c2sc=5 ;  //5
      if (c2s==4) c2sc=4 ;  //4
      if (c2s==3) c2sc=3.2 ;  //3

      gscore=c1sc+c2sc;       //计算得分
      if (gscore<10) gscore=gscore+10 ;   //分数为个位数加10
//-----------------------------
putout:   
 //calculate & putout gscore,  return gscore
     print "  c1s = ",c1s,  "   ","    c2s = ",c2s ;
     print "c1sc = ",c1sc,  "     ","c2sc = ",c2sc ;
     print "gscore = ",gscore ;
     print "  " ;     //print 算法测试检验,可注释掉
}//cal_score ()

print_t (){   //打印标题提示等文字
//**  参数 sx,sy, ss3=$, tsize=text size   
  cs.SetFillMode (1);//0不填色,1填色
    cs.SetTextStyle (0);    //0正常,1粗体
     ss3=t$ ;
 cs.SetTextSize (tsize);
    cs.SetColor (255,0,200,60);
 cs.DrawText (ss3,sx+2,sy+3);
    cs.SetColor (255,250,120,0);
 cs.DrawText (ss3,sx,sy);
 cs.SetFillMode (0);//0不填色,1填色
    cs.SetColor (255,220,70,250);
    cs.SetColor (255,250,250,0);
    cs.DrawText (ss3,sx,sy);
  cs.SetFillMode (1);//0不填色,1填色
      cs.Update ();
}//print _t ()
 
myToolBarProc(int nBtn,int nContext){
      if(nBtn==100){//redeal 重新开始
            redeal ();
              }  
      if(nBtn==101){//洗牌
            setDisplay (1);
            shuffle_cards ();
             }
      if(nBtn==102){//发牌
            setDisplay (1);
            shuffle_cards ();
             game1 ();
              }
      if(nBtn==103){//翻牌
           setDisplay (1);
            result () ;
              }
      if(nBtn==104){//退出程序
          clearOutput();
          cs.ClearDraw (0,src);
          setDisplay (0);
          exit (0);
               }
     if(nBtn==105){//@About
           drawcover ();
           //drawcards ();
                }
}//myToolBar ()

myMenuProc(int nMen,int nContext){
     if(nMen==200){  //重新开始
           redeal ();
                 }   
     if(nMen==201){   // 洗牌
           shuffle_cards ();
                  }   
     if(nMen==202){    //发牌
           setDisplay (1);
            shuffle_cards ();
            game1 ();    
                   }
      if (nMen==203){  //翻牌
             result ();
                    }
    if (nMen==204){//选项:洗牌验牌
          shuffle_cards ();
          sleep (1000);
          showcard ();
              }
  if(nMen==205){//close canvas
        setDisplay (0);  
             }  
    if(nMen==206){//show canvas
          setDisplay (1);    
             }
    if (nMen==207){//Exit 
        clearOutput();
        cs.ClearDraw (0,src);
        exit (0);
          }
  }//myMenu()

 

 

相关推荐

相关文章