最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語言實現(xiàn)小貓釣魚游戲

 更新時間:2019年01月15日 15:28:10   作者:連長少尉  
這篇文章主要為大家詳細介紹了C語言實現(xiàn)小貓釣魚游戲,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C語言實現(xiàn)小貓釣魚游戲的具體代碼,供大家參考,具體內(nèi)容如下

#include<stdio.h>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
 
 
typedef struct
{
 int data[3600];
 int col[3600];
 int top;
} stack;
 
typedef struct
{
 int data[3600];
 int col[3600];
 int head;
 int tail;
} queue;
 
queue p1, p2;
stack table;
 
void printmenu();
void deal();
void printp1();
void printtable();
void printzzz();
void judge(int a, int player);
void game();
void ask();
 
int main()
{
 while(1)
 {
  char ch;
  printmenu();
  scanf("%c",&ch);
  switch(ch)
  {
  case '1':
   game();
   break;
 
  case '2':
   exit(0);
 
  default:
   system("cls");
   break;
  }
 }
 
 return 0;
}
 
void printmenu()
{
 printf("*****************************\n");
 printf("*       *\n");
 printf("*       *\n");
 printf("*   金鉤釣魚   *\n");
 printf("*       *\n");
 printf("*       *\n");
 printf("*       *\n");
 printf("*****************************\n");
 printf("\n\n\n");
 printf("游戲規(guī)則:\n");
 printf("每人各拿一半的牌,然后你放1張牌,\n");
 printf("他放一張牌,如跟上面的牌一樣,\n");
 printf("即可把當中的牌全部吃掉,\n");
 printf("直至對手手上無牌為止。\n\n\n");
 printf("輸入1開始游戲\n");
 printf("輸入2退出程序\n");
}
 
void deal()
{
 p1.head = 1;
 p1.tail = 1;
 p2.head = 1;
 p2.tail = 1;
 table.top = 0;
 int i, card, book[60];
 srand((unsigned)time(0));
 memset(book, 0, sizeof(book));
 for(i = 1; i <= 27;)
 {
  card = rand()%55;
  if(card == 0)
   continue;
  else if(card >= 1 && card <= 13 && book[card] == 0)
  {
   p1.data[p1.tail] = card;
   p1.col[p1.tail] = 1;
   p1.tail++;
   book[card]=1;
   i++;
  }
  else if(card >= 14 && card <= 26 && book[card] == 0)
  {
   p1.data[p1.tail] = card - 13;
   p1.col[p1.tail] = 2;
   p1.tail++;
   book[card]=1;
   i++;
  }
  else if(card >= 27 && card <= 39 && book[card] == 0)
  {
   p1.data[p1.tail] = card - 26;
   p1.col[p1.tail] = 3;
   p1.tail++;
   book[card]=1;
   i++;
  }
  else if(card >= 40 && card <= 52 && book[card] == 0)
  {
   p1.data[p1.tail] = card - 39;
   p1.col[p1.tail] = 4;
   p1.tail++;
   book[card]=1;
   i++;
  }
  else if(card == 53)
  {
   p1.data[p1.tail] = card;
   p1.col[p1.tail] = 5;
   p1.tail++;
   book[card]=1;
   i++;
  }
  else if(card == 54)
  {
   p1.data[p1.tail] = card;
   p1.col[p1.tail] = 5;
   p1.tail++;
   book[card]=1;
   i++;
  }
 }
 for(i = 1; i <= 27;)
 {
  card = rand()%55;
  if(card == 0)
   continue;
  else if(card >= 1 && card <= 13 && book[card] == 0)
  {
   p2.data[p2.tail] = card;
   p2.col[p2.tail] = 1;
   p2.tail++;
   book[card]=1;
   i++;
  }
  else if(card >= 14 && card <= 26 && book[card] == 0)
  {
   p2.data[p2.tail] = card - 13;
   p2.col[p2.tail] = 2;
   p2.tail++;
   book[card]=1;
   i++;
  }
  else if(card >= 27 && card <= 39 && book[card] == 0)
  {
   p2.data[p2.tail] = card - 26;
   p2.col[p2.tail] = 3;
   p2.tail++;
   book[card]=1;
   i++;
  }
  else if(card >= 40 && card <= 52 && book[card] == 0)
  {
   p2.data[p2.tail] = card - 39;
   p2.col[p2.tail] = 4;
   p2.tail++;
   book[card]=1;
   i++;
  }
  else if(card == 53 && book[card] == 0)
  {
   p2.data[p2.tail] = card;
   p2.col[p2.tail] = 5;
   p2.tail++;
   book[card]=1;
   i++;
  }
  else if(card == 54 && book[card] == 0)
  {
   p2.data[p2.tail] = card;
   p2.col[p2.tail] = 5;
   p2.tail++;
   book[card]=1;
   i++;
  }
 }
 
 return;
}
 
void printp1()
{
 int i;
 printf("您的牌有: \n");
 for(i = p1.tail-1; i >= p1.head; i--)
 {
  if(p1.col[i] == 1)
  {
   printf("方片");
  }
  else if(p1.col[i] == 2)
  {
   printf("紅桃");
  }
  else if(p1.col[i] == 3)
  {
   printf("黑桃");
  }
  else if(p1.col[i] == 4)
  {
   printf("梅花");
  }
  if(p1.data[i] == 11)
  {
   printf("J ");
  }
  else if(p1.data[i] == 12)
  {
   printf("Q ");
  }
  else if(p1.data[i] == 13)
  {
   printf("K ");
  }
  else if(p1.data[i] == 53)
  {
   printf("小王 ");
  }
  else if(p1.data[i] == 54)
  {
   printf("大王 ");
  }
  else
   printf("%d ", p1.data[i]);
 }
 printf("\n\n");
 return;
}
 
void printtable()
{
 int i;
 printf("桌上的牌有:\n");
 if(table.top == 0)
 {
  printf("(無)\n");
 }
 for(i = 1; i <= table.top; i++)
 {
  if(table.col[i] == 1)
  {
   printf("方片");
  }
  else if(table.col[i] == 2)
  {
   printf("紅桃");
  }
  else if(table.col[i] == 3)
  {
   printf("黑桃");
  }
  else if(table.col[i] == 4)
  {
   printf("梅花");
  }
  if(table.data[i] == 11)
  {
   printf("J ");
  }
  else if(table.data[i] == 12)
  {
   printf("Q ");
  }
  else if(table.data[i] == 13)
  {
   printf("K ");
  }
  else if(table.data[i] == 53)
  {
   printf("小王 ");
  }
  else if(table.data[i] == 54)
  {
   printf("大王 ");
  }
  else
   printf("%d ", table.data[i]);
 }
 printf("\n\n\n");
 return;
}
 
void printzzz()
{
 system("cls");
 Sleep(400);
 printf("正 ");
 Sleep(400);
 printf("在 ");
 Sleep(400);
 printf("出 ");
 Sleep(400);
 printf("牌 ");
 Sleep(400);
 printf(". ");
 Sleep(400);
 printf(". ");
 Sleep(400);
 printf(". ");
 Sleep(800);
 judge(table.data[table.top], 1);
 system("cls");
 printf("玩家2 開始回合??!\n\n\n\n");
 printtable();
 table.top++;
 table.data[table.top] = p2.data[p2.head];
 table.col[table.top] = p2.col[p2.head];
 p2.head++;
 Sleep(600);
 printf("玩 ");
 Sleep(400);
 printf("家 ");
 Sleep(400);
 printf("2 ");
 Sleep(400);
 printf("正 ");
 Sleep(400);
 printf("在 ");
 Sleep(400);
 printf("出 ");
 Sleep(400);
 printf("牌 ");
 Sleep(400);
 printf(". ");
 Sleep(400);
 printf(". ");
 Sleep(400);
 printf(". ");
 Sleep(1000);
 judge(table.data[table.top], 2);
 return;
}
 
void judge(int a, int player)
{
 int i, j, sum = 2;
 if(player == 1)
 {
  for(i = table.top-1; i >= 1; i--, sum++)
  {
   if(a == table.data[i] || ((a == 53 || a == 54) && (table.data[i] == 53 || table.data[i] == 54)))
   {
    for(j = table.top; j >= i; j--)
    {
     p1.data[p1.tail] = table.data[table.top];
     p1.col[p1.tail] = table.col[table.top];
     p1.tail++;
     table.top--;
    }
    break;
   }
  }
 
  if(i != 0)
  {
   system("cls");
   Sleep(400);
   printf("玩 ");
   Sleep(400);
   printf("家 ");
   Sleep(400);
   printf("1 ");
   Sleep(400);
   printf("贏 ");
   Sleep(400);
   printf("了 ");
   Sleep(400);
   printf("%d ", sum);
   Sleep(400);
   printf("張");
   Sleep(400);
   printf("牌 ");
   Sleep(400);
   printf("! ");
   Sleep(400);
   printf("! ");
   Sleep(400);
   printf("! ");
   Sleep(2000);
   system("cls");
  }
 }
 else if(player == 2)
 {
  for(i = table.top-1; i >= 1; i--, sum++)
  {
   if(a == table.data[i] || ((a == 53 || a == 54) && (table.data[i] == 53 || table.data[i] == 54)))
   {
    for(j = table.top; j >= i; j--)
    {
     p2.data[p2.tail] = table.data[table.top];
     p2.col[p2.tail] = table.col[table.top];
     p2.tail++;
     table.top--;
    }
    break;
   }
  }
 
  if(i != 0)
  {
   system("cls");
   Sleep(400);
   printf("玩 ");
   Sleep(400);
   printf("家 ");
   Sleep(400);
   printf("2 ");
   Sleep(400);
   printf("贏 ");
   Sleep(400);
   printf("了 ");
   Sleep(400);
   printf("%d ", sum);
   Sleep(400);
   printf("張");
   Sleep(400);
   printf("牌 ");
   Sleep(400);
   printf("! ");
   Sleep(400);
   printf("! ");
   Sleep(400);
   printf("! ");
   Sleep(2000);
   system("cls");
  }
 }
 return;
}
 
void game()
{
 deal();
 getchar();
 
 while(p1.head != p1.tail && p2.head != p2.tail)
 {
  system("cls");
  int i;
  printf("玩家1 開始回合??!\n\n\n\n");
  printp1();
  printtable();
  printf("按回車來出牌\n");
  getchar();
  table.top++;
  table.data[table.top] = p1.data[p1.head];
  table.col[table.top] = p1.col[p1.head];
  p1.head++;
  printzzz();
 }
 
 if(p1.head == p1.tail)
 {
  printf("恭喜您取得了勝利!??!\n");
  printf("感謝使用本程序\n");
  system("pause");
 }
 else
 {
  printf("你沒有牌了!");
  printf("不好意思,您輸了。。。\n");
  printf("不要灰心,可以再來一局?。n");
  system("pause");
 }
 return;
}
 
void ask()
{
 char ch;
 
 system("cls");
 printf("你確定要退出?\n");
 printf("(輸入y確認對出)\n");
 printf("Y/N\n");
 scanf("%c", &ch);
 
 if(ch == 'y' || ch == 'Y')
 {
  exit(0);
 }
 else
 {
  return;
 }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 劍指offer之C語言不修改數(shù)組找出重復(fù)的數(shù)字

    劍指offer之C語言不修改數(shù)組找出重復(fù)的數(shù)字

    今天小編就為大家分享一篇關(guān)于劍指offer之C語言不修改數(shù)組找出重復(fù)的數(shù)字,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-02-02
  • C++計算圓形、矩形和三角形的面積

    C++計算圓形、矩形和三角形的面積

    這篇文章介紹了C++計算圓形、矩形和三角形面積的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • C++ 壓縮文件及文件夾方法 使用zlib開源庫

    C++ 壓縮文件及文件夾方法 使用zlib開源庫

    下面小編就為大家分享一篇C++ 壓縮文件及文件夾方法 使用zlib開源庫,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • VSCODE調(diào)試RDKit內(nèi)核的方法步驟(C++)

    VSCODE調(diào)試RDKit內(nèi)核的方法步驟(C++)

    本文主要介紹了VSCODE調(diào)試RDKit內(nèi)核的方法步驟,這個過程可以分為三個部分:安裝 RDKit 所需環(huán)境,安裝 VSCode 相應(yīng)插件, 寫調(diào)試代碼編譯,感興趣的可以了解一下
    2021-08-08
  • 一文讀懂C++中的繼承之菱形繼承(案例分析)

    一文讀懂C++中的繼承之菱形繼承(案例分析)

    這篇文章主要介紹了C++中的繼承之菱形繼承的相關(guān)知識,通過案例給大家詳細分析介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2021-04-04
  • Qt QFile文件操作的具體使用

    Qt QFile文件操作的具體使用

    很多應(yīng)用程序都需要具備操作文件的能力,Qt 框架提供了 QFile 類專門用來操作文件。本文就來詳細的介紹一下,感興趣的可以了解一下
    2021-11-11
  • C++中賦值運算符與逗號運算符的用法詳解

    C++中賦值運算符與逗號運算符的用法詳解

    這篇文章主要介紹了C++中賦值運算符與逗號運算符的用法詳解,是C++入門學習中的基礎(chǔ)知識,需要的朋友可以參考下
    2015-09-09
  • C語言實現(xiàn)學生檔案管理系統(tǒng)

    C語言實現(xiàn)學生檔案管理系統(tǒng)

    這篇文章主要為大家詳細介紹了C語言實現(xiàn)學生檔案管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • C++實現(xiàn)LeetCode(52.N皇后問題之二)

    C++實現(xiàn)LeetCode(52.N皇后問題之二)

    這篇文章主要介紹了C++實現(xiàn)LeetCode(52.N皇后問題之二),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • 快速模式匹配算法(KMP)的深入理解

    快速模式匹配算法(KMP)的深入理解

    本篇文章是對快速模式匹配算法(KMP)進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05

最新評論

巫山县| 化州市| 峨眉山市| 祁东县| 濮阳县| 江孜县| 和龙市| 威信县| 重庆市| 天镇县| 北流市| 东乡县| 毕节市| 通榆县| 延安市| 绵阳市| 资溪县| 秀山| 和平县| 弥渡县| 邻水| 宜丰县| 金华市| 杭锦后旗| 靖边县| 垫江县| 鄂托克旗| 来凤县| 错那县| 呼和浩特市| 灵璧县| 屏东市| 柘荣县| 汤阴县| 黔江区| 礼泉县| 莱西市| 加查县| 公主岭市| 浏阳市| 双牌县|