示例#1
0
int p_seven()
{
    char buf1[8],log[80];
    char *kind[9]= {"¯QÀs","³æ­F","¨ß­F","¤T±ø","¶¶¤l","¦Pªá","¸¬Äª",
                    "ÅK¤ä","¬h¤B"
                   };
    char *poker[52]= {"¢±","¢±","¢±","¢±","¢²","¢²","¢²","¢²",
                      "¢³","¢³","¢³","¢³","¢´","¢´","¢´","¢´","¢µ","¢µ","¢µ","¢µ",
                      "¢¶","¢¶","¢¶","¢¶","¢·","¢·","¢·","¢·","¢¸","¢¸","¢¸","¢¸",
                      "10","10","10","10","¢Ø","¢Ø","¢Ø","¢Ø","¢ß","¢ß","¢ß","¢ß",
                      "¢Ù","¢Ù","¢Ù","¢Ù","¢Ï","¢Ï","¢Ï","¢Ï"
                     };
    int cardlist[52]= {0};
    int mark[2]= {7,7}, set[6],key,tax=0; /* tax ¬°ª±®aĹ®É©âªºµ| */
    int i,j,k,x,m,ch,z=1;
    int win,color,color2,bet;
    int host_card[7]= {0}, guest_card[7]= {0};

    time_t now = time(0);
    time(&now);

    while(-1) {
        clear();
        setutmpmode(SEVENCARD);
        showtitle("½ä«°¤C±i", BoardName);
        show_money(bet=0);
        do
        {
            getdata(21, 0,"­n¤Uª`¦h¤Ö©O(¤W­­250000)? «ö Enter Â÷¶}>", buf1, 7, 1, 0);
            bet=atoi(buf1);
            if(bet<0) bet=0;
        } while(bet>250000);
        if(!bet) return 0;
        if(bet>cuser.silvermoney)
        {
            pressanykey("§Aªº²{ª÷¤£°÷³á.. :)");
            return 0;
        }

        demoney(bet);
        show_money(bet);
        move(21,0);
        prints("(«ö ¡ô¡õ¡ö¡÷ ©Î ijkl ¿ïµP, ¿ï¦n«ö enter ÅuµP)");

        for(i=0; i<52; i++) cardlist[i]=0;
        mark[0]=mark[1]=7;
        z=1;

        for(i=1; i<=52; i++) {
            m=0;
            do {
                j=(time(0)+cuser.silvermoney+random())%52;
                if (cardlist[j]==0) {
                    cardlist[j]=i;
                    m=1;
                }
            } while(m==0);
        };
        for(i=0; i<52; i++)cardlist[i]--; /* ¬~µP */

        j=0;
        for(i=0; i<7; i++) {
            host_card[i]=cardlist[j];
            j++;
            guest_card[i]=cardlist[j];
            j++;
        }        /* µo«e¤Q¥|±iµP */

        for(i=0; i<7; i++) {
            for(j=0; j<(6-i); j++) {
                if(guest_card[j]>guest_card[j+1]) {
                    x=guest_card[j];
                    guest_card[j]=guest_card[j+1];
                    guest_card[j+1]=x;
                }
                if(host_card[j]>host_card[j+1]) {
                    x=host_card[j];
                    host_card[j]=host_card[j+1];
                    host_card[j+1]=x;
                }
            }
        }        /* ±Æ§Ç */
        move(1,0);
        prints("¥»¹CÀ¸¥Ñ¯îÂÕ¤Û¹Ò(weird.twbbs.org)¯¸ªø weiren ³]­p´£¨Ñ! ¯S¦¹·PÁÂ!!\n");
        prints("e-mail: [email protected]");

        move(3,0);
        prints("¢~¢w¢~¢w¢~¢w¢~¢w¢~¢w¢~¢w¢~¢w¢w¢w¢¡");
        move(4,0);
        prints("¢x  ¢x  ¢x  ¢x  ¢x  ¢x  ¢x      ¢x");
        move(5,0);
        prints("¢x  ¢x  ¢x  ¢x  ¢x  ¢x  ¢x      ¢x");
        move(6,0);
        prints("¢x  ¢x  ¢x  ¢x  ¢x  ¢x  ¢x      ¢x");
        move(7,0);
        prints("¢x  ¢x  ¢x  ¢x  ¢x  ¢x  ¢x      ¢x");
        move(8,0);
        prints("¢x  ¢x  ¢x  ¢x  ¢x  ¢x  ¢x      ¢x");
        move(9,0);
        prints("¢¢¢w¢¢¢w¢¢¢w¢¢¢w¢¢¢w¢¢¢w¢¢¢w¢w¢w¢£");

        for(i=0; i<7; i++) {
            print_Scard(guest_card[i],11,0+4*i);  /* ¦L¥X«e¤C±iµP */
        }

        j=2;
        k=0;
        x=0;
        move(15,2);
        do {
            ch=igetkey();
            switch (ch)
            {
            case KEY_RIGHT:
            case 'l':
                j+=4;
                if(j>26)j=26;
                break;
            case KEY_LEFT:
            case 'j':
                j-=4;
                if(j<2)j=2;
                break;
            case KEY_UP:
            case 'i':
                k=(j-2)/4;
                if(x<2&&mark[0]!=k&&mark[1]!=k) {
                    if(mark[0]==7)mark[0]=k;
                    else mark[1]=k;
                    x++;
                    cursor_show(15,j);
                }
                break;
            case KEY_DOWN:
            case 'k':
                k=(j-2)/4;
                if(mark[0]==k) {
                    mark[0]=7;
                    x--;
                }
                if(mark[1]==k) {
                    mark[1]=7;
                    x--;
                }
                cursor_clear(15,j);
                break;
            case 13:   /* ¿ï¥X¨â±i«á«ö enter */
                if(x==2)z=0;
                break;
                prints("¥»¹CÀ¸¥Ñ¯îÂÕ¤Û¹Ò(weird.twbbs.org)¯¸ªø weiren ³]­p\n");
                prints("e-mail: [email protected]");
            }
            move(15,j);
        } while(z==1);

        if(mark[0]>mark[1]) {
            i=mark[0];
            mark[0]=mark[1];
            mark[1]=i;
        }
        for(i=1; i<18; i++) {
            move(i,0);
            clrtoeol();
        }
        print_Scard(guest_card[mark[0]],11,0);
        print_Scard(guest_card[mark[1]],11,4);
        j=0;
        for(i=0; i<7; i++) {
            if(i!=mark[0]&&i!=mark[1]) {
                print_Scard(guest_card[i],11,16+j*4);
                set[j]=guest_card[i];
                j++;
            }
        }                   /* ¦L¥Xª±®a¤À¦n¨â°ô«áªºµP */
        set[5]=5;
        if(diedragon(set,guest_card[mark[0]],guest_card[mark[1]])==1)
        {
            ;
            pressanykey("­ËÀs!");
            continue;
        }
        if(guest_card[mark[0]]/4==guest_card[mark[1]]/4)x=1;

        key=find_host(host_card);
        print_hostcard(host_card,key,log);
        i=bigsmall(host_card,guest_card,key,mark);
        switch(i) {
        case 0:
            win=2;
            color=41;
            color2=41;
            break; /* ª±®a duA duB ¬ÒĹ  */
        case 1:
            win=1;
            color=41;
            color2=47;
            break; /*      duA Ĺ duB ¿é */
        case 2:
            win=1;
            color=47;
            color2=41;
            break; /*      duA ¿é duB Ĺ */
        case 3:
            win=0;
            color=47;
            color2=47;
            break; /*      ¨â½ä¬Ò¿é */
        }
        game_log(SEVENCARD,"§ÚªºµP%s%s%s..¹q¸£%s..%s..%d",poker[guest_card[mark[0]]],
                 x==1?"­F":poker[guest_card[mark[1]]],kind[find_all(set)],log,
                 win?(win==1?"¥­¤â":"ŤF"):"¿é¤F",bet);
        move(15,4);
        prints("[1;%d;%dm   %s%s     ¢x  ¢x  [1;%d;%dm         %s         "
               ,color,  color==41?33:30
               ,poker[guest_card[mark[0]]],x==1?"­F":poker[guest_card[mark[1]]]
               ,color2, color2==41?33:30
               ,kind[find_all(set)]);
        i=bet*2-bet/100*tax;
        switch(win) {
        case 2:
            pressanykey("§AŤF %d !!.. :D",i-bet);
            inmoney(i);
            break;
        case 1:
            pressanykey("¥­¤â!!..");
            inmoney(bet);
            break;
        case 0:
            pressanykey("§A¿é¤F³á.. :))" );
            break;
        }
    }
}
示例#2
0
文件: bj.c 项目: yrchen/Athena
void BlackJack()
{
  char buf[256];
  int    num[52]={11,11,11,11,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,
                   7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,
                  10,10,10,10,10,10,10,10};
  int cardlist[52]={0};
  int i,j,m,tmp=0,tmp2,ch;
  int win=2,win_jack=5; /* win ¬°Ä¹®Éªº­¿²v, win_jack ¬°«e¨â±i´N 21 ÂI­¿²v */
  int six=10, seven=20, aj=10, super_jack=20; /* 777, A+J, spade A+J ªº­¿²v */
  int host_count=2, guest_count=1, card_count=3, A_count=0, AA_count=0;
  int host_point=0, guest_point=0, mov_y=4;
  int host_card[12]={0}, guest_card[12]={0};
  long int money;

  int CHEAT=0; /* °µ¹ú°Ñ¼Æ, 1 ´N§@¹ú, 0 ´N¤£§@ */

  time_t now = time(0);
  time(&now);

  clear();
  setutmpmode(BLACKJACK);
  do{
  move(0,0);prints("±z¨­¤WÁÙ¦³ %d ¤¸",cuser.silvermoney);
  getdata(1, 0, "­n©ãª`¦h¤Ö¿ú(1 - 250000)? ", buf, 7, DOECHO,0);
  money=atoi(buf);
  if(!buf[0])return;
  if(check_money(money,SILVER)) return;
  }while((money<1)||(money>250000));
  demoney(money);
  move(2,0);prints("(«ö y ÄòµP, n ¤£ÄòµP, d double)");
  move(0,0);clrtoeol();prints("±zÁÙ¦³ %d »È¨â",cuser.silvermoney);
  for(i=1;i<=52;i++){
    m=0;
    do{
    j=(time(0)+cuser.silvermoney+rand())%52;
    if (cardlist[j]==0){cardlist[j]=i;m=1;}
    }while(m==0);
  };
  for(i=0;i<52;i++)cardlist[i]--; /* ¬~µP */

  if(money>=20000)CHEAT=1;
  if(CHEAT==1){
    if(cardlist[1]<=3){
      tmp2=cardlist[50];
      cardlist[50]=cardlist[1];
      cardlist[1]=tmp2;
    }
  }                             /* §@¹ú½X */

  host_card[0]=cardlist[0];
  if(host_card[0]<4)AA_count++;
  guest_card[0]=cardlist[1];

  if(guest_card[0]<4)A_count++;
  host_card[1]=cardlist[2];
  if(host_card[1]<4)AA_count++; /* µo«e¤T±iµP */

  move(5,0);  prints("¢~¢w¢w¢w¢¡");
  move(6,0);  prints("¢x      ¢x");
  move(7,0);  prints("¢x      ¢x");
  move(8,0);  prints("¢x      ¢x");
  move(9,0);  prints("¢x      ¢x");
  move(10,0); prints("¢x      ¢x");
  move(11,0); prints("¢¢¢w¢w¢w¢£");
  print_card(host_card[1],5,4);
  print_card(guest_card[0],15,0);  /* ¦L¥X«e¤T±iµP */

  host_point=num[host_card[1]];
  guest_point=num[guest_card[0]];

  do{
    m=1;
    guest_card[guest_count]=cardlist[card_count];
    if(guest_card[guest_count]<4)A_count++;
    print_card(guest_card[guest_count],15,mov_y);
    guest_point+=num[guest_card[guest_count]];

    if((guest_card[0]>=24&&guest_card[0]<=27)&&(guest_card[1]>=24&&guest_card[1]<=27)&&(guest_card[2]>=24&&guest_card[2]<=27)){
      move(18,3);prints("     ¢¶¢¶¢¶     ");
      move(3,0);prints("¢¶¢¶¢¶ !!! ±o¼úª÷ %d »È¨â",money*seven);
      inmoney(money*seven);
      game_log("BLACKJACK","¤¤¤F %7d ¤¸ªº "COLOR1"  ¢¶¢¶¢¶   "
        ,money*seven);
      pressanykey("±zÁÙ¦³ %d »È¨â",cuser.silvermoney);
      return;
    }

    if((guest_card[0]==40&&guest_card[1]==0)||(guest_card[0]==0&&guest_card[1]==40)){
      move(18,3);prints(" ¶W¯Å¥¿²Î BLACK JACK  ");
      move(3,0);prints("¶W¯Å¥¿²Î BLACK JACK !!! ±o¼úª÷ %d »È¨â",money*super_jack);
      inmoney(money*super_jack);
      game_log("BLACKJACK","¤¤¤F %7d ¤¸ªº  ¥¿²Î ¢Ï¢Ø "
        ,money*super_jack);
      pressanykey("±zÁÙ¦³ %d »È¨â",cuser.silvermoney);
      return;
    }

    if((guest_card[0]<=3&&guest_card[0]>=0)&&(guest_card[1]<=43&&guest_card[1]>=40))tmp=1;

if((tmp==1)||((guest_card[1]<=3&&guest_card[1]>=0)&&(guest_card[0]<=43&&guest_card[0]>=40))){
      move(18,3);prints(" SUPER BLACK JACK  ");
      move(3,0);prints("SUPER BLACK JACK !!! ±o¼úª÷ %d »È¨â",money*aj);
      inmoney(money*aj);
      game_log("BLACKJACK","¤¤¤F %7d ¤¸ªº  Super¢Ï¢Ø ",money*aj);
      pressanykey("±zÁÙ¦³ %d »È¨â",cuser.silvermoney);
      return;
    }

    if(guest_point==21&&guest_count==1){
      move(18,3);prints("  BLACK JACK  ");
      move(3,0);prints("BLACK JACK !!! ±o¼úª÷ %d »È¨â",money*win_jack);
      inmoney(money*win_jack);
      move(0,0);clrtoeol();prints("±zÁÙ¦³ %d »È¨â",cuser.silvermoney);
    if(money*win_jack>=500000){
      game_log("BLACKJACK","¤¤¤F %7d ¤¸ªº  BlackJack  %s ",money*win_jack);
    }

      pressanykey(NULL);
      return;
    }                        /* «e¨â±i´N 21 ÂI */

    if(guest_point>21){
      if(A_count>0){guest_point-=10;A_count--;};
    }
    move(12,0); clrtoeol();prints("ÂI¼Æ: %d",host_point);
    move(14,0); clrtoeol();prints("ÂI¼Æ: %d",guest_point);
    if(guest_point>21){
      pressanykey("  Ãz±¼°Õ~~~  ");
      return;
    }

    if(guest_count==5){
      move(18,3);prints("            ¹L¤»Ãö            ");
      move(3,0);prints("¹L¤»Ãö !!! ±o¼úª÷ %d »È¨â",money*six);
      inmoney(money*six);
      game_log("BLACKJACK","¤¤¤F %7d ¤¸ªº   ¹L¤»Ãö   ",money*six);
      pressanykey("±zÁÙ¦³ %d »È¹ô",cuser.silvermoney);
      return;
    }

    guest_count++;
    card_count++;
    mov_y+=4;

    do{
      if(ch=='d')m=0;
      if(m!=0)ch=igetkey();
    }while(ch!='y'&&ch!='n'&&ch!='d'&&m!=0); /* §ì key */

    if(ch=='d'&&m!=0&&guest_count==2){
      if(cuser.silvermoney>=money){
        demoney(money);
        money*=2;
      }
      else ch='n';
      move(0,0);clrtoeol();prints("±zÁÙ¦³ %d »È¨â",cuser.silvermoney);
    }                                      /* double */

    if(ch=='d'&&guest_count>2)ch='n';
    if(guest_point==21)ch='n';
  }while(ch!='n'&&m!=0);

  mov_y=8;

  print_card(host_card[0],5,0);
  print_card(host_card[1],5,4);
  host_point+=num[host_card[0]];

  do{

    if(host_point<guest_point){
      host_card[host_count]=cardlist[card_count];
      print_card(host_card[host_count],5,mov_y);
      if(host_card[host_count]<4)AA_count++;
      host_point+=num[host_card[host_count]];
    }
    if(host_point>21){
      if(AA_count>0){host_point-=10;AA_count--;};
    }
    move(12,0); clrtoeol();prints("ÂI¼Æ: %d",host_point);
    move(14,0); clrtoeol();prints("ÂI¼Æ: %d",guest_point);
    if(host_point>21){
      move(14,0); clrtoeol(); prints("ÂI¼Æ: %d  WINNER ",guest_point);

      move(3,0);prints("§AŤF~~~~ ±o¼úª÷ %d »È¨â",money*win);
      inmoney(money*win);
      move(0,0);clrtoeol();prints("±zÁÙ¦³ %d »È¨â",cuser.silvermoney);
      pressanykey(NULL);
      return;
    }
    host_count++;
    card_count++;
    mov_y+=4;
  }while(host_point<guest_point);

  pressanykey("§A¿é¤F~~~~ »È¨â¨S¦¬!");
  return;
}
示例#3
0
int mainNum(int fighting /* Thor.990317: 對戰模式 */)
{
  Num myNumber;
  char buf[80];
  int money;
  /* 倍率        0  1   2   3   4   5   6   7   8   9   10 */
  float bet[11]={0,100, 50, 10, 3 ,1.5,1.2,0.9, 0.8 ,0.5,0.1}; 
  /* initialize variables */
#if 1
  if(!hisList) hisList = (His *)malloc(sizeof(His)); /* pseudo */
  if(!numSet) numSet = (char *)malloc(10*9*8*7*sizeof(char));
#endif

  hisNum = 0;       

  numNum = 10*9*8*7;
  memset(numSet, 0, numNum*sizeof(char));

  srand(time(NULL));

  /* Thor.990317:對戰模式 */
  stand_title(fighting ? "猜數字大戰" :"傻瓜猜數字"); /* clear(); */

  do{
    move(0,0);
    prints("您身上還有 %d 元",cuser.silvermoney);
    getdata(1, 0, "要押注多少錢(1 - 250000)? ", buf, 7, DOECHO,0);
    money=atoi(buf);
    if(!buf[0])return;
    if(check_money(money,SILVER)) return;
  }while((money<1)||(money>250000));

  /* Thor.990221: 有人反應離不開 */
  if(answer("想好您的數字了嗎?[y/N]")!='y')
  {
    pressanykey("不玩了啊? 下次再來哦! ^_^");
    return 0;
  }

  if(fighting)
    ord2Num(rand() % numNum, myNumber); /* Thor.990317:對戰模式 */

  demoney(money);
  /* while there is possibility */
  for(;;)
  {
    Num myGuess, yourGuess;
    int youA,youB, myA, myB;

    if(fighting)  /* Thor.990317:對戰模式 */
    {
      int i , a , b;
      char tmp[50];
     do{
      getdata(b_lines-3, 0, "您猜我的數字是[????]:", tmp, 5, DOECHO,0);
      /* Thor.990317: 為簡化, 不作checking */
      if(!tmp[0]) goto abort_game;
      if(tmp[0] == '!' && HAS_PERM(PERM_SYSOP))
        pressanykey("%d%d%d%d",myNumber[0],myNumber[1],myNumber[2],myNumber[3]);
      for (a=0;a<3;a++)
      for (b=a+1;b<4;b++)
      if(tmp[a]==tmp[b])
        tmp[0]=0;
      if(!tmp[0])
      {
        pressanykey("輸入數字有問題!!"); 
      }
      
      }while  (!tmp[0]);    
      for(i=0;i<4;i++) 
        yourGuess[i] = tmp[i] - '0';
      AB(myNumber,yourGuess, &myA, &myB);
      move(b_lines-2,0); clrtoeol();
      move(b_lines-2,0);
      prints("我說 \033[1m%dA%dB \033[m", myA, myB);
     
      if(myA==4)
      {
        int m = money ,e = ba ;
        /* you win  */
#if 1
        game_log(NumFight,"猜了%d次,贏了%d元,EXP %d 點"
          , hisNum,(int)bet[hisNum]*money,(int)bet[hisNum]*ba);
#endif
        if(hisNum > 10) hisNum = 10;
        m *= bet[hisNum]; e *= bet[hisNum];
        inmoney(m);
//        inexp(e); 
//        pressanykey("您贏了! 好崇拜 ^O^,獎金 %d 元,經驗值 %d 點!",m,e);
        pressanykey("您贏了! 好崇拜 ^O^,獎金 %d 元!",m);
        return 0;
      }  
    }

    /* pickup a candidate number */
    for(;;)
    {
      int i;
      /* pickup by random */
      if(numNum<=0) 
        goto foolme;
      i = rand() % numNum;
      i = getth(i, numSet); /* i-th ordering num */
      numSet[i] = 1; numNum--; /* filtered out */
      ord2Num(i, myGuess); /* convert ordering num to Num */

      /* check history */
      if(matchHis(myGuess))
        break;
    }

    /* show the picked number */
    move(b_lines - 1, 0); clrtoeol();
    move(b_lines - 1, 0); 
    prints("我猜您的數字是 \033[1;37m%d%d%d%d\033[m",myGuess[0], myGuess[1], myGuess[2], myGuess[3]);

    /* get ?A?B */
    for(;;)
    {
      char buf[5];
      /* get response */
      getdata(b_lines, 0, "您的回答[?A?B]:", buf, 5, DOECHO,0);

      if(!buf[0])
      {
abort_game:
        /* abort */
        pressanykey("不玩了啊? 下次再來哦! ^_^");
#if 1
        game_log(NumFight,"猜了%d次,不想玩了!", hisNum);
#endif
        return 0;
      }
      if(isdigit(buf[0]) && (buf[1]|0x20) == 'a'
       &&isdigit(buf[2]) && (buf[3]|0x20) == 'b' )
      {
        youA = buf[0] - '0';
        youB = buf[2] - '0';
        /* check legimate */
        if(youA >= 0 && youA <=4
          && youB >=0 && youB <= 4
          && youA + youB <= 4)
        {
          /* if 4A, end the game */
          if(youA == 4)
          {
           int m=money,e=ba;   
#if 1
           game_log(NumFight,"猜了%d次,輸給電腦!", hisNum);
#endif
           /* I win  */
           if(hisNum > 10) hisNum = 10;  
           m *= bet[10 - hisNum]*0.1; e *= bet[10 - hisNum];
//           pressanykey("我贏了! 厲害吧 ^O^,賠你 %d 元,得到 %d 點經驗值",m,e);
	   pressanykey("我贏了! 厲息a ^O^,賠你 %d 元!",m);
           inmoney(m); 
//           inexp(e); 
           return 0;
          }
          else
            break;
        }
      }
      /* err A B */
      outmsg("輸入格式有誤");
    }
    /* put in history */
    hisNum ++;
    hisList = (His *) realloc(hisList, hisNum * sizeof(His)); /* assume must succeeded */
    memcpy(hisList[hisNum - 1].n, myGuess, sizeof(Num));
    hisList[hisNum - 1].A=youA;
    hisList[hisNum - 1].B=youB;

    move(2+hisNum,0);
    if(fighting) /* Thor.990317: 對戰模式 */
      prints("第 \033[1;37m%d\033[m 次, 你猜 \033[1;36m%d%d%d%d\033[m, 我說 \033[1;33m%dA%dB\033[m; 我猜 \033[1;33m%d%d%d%d\033[m, 你說 \033[1;36m%dA%dB\033[m", hisNum, yourGuess[0], yourGuess[1], yourGuess[2], yourGuess[3], myA, myB, myGuess[0], myGuess[1], myGuess[2], myGuess[3], youA, youB);
    else
      prints("第 \033[1;37m%d\033[m 次, 我猜 \033[1;33m%d%d%d%d\033[m, 你說 \033[1;36m%dA%dB\033[m", hisNum, myGuess[0], myGuess[1], myGuess[2], myGuess[3], youA, youB);
  }
foolme:
  /* there is no posibility, show "you fool me" */
  pressanykey("你騙我! 不跟你玩了 ~~~>_<~~~");
#if 1
      game_log(NumFight,"猜了%d次,耍電腦,被趕出去!", hisNum);
#endif
  return 0;
}