📄 3_5.cpp
字号:
// 3_5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<cstdlib>
#include<conio.h>
#include"ardDeck.h"
using std::cout;
using std::endl;
int contrast(int i, int j) //比较牌面值的大小
{
if(i%13==j%13)
{
if(i>j)
return 1;
else if(i<j)
return 0;
else
{
cout<<"出现内部错误\n";
exit (-1);
}
}
else if(i%13>j%13)
return 1;
else
{
return 0;
}
}
void DealHand(CardDeck &d,int n) // 从d中顺序选取n张牌,对其排序,打印其值
{
int currentcard=d.GetCard();
int i,j,temp;
for(i=currentcard;i<currentcard+n;i++)
for(j=i+1;j<currentcard+n;j++)
if( contrast( d.value(i),d.value(j) ) )
{
temp=d.value(i);
d.SetCardValue(i,d.value(j));
d.SetCardValue(j,temp);
}
cout<<"下面是你的牌(已排序): 作出你的选择\n";
for(i=currentcard;i<currentcard+n;i++)
d.PrintCard(i);
d.SetCard(n);
}
void Game(CardDeck &card,int &total) //
{
DealHand(card,5);
cout<<"\n\n依次比较你的牌是否大于剩余牌中的第一张牌的\n"
<<"大于键入y "<<"小于键入非y键\n\n";
int current=card.GetCard();
for(int times=1;times<=5;times++)
{
cout<<"\n第 "<<times <<" 次\n";
cout<<"your choice: ";
if(getch()=='y')
{
cout<<"你键入是y键\n";
if(contrast( card.value((current-6+times)),card.value(card.GetCard() ) ) )
{
cout<<"right! ";
card.PrintCard(card.GetCard());
total++;
}
else
{
cout<<"error! ";
card.PrintCard(card.GetCard());
}
}
else
{
cout<<"你键入的是非y键\n";
if(contrast( card.value((current-6+times)),card.value(card.GetCard() ) ) )
{
cout<<"error! ";
card.PrintCard(card.GetCard());
}
else
{
cout<<"right! ";
card.PrintCard(card.GetCard());
total++;
}
}
card.SetCard();
}
}
void Print(int times,int wintimes,int totalscore)
{
cout<<"\n\n 统计信息\n";
cout<<"总局数: "<<times-1<<endl;
cout<<"赢局数: "<<wintimes<<endl;
cout<<"总分:"<<totalscore<<endl;
}
int main(int argc, char* argv[])
{
CardDeck card;
int totaltimes=1,wintimes=0,losetimes=0,totalscore=0;
while(true)
{
int times=1;
int flag=0;
card.Shuffle();
cout<<"是否想调出全部牌的信息\n";
cout<<"想(y?)";
if(getch()=='y')
flag=1;
if(flag)
{
cout<<"\n";
for(int i=0;i<=51;i++)
{
if(i%13==0&&i)
cout<<"\n";
card.PrintCard(i);
}
}
while(true)
{
int total=0;
int score=0;
cout<<"\n";
cout<<"\n 第 "<<totaltimes<<" 局\n\n";
Game(card,total);
cout<<"\n";
score=20*total;
cout<<"\n一局结束\n";
times++;
totaltimes++;
if(score<60)
{
cout<<"真不走运,你输了!!!\n";
losetimes++;
}
else
{
cout<<"恭喜你!!!\n";
wintimes++;
}
totalscore+=score;
cout<<"你的得分: "<<score<<endl;
if(times<=4)
{
cout<<"continue(y?)\n";
if(getch()!='y')
{
Print(totaltimes,wintimes,totalscore);
exit(0);
}
}
else
{
cout<<"剩余牌数少于 10 张,如要继续重新洗牌\n";
cout<<"continue(y?)\n";
if(getch()!='y')
{
Print(totaltimes,wintimes,totalscore);
exit(1);
}
else
break;
}
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -