C++制作游戏(整合),《仅1500行》 ,代码奉上

本文分享了一位开发者使用C++编程语言,仅用1500行代码完成的游戏制作过程,涵盖关卡设计和程序实现。作者鼓励读者支持并提出问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//#include<bits/stdc++.h>
#include<iostream>
#include<Windows.h>
#include<conio.h> 
#include<cstring>
#include<cstdio>
#include<ctime>
#include"cmath" 
//#define IsKeyDown(VK_NAME) ((GetAsyncKeyState(VK_NAME) & 0x8000) ? true:false) 
#define mm2 1200
#define mm1 700
#define mm3 1900
#define ctl 857
#define mop 10000
using namespace std;
string xiaotishi[200]={"","首先是活下来,再考虑别的","日出而作,日落而息","食用鱼类可获得不同的增益","",""}; 
/*int vf(int x,int t){
    if(x==t/2-1){return t/2+t/2-t;}
    else{return 100;}
}
int ttle(int fffa)
{
    fffa-=1;
    return fffa;
}*/  
void gettime()
{
    time_t rawtime;
    struct tm *ptminfo;
    time(&rawtime);
    ptminfo = localtime(&rawtime);
    printf(": %02d-%02d-%02d %02d:%02d:%02d(鸡霓太美)",
    ptminfo->tm_year + 1900, ptminfo->tm_mon + 1, ptminfo->tm_mday,
    ptminfo->tm_hour, ptminfo->tm_min, ptminfo->tm_sec);
}
void zairu()//组件
{
	int bl=70;
	int righl=0;
	for(int i=1;i<=20;i++)
	{
		if(xiaotishi[i]!=""){righl+=1;}
	}
	srand((int)time(0));
	int tim=rand()%righl+1;
	system("cls");
	for(int i=1;i<=bl+4;i+=1){
		int timett=25+(int)(75.0 * rand()/(RAND_MAX+1.0));
		if(i==bl+1){
			cout<<"                                                      \n";
			cout<<"                                                      \n";
			cout<<"                                                     \n";
			cout<<"                               (\\                               \n";
			cout<<"                              /  \\                             \n";
			cout<<"                             /    |                             \n";
			cout<<"                            /     |                             \n";
			cout<<"                            |     \\                             \n";
			cout<<"                            /      \\                            \n";
			cout<<"                           |________|____________                  \n";
			cout<<"                           |        |                       \n";
			cout<<"                            \\      /                        \n";
			cout<<"                            |     /                         \n";
			cout<<"                            \\     |                         \n";
			cout<<"                             \\    |                         \n";
			cout<<"                              \\  /                          \n";
			cout<<"                               (/                           \n";
			cout<<"                                                             \n";Sleep(300);	system("cls");continue;		
		}else if(i==bl+2){
			cout<<"                                                      \n";
			cout<<"                                                      \n";
			cout<<"                                                   \n";
			cout<<"                               (\\                               \n";
			cout<<"                             /   \\                             \n";
			cout<<"                            /     |                             \n";
			cout<<"                           /      |                             \n";
			cout<<"                          /       \\                             \n";
			cout<<"                         /         \\                            \n";
			cout<<"                        [___________|___________                  \n";
			cout<<"                         \\          |                       \n";
			cout<<"                          \\        /                        \n";
			cout<<"                           \\      /                         \n";
			cout<<"                            \\     |                         \n";
			cout<<"                             \\    |                         \n";
			cout<<"                              \\  /                          \n";
			cout<<"                               (/                           \n";
			cout<<"                                                             \n";		
			Sleep(300);system("cls");	continue;
		}
		else if(i==bl+3){
			cout<<"                                                      \n";
			cout<<"                                                      \n";
			cout<<"                                                     \n";
			cout<<"                              (\\                               \n";
			cout<<"                             /   \\                             \n";
			cout<<"                           /      |                             \n";
			cout<<"                         /        |                             \n";
			cout<<"                       /          \\                             \n";
			cout<<"                      /            \\                            \n";
			cout<<"                    [_______________|_____                  \n";
			cout<<"                    |               |                       \n";
			cout<<"                      \\            /                        \n";
			cout<<"                       \\          /                         \n";
			cout<<"                         \\        |                         \n";
			cout<<"                           \\      |                         \n";
			cout<<"                             \\   /                          \n";
			cout<<"                              (/                           \n";
			cout<<"                                                            \n";	Sleep(350);system("cls");	continue;
		}
		else if(i==bl+4){
		cout<<"                                                      \n";
		cout<<"                                                      \n";
		cout<<"                                                    \n";
		cout<<"                                   (\\                               \n";
		cout<<"                                   | \\                             \n";
		cout<<"                                   |  |                             \n";
		cout<<"                                   |  |                             \n";
		cout<<"                                   |  \\                             \n";
		cout<<"                                   |   \\                            \n";
		cout<<"                                   |    |                 -                 -\n";
		cout<<"                                   |    |                                                          -                -              \n";
		cout<<"                                   |   /                          -                        -     \n";
		cout<<"                                   |  /                         \n";
		cout<<"                                   |  |                         \n";
		cout<<"                                   |  |                         \n";
		cout<<"                                   | /                          \n";
		cout<<"                                   (/                           \n";
		cout<<"                                                             \n";Sleep(450);system("cls");	continue;		
		}
		else{
		cout<<"                                                      \n\n";
		cout<<"                         正  在  加  载  中...                            \n\n";
		cout<<"                                (\\                               \n";
		cout<<"                                | \\                             \n";
		cout<<"                                |  |                             \n";
		cout<<"                                |  |                             \n";
		cout<<"                                |  \\                             \n";
		cout<<"                                |   \\                            \n";
		cout<<"                                |____|__________________                        \n";
		cout<<"                                |    |                            \n";
		cout<<"                                |   /                            \n";
		cout<<"                                |  /                         \n";
		cout<<"                                |  |                         \n";
		cout<<"                                |  |                         \n";
		cout<<"                                | /                          \n";
		cout<<"                                (/                           \n\n";			
		}
		cout<<"       ";for(int iff=1;iff<=bl;iff++){cout<<"_";}cout<<"\n";
		cout<<"      |";for(int j=1;j<=i;j++){cout<<"▇";}for(int k=1;k<=bl-i;k++){cout<<" ";}cout<<" |\n";
		cout<<"       ";for(int itt=1;itt<=bl;itt++){cout<<"▔";}cout<<"\n";
		cout<<"                                     "<<i*100/bl<<"%                 \n";
		cout<<"                        小提示:"<<xiaotishi[tim];
		Sleep(timett);
		system("cls");
	}Sleep(400);
}
const long long MAXN=10000000000;
int fishjez[30]={0,80,40,60,90,100,85,55,75,25,25,40,60,50,45,130,70};
string cfnm[25]={"","烤肉","烤鱼","荒野烤肉","烤土豆","肉汤","土豆泥","秘制炖肉","","","","",""};
int cfjez[25]={0,95,80,130,105,155,135,200}; 
string gjfxx[30]={"","獠牙","利爪","笙忼术","笙电术","土玄术","战斧","法杖","易闽术","鸡汤术","篮球","易慴术","戟埕术","黑子"};
string fishing[200]={"","石斑鱼","螃蟹","条石斑","鲭鱼","鲶鱼","红鳟鱼","海鲂","小鲨鱼","海参","鳐鱼","沙丁鱼","鳕鱼","蝴蝶鱼","章鱼","秋刀鱼","罗非鱼","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};
string fms[8]={"","I","II","III","IV","V"};
string dfs1[20]={"","","",""}; 
struct o{
	int times;
	int jjes;
}fishs[1000]; 
struct sc{
    int ts;
    int js;
}cfs[505];
int main(){ for(int i=1;i<=7;i++){cfs[i].js =cfjez[i];} 
system("title 快乐游戏机");
for(int i=1;i<=14;i+=1){fishs[i].jjes =fishjez[i];}string gjfx;int ttk=0;
char a1[100][100]={
"################################### ",
"#!             #    *#            # ",
"######      #####   #####    ###### ",
"#                               * # ",
"#####  ##########   ########  ##### ",
"#   ##        *#  #  #       ##   # ",
"#     ###      #  #  #    ###     # ",
"# ####   ########   ######   #### # ",
"#               ## ##             # ",
"#    #########        ########    # ",
"#             ##    ##  @    	   # ",
"############    ####    ########### ",
"#           ##        ##          # ",
"### ##        ###  ###       ###  # ",
"#*   #                       #@   # ",
"################################### ",
"                                    ",
};
char a2[100][100]={
"################################### ",
"#!       ###                      # ",
"#######     ###      ########     # ",
"#      ###     ###       *  #     # ",
"#         ###     ###########     # ",
"#   ######   ###                  # ",
"#        #      ################  # ",
"#   ###  #                        # ",
"#   # *  #         ################ ",
"#   ######      ### *#            # ",
"#            ###      #####       # ",
"#         ###        #     #      # ",
"#      ###          #   #   #   @ # ",
"#   ###      ########   #   #     # ",
"#                       #         # ",
"################################### ",
"                                    ",
};
char a3[100][100]={
"################################### ",
"# @   #####    #   #              # ",
"#  # # &#   #  #   #   # &  #     # ",
"#   #   # ##   #   #   #   *#     # ",
"#       ##    ##   ##  ######     # ",
"#    &  #    #  # #  #            # ",
"################# ################# ",
"#                !                # ",
"################# ################# ",
"#            #  # #  #*           # ",
"#           # ##   ##     # #     # ",
"#  *     ###   #   #@    #   #    # ",
"#     ###      #   #    #  &  #   # ",
"#####          #   #  ########### # ",
"#&  ########   #   #     @        # ",
"################################### ",
"                                    ",
};
char a4[100][100]={
"################################### ",
"#              #   #        *     # ",
"#    ######   #  !  #   ######    # ",
"#          ###       ###          # ",
"#######       ##   ##       ####### ",
"#  *   ##       # #       ##      # ",
"#    ##    ###### #####     ##    # ",
"#  ##    ##            ##     ##  # ",
"#      ##     ##   ##    ##       # ",
"#   ###  @   #  ###  # *    ###   # ",
"# ##*  ##                 ##   ## # ",
"# #      ##    #   #    ##      # # ",
"#          #   #   #   #    @     # ",
"#        #######   #######        # ",
"#                                 # ",
"################################### ",
"                                    ",
};
char a5[100][100]={
"################################### ",
"#!                               *# ",
"#        ####    ###         ###### ",
"#########       #   #####         # ",
"# @            #         ####     # ",
"#######      ##   ######  #  ###  # ",
"#         ###         *#  #    #  # ",
"#      ###        ######   #   #  # ",
"#   ###        ###         #   #  # ",
"#           ###      ###   #   #  # ",
"####     ###      ###  #   #   #  # ",
"#   #####     ####     #  #    #  # ",
"#          ###         #  #    #  # ",
"#     #####    ###########   ###  ##",
"#  ###       ##  @                 #",
"####################################",
"                                    ",
};
    string s20;int fmt;string fucks;
    int k10=0;string sb0="欢迎使用快乐游戏机,尊敬的用户,快乐游戏机竭诚为您服务!",sb1="欢迎来到鸡仙大陆!",sb2="这片大陆危机四伏,你要想方设法的生存下去,并逃出这里!";
    for(int i=0;i<=sb0.size()-1;i++){
        cout<<sb0[i];
        Beep(mm3,45);Sleep(13);}   
    Sleep(620);Beep(mm3,60);
    cout<<endl<<"     请输入游戏机的密码(6位):" ; Sleep(600);system("cls");   
    char hhhh;string qa;
    cout<<"\n\n         0   1   2\n\n";
    cout<<"         3   4   5\n\n";
    cout<<"         6   7   8\n\n";
    cout<<"         坤  9  坤";
    for(int i=1;i<=51;i++){
    	if(i==50){system("cls");system("title 帮帮我");
    	cout<<"\n\n        "; 
    	for(int fo=1;fo<=6;fo++)
    	{cout<<"       ";
    		 for(int j=1;j<=fo;j++){cout<<"·";}
        cout<<"\n\n         0   1   2\n\n";
        cout<<"         3   4   5\n\n";
        cout<<"         6   7   8\n\n";
        cout<<"         坤  9  坤"; Sleep(555);system("cls");
		}
       
		Sleep(400);system("title 孤岛生存");break;} 
        hhhh=_getch();qa+=hhhh;system("cls");cout<<"\n\n        "; 
        for(int mt=1;mt<=i%6;mt++){cout<<"·";}
        cout<<"\n\n         0   1   2\n\n";
        cout<<"         3   4   5\n\n";
        cout<<"         6   7   8\n\n";
        cout<<"         坤  9  坤"; 
        if(i%6==0)
        {Sleep(130);
            if(qa=="123456"){cout<<"\n          密码正确!"<<endl;Beep(mm2,201);break; }
            cout<<"\n          密码错误    ";Beep(mm1,500);
            if(i>1){cout<<"已尝试"<<k10+1<<"次"<<endl;Sleep(300);}k10+=1;
            if(i==8){cout<<"\n";for(int i=1;i<=6;i+=1){Sleep(499);cout<<i;}cout<<"\n";Sleep(555);break;} 
            qa="";system("cls"); 
        cout<<"\n\n         0   1   2\n\n";
        cout<<"         3   4   5\n\n";
        cout<<"         6   7   8\n\n";
        cout<<"         坤  9  坤";
        }     
    }  
		while(2){
         cout<<"请问你想玩什么游戏?"<<endl;Sleep(500);
      cout<<"双城之战请输入:1  抽卡牌请输入:2  解救人质请输入:3  石头剪刀布请输入:4  鸡仙大陆(生存版)请输入:5"<<endl;
        long long zidan=0;
//木材cll1  藤条cll2  棕榈叶cll3  铁锭cll4  石片cll5  青金石cll6
int cl7=0,ml1=0,tl1=0,tl2=0,tl3=0,tl4=0,tl5=0,tl6=0,tl7=0,plof=0; 
int cll1[49]={0,3,2,10,3,2,5,12,20,0,2,4,6,5,1,1,0,0,1,0,0,0,4,0,0,2,500,5,0,0,10,100,0,0,10,10};
int cll2[49]={0,0,10,15,0,2,3,5,12,0,0,3,4,3,5,30,5,0,0,0,1,0,0,0,0,1,0,7,0,40,0,100,0,0,50,0};  
int cll3[49]={0,3,0,15,2,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,2,0,0,10,50,100,80,200,0};
int cll4[49]={0,0,1,7,0,0,0,0,4,0,0,0,2,0,0,0,20,1,1,1,1,5,0,0,2,4,500,0,4,0,0,0,0,0,100,5};  
int cll5[49]={0,0,0,0,1,0,0,2,0,2,3,0,1,0,10,0,5,0,0,0,0,0,0,0,0,0,0,5,0,20,0,0,30,0,0,0};
int jnj[40]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};  
int hs[10]={0,0,0},hss[10]={0,0,0};
int j11[40]={0,1,2,4,6,10,15,20,60,150,151};
int j12[40]={0,7,15,25,50,100,220,340,1314,3000,250250,857857,22222,53453};
int j13[40]={0,25,50,90,175,220,350,700,1100,4500,3838,3838438,43553,114514};
int linjian[40]={0,0,0,0,0,0};
int jjjb[20]={0,7,15,32,60,120,400,700,1000,2500,3830,413,131,3123};
int ve[20]={0,12,12,12};string fz[30]={"","野猪","毒腥","吞噬","火电","咀骨","僵尸","协增","黑子","长臂","召唤","黄眸","蛛形","鸡王"};
int gjs[30]={0,2,3,2,7,10,12,19,31,54,92,8,15,100},xls[30]={0,15,21,70,40,82,100,120,200,2423,104664,5436,3665,200};
int jjjj[20]={0,10,14,5,32,47,69,105,180,350,1000,20,35,1500};
string ssss[30]={"","小野猪","小狮子","小鳄龟","火电怪","土蜥蜴","野人酋长","森林女巫","森林巨人","钏姍钾","蔡虚坤","人物3","人物4","人物5"};
int xxxx[20]={0,160,220,700,340,470,600,1000,1700,20000,500000,114514,20005,1231};
int jbs[40]={0,90,15,120,220,400,550,300,1,8,1,10,35,40,20,400,500,1300,1800,10000,25000};
string sss[20]={"","绿色平原","沙漠丘陵","世纪峡谷","死亡瀑布","黑暗森林","野人部落","僵尸村落","沉船","远山","废弃的篮球场","山顶洞","大山顶洞","超大的山顶洞"};
int xlz[100]={0,320,170,250,300,250,220,220,400,2000};
int gjz[100]={0,28,35,16,14,18,10,13,7,50}; 
int ltz[100]={0,200,400,200,180,220,270,250,100,50};
int wgj[100]={0,120,100,150,130,110,200,500,66666};
int dssgj[100]={0,12,15,5,100,160,220,350,1250,4500,6000,55,70,63};
int dssxl[100]={0,160,220,700,450,1000,1200,2000,7000,20000,500000,100000,320000,780000};
string ds[100]={"","小野猪","小狮子","小鳄龟","火电怪","土蜥蜴","野人酋长","森林女巫","小黄嘉安","钏姍钾","蔡虚坤"};
string wnm[100]={"","天空之刃","风鹰剑","原木刀","阿莫斯之弓","赤沙之杖","无工之剑","狼末","反物质核弹",""};
string cnm[100]={"","宠物1","宠物2","宠物3","宠物4","宠物5","宠物6","","","",""};
int fmtj=0,fmtj2=0,fmtj3=0;int jl=150;
int kjk;int uxl;int fy=0;int cl6=0;string dfs,dfs2; int ppm,ppm2;
int max1=0,max2=0;int zxc=0;int yd;int uyu;
long long q=0,am&
评论 32
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值