YUTU更新了!
游戏适合c++5.11
文件名:“沙盒.cpp”、“game.h”、“sh.h”、“fj.h”。
上代码(萌新不要随便改文件名,否则编译不出来):
fj.h:
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
int fj=15;
char fjt[30][30],fj_jp;
int t=0,drwz,fjsj=1,xm=0;
void qk(){
system("cls");
}
void fj_scdt(){
cout<<"+------------------------------+\n";
for(int i=0;i<30;i++){
cout<<"|";
for(int j=0;j<30;j++){
if(i==29&&j==fj){//€
///o
cout<<"O";
}else if(fjt[i][j]=='z'){
cout<<"*";
fjt[i][j]=' ';fjt[i-1][j]='z';
}else if(fjt[i][j]=='d'){
cout<<"U";
if(fjt[i][j]=='z'){
fjt[i][j]=' ';
xm++;
}
}else{
cout<<" ";//●u
// uuu
}
}
cout<<"|\n";
}
cout<<"+------------------------------+\n";
cout<<"ad控制左右移动,空格发射子弹,t退出";
}
void fj_main() {
t=0;
xm=0;
system("cls");
system("title 沙盒副本——打敌人");
for(int i=0;i<30;i++){
for(int j=0;j<30;j++){
fjt[i][j]=' ';
}
}
while(1){
fj_scdt();
fj_jp=getch();
switch(fj_jp){
case 'a':
fj--;
break;
case 'd':
fj++;
break;
case ' ':
fjt[28][fj]='z';
break;
case 't':
t=1;
break;
}
if(fjsj==5){
drwz=rand();
drwz%=30;
fjt[0][drwz]='d';
fjsj=0;
}else{
fjsj++;
}
system("cls");
if(t){
break;
}
}
system("cls");
cout<<"你一共消灭了"<<xm<<"个敌人。\n";
cout<<"按任意键继续……";
getch();
system("cls");
system("title YUTU制作——沙盒游戏");
}
sh.h
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <cmath>
#include <windows.h>
using namespace std;
char cz[15][30];
void printf_red(const char *s)
{
printf("\033[0m\033[1;31m%s\033[0m", s);
}
void printf_green(const char *s)
{
printf("\033[0m\033[1;32m%s\033[0m", s);
}
void printf_yellow(const char *s)
{
printf("\033[0m\033[1;33m%s\033[0m", s);
}
void printf_blue(const char *s)
{
printf("\033[0m\033[1;34m%s\033[0m", s);
}
void printf_pink(const char *s)
{
printf("\033[0m\033[1;35m%s\033[0m", s);
}
void printf_cyan(const char *s)
{
printf("\033[0m\033[1;36m%s\033[0m", s);
}
void czms(){
char kejiajunchupin,fx,fk=' ';
int sdf1=8,sdf2=8;
while(kejiajunchupin!=27){
kejiajunchupin=getch();
switch(kejiajunchupin){
case 'w':
if(1){
sdf1--;
}
fx='w';
system("cls");
break;
case 's':
if(1){
sdf1++;
}
fx='s';
system("cls");
break;
case 'a':
if(1){
sdf2--;
}
fx='a';
system("cls");
break;
case 'd':
if(1){
sdf2++;
}
fx='d';
system("cls");
break;
case 't':
fk=getch();
system("cls");
break;
case ' ':
if(fx=='w'){
cz[sdf1-1][sdf2]=fk;
}else if(fx=='s'){
cz[sdf1+1][sdf2]=fk;
}else if(fx=='a'){
cz[sdf1][sdf2-1]=fk;
}else if(fx=='d'){
cz[sdf1][sdf2+1]=fk;
}
system("cls");
break;
default :
system("cls");
break;
}
for(int i=0;i<15;i++){
for(int j=0;j<30;j++){
if(i==sdf1&&j==sdf2){
if(fx=='w'){
cout<<"上";
}else if(fx=='s'){
cout<<"下";
}else if(fx=='a'){
cout<<"左";
}else if(fx=='d'){
cout<<"右";
}
}else if(cz[i][j]>31&&cz[i][j]<127){
cout<<cz[i][j]<<cz[i][j];
}else{
cout<<cz[i][j];
}
}
cout<<endl;
}
cout<<"按t切换方块,按空格放方块(方块初始为空格),按ESC退出";
}
}
game.h
#include"sh.h"
#include"fj.h"
using namespace std;
void m(){
printf_red(" ");
system("mode con cols=120 lines=46");
system("title YUTU制作——沙盒游戏");
system("cls");
char dt[15][30],yutu,fx,sj=60;
int sdf1=8,sdf2=8,g=1,die,gw1=9,gw2=9,hp=10,gwhp=1;
for(int i=0;i<15;i++){
for(int j=0;j<30;j++){
dt[i][j]='#';
cz[i][j]=' ';
}
}
dt[9][9]='~';
dt[30][30]='~';
dt[30][29]='~';
dt[30][28]='~';
dt[30][27]='~';
dt[29][27]='~';
dt[3][30]='~';
dt[3][29]='~';
dt[3][28]='~';
dt[3][27]='~';
dt[4][27]='~';
dt[7][7]='w';
dt[5][5]='w';
dt[6][6]='w';
dt[10][10]='w';
dt[21][21]='w';
dt[22][30]='w';
dt[3][29]='w';
dt[3][28]='w';
dt[3][27]='w';
dt[4][27]='w';
dt[8][8]=' ';
dt[10][9]=' ';dt[10][10]=' ';dt[10][11]=' ';dt[9][9]=' ';dt[9][10]='~';dt[9][11]='~';
string name;
cout<<"你的名字叫什么?\n";
cin>>name;
system("cls");
while(1){
for(int i=0;i<15;i++){
for(int j=0;j<30;j++){
if(i==sdf1&&j==sdf2){
if(fx=='w'){
cout<<"上玩";
}else if(fx=='s'){
cout<<"下玩";
}else if(fx=='a'){
cout<<"左玩";
}else if(fx=='d'){
cout<<"右玩";
}
if(dt[i][j]=='~'){
hp--;
die=1;
}
if(hp==0){
sdf1=8;
sdf2=8;//
}
}else if(i==gw1&&j==gw2){
cout<<"(@@)";
if(dt[gw1][gw2]=='~'){
gwhp=0;
gw1=100;
}
}else{
if(sj>50&&sj<170){
if(dt[i][j]=='#'){
cout<<"■■";
}else if(dt[i][j]=='@'){
printf_yellow("■■");
}else if(dt[i][j]=='~'){
printf_red("■■");
}else if(dt[i][j]=='w'){
printf_blue("");
}else{
cout<<dt[i][j]<<dt[i][j]<<dt[i][j]<<dt[i][j];
}
}else{
if(dt[i][j]=='~'){
printf_red("■■");
}else if(dt[i][j]=='w'){
printf_blue("");
}else{
cout<<dt[i][j]<<dt[i][j]<<dt[i][j]<<dt[i][j];
}
}
}
}
cout<<endl;
for(int j=0;j<30;j++){
if(i==sdf1&&j==sdf2){
if(fx=='w'){
cout<<"↑家";
}else if(fx=='s'){
cout<<"↓家";
}else if(fx=='a'){
cout<<"←家";
}else if(fx=='d'){
cout<<"→家";
}
}else if(i==gw1&&j==gw2){
cout<<"u怪u";
}else{
if(sj>50&&sj<170){
if(dt[i][j]=='#'){
cout<<"■■";
}else if(dt[i][j]=='@'){
printf_yellow("■■");
}else if(dt[i][j]=='~'){
printf_red("■■");
}else if(dt[i][j]=='w'){
printf_blue("");
}else{
cout<<dt[i][j]<<dt[i][j]<<dt[i][j]<<dt[i][j];
}
}else{
if(dt[i][j]=='~'){
printf_red("■■");
}else if(dt[i][j]=='w'){
printf_blue("");
}else{
cout<<dt[i][j]<<dt[i][j]<<dt[i][j]<<dt[i][j];
}
}
}
}
cout<<endl;
}
if(sj>50&&sj<170){
cout<<"早上\n";
cout<<"按空格挖掘,按wasd上下左右行走,按x、f放方块,\n按k清空地图,按c创造,按j时间+12,按TAB设置,按g小游戏副本(打敌人)按p切换色调\n有时候野怪懒得游泳,它只有1滴血\n玩家名称:"<<name<<"\n";
cout<<"X:"<<sdf1<<"Y:"<<sdf2<<"\n";
}else{
cout<<"晚上\n";
cout<<name<<":“黑,真他妈黑啊”\n";
}
if(gwhp==0){
cout<<"野怪意外死亡,已经跑走了\n";
}
if(sdf1<0||sdf1>=15||sdf2<0||sdf2>=30){
hp=0;
die=2;
}
for(int i=1;i<=hp;i++){
if(i%2==1){
cout<<"(";
}else{
cout<<")";
}
}
if(hp==0){
if(die==1){
cout<<"你发现地板是熔岩做的\n";
}else if(die==2){
cout<<name<<"掉出了这个世界\n";
}else if(die==3){
cout<<"野怪把"<<name<<"吃掉了\n";
}
sdf1=8;
sdf2=8;
hp=10;
}
yutu=getch();
switch(yutu){
case 'w':
if(dt[sdf1-1][sdf2]==' '||dt[sdf1-1][sdf2]=='~'||dt[sdf1-1][sdf2]=='w'){
sdf1--;
}
fx='w';
system("cls");
break;
case 's':
if(dt[sdf1+1][sdf2]==' '||dt[sdf1+1][sdf2]=='~'||dt[sdf1+1][sdf2]=='w'){
sdf1++;
}
fx='s';
system("cls");
break;
case 'a':
if(dt[sdf1][sdf2-1]==' '||dt[sdf1][sdf2-1]=='~'||dt[sdf1][sdf2-1]=='w'){
sdf2--;
}
fx='a';
system("cls");
break;
case 'd':
if(dt[sdf1][sdf2+1]==' '||dt[sdf1][sdf2+1]=='~'||dt[sdf1][sdf2+1]=='w'){
sdf2++;
}
fx='d';
system("cls");
break;
case ' ':
if(fx=='w'&&dt[sdf1-1][sdf2]!='~'&&dt[sdf1-1][sdf2]!='w'){
dt[sdf1-1][sdf2]=' ';
}else if(fx=='s'&&dt[sdf1+1][sdf2]!='~'&&dt[sdf1+1][sdf2]!='w'){
dt[sdf1+1][sdf2]=' ';
}else if(fx=='a'&&dt[sdf1][sdf2-1]!='~'&&dt[sdf1][sdf2-1]!='w'){
dt[sdf1][sdf2-1]=' ';
}else if(fx=='d'&&dt[sdf1][sdf2+1]!='~'&&dt[sdf1][sdf2+1]!='w'){
dt[sdf1][sdf2+1]=' ';
}
sdf1%=15;
sdf2%=30;
system("cls");
break;
case 'x':
if(fx=='w'){
dt[sdf1-1][sdf2]='@';
}else if(fx=='s'){
dt[sdf1+1][sdf2]='@';
}else if(fx=='a'){
dt[sdf1][sdf2-1]='@';
}else if(fx=='d'){
dt[sdf1][sdf2+1]='@';
}
system("cls");
break;
case 'f':
if(fx=='w'){
dt[sdf1-1][sdf2]='@';
}else if(fx=='s'){
dt[sdf1+1][sdf2]='@';
}else if(fx=='a'){
dt[sdf1][sdf2-1]='@';
}else if(fx=='d'){
dt[sdf1][sdf2+1]='@';
}
system("cls");
break;
case 'k':
for(int i=0;i<=15;i++){
for(int j=0;j<=30;j++){
dt[i][j]=' ';
}
}
system("cls");
break;
case 'c':
czms();
system("cls");
break;
case 'j':
sj+=120;
system("cls");
break;
case 9:
system("cls");
while(1){
cout<<"<功能——设置>\n";
if(g==1){
cout<<"血量=20\n ";
} else if(g==2){
cout<<"修改名字\n ";
}else if(g==0){
cout<<"退出\n";
}
cout<<"ws控制列表,空格确定\n";
yutu=getch();
if(yutu=='w'){
g--;
g%=3;
}else if(yutu=='s'){
g++;
g%=3;
}else if(yutu==' '){
if(g==1){
hp=20;
}else if(g==2){
cout<<"输入你的新名字:";
cin>>name;
}else if(g==0){
break;
}
}
system("cls");
}
case 'g':
fj_main();
default:
system("cls");
break;
}
if(gwhp==1){
if(gw1<sdf1&&dt[gw1+1][gw2]==' '||gw1<sdf1&&dt[gw1+1][gw2]=='~'||gw1<sdf1&&dt[gw1+1][gw2]=='w'){
gw1++;
}else if(gw1>sdf1&&dt[gw1-1][gw2]==' '||gw1<sdf1&&dt[gw1-1][gw2]=='~'||gw1<sdf1&&dt[gw1-1][gw2]=='w'){
gw1--;
}else if(gw2<sdf2&&dt[gw1][gw2+1]==' '||gw1<sdf1&&dt[gw1][gw2+1]=='~'||gw1<sdf1&&dt[gw1][gw2+1]=='w'){
gw2++;
}else if(gw2>sdf2&&dt[gw1][gw2-1]==' '||gw1<sdf1&&dt[gw1][gw2-1]=='~'||gw1<sdf1&&dt[gw1][gw2-1]=='w'){
gw2--;
}else if(sdf1==gw1&&sdf2==gw2){
hp--;
die=3;
}
}else{
gw1=4;
gw2=2;
gwhp=1;
}
sj++;
sj%=240;
}
}
沙盒.cpp
#include"game.h"
int main(){m();}