栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++实现简单移动“吃”钱小游戏

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++实现简单移动“吃”钱小游戏

#include
#include
#include
#include
using namespace std;
int eee = 0,ala = 0;
int fen = true;
int x = 1,y = 1,nextx,nexty,ranx,rany,scole = 0,er = 1;
int random(int b)
{
    return rand()%b+1;
}
void SetCCPos(int x, int y){
    HANDLE hOut;
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD pos;
    pos.X = x;pos.Y = y;
    SetConsoleCursorPosition(hOut, pos);
}
int main()
{
    srand((int)time(0));
    char giao[7];
    int len;
    cout << "输入想要的大小" << endl;
    cin >> len;
    system("cls");
    cout << "输入想要的等级变化(1-7级)。" << endl;
    for(int i = 0;i <= 6;i++){
        cout << i+1 << "级:";
        cin >> giao[i];
    }
    system("cls");
    int abc = len-2;
    char a[len][len],now[len][len];
    for(int i = 0;i <= len-1;i++){
        for(int j = 0;j <= len-1;j++){
            if(i == 0 or j == 0 or i == len-1 or j == len-1)
                a[i][j] = '*';
            else if(i == 1 and j == 1)
                a[i][j] = giao[eee];
            else
                a[i][j] = ' ';
        }
    }
    for(int i = 0;i < len;i++){
        for(int j = 0;j < len;j++){
            cout << a[i][j] << " ";
            if(a[i][j] != giao[eee] and a[i][j] != '$')
                now[i][j] = a[i][j];
            else
                now[i][j] = ' ';
        }
        cout << endl;
    }
    cout << "退出按p,移动awsd。" << endl << "目标:“吃”$。每10分升级,最高7级。" << endl;
    cout << "你的分数目前是:" << scole << endl;
    cout << "你的等级目前是:" << eee+1 << endl;
    char b;
    for(int fdfdbsdbqpxpmfj;true;b = getch()){
        if(b == 'w'){
            nextx = -1;
            nexty = 0;
        }
        else if(b == 'a'){
            nextx = 0;
            nexty = -1;
        }
        else if(b == 's'){
            nextx = 1;
            nexty = 0;
        }
        else if(b == 'd'){
            nextx = 0;
            nexty = 1;
        }
        else if(b == 'p'){
            cout << "你的分数是:" << scole << endl << "感谢游玩!";
            exit(0);
        }
        if(a[x+nextx][y+nexty] != '*'){
            if(a[x+nextx][y+nexty] == '$'){
                scole++;
                fen = true;
                SetCCPos(16,len+2);
                cout << scole;
            }
            a[x][y] = ' ';
            a[x+nextx][y+nexty] = giao[eee];
            x += nextx;
            y += nexty;
        }
        if(fen){
            ranx = random(abc);
            rany = random(abc);
            while(a[ranx][rany] == giao[eee]){
                ranx = random(abc);
                rany = random(abc);
            }
            a[ranx][rany] = '$';
            fen = false;
        }
        for(int i = 0;i < len;i++){
            for(int j = 0;j < len;j++){
                if(a[i][j] != now[i][j]){
                    SetCCPos(j*2,i);
                    cout << a[i][j];
                }
            }
        }
        if(scole%10 == 0 and eee != 6 and scole != 0){
            eee = scole/10;
            ala = scole/10+1;
            SetCCPos(16,len+3);
            cout << eee+1;
        }
        if(eee == 6 and er == 1){
            system("cls");
            SetCCPos(0,0);
            cout << "你赢了,恭喜你!" << endl;
            exit(0);
        }
        for(int i = 0;i < len;i++){
            for(int j = 0;j < len;j++){
                now[i][j] = a[i][j];
            }
        }
    }
    return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/529204.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号