コード例 #1
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;
}
コード例 #2
0
ファイル: guessnum.c プロジェクト: jcppkkk/MapleBBS-3.00
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;
}