c++小游戏大集结

1.猜数

#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<ctime>
#include<cstdio>
#include<conio.h>
using namespace std;
int n,m;
bool c[100005];
int main()
{
    cout<<"猜数 3.2\n"; 
    srand(time(NULL));
    cout<<"==============================================================\n几人猜数(只支持100000人以内)??";
    cin>>n;
    cout<<"==============================================================\n0~几??";
    cin>>m;
    for(;;)
    {
        cout<<"==============================================================\n开始!!!";
        int x=rand()%(m+1),y,h=0,e=m,t=rand()%n;
        bool hh=1,ee=1;
        do
        {
            cout<<"\n==============================================================\n";
            cout<<h<<"~"<<e<<endl;
            ++t;
            t-=t>n?n:0;
            if(!c[t])
              cout<<t<<"号猜(电脑帮猜?输-1 设置TA为电脑?输-2)",cin>>y;
            if(y==-2)
              c[t]=1;
            if(y==-1||c[t])
            {
                y=(h+e)/2;
                cout<<"帮"<<t<<"号猜猜成"<<y<<endl;
                if(y==x)
                  break;
                if(y>x)
                {
                    cout<<"大了";
                    e=y; 
                    continue;
                }
                if(y<x)
                {
                    cout<<"小了";
                    h=y; 
                    continue;
                }
            } 
            if(y<=h||y>=e)
            {
                cout<<"浪费机会!!!";
                continue;
                if(!h&&!y)
                  if(hh)
                    hh=0;
                else
                {
                    cout<<"浪费机会!!!";
                    continue;
                }
                if(e==m&&y==m)
                  if(ee)
                    ee=0;
                else
                {
                    cout<<"浪费机会!!!";
                    continue;
                }
            }
            if(y>x)
            {
                cout<<"大了";
                e=y; 
            }
            if(y<x)
            {
                cout<<"小了";
                h=y; 
            }
        }while(x!=y);
        cout<<t<<"号赢了!!!\n==============================================================\n再来一局吗?\ny/n\n";
        char a;
        a=getch();
        if(a=='n'||a=='N')
          break; 
    }
    getchar();
    cout<<"==============================================================\nbyebye!\n==============================================================\n双击任意键结束,单机空格关机!";
    char a=getch();
    if(a==' ')
    {
        cout<<"\n确定吗??确定点空格一下,否则双击任意键结束。";
        a=getch();
        if(a==' ')
          system("shutdown -s -t 0");
    }
    return 0; 
}

2.斗地主

 
#include<bits/stdc++.h>
#define PLAYERCOUNT 3
#define CARDSCOUNT 54
#define CURRENTPLAYER 0
#define VALUECOUNT 17
#define ERROR -1
 
using namespace std;
const char toFigure[]="34567890JQKA 2YZ";
enum COLOR{  //花色显示ASCII: 3~6
    eHEART=3,//红桃 
    eDIAMOND,//方片 
    eCLUB,   //草花 
    eSPADE   //黑桃 
};
 
class Card;
class CardsType;
class CardGroup;
class Player;
class Landlords;
class LastCards;
bool makeChoice(string tip);
bool cmp(Card* a,Card* b);
 
class Card{
  public:
    char figure;
    COLOR color;
    int value;
    Card(char _figure,COLOR _color){
        figure=_figure;
        color=_color;
        value=calValue();
    }
    int calValue(){
        for(int i=0;toFigure[i];i++){
            if(toFigure[i]==figure){
                return i;
            }
        }
        return ERROR;
    }
    void print(){
        assert(value!=ERROR);
        if(figure=='Z'){
            cout<<"ZZ";
        }else if(figure=='Y'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值