(完整word版)数据结构纸牌游戏c代码

合集下载

C语言程序设计21点扑克牌游戏

C语言程序设计21点扑克牌游戏

实用标准文案实验报告课程名称:C语言程序设计实验项目:21点扑克牌游戏设计专业班级:电子信息工程实验室号:信息205 实验组号:xx 实验时间:2010-5-4 批阅时间:指导教师:成绩:沈阳工业大学实验报告(适用计算机程序设计类)专业班级:电子信息工程0902 学号:姓名:实验名称:21点扑克牌游戏附件A 沈阳工业大学实验报告(适用计算机程序设计类)专业班级:电子信息工程0902 学号:姓名:实验步骤或程序:(我所做的程序是作弊程序改动已经加粗)#include<time.h>#include<stdio.h>#include<conio.h>#include<stdlib.h>void Wait_f(int);void Pause_f();/*暂停,按任意键继续*/int Random_f(long ,long );/*返回两个参数之间的随机数*/void Replay_f(char *);/*询问是否重开一局*/void Hit_f(int *);/*发一张牌*/void Deal_f(int *,int *,int *,int *);/*双方各发两张牌*/void Bet_f(int *,int *);/*接受下注的数目*/void Print_f(int ,int ,int ,int );/*打印结果*/void Rules_f();/*显示游戏规则*/void Results_f(int ,int ,int ,int *,int *,int *,int *);/*统计结果(输赢平)*/void Hit_f2(int * npTotal,int a);int nnn;int main(){int nPlayer=0,nCpu=0,nWin=0,nLose=0,nDraw=0,nPlayerTurns=0, nCpuTurns=0,nMoney=0,nBet;/* nPlayer——玩家手中全部牌的点数和,nPlayerTurns——玩家手中牌的数量*/char chAnswer;char mmm;int a;system("cls");/*执行系统命令“清屏”*/Rules_f();printf("\t\t\tWOULD YOU LIKE TO PLAY? ");scanf("%c",&chAnswer);if((chAnswer=='y')||(chAnswer=='Y')){printf("\t\t\tI WILL LET YOU START WITH $100\n");nMoney=100;printf("\t\t\t");Pause_f();}else{return(0);}do{system("cls");if(nMoney<0){printf("Your broke\n");return(0);}Bet_f(&nBet,&nMoney);/*接受下注的数目*/Deal_f(&nPlayer,&nCpu,&nPlayerTurns,&nCpuTurns);/*双方各发两张牌*/ printf("\t\t\tWould you want to cheat? yes or no?");scanf("%c",&mmm);if((mmm=='y')||(mmm=='Y')){printf("%d",nnn);printf("\t\t\twhich card do you want?");scanf("%d",&a);}system("cls");do{printf("\t\t\tWould You Like To Hit or Stay :");/*询问玩家是否接着要牌*/scanf(" %c",&chAnswer);if((chAnswer=='h')||(chAnswer=='H')){nPlayerTurns++;/*计算总牌数*/if(nPlayerTurns>5)/*看是否允许再要牌*/{printf("\t\t\tYou Can't Have more than 5 cards");}}if((nPlayerTurns<6)&&(chAnswer=='h')){printf("\n");if((mmm=='y')||(mmm=='Y'))Hit_f2(&nPlayer,a);else Hit_f(&nPlayer);/*为玩家发一张牌*/}}while((chAnswer=='h')||(chAnswer=='H'));for(;(nCpu<16)&&(nCpuTurns<6);nCpuTurns++)/*计算机要牌的条件*/{printf("\n");printf("\t\t\tThe Dealer Takes A Card");Hit_f(&nCpu);/*为计算机发一张牌*/}printf("\n\n");printf("\t\t\tThe Dealer Has A Total: %d\n", nCpu);/*显示总点数*/printf("\t\t\tYou Have A Total Of: %d\n", nPlayer);printf("\n");Results_f(nPlayer,nCpu,nBet,&nMoney,&nDraw,&nWin,&nLose);/*计算最后的结果(统计输赢平的局数)*/Replay_f(&chAnswer);/*询问是否重开一局*/}while((chAnswer=='y')||(chAnswer=='Y'));Print_f(nWin,nLose,nDraw,nMoney);/*打印最后结果*/printf("\n");printf("\t\t\t\t");return(0);}void Rules_f() /*这个函数显示游戏规则*/{printf("\t\t WELCOME TO ISAAC SHAFFERS BLACK JACK GAME\n");printf("\t\t\t HERE ARE SOME SIMPLE RULES\n");printf("\t\t\t1:You Can only have a max of 5 cards.\n");printf("\t\t\t2:If you bust you automatically lose.\n");printf("\t\t\t3:If you win you win double what you bet");printf("\t\t\t4:The Dealer stops at or after 16.\n");printf("\t\t\t\t");getchar();}void Bet_f(int* npBet,int* npMoney) /*该函数接受玩家下注,并计算赌资的总数*/{system("cls");printf("\t\t\tYOU HA VE:$%d\n",*npMoney);printf("\t\t\tHow Much Do You Wish To Bet:");scanf("%d",npBet);if(*npBet<0){*npBet=*npBet*(-1);}*npMoney=*npMoney-*npBet;}void Deal_f(int* npPlayer,int*npCpu,int*npPlayeReturns,int *npCpuReturns)/*该函数是给计算机与玩家各发两张牌*/{int nPlayerCard1,nPlayerCard2,nCpuCard1,nCpuCard2;*npPlayeReturns=2;*npCpuReturns=2;nPlayerCard1=Random_f(13,1);printf("\n\t\t\tDEALING HAND\n");getchar();Pause_f();nPlayerCard2=Random_f(13,1);Pause_f();nCpuCard1=Random_f(13,1);Pause_f();nCpuCard2=Random_f(13,1);if (nPlayerCard1>=10){nPlayerCard1=10;}if (nPlayerCard2>=10){nPlayerCard2=10;}if (nCpuCard1>=10){nCpuCard1=10;}if (nCpuCard2>=10){nCpuCard2=10;}*npPlayer=nPlayerCard1+nPlayerCard2;*npCpu=nCpuCard1+nCpuCard2;printf("\t\t\tYOU HA VE a total of:%d\n",*npPlayer);printf("[%d]", nPlayerCard1);printf("[%d]",nPlayerCard2);printf("\n");printf("\t\t\tThe DEALER HAS A %d SHOWING",nCpuCard1);printf("\n");printf("[*][%d]",nCpuCard1);nnn=nCpuCard2;}void Hit_f(int * npTotal) /* 发一张牌,返回点数之和*/{int nCard;nCard=Random_f(13,1);if(nCard>=10){nCard=10;}* npTotal=* npTotal+nCard;printf("\t\t\tThe card is a :%d\n", nCard);printf("\t\t\tTotal is :%d\n", * npTotal);}void Results_f(int nPlayer,int nCpu,int nBet,int * npMoney,int * npDraw,int* npWin,int * npLose)/*统计结果(输赢平及输赢平的局数)*/ {if(nCpu==nPlayer){printf("\t\t\tIT WAS A DRAW HOUSE WINS\n");++* npDraw;}if(nPlayer>21){printf("\t\t\tYou Bust\n");++* npLose;}else{if(nCpu<nPlayer){printf("\n\t\t\tYOU WIN");*npMoney=*npMoney+(nBet*2);++* npWin;}}if(nCpu>21){printf("\t\t\tDealer Bust\n");if(nPlayer<=21){printf("\n\t\t\tYOU WIN");++* npWin;*npMoney=*npMoney+(nBet*2);}}else{if(nCpu>nPlayer){printf("\t\t\tYOU LOSE\n");++* npLose;}}}void Replay_f(char *chpAns) /*询问是否重开一局*/ {printf("\n\t\tWould You Like To Play This Game Again:");scanf("%c",chpAns);}void Print_f(int nWins,int nLose,int nDraw,int nMoney){printf("\t\t\t\tWINS:%d\n", nWins);printf("\t\t\t\tLOSE:%d\n", nLose);printf("\t\t\t\tDRAWS:%d\n",nDraw);printf("\t\t\t\tMONEY:%d\n",nMoney);}void Wait_f(int nMilli){int nStart1,nStart2;for(nStart1=0;nStart1<nMilli*100;nStart1++)for(nStart2=0;nStart2<nMilli*100;nStart2++){;}}void Pause_f(){printf("Press Any Key To Continue");getchar();}int Random_f(long lBigNumber, long lSmallNumber) /*选择两个参数之间的随机数*/{int nRan;srand((unsigned)time(NULL));nRan=rand()%(lBigNumber-(lSmallNumber-1))+lSmallNumber;return(nRan);}void Hit_f2(int * npTotal,int a) /* 发一张牌,返回点数之和*/{int nCard;nCard=a;if(nCard>=10){nCard=10;}* npTotal=* npTotal+nCard;printf("\t\t\tThe card is a :%d\n", nCard);printf("\t\t\tTotal is :%d\n", * npTotal);}。

扑克牌小游戏c++代码

扑克牌小游戏c++代码

#include <iostream.h>#include <string.h>#include <conio.h>#include <stdlib.h>#include <stdio.h>#include <time.h>class Playing_Card{private:int m_Value;char m_Face[3];char m_Suit ;public:Playing_Card();void showcard();void Card_Make(int);};class Deck{private:Playing_Card m_cardarray[54];int m_lastdelt;public:Deck();void MakeDeck() ;void Deal_One();void ShowDeck();void DeckShuff(int);void Remove_Card();void Senddeck();};void Program_Init();int main();void Center_Text(char []);int get_number();char Get_Key();void DeckMakeDriver();int getRandInt(int min, int max); void prog_close();int main()srand( (unsigned)time( NULL ) );int Card_Number = 0;Program_Init();DeckMakeDriver();prog_close();//退出return 1;}Playing_Card::Playing_Card(){int i;for(i=1;i<=3;){m_Face[i] = ' ';i++;}m_Suit = ' ';m_Value = 0;}//******************************************************************* void Program_Init()//显示初始界面{Center_Text("C++课程设计实验报告");cout << endl;cout<<endl;Center_Text("扑克牌相关");cout << endl <<"\n" ; cout<<endl;Center_Text("设计:郇志伟");cout << endl <<"\n" ;cout<<endl;Center_Text("2006-9-20");cout << endl <<"\n" ;Center_Text("Hit the <Enter> key to Continue..");cin.get();}//******************************************************************* char Get_Key(){char x;x = cin.get();cout << endl;return x;}void Playing_Card::showcard(){cout << " ";cout << m_Face ;cout.width(1);cout << m_Suit;cout << " ";}//******************************************************************* void Center_Text(char ShellText[80]){int length;int center;length= strlen(ShellText);center = (80 - length)/2;for(;center!=0;center--){cputs(" ");}cputs(ShellText);}int get_number(){int Input_Integer = 0;Center_Text("Please enter an integer between 0 and 53. 54to quit.");cout << endl;cin >> Input_Integer;return Input_Integer;}//******************************************************************* void Playing_Card::Card_Make(int num){int i = 0;char j;if(num==53){strcpy(m_Face,"jo");m_Suit='2';m_Value=15;}if(num==52){strcpy(m_Face,"jo");m_Suit='1';m_Value=14;}if(num<=51){int face_num = num % 13;switch(face_num){case 0: strcpy(m_Face," A");break;case 9: strcpy(m_Face,"10");break;case 10: strcpy(m_Face," J");break;case 11: strcpy(m_Face," Q");break;case 12: strcpy(m_Face," K");break;default:j = char(face_num + 49);if(i<3){m_Face[i] = ' '; i++;m_Face[i] = j;i++;m_Face[i] = NULL;break;}}if(num <= 12)m_Suit = 6;if(num >12 && num <= 25)m_Suit = 3;if(num >25 && num <= 38)m_Suit = 5;if(num >38 && num <= 51)m_Suit = 4;if(face_num <= 9)m_Value = face_num + 1;if(face_num >= 10)m_Value = 10;}}//******************************************************************* void DeckMakeDriver(){Deck deck_1;deck_1.MakeDeck();//创建一副扑克deck_1.ShowDeck();//显示一副扑克Get_Key();deck_1.DeckShuff(250);//洗牌deck_1.ShowDeck();//显示一副扑克Get_Key();deck_1.Senddeck();//依次分发给4个人并显示Get_Key();cout << endl <<endl << endl;char y;do{deck_1.Deal_One();//删除一张牌cout << endl;cout << endl << endl << "Y to Deal One more N to quit"<< endl;cin >> y;y = toupper(y);}while(y == 'Y' );}//******************************************************************* void Deck::MakeDeck() //创建一副扑克{m_lastdelt = 53;while(m_lastdelt >-1){m_cardarray[m_lastdelt].Card_Make(m_lastdelt);m_lastdelt--;}}//******************************************************************* void Deck::ShowDeck() //显示一副扑克{int index = m_lastdelt + 1;int newline = 0;Center_Text("Current Deck of Cards from top to bottom");cout << endl;while(index<=53){if(newline % 11== 0) cout << endl;m_cardarray[index].showcard();newline++;index++;}cout<<endl;}//*******************************************************************int getRandInt(int min, int max){int numToReturn;numToReturn = rand();numToReturn = numToReturn % (max - min + 1) + min;return numToReturn;}//******************************************************************* void Deck::DeckShuff( int times) //洗牌{int x, split;Center_Text("Shuffling Deck");cout << endl;for(x=0;x<=times;x++){split = getRandInt(20,35);Deck topdeck;Deck bottomdeck;int i;int bottomdeckindex = 1;int topdeckindex = 1;for(i=0;i<=split - 1;){topdeck.m_cardarray[topdeckindex] = this->m_cardarray[i];topdeckindex++;i++;}for(i=(split);i< 54;){bottomdeck.m_cardarray[bottomdeckindex] = this->m_cardarray[i];bottomdeckindex++;i++;}int deckoutindex = 0;int numcardstomovetop;int numcardstomovebottom;int j;int h = 0;bottomdeckindex = 54 - split;topdeckindex =split;while(deckoutindex <= 53){numcardstomovetop = getRandInt(2,7);numcardstomovebottom = getRandInt(2,7);for(j=0;j <=numcardstomovebottom;j++){if(bottomdeckindex > 0){this->m_cardarray[deckoutindex] = bottomdeck.m_cardarray[bottomdeckindex];deckoutindex++;bottomdeckindex--;}for(h=0;h<=numcardstomovetop;h++){if((topdeckindex > 0) && (deckoutindex <=54)){this->m_cardarray[deckoutindex]=topdeck.m_cardarray[topdeckindex];deckoutindex++;topdeckindex--;}}}}}this->m_lastdelt = -1;}//*******************************************************************void Deck::Senddeck()//依次分发给4个人并显示{int m_player,n_player;int player1=0,player2=0,player3=0,player4=0;this->m_lastdelt=53;Playing_Card playeri[2][14];Playing_Card playerj[2][13];int time=0;while(time<13){m_player=0,n_player=0;playeri[m_player][player1]=this->m_cardarray[m_lastdelt];m_player++;player1++;m_lastdelt--;playeri[m_player][player2]=this->m_cardarray[m_lastdelt];player2++;m_lastdelt--;playerj[n_player][player3]=this->m_cardarray[m_lastdelt];n_player++;player3++;m_lastdelt--;playerj[n_player][player4]=this->m_cardarray[m_lastdelt];player4++;m_lastdelt--;time++;}playeri[0][13]=this->m_cardarray[1];playeri[1][13]=this->m_cardarray[0];for(int i=0;i<=3;i++){cout<<"player"<<i+1<<":";if(i<=1){for(int j=0;j<=13;j++){playeri[i][j].showcard();}}else{for(int j=0;j<=12;j++){playerj[i-2][j].showcard();}}cout<<'\n';}}//******************************************************************* void prog_close()//退出{cout << endl << endl;cout << " Hit the <Enter> key to Continue.." << endl;cout << endl << endl;Get_Key();cin.get();}//******************************************************************* void Deck::Remove_Card()//删除一张牌。

C课程设计点纸牌游戏程序

C课程设计点纸牌游戏程序
wait(500);
cout<<"["<<playercard1<<"]";
cout<<"["<<playercard2<<"]";
if(playercard1>10).){
cout<<"你的输入有误!:(请重新输入"<<endl;
m=2;
}
}while(m!=0);
if((ans=='h')||(ans=='H'))
}
}
//-----------------------------------------------------------------
void Game::hit2()//确保庄家不会爆庄并且点数大于16
{
int card=0,copycard=0;
float cards=0;
card=random(13,1);//调用函数
C课程设计点纸牌游戏程序
#include<>
#include<>
#include<>
#include<>
#include<>
#include<>
class Game
{
public:
Game()
{
win=0,lose=0,draw=0,playerturns=0,cputurns=0,money=100,bet=0;
void Game::replay(char &ans)//是否继续游戏

数据结构与算法课设-纸牌游戏21点

数据结构与算法课设-纸牌游戏21点

目录备注: (2)一、游戏简介 (2)二、设计要求 (2)2.1 问题描述 (2)2.2 要求分析 (2)三、程序功能 (3)3.1 程序的主要功能描述 (3)3.2序流程图 (3)3.3主界面 (4)3.4功能测试 (4)四、源程序 (6)五、课设心得 (14)备注:由于这次课设开始时以为可以做其他题目,知道周四才知道不行。

但我的21点一几个基本成型,因此没有继续改动,希望老师能够理解。

一、游戏简介又名黑杰克,起源于法国,现已流传到世界各地。

现在在世界各地的赌场中都可以看到二十一点,随着互联网的发展,二十一点开始走向网络时代,比如菲律宾的博彩公司就有该游戏。

该游戏由 2 到 6 个人玩,使用除大小王之外的52 张牌,游戏者的目标是使手中的牌的点数之和不超过 21 点且尽量大。

有着悠久的历史。

1700年左右法国赌场就有这种21点的纸牌游戏。

1931年,当美国内华达州宣布赌博为合法活动时,21点游戏第一次公开出现在内华达州的赌场俱乐部,15年内,它取代掷骰子游戏,而一举成为非常流行的赌场庄家参与的赌博游戏。

二、设计要求编写程序实现游戏,该程序是模拟古老的“21点纸牌游戏”,实现一对一的人机大战。

要求游戏过程中任意一方牌的点数之和超过 21 点,则自动出局;在不超过 21 点的情况下,玩家下注由电脑随机发牌与庄家比累积牌的点数的大小,大者为赢家。

2.1 问题描述本次C++课程设计题目是“21点纸牌游戏”,系统的主要功能是娱乐游戏,有电脑和玩家一起玩这个游戏,玩家设法使自己的牌达到总分21并要比电脑开的点数大而且不超过这个数值。

扑克牌的分值取它们的面值。

J,Q,K分别是11, 12和13分。

2.2 要求分析编写程序实现游戏,该程序是模拟古老的“21点纸牌游戏”,实现1对1的人机大战。

要求游戏过程中任意一方牌的点数之和超过21点,则自动出局;在不超过21点的情况下,玩家下注由电脑随机发牌与庄家比累积牌的点数的大小,大者为赢家。

数据结构课程设计报告—纸牌游戏

数据结构课程设计报告—纸牌游戏

课题设计2:扑克牌游戏1、问题描述编号为1-52张牌,正面向上,从第2张开始,以2为基数,是2的倍数的牌翻一次,直到最后一张牌;然后,从第3张开始,以3为基数,是3的倍数的牌翻一次,直到最后一张牌;然后…从第4张开始,以4为基数,是4的倍数的牌翻一次,直到最后一张牌;...再依次5的倍数的牌翻一次,6的,7的直到以52为基数的翻过,输出:这时正面向上的牌有哪些?存储结构:源程序:#include <stdio.h>void main(){int i,j,a[52];for(i=2;i<=52;i++)for(j=i-1;j<52;j+=i)a[j]=!a[j];printf("正面向上的牌有:");for(i=0;i<52;i++)if(a[i])printf("%4d",i+1);}测试结果:正面向上的牌有:1 4 9 16 25 36 49算法的时间复杂度:T(n)=O(n2)课题设计3:joseph环一. 需求分析:利用单向循环链表存储结构模拟此过程,按照出列的顺序输出各个人的编号。

首先创建一个空链表,初始化链表,构造出一个只有头结点的空链表,建立好一个约瑟夫环。

1. 输入的形式和输入值的范围本程序中,输入报数上限值m和人数上限l,密码,均限定为正整数,输入的形式为一个以“回车符”为结束标志的正整数。

2. 输出的形式从屏幕显示出列顺序。

3. 程序功能提供用户从键盘输入,Joseph约瑟夫环的必要数据,并显示出列顺序。

二、概要设计以单向循环链表实现该结构。

1. 抽象数据类型的定义为:ADT LNode{数据对象:D={ai | ai∈CharSet,i= 1,2,…,n,n≥0}数据关系:R1={&lt; ai-1 ,ai &gt; | ai ∈D,I=2,…,n} 三.源程序:#include<stdio.h>#include<stdlib.h>typedef struct Node{int key;//每个人持有的密码int num;//这个人的编号struct Node *next;//指向下一个节点}Node,*Link;void InitList(Link &L) //创建一个空的链表{L=(Node *)malloc(sizeof(Node));if(!L) exit(1);L->key=0;L->num=0;L->next=L;}void Creater(int n,Link &L) //初始化链表{Link p,q;q=L;for(int i=1;i<=n;i++){p=(Node *)malloc(sizeof(Node));if(!p) exit(1);printf("the key_%d is:",i);scanf("%d",&p->key);p->num=i;L->next=p;L=p;}L->next=q->next;free(q);}void main(){Link L,p,q;int n,x;L=NULL;InitList(L);//构造出一个只有头结点的空链表printf("please input the totle number of people:"); scanf("%d",&n);//总共的人数nprintf("the start key is:");scanf("%d",&x);//初始密码为xCreater(n,L);//建立好一个约瑟夫环p=L;for(int i=1;i<=n;i++){for(int j=1;j<x;j++)p=p->next;q=p->next;x=q->key;printf("%d ",q->num);p->next=q->next;free(q);}}四、测试数据:m的初值为20,n=7 ,7个人的密码依次为3,1,7,2,4,7,4输出:6 7 4 1 5 3 2课题设计4:商品货架管理1、需求分析:设计一个算法,每一次上货后始终保持生产日期越近的商品越靠近栈底。

C++课程设计扑克牌游戏

C++课程设计扑克牌游戏

//*******************preprocessor directives***********************#include <iostream.h>#include <string.h>#include <conio.h>#include <stdlib.h>#include <stdio.h>#include <time.h>// used to seed the random number generator//*******************************扑克类**************************************** class Playing_Card{friend class PerDeck;public:int m_Value; //扑克的实际面值,用整型值表示,从1开始,1~13char m_Face[3]; //扑克的数字大小,用字符串的形式表示,为A,2,3,....,10,J,Q,K int order;char m_Suit; //扑克的花色(黑、红、梅、方)public:Playing_Card();// 构造函数,初始化扑克牌对象,实际上是将对象清零void showcard();// 显示扑克牌对象的面值,花色void Card_Make(int); //为一张扑克牌对象赋予特定的面值和花色void AskPaidui(); //询问是否进行扑克小人游戏void Paidui(); //扑克小人排序游戏int getCount();};//*************************** 一副扑克(54张)**************************class Deck{friend class PerDeck;friend class PlayDEck;public:Playing_Card m_cardarray[54],temp;// 一副扑克牌有54张扑克牌组成(包括大小王)int m_lastdelt; //标记这副扑克牌删除的张数public:Deck();// 构造函数,初始化一副扑克牌对象,实际上是将其内的54张扑克牌清零void MakeDeck();// 生成一副扑克,即对其内的54张扑克牌赋予正确的面值及花色void ShowDeck();// 显示余下的所有的扑克牌void DeckShuff(int);// 洗牌,其参数是洗牌的次数//void Remove_Card();// 将删除的那张扑克牌的内容清零,使这张牌在屏幕上显示不出来};//mistakenly using a nonexistant card//can bu used to send a card ??//************************某个人拿的牌******************************class PerDeck{public:Playing_Card m_Card[20],temp;//最多有20张牌int nNum;//实际张数PerDeck(){}void MakePerDeck(Deck&,int);//对象初始化,参数为指定的那副牌及实际赋值个数void Show();// 显示void SortFace();//按面值排序void SortSuit();//按花色排序void Delete(int n);//删除序号为n的那一张};//*********************************四个人玩牌的过程****************************************class PlayDeck{public :PerDeck m_deck[4];//一共是4个人玩牌int delt,sort;public:PlayDeck(){}void PlayCard(Deck&);//用指定的那副牌对四个人分别赋值void ShowAll();// 显示void DeleteOne(int row,int column);//删除一张,参数为第row个人的第column 那一张void DeleteAll(int,int,int,int);//删除一轮,参数分别代表4个人各删除哪一张void SortDeckFace();//对整副牌按面值排序void SortDeckSuit();//对整副牌按花色排序void AskSort();//询问排序方法void AskDelete();//询问删除方法int get_int(); //获得一个整数};//*************************************************//***************************prototypes**********************************void Program_Init();// 程序初始化,输出初始化信息int main();void Center_Text(char []);// 将参数(字符串)显示在屏幕的中间int get_number();// 接收用户输入的数值,作为函数值返回int choose_number();//判断选择是删除一张还是一轮的办法char Get_Key();// 获得一个字符,作为函数值返回void DeckMakeDriver();// 主要算法,调用多个函数,执行声成牌,洗牌删除等操作int getRandInt(int min, int max);// 取得两参数见的随机值void prog_close();// 暂停程序运行,查看中间运行结果char continue_quit();//****************************Main*************************************int main(){srand( (unsigned)time( NULL ) );// 初始化随机数种子int Card_Number = 0;Program_Init();// 显示程序初始化信息DeckMakeDriver();// 调用函数的主要算法,包含程序的主要操作过程prog_close();// 暂停程序的运行,供用户查看运行结果return 1;// 结束}Deck :: Deck()// 初始化一副牌,将54张牌清零{int lastdelt = 0;int i;for(i=0;i<=53;i++){m_cardarray[i] = Playing_Card();//构造一个临时对象赋值}}void Deck::DeckShuff( int times) //洗牌,参数为次数{int x, split; //split是分开成两部分的位置,如上部分、下部分Center_Text(" 开始洗牌……");cout << endl;for(x=0;x<=times;x++)// 开始循环,每循环一次将牌全部重排一遍{split = getRandInt(20,35);// 随机选取split的值Deck topdeck;// 生成两副扑克牌对象Deck bottomdeck;int i;int bottomdeckindex = 1;int topdeckindex = 1;for(i=0;i<=split - 1;)//将初始的那副牌的上边部分的张数赋值到新生成的牌的对象中{topdeck.m_cardarray[topdeckindex] = this->m_cardarray[i];topdeckindex++;i++;}for(i=(split);i< 54;)// 将下边的部分的张数赋值到新生成的对象中{bottomdeck.m_cardarray[bottomdeckindex] = this->m_cardarray[i];bottomdeckindex++;i++;}int deckoutindex = 0;int numcardstomovetop;int numcardstomovebottom;int j;int h = 0;bottomdeckindex = 54 - split;//下部分扑克牌的张数topdeckindex =split;// 上部分扑克牌的张数while(deckoutindex <= 53){numcardstomovetop = getRandInt(2,7);//从上部分抽取的张数,是2-7之间的随机数numcardstomovebottom = getRandInt(2,7);// 在下部分扑克牌中随机选择2~7之间的随机数/*将下部分的牌赋值给原来的那副牌*/for(j=0;j <=numcardstomovebottom;j++)//从0开始循环numcardstomovebottom 次{if(bottomdeckindex > 0) //当下部分那副牌没有循环完时继续{ /*从下部分那副牌的最后张数开始,依次向c初始的扑克牌赋值*/this->m_cardarray[deckoutindex] = bottomdeck.m_cardarray[bottomdeckindex];deckoutindex++;bottomdeckindex--;}for(h=0;h<=numcardstomovetop;h++)//下部分的扑克牌赋值完成后,对上部分的牌进行同样的操作{if((topdeckindex > 0) && (deckoutindex <=54)){this->m_cardarray[deckoutindex]=topdeck.m_cardarray[topdeckindex];deckoutindex++;topdeckindex--;}}}}}Center_Text(" 完成洗牌");cout<<endl;this->m_lastdelt = -1; //将删除牌的张数复原为-1(未删除)}void Deck::MakeDeck()// 对一副牌逐一赋值{m_lastdelt = 53;// 赋初值,该值作为生成每张扑克牌的参数while(m_lastdelt >-1)// 判断是不是生成了54张牌{m_cardarray[m_lastdelt].Card_Make(m_lastdelt); // 调用Card——Make,对牌赋值,完成一副牌m_lastdelt--;// 生成一张牌后改变生成的参数}}void Deck::ShowDeck()//显示一副扑克牌牌{int index = m_lastdelt + 1; //以此位置为第一张牌,从头显示这副牌Center_Text("完整的一副牌");cout << endl;while(index<=53){if(index % 11 == 0) cout << endl; //每显示11张牌回车m_cardarray[index].showcard();// 按数组的顺序依次显示index++;}cout<<endl;}void PerDeck::Delete(int n)//删除序号为n的那张牌{temp=m_Card[n];for(n;n<nNum;n++)m_Card[n]=m_Card[n+1];m_Card[nNum]=Playing_Card();nNum -=1;}void PerDeck::MakePerDeck(Deck&,int nNum)//对象初始化{}void PerDeck::Show()//显示{int i=0;for(i;i<nNum;i++){if(i==10)cout<<endl<<" ";m_Card[i].showcard();}cout<<endl;}void PerDeck::SortFace()//按面值排序{int i,j=0;for(j;j<nNum-1;j++){for(i=0;i<nNum-j-1;i++){if(m_Card[i].m_Value>m_Card[i+1].m_Value){temp=m_Card[i];m_Card[i]=m_Card[i+1];m_Card[i+1]=temp;}}}}void PerDeck::SortSuit()//按花色排序{int i,j=0;for(j;j<nNum-1;j++)for(i=0;i<nNum-j-1;i++){if(m_Card[i].m_Suit > m_Card[i+1].m_Suit){temp=m_Card[i];m_Card[i]=m_Card[i+1];m_Card[i+1]=temp;}}}}void PlayDeck::AskDelete()//询问删除方法{cout<<endl;cout<<"删除一张,请选择1;"<<endl;cout<<"删除一轮,请选择2;"<<endl;cout<<"退出,选择3;"<<endl;delt=get_int();switch(delt){case 1:Center_Text("输入要删除第row人的第column张牌");cout<<"输入row,column,用空格隔开: ";int row,column;cin>>row>>column;if(row>0&&row<5){if(column>0&&column<=m_deck[row-1].nNum){DeleteOne(row,column);break;}else PlayDeck::AskDelete();}else PlayDeck::AskDelete();case 2:Center_Text("依次输入要删除4个人的第a,b,c,d张牌");cout<<"输入a,b,c,d,用空格隔开"<<endl;int a,b,c,d;cin>>a>>b>>c>>d;if(a>0 && a<=m_deck[0].nNum){if(b>0 && b<=m_deck[1].nNum){if(c>0 && c<=m_deck[2].nNum){if(d>0 && d<=m_deck[3].nNum){DeleteAll(a,b,c,d);break;}else PlayDeck::AskDelete();}else PlayDeck::AskDelete();}else PlayDeck::AskDelete();}else PlayDeck::AskDelete();case 3:exit (0);default:Center_Text("输入错误,请选择一种删除方法或退出");PlayDeck::AskDelete();}}void PlayDeck::AskSort(){int end_of=0,player=0;for(player;player<4;player++){if(m_deck[player].nNum==0){cout<<"玩家"<<player+1<<"没有牌了。

纸牌记忆小游戏C语言源代码

纸牌记忆小游戏C语言源代码

纸牌记忆小游戏C语言源代码#include#include#includeintoutputacard(inta,int b) //输出一张扑克{if(b==11){printf("[%c",a); //Jprintf("%c]",b+63);}else if(b==12){printf("[%c",a); //Qprintf("%c]",b+69);}else if(b==13){printf("[%c",a); //Kprintf("%c]",b+62);}else if(b==1){printf("[%c",a); //Aprintf("%c]",b+64);}else if(b==88)printf("[%c%c]",a,b); //XXelse{printf("[%c",a); //随机输出8张扑克printf("%d]",b);}}int main(){int puke[8][2];inti,j,k;srand((unsigned int)time(NULL));printf("记住下面牌的顺序\n准备好了按<回车>,我会提问你的^-^\n");for(i=0; i<8; i++)for(j=0; j<2; j++){if(j==0)puke[i][j]=3+rand()%3; /*红心是003 方块004 梅花005 黑桃006*/elsepuke[i][j]=1+rand()%12; //A……K}for(k=0; k<8; k++)outputacard(puke[k][0],puke[k][1]); //随机输出8张扑克printf("\n");int puke2[8][2];int puke0[2];intt,rh;for(t=0; t<8; t++){puke2[t][0]=puke[t][0];puke2[t][1]=puke[t][1];}for(t=0; t<8; t++) /*把上面的8张扑克打乱顺序存入另一个数组*/{rh=rand()%7;if(rh!=t){puke0[0]=puke2[t][0];puke0[1]=puke2[t][1];puke2[t][0]=puke2[rh][0];puke2[t][1]=puke2[rh][1];puke2[rh][0]=puke0[0];puke2[rh][1]=puke0[1];}}for(k=0; k<8; k++)outputacard(puke2[k][0],puke2[k][1]); /*打乱顺序后重新输出8张扑克*/ printf("\n");int puke3[8][2],puke4[8][2];for(i=0; i<8; i++) /*为把上面代表两组扑克的数组puke,puke2复制到另外*/for(j=0; j<2; j++) /*两个数组puke3、puke4中,以方便后面输出*/for(j=0; j<2; j++){puke3[i][j]=88;puke4[i][j]=88;}system("pause");system("CLS");inta,b,num=0;int alp1[8]= {0,0,0,0,0,0,0,0},alp2[8]= {0,0,0,0,0,0,0,0}; /* 记录各个位置的牌是否翻开*/while(alp1[0]==0||alp1[1]==0||alp1[2]==0||alp1[3]==0||alp1 [4]==0||alp1[5]==0||alp1[6]==0||alp1[7]==0){printf("依次输入第一行、第二行两张相同的牌的位置\n");for(k=0; k<8; k++)outputacard(puke3[k][0],puke3[k][1]);printf("\n");for(k=0; k<8; k++)outputacard(puke4[k][0],puke4[k][1]);printf("\n");scanf("%d%d",&a,&b);num++;system("CLS");if(puke[a-1][0]==puke2[b-1][0]&&puke[a-1][1]==puke2[b-1][1]&&alp1[a-1]!=1&&alp2 [b-1]!=1&&a>=1&&a<=8&&b>=1&&b<=8){/*如果两张牌相同且没有被翻开过且输入的数字大于0小于8复制puke,puke2中这两个元素的数据到puke3,puke4中,并输出puke3,puke4*/puke3[a-1][0]=puke[a-1][0];puke3[a-1][1]=puke[a-1][1];alp1[a-1]++;puke4[b-1][0]=puke2[b-1][0];puke4[b-1][1]=puke2[b-1][1];alp2[b-1]++;printf("猜对了,厉害!\n");for(k=0; k<8; k++)outputacard(puke3[k][0],puke3[k][1]);printf("\n");for(k=0; k<8; k++)outputacard(puke4[k][0],puke4[k][1]);printf("\n");system("pause");system("CLS");}else if(alp1[a-1]!=1&&alp2[b-1]!=1&&a>=1&&a<=8&&b>=1&&b<=8){/*如果两张牌不相同但没有被翻开过且输入的数字大于0小于9输出原puke3,puke4并显示该位置正确的牌*/printf("你好像记错了,再想想,我相信你!\n");for(i=0; i<8; i++){if(i==a-1)outputacard(puke[i][0],puke[i][1]);elseoutputacard(puke3[i][0],puke3[i][1]);}printf("\n");for(k=0; k<8; k++){if(k==b-1){outputacard(puke2[k][0],puke2[k][1]);}elseoutputacard(puke4[k][0],puke4[k][1]);}printf("\n");system("pause");system("CLS");}else if(a>=1&&a<=8&&b>=1&&b<=8) /*如果这两张牌中任意一张已经被翻开,输出如下*/{printf("这两张牌中的某一张好像已经被你翻开了哦\n");for(k=0; k<8; k++)outputacard(puke3[k][0],puke3[k][1]);printf("\n");for(k=0; k<8; k++)outputacard(puke4[k][0],puke4[k][1]);printf("\n");system("pause");system("CLS");}else{printf("每行只有8张牌呦,请输入正确的位置,么么哒\n");for(k=0; k<8; k++)outputacard(puke3[k][0],puke3[k][1]);printf("\n");for(k=0; k<8; k++)outputacard(puke4[k][0],puke4[k][1]);printf("\n");system("pause");system("CLS");}}printf("你一共猜了%d次\n",num);if(num==8)printf("完美\n");else if(num>8&&num<=10)printf("非常棒!\n");else if(num>10&&num<=16)printf("你的记忆力挺不错的!\n");elseprintf("你的记忆力一般般啦,再练练吧!\n"); system("pause"); return 0;}。

斗地主C语言源代码(草版)

斗地主C语言源代码(草版)

斗地主C语言程序模仿版,不完善。

求完善并分享。

/*////////////////////////////////////////////////////////////////////////////////////////////////////////////目前还存在的一些问题:1.玩家不能出连的三代;2.电脑一次只能出一张牌;3.电脑2不能作为地主,而且电脑2现在不能把牌全部出完,我估计是在循环是调用指针时候空指针没有处理好;4.玩家不能自主的选择pass.5.图形这次做的很成功但是当时做动态选择牌的时候失败了,否则效果应该与QQ斗地主一样的。

以上问题由于时间问题没有进一步改进。

希望同道中人完善,交流。

////////////////////////////////////////////////////////////////////////////////////////////////////////////*/#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>#include <malloc.h>#include <bios.h>#define UP 18432 /*向上的键盘输入标志*/#define DOWN 20480 /*向下的键盘输入标志*/#define LEFT 19200 /*向左的键盘输入标志*/#define RIGHT 19712 /*向右的键盘输入标志*/int bkcol, x, y;int a[54];int b[54];int flag[20] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; /* flag[i] == 1表示第i张牌还没有出, flag[i] == 0表示这张牌这次之前就出出去了, flag[i] == -1表示这张牌在本次中出出去了 */char card_value[26] = {'3', '\0', '4', '\0', '5', '\0', '6', '\0', '7', '\0', '8', '\0', '9', '\0', '0', '\0', 'J', '\0', 'Q', '\0', ' K', '\0', 'A', '\0', '2', '\0'};/*加一个'\0'是为了后面以字符串格式输出*/struct card_node *s1 = NULL, *s2 = NULL;struct card_node *com1;struct card_node *com2;struct card_node{int kind;int num;struct card_node *next;}card[54];void first_look (){settextjustify(CENTER_TEXT, CENTER_TEXT); cleardevice();x = getmaxx() / 2;y = getmaxy() / 2;setcolor (RED);settextstyle (GOTHIC_FONT, 0, 8);outtextxy (x, y - 70, "Lord Card");settextstyle (3, 0, 1);outtextxy (x + 110, y + 40, "Produced By Li Chao"); outtextxy (x + 110, y + 80, "Version 1.00");getch ();}void table (int x1, int y1){settextjustify(CENTER_TEXT, CENTER_TEXT); bkcol = BLACK; /*MAGENTA*/cleardevice();setbkcolor(bkcol);setfillstyle (SOLID_FILL, LIGHTRED);bar (x1 - 140, y1 - 45, x1 + 136, y1 + 40);setcolor (WHITE);rectangle (x1 - 141, y1 - 46, x1 + 137, y1 + 41);moveto (x1 , y1 - 8);settextstyle (GOTHIC_FONT, 0, 6);outtext ("Lord Card");}void delete_table (int x1, int y1){setfillstyle (SOLID_FILL, BLACK);bar (x1 - 141, y1 - 46, x1 + 137, y1 + 41);}void operation (int t){settextstyle (3, 0, 2);switch (t){case 1:setcolor (RED);outtextxy (x - 10, 20, "START");outtextxy (x - 10, 50, "ABOUT PRODUCER"); outtextxy (x - 10, 80, "EXIT");break;case 2:setcolor (WHITE);outtextxy (x - 10, 20, "START");outtextxy (x - 10, 80, "EXIT");setcolor (RED);outtextxy (x - 10, 50, "ABOUT PRODUCER"); break;case 3:setcolor (WHITE);outtextxy (x - 10, 20, "START");outtextxy (x - 10, 50, "ABOUT PRODUCER"); setcolor (RED);outtextxy (x - 10, 80, "EXIT");break;}}int choose_operation (){int key, t = 1;operation (1);while (1){while ( bioskey(1) == 0 );key = bioskey(0);switch (key){case UP:if (t == 1)operation (t);elseoperation (--t);break;case DOWN:if (t == 3)operation (t);elseoperation (++t);break;case LEFT:break;case RIGHT:break;default :return t;}void init_graph (){int gdriver = EGA, gmode = EGAHI, errorcode;/* registerbgidriver(EGAVGA_driver); */initgraph(&gdriver, &gmode, "");errorcode = graphresult();if (errorcode != grOk){printf("Graphics error: %s", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1);}}void player_name(){setcolor (RED);settextstyle (3, 0, 1);outtextxy (x - 260, 10, "COMPUTER 1 :");outtextxy (x + 256, 10, "COMPUTER 2 :");outtextxy (x - 180, y + 55, "PLAYER :");}void init_card (){int i, j;for (i = 0; i <= 3; i++)for (j = 13 * i; j < 13 * i + 13; j++){card[j].kind = i;card[j].num = j - i * 13;if (card[j].num == 7)card[j].card = "10";elsecard[j].card = & card_value[2 * (j - i * 13)];card[j].next = NULL;}card[52].kind = 5;card[53].kind = 4;card[52].num = 13;card[53].num = 14;card[52].card = "JOKER";card[53].card = "JOKER";card[53].next = NULL;struct card_node * back_up (struct card_node *head) /* 用来备份用的*/{struct card_node *p, *head1, *q;head1 = (struct card_node *) malloc (sizeof (struct card_node));head1 -> kind = head -> kind;head1 -> num = head -> num;head1 -> card = head -> card;head1 -> next = NULL;for (p = head -> next, q = head1; p != NULL; p = p -> next){q -> next = (struct card_node *) malloc (sizeof (struct card_node));q = q -> next;q -> kind = p -> kind;q -> num = p -> num;q -> card = p -> card;q -> next = NULL;}return head1;}void card_drawn (int x, int y, int kind, int num, int color) /*传递坐标和牌的花色以及大小,宽60,高80*/{char str[6];setfillstyle (SOLID_FILL, color);bar (x - 30, y - 40, x + 30, y + 40);setcolor (BLUE);rectangle (x - 29, y - 39, x + 29, y + 39);switch (kind){case 0:setcolor (RED);sprintf (str, "%c", 3);break;case 1:setcolor (RED);sprintf (str, "%c", 4);break;case 2:setcolor (BLACK);sprintf (str, "%c", 3);break;case 3:setcolor (BLACK);sprintf (str, "%c", 5);break;case 5:setcolor (LIGHTGRAY);sprintf (str, "%s", "JOKER");break;case 4:setcolor (RED);sprintf (str, "%s", "JOKER");break;}if ( kind <= 3){settextstyle (0, 0, 2);outtextxy (x - 20, y - 29, str);outtextxy (x + 21, y + 30, str);if (num == 7){settextstyle (0, 0, 1);outtextxy (x - 21, y - 15, card[kind * 13 + num].card); outtextxy (x + 21, y + 16, card[kind * 13 + num].card); settextstyle (4, 0, 4);outtextxy (x, y - 5, card[kind * 13 + num].card);}else{settextstyle (1, 0, 1);outtextxy (x - 21, y - 15, card[kind * 13 + num].card); outtextxy (x + 21, y + 10, card[kind * 13 + num].card); settextstyle (4, 0, 5);outtextxy (x - 1, y - 5, card[kind * 13 + num].card);}}else{settextstyle (0, 1, 1);outtextxy (x - 21, y - 18, str);outtextxy (x + 21, y + 18, str);settextstyle (4, 0, 5);outtextxy (x, y - 3, "G");}}void lord_choice (int q)setcolor (BLUE);settextstyle (3, 0, 1);outtextxy (x, y + 50, "Do You Want To Be the Lord ?"); if (q == 1){setcolor (BLUE);outtextxy (x + 40, y + 65, "No");setcolor (LIGHTGRAY);outtextxy (x - 40, y + 65, "Yes");}else{setcolor (LIGHTGRAY);outtextxy (x + 40, y + 65, "No");setcolor (BLUE);outtextxy (x - 40, y + 65, "Yes");}}int choose_lord (){int flag = 1, key;lord_choice (1);while (1){while (bioskey (1) == 0);key = bioskey (0);switch (key){case LEFT:lord_choice (1);flag = 1;break;case RIGHT:lord_choice (2);flag = 2;break;case UP:break;case DOWN:break;default :return flag;}}}void cardback_drawn(int x, int y) /*只用传递坐标*/ {int i;setfillstyle (SOLID_FILL, WHITE);bar (x - 40, y - 30, x + 40, y + 30);setcolor (BLUE);rectangle (x - 39, y - 29, x + 39, y + 29);setcolor (RED);for (i = 0; i <= 56; i = i + 2)line (x - 38, y - 28 + i, x + 38, y - 28 + i);for (i = 0; i <= 76; i = i + 2)line (x - 38 + i, y - 28, x - 38 + i, y + 28);}void clear (){cleardevice();}void close (){closegraph ();}void wash_card (){int t, i, j, k;randomize ();for (k = 0; k <= 1000; k++){i = rand () % 54;j = rand () % 54;t = b[i];b[i] = b[j];b[j] = t;}}struct card_node * distribute_lord (){struct card_node * head;head = & card[b[0]];card[b[0]].next = & card[b[1]];card[b[1]].next = & card[b[2]];card[b[2]].next = NULL;return head;}struct card_node * distribute_player ()struct card_node * head;int i;head = & card[b[3]];for (i = 3; i <= 18; i++)card[b[i]].next = & card[b[i + 1]];card[b[i]].next = NULL;return head;}struct card_node * distribute_com1 (){struct card_node * head;int i;head = & card[b[20]];for (i = 20; i <= 35; i++)card[b[i]].next = & card[b[i + 1]];card[b[i]].next = NULL;return head;}struct card_node * distribute_com2 (){struct card_node * head;int i;head = & card[b[37]];for (i = 37; i <= 52; i++)card[b[i]].next = & card[b[i + 1]];card[b[i]].next = NULL;return head;}void show_lord (struct card_node * head){int i;struct card_node * p;for (p = head, i = 0; p != NULL; p = p -> next){card_drawn (x - 80 + i * 80, y - 115, p -> kind, p -> num, WHITE); i++;}}void show_player (struct card_node * head, int x, int y){int i;struct card_node * p;for (p = head, i = 0; p != NULL; p = p -> next){i++;}}void show_player_1 (struct card_node * head, int x, int y, int j){int i;struct card_node * p;for (p = head, i = 0; p != NULL; p = p -> next){if (i == j - 1){card_drawn (x - 160 + i * 20, y + 115, p -> kind, p -> num, YELLOW); i++;}else{card_drawn (x - 160 + i * 20, y + 125, p -> kind, p -> num, WHITE); i++;}}}void show_player_2 (struct card_node * head, int x, int y, int j){int i;struct card_node * p;for (p = head, i = 0; p != NULL; p = p -> next){if (i == j - 1){card_drawn (x - 160 + i * 20, y + 125, p -> kind, p -> num, YELLOW); i++;}else{card_drawn (x - 160 + i * 20, y + 125, p -> kind, p -> num, WHITE); i++;}}}void show_com1 (struct card_node * head){int i;struct card_node * p;for (p = head, i = 0; p != NULL; p = p -> next)cardback_drawn (x - 270, y - 120 + i * 15);i++;}}void show_com2 (struct card_node * head){int i;struct card_node * p;for (p = head, i = 0; p != NULL; p = p -> next){cardback_drawn (x + 270, y - 120 + i * 15);i++;}}void about_producer1 (){setcolor (RED);settextstyle (4, 0, 4);outtextxy (120, 20, "About Producer :");settextstyle (1, 0, 2);outtextxy (43, 59, "Li Chao:");outtextxy (80, 230, "Wang Zhanghu:");outtextxy (55, 290, "Hu Yuan:");setcolor (BLUE);settextstyle (3, 0, 1);outtextxy (219, 60, "Software Program Class 0603");outtextxy (218, 90, "Student Number: 012006001701");outtextxy (216, 130, "Thanks for Wang & Hu's help,");outtextxy (476, 130, "and thanks to my teacher");outtextxy (351, 160, "Mr.Shen for his help in my C Programing Language study. "); outtextxy(480,190,"TEL:159****2688.");outtextxy(480,220,"E-mail:*************");outtextxy (219, 230, "Class 0604");outtextxy (310, 260, "Student Number: 012006001701");outtextxy (219, 290, "Class 0603");outtextxy (310, 320, "Student Number: 012006001701");}void about_producer2 (){setcolor (RED);settextstyle (4, 0, 4);outtextxy (120, 20, "About Producer :");settextstyle (1, 0, 2);outtextxy (80, 210, "Wang Zhanghu:");outtextxy (55, 270, "Hu Yuan:");setcolor (BLUE);settextstyle (3, 0, 1);outtextxy (219, 90, "Class 0603");outtextxy (310, 120, "Student Number: 012006001701");outtextxy (219, 210, "Class 0604");outtextxy (310, 240, "Student Number: 012006003121");outtextxy (219, 270, "Class 0603");outtextxy (310, 300, "Student Number: 012006003713");}void about_producer3 (){setcolor (RED);settextstyle (4, 0, 4);outtextxy (120, 20, "About Producer :");settextstyle (1, 0, 2);outtextxy (43, 59, "Li Chao:");outtextxy (80, 230, "Wang Zhanghu:");outtextxy (55, 290, "Hu Yuan:");setcolor (BLUE);settextstyle (3, 0, 1);outtextxy (219, 60, "Software Program Class 0603");outtextxy (218, 90, "Student Number: 012006001701");outtextxy (216, 130, "Thanks for Wang & Hu's help,");outtextxy (476, 130, "and thanks to my girlfriend");outtextxy (351, 160, "Liu Jieyi and I will love her forever !! ");outtextxy(480,190,"TEL:159****2688.");outtextxy(480,220,"E-mail:*************");outtextxy (219, 230, "Class 0604");outtextxy (310, 260, "Student Number: 012006001701");outtextxy (219, 290, "Class 0603");outtextxy (310, 320, "Student Number: 012006001701");}struct card_node * card_soft (struct card_node *head) /*直接插入排序啦*/{struct card_node *p, *q, *r;for (p = head, q = head, r = head; p -> next != NULL; ){if ((p -> next -> num < p -> num) || ((p -> next -> num == p -> num) && (p -> next -> kind < p -> kind))){p = p -> next;{q -> next = p -> next;head = p;head -> next = r;r = head;p = q;}else{for (r = head; (r -> next -> num < p -> num) || ((r -> next -> num == p -> num) && (r -> next -> kind < p -> kind)); r = r -> next);q -> next = p -> next;p -> next = r -> next;r -> next = p;r = head;p = q;}}else{p = p -> next;q = q -> next;}}return head;}void delete_player (int x, int y){setfillstyle (SOLID_FILL, BLACK);bar (x - 225, y + 70, x + 220, y + 175);}void delete_head2 (){setfillstyle (SOLID_FILL, BLACK);bar (x - 200, y - 120, x + 200, y + 40);}void delete_com1 (int x, int y){setfillstyle (SOLID_FILL, BLACK);bar (x - 310, y - 150, x - 230, y + 180);}void delete_com2 (int x, int y)setfillstyle (SOLID_FILL, BLACK);bar (x + 230, y - 150, x + 310, y + 155);}/*int choose_card (struct card_node *head, int s) s == 1表示是地主,否则不是地主{struct card_node *p, *q;int key, i, j, t, flag[20]; flag[i] == 1表示第i张牌还没有出, j是用来记忆当前有多少张牌flag[20] = 1;j = 20;t = 30;if (s == 0){for (i = 0; i < 3; i++)flag[17 + i] = 0;j = 17;t = 0;}i = 1;p = head;q = head;delete_player (x, y);delete_table (x, y);show_player_2 (p, x - t, y + 5, i);while (1){while (bioskey (1) == 0);key = bioskey (0);switch (key){case LEFT:if (i == 1)break;else{delete_player (x, y);show_player_2 (p, x - t, y + 5, --i);break;}case RIGHT:if (i == j)break;else{delete_player (x, y);break;}case UP:{delete_player (x, y);show_player_1 (p, x - t, y + 5, i); flag[i - 1] = 0;break;}case DOWN:delete_player (x, y);show_player_2 (p, x - t, y + 5, i); flag[i - 1] = 1;break;default :return i;}}}*/void print_pointer_1 (int i, int color) {int arw[16];arw [0] = x - 217 + i * 20;arw [1] = y + 171;arw [2] = x - 213 + i * 20;arw [3] = y + 171;arw [4] = x - 213 + i * 20;arw [5] = y + 165;arw [6] = x - 210 + i * 20;arw [7] = y + 165;arw [8] = x - 215 + i * 20;arw [9] = y + 161;arw [10] = x - 220 + i * 20;arw [11] = y + 165;arw [12] = x - 217 + i * 20;arw [13] = y + 165;arw [14] = x - 217 + i * 20;arw [15] = y + 171;setfillstyle (SOLID_FILL, color); setcolor (BLACK);fillpoly (8, arw);}void print_pointer_2 (int i, int color) {int arw[16];arw [0] = x - 217 + i * 20;arw [2] = x - 213 + i * 20;arw [3] = y + 70;arw [4] = x - 213 + i * 20;arw [5] = y + 75;arw [6] = x - 210 + i * 20;arw [7] = y + 75;arw [8] = x - 215 + i * 20;arw [9] = y + 80;arw [10] = x - 220 + i * 20;arw [11] = y + 75;arw [12] = x - 217 + i * 20;arw [13] = y + 75;arw [14] = x - 217 + i * 20;arw [15] = y + 70;setfillstyle (SOLID_FILL, color);setcolor (BLACK);fillpoly (8, arw);}void player_pass (){settextstyle (3, 0, 3);setcolor (RED);outtextxy (x + 30, y + 20, "PASS");}void com1_pass (){settextstyle (3, 1, 3);setcolor (RED);outtextxy (x - 180, y - 10, "PASS");}void com2_pass (){settextstyle (3, 1, 3);setcolor (RED);outtextxy (x + 180, y - 10, "PASS");}void showcard_com1 (struct card_node * head1, struct card_node * head2) /*head1 表示传递电脑出的牌, head2表示电脑所剩下的牌*/{struct card_node * p1, * p2;p1 = head1;p2 = head2;if (p1 == NULL)com2_pass ();s1 = NULL;}else if (p1 == p2){com1 = com1 -> next;head2 = com1;p1 -> next = NULL;s1 = head1;show_player (head1, x, y - 200);delete_com1 (x, y);show_com1 (head2);}else{for (p2 = head2; p2 -> next != p1; p2 = p2 -> next);p2 -> next = p1 -> next;p1 -> next = NULL;s1 = head1;show_player (head1, x, y - 200);delete_com1 (x, y);show_com1 (head2);}}void showcard_com2 (struct card_node * head1, struct card_node * head2) /*head1 表示传递电脑出的牌, head2表示电脑所剩下的牌*/{struct card_node * p1, * p2;p1 = head1;p2 = head2;if (p1 == NULL){com2_pass ();s2 = NULL;}else if (p1 == p2){com2 = com2 -> next;head2 = com2;p1 -> next = NULL;s2 = head1;show_player (head1, x, y - 200);delete_com2 (x, y);show_com2 (head2);}else{for (p2 = head2; p2 -> next != p1; p2 = p2 -> next);p1 -> next = NULL;s2 = head1;show_player (head1, x + 280, y - 200);delete_com2 (x, y);show_com2 (head2);}}int justify (struct card_node * head, struct card_node *s1, struct card_node *s2) /*s1, s2用来表示电脑上次出的牌*/{struct card_node *p;int flag = 0, k = 0; /*k表示出牌的个数,flag表示出来的牌是否符合标准*/for (k = 0, p = head; p != NULL; p = p -> next)k++;p = head;if (k == 1){if (s1 == NULL && s2 == NULL)flag = 1;else if (s2 != NULL && p -> num > s2 -> num)flag = 1;else if (s1 != NULL && s2 == NULL && p -> num > s1 -> num)flag = 1;else flag = 0;}else if (k == 2 && (p -> num == p -> next -> num) && s1 == NULL && s2 == NULL)flag = 1;else if (k == 3 && (p -> num == p -> next -> num) && (p -> num == p -> next -> next -> num) && s1 == NULL && s2 == NULL)flag = 1;else if (k == 4 && (((p -> num == p -> next -> num) && (p -> num == p -> next -> next -> num)) || ((p -> next -> num == p -> next -> next -> num) && (p -> next -> num == p -> next -> next -> next -> num))) && s1 == NULL && s2 == NULL)flag = 1;else if (k > 4 && p -> num != p -> next -> num && s1 == NULL && s2 == NULL)for (p = head; p -> next != NULL; p = p -> next){if (p -> num == p -> next -> num - 1)flag = 1;elsereturn 0;}else if (k >= 6 && k % 2 == 0 && p -> num == p -> next -> num && s1 == NULL && s2 == NULL)for (p = head; p -> next -> next != NULL; p = p -> next -> next){if (p -> num == p -> next -> num && p -> num == p -> next -> next -> num - 1)flag = 1;return 0;}elseflag = 0;return flag;}struct card_node * justify_com (struct card_node * head1, struct card_node * head2) /*head1传递的是玩家出的牌,head2传递的是电脑所剩下的牌,返回电脑出的牌*/{struct card_node *p1, *p2;int k;p2 = head2;for (k = 0, p1 = head1; p1 != NULL; p1 = p1 -> next)k++;if (k == 1){for (p2 = head2, p1 = head1; p2 -> num <= p1 -> num && p2 != NULL; p2 = p2 -> next);return p2;}elsereturn NULL;}int examine_player(struct card_node * head1, struct card_node * head2) /*head1传递的是电脑的牌, head2传递的是玩家有的牌,返回值为0表示玩家没有比电脑的更大的牌*/{int flag = 0;struct card_node *p1, *p2;for (p1 = head1, p2 = head2; p2 != NULL; p2 = p2 -> next)if (p2 -> num > p1 -> num)flag = 1;return flag;}struct card_node * choose_card (struct card_node *head, struct card_node *com1, struct card_node *com2){struct card_node *p, *q, *head1, *head2, *r; /*head2是用来指向已经出了的int key, i = 0, t = 0, j, k, justify1 = 1, flag1[20], m = 0; /* j是用来记忆当前有多少张牌 */if (s2 != NULL)m = examine_player (s2, head);else if (s1 != NULL)m = examine_player (s1, head);elsem = 1;if (m == 0){while (1){while (bioskey (1) == 0);key = bioskey (0);switch (key){case LEFT:break;case RIGHT:break;case UP:break;case DOWN:break;default:delete_head2 ();player_pass ();while (1){while (bioskey (1) == 0);key = bioskey (0);switch (key){case LEFT:break;case RIGHT:break;case UP:break;case DOWN:break;default:delete_head2 ();for (p = com2; p != NULL && p -> num <= com1 -> num; p = p -> next);showcard_com1 (com1, com1);showcard_com2 (p, com2);return head;}}}}else{head1 = back_up (head);for (i = 0; i < 20; i++)flag1[i] = flag[i];for (i = 0, j = 0; i < 20; i++) {if ( flag[i] == 1 )j++;elseflag[i] = 0;}for (i = 0; i < 20; i++){if (i < j)flag[i] = 1;elseflag[i] = 0;}i = 0;p = head;q = head;head2 = head;print_pointer_1 (0, WHITE); while (1){while (bioskey (1) == 0);key = bioskey (0);switch (key){case LEFT:if (i == 0)break;else{print_pointer_1 (i, BLACK); print_pointer_1 (--i, WHITE); break;}case RIGHT:if (i == j - 1)break;elseprint_pointer_1 (i, BLACK);print_pointer_1 (++i, WHITE);break;}case UP:print_pointer_2 (i, YELLOW);flag[i] = -1;break;case DOWN:print_pointer_2 (i, BLACK);flag[i] = 1;break;default :for (k = 0; k < 20; k++)if (flag[k] == -1)t = 1;if (t == 1){for (i = 0; flag[i] != -1 && head2 -> next != NULL; i++) head2 = head2 -> next;for (i = 0, r = head2; flag[i] != 1 && head != NULL; i++) {head = head -> next;if (flag[i + 1] == -1){r -> next = head;r = r -> next;}}for (p = head; i < j; i++){if (flag[i] == 1){q = p;p = p -> next;}else{q -> next = p -> next;if (flag[i] == -1){r -> next = p;r = r -> next;}p = q -> next;}}r -> next = NULL;justify1 = justify (head2, s1, s2);if (justify1 == 1){delete_head2 ();show_player (head2, x + 115, y - 130);s1 = justify_com (head2, com1);if (s1 == NULL){com1_pass ();s2 = justify_com (head2, com2);}elseshowcard_com1 (s1, com1);s2 = justify_com (s1, com2);if (s2 == NULL)com2_pass ();elseshowcard_com2 (s2, com2);/*应该插入一个函数来让你选择是否PASS*/ return head;}else{for (i = 0; i < 20; i++)flag[i] = flag1[i];return head1;}}elsebreak;}}}}void you_win (){setfillstyle (SOLID_FILL, BLACK);bar (x - 320, y - 300, x + 430, y + 300);settextstyle (3, 0, 5);setcolor (RED);outtextxy (x - 90, y - 70, "Congratulations");outtextxy (x + 90, y + 50, "You Win !!"); }void you_lose (){setfillstyle (SOLID_FILL, BLACK);bar (x - 320, y - 300, x + 430, y + 300); settextstyle (3, 0, 5);setcolor (RED);outtextxy (x - 90, y - 70, "I'm so sorry..."); settextstyle (3, 0, 8);outtextxy (x + 90, y + 50, "You lose ..."); }int main (void){int gdriver, gmode;int i;int t = 1, flag2 = 1, r;struct card_node *lord;struct card_node *player;struct card_node *p;init_graph ();first_look ();while (flag2 == 1){table (x, y);operation (1);t = choose_operation ();for (i = 0; i < 20; i++)flag[i] = 1;if (t == 1){table (x, y);player_name ();init_card ();for (i = 0; i <= 53; i++)b[i] = i;wash_card ();lord = distribute_lord ();player = distribute_player ();com1 = distribute_com1 ();com2 = distribute_com2 ();show_lord (lord);show_com1 (com1);show_com2 (com2);r = choose_lord (); /*选择是否当地主*/if (r == 1){for (p = player; p -> next != NULL; p = p -> next);p -> next = lord;table (x, y);player_name ();show_player (player, x - 30, y);show_com1 (com1);show_com2 (com2);player = card_soft (player);com1 = card_soft (com1);com2 = card_soft (com2);getch ();show_player (player, x - 30, y);getch ();delete_table (x, y);while (player != NULL && com1 != NULL && com2 != NULL) {player = choose_card (player, com1, com2);delete_player (x, y);show_player (player, x - 30, y);}}else{for (i = 0; i < 3; i++)flag[17 + i] = 0;for (p = com1; p -> next != NULL; p = p -> next);p -> next = lord;table (x, y);player_name ();show_com1 (com1);show_player (player, x - 30, y);show_com2 (com2);player = card_soft (player);com1 = card_soft (com1);com2 = card_soft (com2);getch ();show_player (player, x - 30, y);getch ();delete_table (x, y);while (player != NULL && com1 != NULL && com2 != NULL) {player = choose_card (player, com1, com2);show_player (player, x - 30, y); }}getch ();if (player == NULL)you_win ();elseyou_lose ();getch ();}else if (t == 2){table (x + 175, y - 120);about_producer1 ();getch ();}elseflag2 = 0;}close ();return 0;}。

C语言21点纸牌游戏系统详细设计

C语言21点纸牌游戏系统详细设计
printf("赢得:%d局\n", nWins);
printf("输掉:%d局\n", nLose);
printf("平局:%d局\n",nDraw);
printf("剩余资金:%d元\n",nMoney);
}
void Wait_f(int nMilli)
{
int nStart1,nStart2;
{
printf("%d\n",nnn);
printf("您想要哪一张牌");
scanf("%d",&a);
}
system("cls");
do
{
printf("想要继续要牌吗(H开启作弊模式)\n");/*询问玩家是否接着要牌*/
scanf(" %c",&chAnswer);
if((chAnswer=='h')||(chAnswer=='H'))
printf("总点数是:%d点\n", * npTotal);
}
void Results_f(int nPlayer,int nCpu,int nBet,int * npMoney,int * npDraw,int
* npWin,int * npLose)/*统计结果(输赢平及输赢平的局数)*/
{
printf("4:庄家点数等于或大于16时游戏停止。\n");
printf("5:您将获得100元初始基金!\n");
printf("提示:游戏中“是”输入“y”,“否”输入“n”。\n");

C语言扑克牌系统

C语言扑克牌系统

#include<stdio.h>#include<stdlib.h>//2合一随机函数#include<time.h>//定义扑克牌结构体typedef struct card{char *face;char *suit;}Card;Card deck[52];//定义一副牌数组//定义初始化面initCard函数void initCard(){char *suit[4]={"\003","\004","\005","\006"};//红桃、方块、梅花、黑桃char *face[13]={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};for (int i=0;i<52;i++){deck[i].face=face[i%13];//人发13张牌deck[i].suit=suit[i/13];//发4个人的牌}}//定义洗牌函数void shuffle(){int j;Card temp;//定义一张牌中间变量for(int i=0;i<52;i++){j=rand()%52;temp=deck[i];deck[i]=deck[j];deck[j]=temp;}}//定义菜单函数void caidan(){printf("+*+*++++++++++++++++++++++++++++++++++++++*+\n");printf("+*+ 主菜单+*+\n");printf("+*+ 1.初始化扑克+*+\n");printf("+*+ 2.洗牌、发牌+*+\n");printf("+*+ 3.退出菜单+*+\n");printf("+*+*++++++++++++++++++++++++++++++++++++*+*+\n");}//打印一副牌函数void printfCard(){for(int i=0;i<52;i++){printf("%s%s\t",deck[i].suit,deck[i].face);if((i+1)%5==0)//分5张牌一行{printf("\n");}}}//打印玩家的牌void printfCard(int n){int count=0;for(int i=n-13;i<n;i++)//n-13表示减去发出去的牌,用还剩下的牌再发{printf("%s%s\t",deck[i].suit,deck[i].face);count++;if(count%5==0){printf("\n");}}}//定义发牌函数void deal(){printf("\n第一位玩家的牌是:\n");printfCard(13);printf("\n第二位玩家的牌是:\n");printfCard(26);printf("\n第三位玩家的牌是:\n");printfCard(39);printf("\n第四位玩家的牌是:\n");printfCard(52);}//主函数void main(){initCard();int a;int loop=1;srand(time(0));//调用随机函数while(loop){caidan();printf("请输入菜单功能编号:");scanf("%d",&a);fflush(stdin);//清除缓存switch(a){case 1:initCard();printfCard();printf("\n");break;case 2:shuffle();deal();printf("\n");break;case 3:loop=0;break;default:printf("选择错误,请重新选择!\n");break;}}}。

扑克牌游戏c源代码

扑克牌游戏c源代码

扑克牌游戏c++源代码/*第1题扑克牌游戏--源代码及关键源代码注解如下:*///* This Program was written entirely by the author Frank Vokoun.//*******************preprocessor directives***********************//#include &lt;iostream.h&gt;#include &lt;string.h&gt;#include &lt;conio.h&gt;#include &lt;stdlib.h&gt;#include &lt;stdio.h&gt;#include &lt;time.h&gt;// used to seed the random number generator////*********************************************************************** class Playing_Card //扑克类{private:int m_Value;char m_Face[3]; //扑克的数字大小char m_Suit ; //扑克的花色(黑、红、梅、方)public:Playing_Card();// CONSTRUCTORvoid showcard();// Displays an object of class Playing_Card void Card_Make(int);};class Deck//一副扑克(52张){private:Playing_Card m_cardarray[52];// Object array of class Playing_Cardint m_lastdelt;public:Deck();// CONSTRUCTOR initializes empty Deck objectvoid MakeDeck();// makes a complete object of class Deckvoid Deal_One();// Deals a card from top of the deckvoid ShowDeck();// Displays a Deck object to the screenvoid DeckShuff(int);// &quot;Shuffles&quot; a Deck object for int timesvoid Remove_Card();// Removes used card from Deck Prevents};//mistakenly using a nonexistant card //can bu used to send a card ??//***************************prototypes**********************************void Program_Init();// Program informationint main();void Center_Text(char []);// Centers textint get_number();// Gets a integer from userchar Get_Key();// Gets a char from user, pauses programvoid DeckMakeDriver();// Tests Several Functions including Makedeck int getRandInt(int min, int max);// Random number generatorvoid prog_close();// pauses before program termination//****************************Main*************************************int main()//************************************************************************** //*int main:Main Function Calls other functions//*//*expects:None.//*Returns:Integer 0;//*Side effects None//*//*Tasks(1) Seeds the Random number generator//*(2) Calls Program Init function for Title etc.//*(3) Call DeckMakeDriver to Test MakeDeck and DeckShuff.//*//***********************************************************************{srand( (unsigned)time( NULL ) );// Seeds GetRandIntint Card_Number = 0;Program_Init();// Showd title etc.DeckMakeDriver();// The Main Function Driver Tests Deck and//Playing_Card classesprog_close();// pauses screen outputreturn 1;}Playing_Card::Playing_Card()// CONSTRUCTOR//************************************************************************** //*Playing_Card Playing_Card CONSTRUCTOR FOR CLASS Playing_Card//*//*expects:None.//*Returns:None//*Side effects None//*//*Tasks Constructs object of class playing_card replaces default constructor//*********************************************************************// Constructor replaces default constructor{int i;for(i=1;i&lt;=3;)// inits string variable to blanks{m_Face[i] = &#39; &#39;;i++;}m_Suit = &#39; &#39;;// inits char variable to blankm_Value = 0;}void Program_Init()//************************************************************************* //*void Program_Init():Shows Title//*//*expects None//*returns:None//*Side Effects:Text is centered on screen//*//*Task(s)Output program information to screen.//*//***********************************************************************{Center_Text(&quot;Lab #5&quot;);cout &lt;&lt; endl;Center_Text(&quot;A Deck Driver&quot;);cout &lt;&lt; endl &lt;&lt;&quot;\n&quot; ;Center_Text(&quot;By Frank Vokoun&quot;);cout &lt;&lt; endl &lt;&lt;&quot;\n&quot; ;Center_Text(&quot;(C) 2001, Frank Vokoun&quot;);cout &lt;&lt; endl &lt;&lt;&quot;\n&quot; ;Center_Text(&quot;Hit the &lt;Return&gt; key to Continue..&quot;);cin.get();}char Get_Key()//*********************************************************************** //*char Get_Key():Uses a input prompt to get a char//*//*expects:None.//*Returns:Input char.//*Side effects:Pauses Program execution (desired effect).//*//*Task(s):Gets a char from the user..//*//********************************************************************** {char x;x = cin.get();cout &lt;&lt; endl;return x;}void Playing_Card::showcard()//*****************************************************************//*void showcard(card):Displays a Playing Cards object to the screen//*//* Expects:None -&gt; Uses calling members Playing_Card object//* Returns:None//* Side Effects:Displays//*//*Task(s):Displays the object of class Playing_Card to screen//*//*********************************************************************** {cout &lt;&lt; &quot; &quot;;cout &lt;&lt; m_Face ;cout.width(1);cout &lt;&lt; m_Suit;cout &lt;&lt; &quot; &quot;;}void Center_Text(char ShellText[80])//********************************************************************** //*Void Center_Text:Displays text centered on the screen.//*//*expects:The text to display.//*Returns:None.//*Side effects:Outputs Centered text on screen.//*//*******************************************************************{int length;int center;length= strlen(ShellText);center = (80 - length)/2;for(;center!=0;center--){cputs(&quot; &quot;);}cputs(ShellText);}int get_number()//******************************************************************** //*//*int get_number:Gets an integer from the user.//*expects:None.//*Returns:Integer.//*Side effects:None.//*Task(s):Asks the user to enter an integer then returnsthat integer.//*.//********************************************************************** {int Input_Integer = 0;Center_Text(&quot;Please enter an integer between 0 and 51. 52 to quit.&quot;);cout &lt;&lt; endl;cin &gt;&gt; Input_Integer;return Input_Integer;}void Playing_Card::Card_Make(int num)//********************************************************************* //* Get_Card(int):Creates a Playing_Card object based on an interger input.//* Expects:int//* Returns:None -&gt; uses Calling members Playing_Card object//* Side Effects:None//*//*Tasks: 1. assign a face value//* 2. assign a m_Suit(char type)//* 3. assign a point value//*//******************************************************************** {int i = 0;char j;int face_num = num % 13;switch(face_num)// Assigns a Face value for string cards{case 0: strcpy(m_Face,&quot; A&quot;);break;case 9: strcpy(m_Face,&quot;10&quot;);break;case 10: strcpy(m_Face,&quot; J&quot;);break;case 11: strcpy(m_Face,&quot; Q&quot;);break;case 12: strcpy(m_Face,&quot; K&quot;);break;default:j = char(face_num + 49);// Fills string with number mod 13if(i&lt;3){m_Face[i] = &#39; &#39;; i++;m_Face[i] = j;i++;m_Face[i] = NULL;break;}}if(num &lt;= 12)m_Suit = 6;// assigns suit use ascii values forif(num &gt;12 &amp;&amp; num &lt;= 25)m_Suit = 3;//card symbolsif(num &gt;25 &amp;&amp; num &lt;= 38)m_Suit = 5;if(num &gt;38 &amp;&amp; num &lt;= 51)m_Suit = 4;if(face_num &lt;= 9)m_Value = face_num + 1;// Card value&#39;s Ace = 1 if(face_num &gt;= 10)m_Value = 10;}void DeckMakeDriver()//********************************************************************//* DeckMakeDriver():Used to test the various deck functions Deckmake,//*Deckshuff, Deckcopy etc.//*Expects:None.//* Returns:None.//* Side effects:None//*//* Tasks: 1. Call make Deck//* 2. Show Deck//* 3. Call shuffle//* 4. Call show deck//* 5. While !Done Call//* a. Deal one//* b. Show card//*//*Note the dot operator is need to access object because this is not a member of the class //**********************************************************************{Deck deck_1;deck_1.MakeDeck();// Creates the Deck.deck_1.ShowDeck();// Displays deck to screen.Get_Key();// Pauses Program.deck_1.DeckShuff(250);// Shuffles the deck 250 timesdeck_1.ShowDeck();// Displays deck to screen.cout &lt;&lt; endl &lt;&lt;endl &lt;&lt; endl;char y;do{deck_1.Deal_One();cout &lt;&lt; endl;cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; &quot;Y to Deal One more N to quit&quot;&lt;&lt; endl;cin &gt;&gt; y;y = toupper(y);}while(y == &#39;Y&#39; );}void Deck::MakeDeck()// creates a full deck not a construct//************************************************************************** //* Deck Make Deck():Creates a Deck Object//* Expects:none -&gt; uses calling functions deck object//*Returns:none -&gt; uses calling functions Deck object //* Side effects:none//* Tasks: 1. Create a Full Deck structure of unique card structures//* a. have the decks last delt variable = to the top card//***********************************************************************{m_lastdelt = 51;// Set Deck to emptywhile(m_lastdelt &gt;-1)// iterate until deck is full.{m_cardarray[m_lastdelt].Card_Make(m_lastdelt); // call card make for every card object m_lastdelt--;// inside the deck object ie cardarray}}void Deck::ShowDeck()//********************************************************************//* void ShowDeck:Displays the deck in a organized readable fashion to the screen //* Expects:none shows calling functions object of class deck//* Returns:none//* Side Effects:None//* Tasks: 1. set an index to lastdealt + 1//* 2. call ShowCard passing in card[index]//*********************************************************************{int index = m_lastdelt + 1;int newline = 0;Center_Text(&quot;Current Deck of Cards from top to bottom&quot;);cout &lt;&lt; endl;while(index&lt;=51){if(newline % 11 == 0) cout &lt;&lt; endl;m_cardarray[index].showcard();// calls showcard for every card innewline++;// the cardarray objectindex++;}}int getRandInt(int min, int max)//*********************************************************************//*int GetRandInt:Returns a random number between min and max//*//* BORROWED FUNCTION:Used with permission from Prof. Steve Samuelson.//*//*Expects:min -- smallest possible number to return//*max -- largest possible number to return//* Returns: A number between min and max//* Side Effects:None//*//* Tasks: 1. set a num = to random number generator.//* 2. make num = num % (max - min +1); add min.//* 3. Return the num//*******************************************************************{int numToReturn;numToReturn = rand();numToReturn = numToReturn % (max - min + 1) + min;return numToReturn;}void Deck::DeckShuff( int times) //洗牌次数//********************************************************************//*Deck DeckShuff(Deck, int):Simulates the shuffling of a deck of cards//*expects:none -&gt; uses calling functions Deck object//*Returns:none -&gt; manipulates calling functions object of class Deck USING //* A THIS POINTER//*Side effects:no unintended effects.//*//*Task(s) 1. To randomly arrange the elements of the Deck structure Playing_Card//*array.//* A. split the Deck structure into two halves at a random location//*between 20 and 35.//* B. Alternating between the two halves move a random number of //*Playing_Card structures to the original deck structure, Until//*it is full of cards (52cards in a deck).* this is also the//*number of cards available in the to halves.//* C. Since it is a full unused deck set the lastdelt variable to -1//*//*//*********************************************************************{int x, split; //split是分开成两部分的位置,如上部分、下部分Center_Text(&quot;Shuffling Deck&quot;);cout &lt;&lt; endl;for(x=0;x&lt;=times;x++)// iterate input number of times {split = getRandInt(20,35);// Get split locationDeck topdeck;// Create 2 new unfilled decks Deck bottomdeck;int i;int bottomdeckindex = 1;int topdeckindex = 1;for(i=0;i&lt;=split - 1;){topdeck.m_cardarray[topdeckindex] = this-&gt;m_cardarray[i];topdeckindex++;i++;}for(i=(split);i&lt; 52;)// move remaining cards to bottom deck{bottomdeck.m_cardarray[bottomdeckindex] = this-&gt;m_cardarray[i]; bottomdeckindex++;i++;}int deckoutindex = 0;// set deck to fill&#39;s index to zeroint numcardstomovetop;int numcardstomovebottom;int j;int h = 0;bottomdeckindex = 52 - split;// set index to num cards in bottom topdeckindex =split;// set index to num cards in topwhile(deckoutindex &lt;= 51){numcardstomovetop = getRandInt(2,7);//从上部分抽取的张数,是2-7之间的随机数numcardstomovebottom = getRandInt(2,7);// Move a random number of cards(2-7)for(j=0;j &lt;=numcardstomovebottom;j++)//from bottomdeck to original deck{if(bottomdeckindex &gt; 0)// check for available cards{this-&gt;m_cardarray[deckoutindex] = bottomdeck.m_cardarray[bottomdeckindex]; deckoutindex++;bottomdeckindex--;}for(h=0;h&lt;=numcardstomovetop;h++)// Move a random number of cards (2 to 7){//from topdeck to original deck.if((topdeckindex &gt; 0) &amp;&amp; (deckoutindex &lt;=52))// check for available cards{//and slotsthis-&gt;m_cardarray[deckoutindex]=topdeck.m_cardarray[topdeckindex]; deckoutindex++;topdeckindex--;}}}}}this-&gt;m_lastdelt = -1;// Return a complete shuffled deck}void prog_close()//*******************************************************************//*void prog_close:Waits for user input to end//*Inputs:None//*Returns:None//*Side effects:Output text to screen/waits for user input to//*end program.//*//*task(s) 1. Pauses Program so the last output can be seen//*//*********************************************************************** {cout &lt;&lt; endl &lt;&lt; endl;cout &lt;&lt; &quot; Hit the &lt;Return&gt; key to Continue..&quot; &lt;&lt; endl;cout &lt;&lt; endl &lt;&lt; endl;Get_Key();// Necesary for clear input.cin.get();}void Deck::Remove_Card()//*****************************************************************//* Deck Remove_Card(Deck deck_1):Removes the card delt from dealing deck.//*Expects:The Deck that delt the card.//*Returns:The Deck without the card delt.//*Side effects:None.//*//*Task(s):Remove card delt from Deck//****************************************************************{m_cardarray[m_lastdelt]= Playing_Card();// reinits used card prevents mistakes}void Deck::Deal_One()//************************************************************************** *****************//* Deck Deal one(Deck):Deals a card from the top of the deck//* Expects: A deck to deal from//* Returns:The deck minus the card delt//* Side effects:lastdealt in the deck is incremented//*//* Tasks: 1. Check if lastdealt = 51 if so Error//* 2. Increment last dealt//* 3. Return card[last dealt]//************************************************************************** {if(m_lastdelt != 51)// Checks for available cards{m_lastdelt++;cout.width(5);cout &lt;&lt;&quot; Card delt&quot;;m_cardarray[m_lastdelt].showcard();}else{cout &lt;&lt; &quot;Out of range Error&quot;;prog_close();}}Deck :: Deck()// CONSTRUCTOR replaces default//**********************************************************************//* Deck Deck Class Deck CONSTRUCTOR//* Expects: A deck to deal from//* Returns:The deck minus the card delt//* Side effects:lastdealt in the deck is incremented//*//* Tasks: 1. Check if lastdealt = 51 if so Error//* 2. Increment last dealt//* 3. Return card[last dealt]//******************************************************************* {int lastdelt = 0;int i;for(i=0;i&lt;=51;i++){m_cardarray[1] = Playing_Card();// calls constructor class Playing_Card}// for every Playing_Card object in}// the class Deck&#39;s array.。

斗地主洗牌发牌报告--数据结构(C语言)

斗地主洗牌发牌报告--数据结构(C语言)

数据结构作业报告——斗地主洗牌发牌报告摘要1.实验目的编斗地主洗发牌的程序可以让我们了解随机数的生成,全局变量和指针的用法,熟悉线性表的基本操作,以及排序的基本思路和方法。

2.实验方法本程序主要是利用全局变量来统筹整个程序,辅之的是指针变量。

总共有三个子函数,分别为洗牌子函数,排序子函数,发牌子函数。

洗牌这个子函数利用了随机数的生成,而主函数通过指针变量把生成的随机数赋值给全局变量,再通过冒泡排序法对全局变量进行排序,最后按编号换算进行输出。

3.实验结果由运行出来的结果可以看出,此洗牌发牌符合斗地主的规则,是合法的。

随机发的牌没有重复,没有遗漏,且按照斗地主的牌的大小进行排列,即从小到大分别为:3,4,5,6,7,8,9,10,J,Q,K,A,2,小鬼,大鬼。

所以此程序是正确的,成功的。

内容一.问题重述设计一个程序生成一副总共54张的牌,来给三个玩家发牌,发给每位玩家17张牌,剩下三张作为底牌。

每次发出的牌都不一样,而且按从小到大的顺序显示每个玩家拿到的牌和底牌。

二.算法描述本程序除了运用一些条件语句,判断语句之外,主要运用了两个算法,一个是随机数的生成,一个是冒泡排序法。

随机数的生成的复杂度为O(N),其中N=54,这是在运行结果最佳的状况下才会出现的,一旦生成的随机数相同的话,通过if语句会重新生成随机数,直到生成不同的随机数。

冒泡排序法的空间复杂度为O(1),时间复杂度为O(N2),本程序中的N为54,而且运行了两次冒泡排序法,分别为牌数和花色进行排序,所以空间复杂度为2×O(1),时间复杂度为2×O(542)。

三.变量说明a[17],b[17],c[17],d[3]为全局变量的数组,分别存放玩家一,二,三的牌,以及三个底牌。

四.函数与思路说明本程序总共有3个子函数,1个主函数,其中3个子函数分别为Xipai()子函数,Paxu()子函数,Fapai()子函数。

Xipai()这个子函数利用了srand(time(0)),rand()来生成随机数1到54。

扑克牌3张两人比大小C语言代码

扑克牌3张两人比大小C语言代码

扑克牌3张两人比大小,C语言代码背景:两个人每人发3张牌(各从一副牌中),每张牌包括花色(红桃(Heart)>黑桃(Spade)>方块(Diamond)>梅花(Club))和大小(从小到大依次是:2-10、J、Q、K、A),谁手上有最大的一张或多张(如果有相同的牌)牌谁获胜。

输入:A的3张牌(未排序)和B的3张牌(未排序)。

(参见用例)输出:A的3张牌的排序后的输出和B的3张牌的排序后的输出,以及A和B谁获胜。

(参见用例)H2 C3↵H3 DJ↵View plainis B!↵: H2 DA C3↵: H4 H3 DJ↵Unlimited256MTest Case 3View plainCA CB↵CJ CQ↵View plainError!↵Unlimited256MTest Case 4View plainCA CJ↵DK DK↵View plainError!↵Unlimited256MTest Case 5View plainSJ SK↵SJ SK↵View plainis X!↵: SA SK SJ↵: SA SK SJ↵Unlimited代码#include<>int asc(char p[][3]);int isError(char p1[][3]);void compare(char p3[][3],char p4[][3]);int main(){char a[3][3],b[3][3],c;int i,j,resulta,resultb,result,flag=0;printf("请输入A的扑克牌,扑克牌之间以空格隔开,然后按下回车:\n");for(i=0;i<3;i++){for(j=0;j<3;j++){c=getchar();if(c!=' '&&c!=10){if(j==0){if(c=='H'||c=='S'||c=='D'||c=='C'){if(c=='H')c='Z';}else{printf("Input Error!\n");return 0;}}if(j==1){if(c=='J'||c=='Q'||c=='K'||c=='A'||(c>='1'&&c<='9')){if(c=='J')c=59;if(c=='Q')c=60;if(c=='K')c=61;if(c=='A')c=62;if(c=='1')flag=1;}else{printf("Input Error!\n");return 0;}}if(j==2){if(c!='0'){printf("Input Error!\n");return 0;}else{flag=0;c=58;a[i][1]=c;break;}}a[i][j]=c;}else{if(flag==1){printf("Input Error!\n");return 0;}if(j==2)break;j--;}}}printf("请输入B的扑克牌,扑克牌之间以空格隔开,然后按下回车:\n"); for(i=0;i<3;i++){for(j=0;j<3;j++){c=getchar();if(c!=' '&&c!=10){if(j==0){if(c=='H'||c=='S'||c=='D'||c=='C'){if(c=='H')c='Z';}else{printf("Input Error!\n");return 0;}}if(j==1){if(c=='J'||c=='Q'||c=='K'||c=='A'||(c>='1'&&c<='9')){if(c=='J')c=59;if(c=='Q')c=60;if(c=='K')c=61;if(c=='A')c=62;if(c=='1')flag=1;}else{printf("Input Error!\n");return 0;}}if(j==2){if(c!='0'){printf("Input Error!\n");return 0;}else{flag=0;c=58;b[i][1]=c;break;}}b[i][j]=c;}else{if(flag==1){printf("Input Error!\n");return 0;}if(j==2)break;j--;}}}resulta=asc(a);if(resulta==0)return 0;resultb=asc(b);if(resultb==0)return 0;result=isError(a);if(result==0)return 0;result=isError(b);if(result==0)return 0;compare(a,b);for(i=0;i<3;i++){a[i][2]='\0';b[i][2]='\0';}printf("A: ");for(i=0;i<2;i++){if(a[i][1]>='2'&&a[i][1]<='9'&&a[i][0]!='Z') printf("%s ",a[i]);else{if(a[i][0]=='Z'){if(a[i][1]==58){printf("H");printf("10 ");}if(a[i][1]==59){printf("H");printf("J ");}if(a[i][1]==60){printf("H");printf("Q ");}if(a[i][1]==61){printf("H");printf("K ");}if(a[i][1]==62){printf("H");printf("A ");}if(a[i][1]>='2'&&a[i][1]<='9'){printf("H");printf("%c ",a[i][1]);}}else{if(a[i][1]==58){printf("%c",a[i][0]);printf("10 ");}if(a[i][1]==59){printf("%c",a[i][0]);printf("J ");}if(a[i][1]==60){printf("%c",a[i][0]);printf("Q ");}if(a[i][1]==61){printf("%c",a[i][0]);printf("K ");}if(a[i][1]==62){printf("%c",a[i][0]);printf("A ");}}}}for(i=2;i<3;i++){if(a[i][1]>='2'&&a[i][1]<='9'&&a[i][0]!='Z') printf("%s",a[i]);else{if(a[i][0]=='Z'){if(a[i][1]==58){printf("H");printf("10");}if(a[i][1]==59){printf("H");printf("J");}if(a[i][1]==60){printf("H");printf("Q");}if(a[i][1]==61){printf("H");printf("K");}if(a[i][1]==62){printf("H");printf("A");}if(a[i][1]>='2'&&a[i][1]<='9'){printf("H");printf("%c",a[i][1]);}}else{if(a[i][1]==58){printf("%c",a[i][0]);printf("10");}if(a[i][1]==59){printf("%c",a[i][0]);printf("J");}if(a[i][1]==60){printf("%c",a[i][0]);printf("Q");}if(a[i][1]==61){printf("%c",a[i][0]);printf("K");}if(a[i][1]==62){printf("%c",a[i][0]);printf("A");}}}}printf("\nB: ");for(i=0;i<2;i++){if(b[i][1]>='2'&&b[i][1]<='9'&&b[i][0]!='Z') printf("%s ",b[i]);else{if(b[i][0]=='Z'){if(b[i][1]==58){printf("H");printf("10 ");}if(b[i][1]==59){printf("H");printf("J ");}if(b[i][1]==60){printf("H");printf("Q ");}if(b[i][1]==61){printf("H");printf("K ");}if(b[i][1]==62){printf("H");printf("A ");}if(b[i][1]>='2'&&b[i][1]<='9'){printf("H");printf("%c ",b[i][1]);}}else{if(b[i][1]==58){printf("%c",b[i][0]);printf("10 ");}if(b[i][1]==59){printf("%c",b[i][0]);printf("J ");}if(b[i][1]==60){printf("%c",b[i][0]);printf("Q ");}if(b[i][1]==61){printf("%c",b[i][0]);printf("K ");}if(b[i][1]==62)printf("%c",b[i][0]);printf("A ");}}}}for(i=2;i<3;i++){if(b[i][1]>='2'&&b[i][1]<='9'&&b[i][0]!='Z') printf("%s",b[i]);else{if(b[i][0]=='Z'){if(b[i][1]==58){printf("H");printf("10");}if(b[i][1]==59){printf("H");printf("J");}if(b[i][1]==60){printf("H");printf("Q");}if(b[i][1]==61){printf("H");printf("K");}if(b[i][1]==62){printf("H");printf("A");}if(b[i][1]>='2'&&b[i][1]<='9'){printf("H");printf("%c",b[i][1]);}else{if(b[i][1]==58){printf("%c",b[i][0]);printf("10");}if(b[i][1]==59){printf("%c",b[i][0]);printf("J");}if(b[i][1]==60){printf("%c",b[i][0]);printf("Q");}if(b[i][1]==61){printf("%c",b[i][0]);printf("K");}if(b[i][1]==62){printf("%c",b[i][0]);printf("A");}}}}printf("\n");return 0;}int asc(char p[][3]){int m,temp[2];if(p[0][1]==p[1][1]){if(p[0][0]==p[1][0]){printf("Input Error!\n");return 0;}}if(p[1][1]==p[2][1]){if(p[1][0]==p[2][0]){printf("Input Error!\n");return 0;}}if(p[0][1]==p[2][1]){if(p[0][0]==p[2][0]){printf("Input Error!\n");return 0;}}m=0;if(p[m][0]<p[m+1][0]){temp[0]=p[m][0];temp[1]=p[m][1];p[m][0]=p[m+1][0];p[m][1]=p[m+1][1];p[m+1][0]=temp[0];p[m+1][1]=temp[1];}if(p[m][0]<p[m+2][0]){temp[0]=p[m][0];temp[1]=p[m][1];p[m][0]=p[m+2][0];p[m][1]=p[m+2][1];p[m+2][0]=temp[0];p[m+2][1]=temp[1];}m=1;if(p[m][0]<p[m+1][0]){temp[0]=p[m][0];temp[1]=p[m][1];p[m][0]=p[m+1][0];p[m][1]=p[m+1][1];p[m+1][1]=temp[1];}if(p[0][0]==p[1][0]){if(p[0][1]<p[1][1]){temp[0]=p[0][0];temp[1]=p[0][1];p[0][0]=p[1][0];p[0][1]=p[1][1];p[1][0]=temp[0];p[1][1]=temp[1];}}if(p[0][0]==p[2][0]){if(p[0][1]<p[2][1]){temp[0]=p[0][0];temp[1]=p[0][1];p[0][0]=p[2][0];p[0][1]=p[2][1];p[2][0]=temp[0];p[2][1]=temp[1];}}if(p[1][0]==p[2][0]){if(p[1][1]<p[2][1]){temp[0]=p[1][0];temp[1]=p[1][1];p[1][0]=p[2][0];p[1][1]=p[2][1];p[2][0]=temp[0];p[2][1]=temp[1];}}return 1;}int isError(char p1[][3]){if(p1[0][1]==p1[1][1]){printf("Input Error!\n");return 0;}if(p1[1][0]==p1[2][0])if(p1[1][1]==p1[2][1]){printf("Input Error!\n");return 0;}return 1;}void compare(char p3[][3],char p4[][3]){int x;for(x=0;x<3;x++){if(p3[x][1]==p4[x][1]&&p3[x][0]==p4[x][0])continue;if(p3[x][0]>p4[x][0]||(p3[x][0]==p4[x][0]&&p3[x][1]>p4[x][1])){ printf("Winner is A!\n");return;}if(p3[x][0]<p4[x][0]||(p3[x][0]==p4[x][0]&&p3[x][1]<p4[x][1])){ printf("Winner is B!\n");return;}}printf("Winner is X!\n");}。

C++扑克牌游戏---抽王八_代码

C++扑克牌游戏---抽王八_代码

….H头文件,.cpp执行文件//Card.hclass Player;void gotoxy(int x,int y);class Card{private:int amount;char color; //3 red 4 square 5 plum 6 blackCard * pcard;public:Card():amount(14),color(3){}void set(int ,char);void show(int x=0,int y=0); //横着输// void print(int =0,int y=0); // 背面show 正面print 背面stand 竖的line 封底// void showstand(int x=0,int y=0); //竖着输出// void printstand(int x=0,int y=0); //背面// void showstandline(int x=0,int y=0);// void printstandline(int x=0,int y=0);// void printline(int x=0,int y=0);void showline(int x=0,int y=0); //作为封底用的void setpcard(Card *);void exact(int no); //精确输出JQKACard * backpcard();int backamount();friend void Giveout(Player *,int);friend void showplayer(Player *player,int n);};//Player.hclass Card;class Player{private:int number;int Flag;Card * phead;public:Player():number(0),phead(0){}Card* & backph(); //外部接口int & backflag();int & backno();void showcard(int,int); //需要player的位置坐标void setpp(Card *);friend void change(Player &player);friend void Giveout(Player * ,int);friend void showplayer(Player *player,int n);};//Game.h#include"Card.h"#include"Player.h"void cancel(Card *pc,Card * &ph);void canceldouble(Player *player,int n) ;void Giveout(Player * player,int a);void showplayer(Player *player,int n);void vircancel(Card *pc,Player & player) ;void comparecard(Player & player,Card * pc);Card *find(Card * ph,int n) ;void index(Card * &ph,Card *pc,int n);int playgame(Player * player,int n) ;void introduction();void end();//Card的实现#include<iostream>#include"Card.h"#include<stdlib.h>using namespace std;//enum Color {red,black,square,plum};//gotoxy()函数#include <windows.h> //void gotoxy(int y,int x)// vc下没有,要自定义!{COORD To = {x,y};SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),To); }void Card::exact(int no){if(no<11)cout<<no;else{switch(no){case 11:cout<<'J';break;case 12:cout<<'Q';break;case 13:cout<<'K';break;case 14:cout<<'A';break;case 15:cout<<"王";break;}}}void Card::show(int x,int y) //可以定位的{int i=0;gotoxy(x,y); //使用gotoxy语句代替回车换行,可以具体定位cout<<"/"<< "--------";gotoxy(x+1,y);cout<<"| " ;exact(amount);gotoxy(x+2,y);cout<<"| "<<color;for(i=0;i<3;i++){gotoxy(x+3+i,y);cout<<"|";}gotoxy(x+3+i,y);cout<<'\\';cout<<"--------";}void Card::showline(int x,int y){int i=0;cout<<"--";cout<<'\\';for(i=0;i<3;i++){gotoxy(x+i+1,y+2);cout<<"|";}gotoxy(x+1+i,y );cout<<color;cout<<" |";gotoxy(x+2+i,y );exact(amount);if(amount==10 || amount==15)cout<<"|";elsecout<<" |" ;gotoxy(x+3+i,y );cout<<"--/";}/*void Card:: print(int x,int y){int i=0;gotoxy(x,y); //使用gotoxy语句代替回车换行,可以具体定位cout<<"/"<< "--------";gotoxy(x+1,y);cout<<"| " ;gotoxy(x+2,y);cout<<"| " ;for(i=0;i<3;i++){gotoxy(x+3+i,y);cout<<"|";}gotoxy(x+3+i,y);cout<<'\\';cout<<"--------";}void Card::printline(int x,int y){int i=0;cout<<"--";cout<<'\\';for(i=0;i<3;i++){gotoxy(x+i+1,y+2);cout<<"|";}gotoxy(x+1+i,y );cout<< " |";gotoxy(x+2+i,y );cout <<" |" ;gotoxy(x+3+i,y );cout<<"--/";} //做好一个先吧,恩,好的,哈哈!void Card::showstand(int x ,int y){gotoxy(x,y);cout<<"/--------\\";gotoxy(x+1,y);cout<<"| ";exact(amount);cout<<" |";gotoxy(x+2,y);cout<<"| "<<color<<" |";for(int i=0;i<2;i++){gotoxy(x+3+i,y);cout<<"| |";}}void Card::showstandline(int x,int y){x=x+5;gotoxy(x,y);cout<<"| "<<color<<" |";gotoxy(x+1,y);cout<<"| ";exact(amount);cout<<" |";gotoxy(x+2,y);cout<<"\\--------/";}void Card::printstand(int x,int y) {gotoxy(x,y);cout<<"/--------\\";gotoxy(x+1,y);cout<<"| |";gotoxy(x+2,y);cout<<"| |";for(int i=0;i<2;i++){gotoxy(x+3+i,y);cout<<"| |";}}void Card:: printstandline(int x,int y) {x=x+5;gotoxy(x,y);cout<<"| |";gotoxy(x+1,y);cout<<"| |";gotoxy(x+2,y);cout<<"\\--------/";}*/void Card::set(int a,char b){amount=a;color=b;pcard=0;}void Card::setpcard(Card *pc){pcard=pc;}Card* Card::backpcard(){return pcard;}int Card::backamount(){}PLayer的实现#include<iostream>#include"Player.h"#include"Card.h"//#include<stdlib.h>//#include<time.h>using namespace std;void Player::setpp(Card *pc){phead=pc;}Card * & Player::backph(){return phead;}int & Player::backflag(){return Flag;}int& Player::backno(){//int &b=number;return number;}void Player::showcard(int x=0,int y=0) //显示一个player中的牌{int count=0;Card *ph=phead;if(ph){while(ph->backpcard()) //挑出最后一个{if(count==13){ph->show(x,y);ph->showline(x,y+6);x=x+8;y=0;gotoxy(x,y);ph=ph->backpcard();}ph->show(x,y);ph=ph->backpcard();count++;y+=5;//gotoxy(y,1);}ph->show(x,y);ph->showline(x,y+6);}}//Game#include"Game.h"#include<stdlib.h>#include<time.h>#include<iostream>using namespace std;void cancel(Card *pc,Card * &ph){Card * q=ph;if(pc==ph) //头指针时{ph=ph->backpcard(); //转移pheaddelete pc;}else{while((q!=0) && (q->backpcard()!=pc)){q=q->backpcard();}q->setpcard(pc->backpcard()); //前一个接后一个delete pc;}}void canceldouble(Player *player,int n){for(int i=0;i<n;i++){Card * & ph=player[i].backph();Card *ph2=0,*ph1=0,*ph3=ph; //玩家牌的头指针int & num=player[i].backno(); //玩家牌数ph1=ph3;ph2=ph1->backpcard();for(int j=0;j<num-1 && ph1->backpcard()!=0 && ph3 !=0 ;j++)//张数次数//判别double{int flag=1;for(int k=j+1;k<num && ph2!=0;k++) //判断并删除重复的牌{if(ph1->backamount()==ph2->backamount()) //注意大王{if(ph1->backpcard()==ph2)ph3=ph2->backpcard();elseph3=ph1->backpcard(); //接下一个对象cancel(ph1,ph);cancel(ph2,ph);num-=2;flag=0;j-=1;break;}ph2=ph2->backpcard();}if(flag)ph3=ph1->backpcard(); //外层循环ph1=ph3;if(ph1!=0)ph2=ph1->backpcard();}}}void Giveout(Player * player,int a) //发牌4份{srand(time(0)); //每一局牌都不一样int random[52]={0},count=0,judge=0;for(int i=0;i<a;i++) //产生N个player{Card *phead=0,*pnew=0,*ptail=0;int & no=player[i].backno();do{int number1,number2;int flag=1;pnew=new Card;number1=rand()%52+8; //8--59for(int j=0;j<count;j++) //判断随机产生的数是否会重复,避免重复的!{if(random[j]==number1)flag=0;}if(flag) //不重复时新建card{random[count]=number1;count++; //number2=number1/4; //2--14 点数number1=number1%4+3; //3--6 花色if(random[count-1]==35)pnew->set(15,0);elsepnew->set(number2,number1);if(!phead)phead=ptail=pnew;else{ptail->setpcard(pnew); //连接下一个的地址ptail=pnew; //新生成的变为tail}no++; //记录player中的牌数}if(i<52%a)judge=52/a+1;else //每个player的定牌数judge=52/a;}while(no<judge && count<52);player[i].setpp(phead);}}void showplayer(Player *player,int n){int j=0,x=0;for(j=0;j<n;j++){int y=0;cout<<"the card of player "<<j+1<<" :"<<player[j].backno()<<"张";player[j].showcard(x+1,y);x=x+8*(player[j].backno()/14+1); //具体的距离由玩家的牌数确定!!cout<<endl;}}/*void printplayer(Player *player,int n){int j=0,i=0;for(j=0;j<n;j++){cout<<"player "<<j+1<<" :"<<player[j].backno()<<"张";player[j].printcard( );// x=x+8*(player[j].backno()/14+1); //具体的距离由玩家的牌数确定!!cout<<endl;}}*/int playgame(Player * player,int n) //输出玩家号{int no=0,count=0; //记录没牌的玩家数//判定玩家是否有牌,几个人有牌并标记int max=player[0].backno(),b=0;for(int a=1;a<n;a++){if(max<player[a].backno()){max=player[a].backno();b=a;}}cout<<"Begin from the player " <<1+b<<" who has the most cards "<<endl<<endl; for(int i=b;i<n;i++){count=0;for(int j=0;j<n;j++){cout<<"the number of "<<j+1 <<" player's cards:";cout<<player[j].backno()<<endl;int &x=player[j].backflag();if(player[j].backno()==0){cout<<"00"<<endl;count++;x=0;}else{cout<<"!!"<<endl;x=1;}}if(count<n-1){while(player[i].backflag()==0 ) //确保被抽取的有牌{i++;if(i==n)i=0;}cout<<"玩家"<<i+1<<" 抽取";int reserve=i;if(i==n-1)i=-1;while(player[i+1].backflag()==0 )i++;if(i==n-1)i=-1;}cout<<"玩家"<<i+2<<"的第N张牌:输入N(>0):";do{cin>>no;if(no<=0)cout<<"reinput!";}while(no<=0);getchar();while( no<0 || no>player[i+1].backno()){cout<<"数据无效,重输:";cin>>no; //有效性}Card *ph=find(player[i+1].backph(),no); //抽到牌的地址而后就在i+2中假删除vircancel(ph,player[i+1]);//架空comparecard(player[reserve],ph); //较牌}elsebreak;}int k=0;for( k=0;k<n;k++){if(player[k].backflag())break;}return k;}void vircancel(Card *pc,Player & player) //架空{Card *&ph=player.backph();Card * q=ph;if(pc==ph) //头指针时ph=ph->backpcard(); //转移pheadelse{while((q!=0) && (q->backpcard()!=pc)){q=q->backpcard();}q->setpcard(pc->backpcard()); //前一个接后一个}player.backno()-=1;}Card *find(Card * ph,int n) //返回找到的地址{int count=1;if(n==0)return 0;else{for(;count!=n;) //n==0时,会无限循环,到ph==0时,空指向会报错的{ph=ph->backpcard();count++;}return ph;}}void comparecard(Player & player,Card * pc){int flag=1;// char ch;Card *phead=player.backph();while(phead!=0){if(pc->backamount()==phead->backamount()) //相同{cout<<"\n有相同的牌^_^ ";cout<<" 输出相同的牌";system("pause");system("cls");pc->show(1,0); //showpc->showline(1,6); //缺位置坐标phead->show(1,10);phead->showline(1,16); //删除cout<<endl;cancel(phead,player.backph());delete pc;player.backno()-=1;flag=0;break;}phead=phead->backpcard();}//不同if(flag){cout<<"\n没有找到相同的牌! ";system("pause");/*do{ch=getchar();}while(ch!=10);*/system("cls");int x=0; //插入位置srand(time (0));x=rand()%(player.backno()+1);index(player.backph(),pc,x);player.backno()+=1;}}void index(Card *& ph,Card *pc,int n){Card * pn=find(ph,n); //注意n的取值可能为零的if(n==0){pc->setpcard(ph);ph=pc;}else{pc->setpcard(pn->backpcard());pn->setpcard(pc);}}void change(Player &player){Card * &pc=player.backph(),*px;Card * pt=pc->backpcard();px=pc;if(pc->backamount()< pt->backamount()){pc->setpcard(0);pc=pt;pc->setpcard(px);}}void introduction(){cout<<endl<<endl<<"\t\t\t欢迎进入本游戏!"<<endl;cout<<"\n\t\t本游戏起源于四小鬼争夺霸王称号的传说!"<<endl<<"\n\t他们通过玩了一局扑克牌游戏,定出谁是获得者.最后一小鬼胜出赢得此称号.";cout<<"\n\n\t可是其他三小鬼不服气,就暗暗商议,决定大唱反调,称他为王霸."<<"\n\n\t 三小鬼笑翻了天,引来其他小鬼.";cout<<"\n\n \t 其他小鬼觉得有意思,就争相玩了起来,并更改为(王8).\n\n\t以此来和扑克映衬,小乐以借此消磨那些没乐趣的时光!"<<endl;cout<<"\n\n\t\ Now 小鬼们,来试试吧,看看谁是传说中的……!"<<" 啊……哈哈哈"<<endl;}void end(){cout<<endl<<endl<<"\t\t谢谢! 祝你下次游戏愉快!\n";}//主函数#include"Game.h"#include<iostream>#include<stdlib.h>using namespace std;void main(){char choice;do{int n=0,flag=0;/* Card pc;pc.set(8,4);pc.show(0,0);pc.showline(0,9);cout<<endl;*/introduction();system("pause");//引入语cout<<"\t Input the number of player:"; //要N个玩家cin>>n;getchar();Player *player=new Player[n];cout<<"随机给玩家发牌: " ;system("pause");system("cls");Giveout(player,n); //给玩家发牌showplayer(player,n);cout<<"输出除对后玩家的的牌";system("pause");system("cls"); //清屏canceldouble(player,n); //删除重复的牌showplayer(player,n); //显示玩家的牌cout<<" 正式开始游戏: ";system("pause");system("cls"); //清屏flag=playgame(player,n);cout<<"\n\nloser is player "<<flag+1<<endl;gotoxy(13,0);cout<<"\nNow we know who is the …… \n ";system("pause");change(player[flag]);player[flag].showcard(12,35);system("pause");gotoxy(23,0);cout<<" hah ,let's yell out loudly ……\n\n";cout<<"\t hah. 啊哈哈哈\n";system("pause");cout<<"\n\n\tWell done \n\n";system("pause");end();cout<<"任意键继续, N 结束游戏!"<<endl;cin>>choice;}while(!(choice=='n'||choice=='N'));}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档