YUTU更新了一些地方:
重力控制、怪物自主移动、道具栏、跳跃极限、色调控制。
(创造和打敌人副本维护中,暂不开放)
void photo_man()是后期做背包、合成需要的,现在暂时没有用处。
void muzic_die()是死亡画面,摔死有时候不会播放死亡画面,这是bug。
合成界面尚未更新,请务必不要按下“H”。
自测可运行(c++ 5.11)。
好了不说了,上代码。
(不要随意修改文件名,如运行不了,用作者提供的文件名)
(第一次运行,请把所有的文件编译一次)
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"
#define qdo 262
#define qre 294
#define qmi 330 //q前缀为低音,1后缀为高音,s前缀为半音阶
#define qfa 349
#define qso 392
#define qla 440
#define qsi 494
#define do 523
#define re 578
#define mi 659
#define fa 698
#define so 784
#define la 880
#define si 988
#define do1 1046
#define re1 1175
#define mi1 1318
#define fa1 1480
#define so1 1568
#define la1 1760
#define si1 1976
#define sqdo 277
#define sqre 311
#define sqfa 370
#define sqso 415
#define sqla 466
#define sdo 554
#define sre 622
#define sfa 740
#define sso 831
#define sla 932
#define sdo1 1046
#define sre1 1245
#define sfa1 1480
#define sso1 1661
#define sla1 1865
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
string name,shijie="平坦世界";
char dt[15][30],yutu,fx,sj=60,sl[15][30]; // 0 1 2 3
int sdf1=8,sdf2=8,g=1,die,gw1=9,gw2=9,hp=10,gwhp=1,wpl[9]={0,1,2,3,0,0,0,0,0},wplgs[9]={0,0,100,0,0,0,0,0,0},nj=100;
int pai = 400,ban = 200,ting = 128;
int szt=0,gzt=0;
int slsh=0;
//合成
int xz=5;
bool tc=1;
string q=" 空",w=" 空",e=" 空";//[][][]
string a=" 空",s=" 空",d=" 空";//[][][]
string z=" 空",x=" 空",c=" 空";//[][][]
struct mob{
int hp,number,dw;
string name;
};
struct block{
int dlw;
string ym;
char yz;
int wz1,wz2;
};
void color(int a)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
/* 1 深蓝色
2 深绿色
3 深青色
4 深红色
5 深粉色
i 黄色
7 深白色
8 灰色
9 浅蓝色
10 浅绿色
11 浅青色
12 浅红色
13 浅粉色
14 浅黄色
15 浅白色
背景
1~15 黑色
16~31 深蓝色
32~47 深绿色
48~63 深青色
64~79 深红色
'S'~95 深粉色
96~111 深黄色
112~127 深白色
128~143 灰色
144~159 浅蓝色
160~1'A' 浅绿色
176~191 浅青色
192~207 浅红色
208~223 浅粉色
224~239 浅黄色
240~255 浅白色
*/
}
void photo(char n){
if(n=='r'){
color(12);
cout<<"■";
}else if(n=='b'){
color(1);
cout<<"■";
}else if(n=='y'){
color(14);
cout<<"■";
}else if(n=='g'){
color(10);
cout<<"■";
}else if(n=='w'){
color(15);
cout<<"■";
}else if(n=='p'){
color(13);
cout<<"■";
}else if(n=='k'){
cout<<" ";
}
}
void photo_man(){
if(name=="Dream"){
// 1 2 3 4 5 6 7 8 9 10
photo('k');photo('k');photo('g');photo('g');photo('g');photo('g');photo('g');photo('g');cout<<endl;
photo('k');photo('k');photo('g');photo('g');photo('g');photo('g');photo('g');photo('g');cout<<endl;
photo('k');photo('k');photo('g');photo('g');photo('g');photo('g');photo('g');photo('g');cout<<endl;
photo('k');photo('k');photo('g');photo('g');photo('g');photo('g');photo('g');photo('g');cout<<endl;
photo('k');photo('k');photo('g');photo('g');photo('g');photo('g');photo('g');photo('g');cout<<endl;
photo('k');photo('k');photo('g');photo('g');photo('g');photo('g');photo('g');photo('g');cout<<endl;//head
photo('g');photo('g');photo('g');photo('w');photo('w');photo('w');photo('w');photo('g');photo('g');photo('g');cout<<endl;
photo('g');photo('g');photo('w');photo('w');photo('w');photo('w');photo('w');photo('w');photo('g');photo('g');cout<<endl;
photo('g');photo('g');photo('w');photo('k');photo('w');photo('k');photo('w');photo('w');photo('g');photo('g');cout<<endl;
photo('g');photo('g');photo('w');photo('w');photo('w');photo('w');photo('w');photo('w');photo('g');photo('g');cout<<endl;
photo('g');photo('g');photo('w');photo('w');photo('w');photo('w');photo('w');photo('w');photo('g');photo('g');cout<<endl;
photo('g');photo('g');photo('g');photo('w');photo('w');photo('w');photo('w');photo('g');photo('g');photo('g');cout<<endl;//body
photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');cout<<endl;
photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');cout<<endl;
photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');cout<<endl;
photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');cout<<endl;
photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');cout<<endl;
photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');photo('g');photo('g');photo('k');photo('k');cout<<endl;//feet
}
}
void muzic_die(){
char muzic_die_char='~';
system("cls");
cout<<" 你死了\n";
cout<<" "<<name<<"死于:";
if(die==1){
cout<<"发现地板是岩浆做的\n";
}else if(die==2){
cout<<name<<"掉出了这个世界\n";
}else if(die==3){
cout<<"被野怪吃掉了\n";
}else if(die==4){
cout<<"被摔死了\n";
}else {
cout<<"死了\n";
}
cout<<"按空格键重生";
while(muzic_die_char!=' '){
Beep(do1,pai+ban) ;Beep(so,pai+ban) ;Beep(mi,pai) ;Beep(do,pai*2) ;
if(VK_SPACE){
muzic_die_char=' ';
}
}
hp=10;
sdf1=8;
sdf2=8;
shijie="平坦世界";
dt[8][8]=' ';
system("cls");
}
void sc(){
if(shijie=="平坦世界"){
for(int i=0;i<15;i++){
for(int j=0;j<30;j++){
if(i==sdf1&&j==sdf2){
color(15);
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){
color(14);
cout<<"(@@)";
if(dt[gw1][gw2]=='~'){
gwhp=0;
gw1=100;
}
}else{
if(1){
if(dt[i+1][j]==' '||dt[i][j+1]==' '||dt[i][j-1]==' '||dt[i-1][j]==' '){
if(dt[i][j]=='#'){
color(8);
cout<<"■■";
}else if(dt[i][j]=='@'){
color(7);
cout<<"■■";
}else if(dt[i][j]=='~'){
color(4);
cout<<"■■";
}else if(dt[i][j]=='w'){
printf_blue("");
}else if(dt[i][j]=='c'){
printf_green("^^^^");
}else{
color(8);
cout<<dt[i][j]<<dt[i][j]<<dt[i][j]<<dt[i][j];
}
}else{
cout<<" ";
}
}else{
if(dt[i+1][j]==' '||dt[i][j+1]==' '||dt[i][j-1]==' '||dt[i-1][j]==' '){
if(dt[i][j]=='~'){
printf_red("■■");
}else if(dt[i][j]=='w'){
printf_blue("");
}else{
color(8);
cout<<dt[i][j]<<dt[i][j]<<dt[i][j]<<dt[i][j];
}
}else{
cout<<" ";
}
}
}
}
cout<<endl;
for(int j=0;j<30;j++){
if(i==sdf1&&j==sdf2){
color(15);
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){
color(14);
cout<<"u怪u";
}else{
if(1){
if(dt[i+1][j]==' '||dt[i][j+1]==' '||dt[i][j-1]==' '||dt[i-1][j]==' '){
if(dt[i][j]=='#'){
color(8);
cout<<"■■";
}else if(dt[i][j]=='@'){
color(7);
cout<<"■■";
}else if(dt[i][j]=='~'){
color(4);
cout<<"■■";
}else if(dt[i][j]=='w'){
printf_blue("");
}else if(dt[i][j]=='c'){
printf_yellow("■■");
}else{
cout<<dt[i][j]<<dt[i][j]<<dt[i][j]<<dt[i][j];
}
}else{
cout<<" ";
}
}else{
if(dt[i+1][j]==' '||dt[i][j+1]==' '||dt[i][j-1]==' '||dt[i-1][j]==' '){
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{
cout<<" ";
}
}
}
}
cout<<endl;
}
if(1){
cout<<"早上\n";
cout<<"按空格挖掘,按wasd上下左右行走,按x、f放方块,\n按k清空地图,按c创造,按j时间+12,按TAB设置,按g小游戏副本(打敌人)\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<<")";
}
}
cout<<endl;
for(int i=0;i<9;i++){
if(wpl[i]==0){
cout<<" 无 ";
cout<<"×"<<" ";
}else if(wpl[i]==1){
cout<<" 石块 ";
cout<<"×"<<setw(2)<<wplgs[i];
}else if(wpl[i]==2){
cout<<" 镐子 ";
cout<<"×"<<setw(2)<<wplgs[i];
}
}
cout<<"\n耐久度:"<<nj;
if(hp==0){
muzic_die();
}
cout<<endl;
}else if(shijie=="森林"){
for(int i=0;i<15;i++){
for(int j=0;j<30;j++){
if(i==sdf1&&j==sdf2){
color(15);
if(fx=='w'){
cout<<"上玩";
}else if(fx=='s'){
cout<<"下玩";
}else if(fx=='a'){
cout<<"左玩";
}else if(fx=='d'){
cout<<"右玩";
}
if(sl[i][j]=='~'){
hp--;
die=1;
}
if(hp==0){
sdf1=8;
sdf2=8;
}
}else if(i==gw1&&j==gw2){
color(11);
cout<<"(\\/)";
if(sl[gw1][gw2]=='~'){
gwhp=0;
gw1=100;
}
}else{
if(1){
if(sl[i+1][j]==' '||sl[i][j+1]==' '||sl[i][j-1]==' '||sl[i-1][j]==' '){
if(sl[i][j]=='#'){
color(10);
cout<<"■■";
}else if(sl[i][j]=='@'){
color(7);
cout<<"■■";
}else if(sl[i][j]=='~'){
color(4);
cout<<"■■";
}else if(sl[i][j]=='w'){
printf_blue("");
}else if(sl[i][j]=='c'){
printf_green("^^^^");
}else{
color(8);
cout<<sl[i][j]<<sl[i][j]<<sl[i][j]<<sl[i][j];
}
}else{
cout<<" ";
}
}else{
if(sl[i+1][j]==' '||sl[i][j+1]==' '||sl[i][j-1]==' '||sl[i-1][j]==' '){
if(sl[i][j]=='~'){
printf_red("■■");
}else if(sl[i][j]=='w'){
printf_blue("");
}else{
color(8);
cout<<sl[i][j]<<sl[i][j]<<sl[i][j]<<sl[i][j];
}
}else{
cout<<" ";
}
}
}
}
cout<<endl;
for(int j=0;j<30;j++){
if(i==sdf1&&j==sdf2){
color(15);
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){
color(11);
cout<<"v怪v";
}else{
if(1){
if(sl[i+1][j]==' '||sl[i][j+1]==' '||sl[i][j-1]==' '||sl[i-1][j]==' '){
if(sl[i][j]=='#'){
color(10);
cout<<"■■";
}else if(sl[i][j]=='@'){
color(7);
cout<<"■■";
}else if(sl[i][j]=='~'){
color(4);
cout<<"■■";
}else if(sl[i][j]=='w'){
printf_blue("");
}else if(sl[i][j]=='c'){
printf_yellow("■■");
}else{
cout<<sl[i][j]<<sl[i][j]<<sl[i][j]<<sl[i][j];
}
}else{
cout<<" ";
}
}else{
if(sl[i+1][j]==' '||sl[i][j+1]==' '||sl[i][j-1]==' '||sl[i-1][j]==' '){
if(sl[i][j]=='~'){
printf_red("■■");
}else if(sl[i][j]=='w'){
printf_blue("");
}else{
cout<<sl[i][j]<<sl[i][j]<<sl[i][j]<<sl[i][j];
}
}else{
cout<<" ";
}
}
}
}
cout<<endl;
}
if(sj>50&&sj<170){
cout<<"早上\n";
cout<<"按空格挖掘,按wasd上下左右行走,按x、f放方块,\n按k清空地图,按c创造,按j时间+12,按TAB设置,按g小游戏副本(打敌人)\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(1){
cout<<"◆";
}
}
cout<<endl;
for(int i=0;i<9;i++){
if(wpl[i]==0){
cout<<" 无 ";
cout<<"×"<<" ";
}else if(wpl[i]==1){
cout<<" 石块 ";
cout<<"×"<<setw(2)<<wplgs[i];
}else if(wpl[i]==2){
cout<<" 镐子 ";
cout<<"×"<<setw(2)<<wplgs[i];
}
}
cout<<"\n耐久度:"<<nj;
if(hp==0){
muzic_die();
}
cout<<endl;
}
cout<<"世界:"<<shijie;
if(hp==0){
muzic_die();
}
}
void hc_photo_sc(){
if(xz==1){
color(15);
cout<<q;
color(8);
cout<<w;
color(8);
cout<<e<<endl;
color(8);
cout<<a;
color(8);
cout<<s;
color(8);
cout<<d<<endl;
color(8);
cout<<z;
color(8);
cout<<x;
color(8);
cout<<c;
}else if(xz==2){
color(8);
cout<<q;
color(15);
cout<<w;
color(8);
cout<<e<<endl;
color(8);
cout<<a;
color(8);
cout<<s;
color(8);
cout<<d<<endl;
color(8);
cout<<z;
color(8);
cout<<x;
color(8);
cout<<c;
}else if(xz==3){
color(8);
cout<<q;
color(8);
cout<<w;
color(15);
cout<<e<<endl;
color(8);
cout<<a;
color(8);
cout<<s;
color(8);
cout<<d<<endl;
color(8);
cout<<z;
color(8);
cout<<x;
color(8);
cout<<c;
}else if(xz==4){
color(8);
cout<<q;
color(8);
cout<<w;
color(8);
cout<<e<<endl;
color(15);
cout<<a;
color(8);
cout<<s;
color(8);
cout<<d<<endl;
color(8);
cout<<z;
color(8);
cout<<x;
color(8);
cout<<c;
}else if(xz==5){
color(8);
cout<<q;
color(8);
cout<<w;
color(8);
cout<<e<<endl;
color(8);
cout<<a;
color(15);
cout<<s;
color(8);
cout<<d<<endl;
color(8);
cout<<z;
color(8);
cout<<x;
color(8);
cout<<c;
}else if(xz==6){
color(8);
cout<<q;
color(8);
cout<<w;
color(8);
cout<<e<<endl;
color(8);
cout<<a;
color(8);
cout<<s;
color(15);
cout<<d<<endl;
color(8);
cout<<z;
color(8);
cout<<x;
color(8);
cout<<c;
}else if(xz==7){
color(8);
cout<<q;
color(8);
cout<<w;
color(8);
cout<<e<<endl;
color(8);
cout<<a;
color(8);
cout<<s;
color(8);
cout<<d<<endl;
color(15);
cout<<z;
color(8);
cout<<x;
color(8);
cout<<c;
}else if(xz==8){
color(8);
cout<<q;
color(8);
cout<<w;
color(8);
cout<<e<<endl;
color(8);
cout<<a;
color(8);
cout<<s;
color(8);
cout<<d<<endl;
color(8);
cout<<z;
color(15);
cout<<x;
color(8);
cout<<c;
}else if(xz==9){
color(8);
cout<<q;
color(8);
cout<<w;
color(8);
cout<<e<<endl;
color(8);
cout<<a;
color(8);
cout<<s;
color(8);
cout<<d<<endl;
color(8);
cout<<z;
color(8);
cout<<x;
color(15);
cout<<c;
}
}
void hc(){//fdjfhdybfbdsvvfgsvdfvsdfvfvdfbgvbdcvbcxcvcxcvcxcvcxcvcxvcxcvbcxvcxcvbcxcvcxvbcxcvbcxcvbvcvbnvcbnvcvbnbvcbnbvcvbnbvcvbnbvcvbnvc
system("cls");
//合成
//[][][]
//[][][]
//[][][]
// []
while(tc){
if(KEY_DOWN('E')){
for(int i=0;i<=10;i++){
cout<<"正在退出中";
for(int j=0;j<i%3;j++){
cout<<".";
}
system("cls");
}
tc=false;//zxscdvfgbnhmj,kxzscdvfgbnhmjrvftbynmudsigtryhsitfrkafrgbnh
}else if(KEY_DOWN('S')&&xz<7){
system("cls");
xz+=3;
hc_photo_sc();
}else if(KEY_DOWN('W')&&xz>3){
system("cls");//fbyegtrhgte
xz-=3;
hc_photo_sc();
}else if(KEY_DOWN('A')&&xz%3!=0){
system("cls");
xz-=1;
hc_photo_sc();
}else if(KEY_DOWN('D')&&xz!=1||xz!=4||xz!=7){
system("cls");
xz+=1;
hc_photo_sc();
}
}
}
void m(){// wdnwnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn7
printf_red(" ");
system("mode con cols=120 lines=46");
system("title YUTU和深莫的森林制作——沙盒游戏");
system("cls");
for(int i=0;i<15;i++){
for(int j=0;j<30;j++){
if(i==0){
dt[i][j]='c';
cz[i][j]=' ';
}else{
dt[i][j]='#';
cz[i][j]=' ';
}
if(i<5){
sl[i][j]=' ';
}else if(i>5){
sl[i][j]='#';
}else{
sl[i][j]='c';
}
}
}
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]='~';
cout<<"你的名字叫什么?\n";
cin>>name;
system("cls");
sc();
while(1){
if(gwhp==1){
if(gzt==125000-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;
}
system("cls");
if(shijie=="平坦世界"){
if(dt[sdf1+1][sdf2]==' '){
sdf1++;
slsh++;
}else{
if(slsh>2){
hp-=slsh-2;
slsh=0;
die=4;
}
}
}else{
if(sl[sdf1+1][sdf2]==' '){
sdf1++;
slsh++;
}else{
if(slsh>2){
hp-=slsh-2;
slsh=0;
}
}
}
sc();
}
}else{
gw1=4;
gw2=2;
gwhp=1;
}
if(KEY_DOWN('w')||KEY_DOWN('W')){
if(dt[sdf1+1][sdf2]!=' '||dt[sdf1+2][sdf2]!=' '&&szt!=2){
if(shijie=="平坦世界"){
if(dt[sdf1+1!=' '][sdf2]) {
if(dt[sdf1-1][sdf2]==' '||dt[sdf1-1][sdf2]=='~'||dt[sdf1-1][sdf2]=='w'){
sdf1--;
}
}
}else{
if(sl[sdf1+1!=' '][sdf2]) {
if(sl[sdf1-1][sdf2]==' '||sl[sdf1-1][sdf2]=='~'||sl[sdf1-1][sdf2]=='w'){
sdf1--;
}
}
}
system("cls");
sc();
szt++;
szt%=3;
}fx='w';
}else if(KEY_DOWN('s')||KEY_DOWN('S')){
if(shijie=="平坦世界"){
if(sl[sdf1+1!=' '][sdf2]) {
if(dt[sdf1+1][sdf2]==' '||dt[sdf1+1][sdf2]=='~'||dt[sdf1+1][sdf2]=='w'){
sdf1++;slsh++;
}
}
}else{
if(sl[sdf1+1][sdf2]==' '||sl[sdf1+1][sdf2]=='~'||sl[sdf1+1][sdf2]=='w'){
sdf1++;slsh++;
}
}
fx='s';
die=4;
system("cls");
sc();
}else if(KEY_DOWN('a')||KEY_DOWN('A')){
if(shijie=="平坦世界"){
if(dt[sdf1][sdf2-1]==' '||dt[sdf1][sdf2-1]=='~'||dt[sdf1][sdf2-1]=='w'){
sdf2--;
}
}else{
if(sl[sdf1][sdf2-1]==' '||sl[sdf1][sdf2-1]=='~'||sl[sdf1][sdf2-1]=='w'){
sdf2--;
}
}
fx='a';
system("cls");
sc();
}else if(KEY_DOWN('d')||KEY_DOWN('D')){
if(shijie=="平坦世界"){
if(dt[sdf1][sdf2+1]==' '||dt[sdf1][sdf2+1]=='~'||dt[sdf1][sdf2+1]=='w'){
sdf2++;
}
}else{
if(sl[sdf1][sdf2+1]==' '||sl[sdf1][sdf2+1]=='~'||sl[sdf1][sdf2+1]=='w'){
sdf2++;
}
}//sfdfsafasdfa
fx='d';
system("cls");
sc();
}else if(KEY_DOWN(' ')){
if(shijie=="平坦世界"){
if(wplgs[2]>0){
if(fx=='w'&&dt[sdf1-1][sdf2]!='~'&&dt[sdf1-1][sdf2]!='w'){
dt[sdf1-1][sdf2]=' ';
wplgs[1]++;
nj--;
}else if(fx=='s'&&dt[sdf1+1][sdf2]!='~'&&dt[sdf1+1][sdf2]!='w'){
dt[sdf1+1][sdf2]=' ';
wplgs[1]++;
nj--;
}else if(fx=='a'&&dt[sdf1][sdf2-1]!='~'&&dt[sdf1][sdf2-1]!='w'){
dt[sdf1][sdf2-1]=' ';
wplgs[1]++;
nj--;
}else if(fx=='d'&&dt[sdf1][sdf2+1]!='~'&&dt[sdf1][sdf2+1]!='w'){
dt[sdf1][sdf2+1]=' ';
wplgs[1]++;
nj--;
}
}
if(nj==0){
nj=100;
wplgs[2]--;
}
}else{
if(wplgs[2]>0){
if(fx=='w'&&sl[sdf1-1][sdf2]!='~'&&sl[sdf1-1][sdf2]!='w'){
sl[sdf1-1][sdf2]=' ';
wplgs[1]++;
nj--;
}else if(fx=='s'&&sl[sdf1+1][sdf2]!='~'&&sl[sdf1+1][sdf2]!='w'){
sl[sdf1+1][sdf2]=' ';
wplgs[1]++;
nj--;
}else if(fx=='a'&&sl[sdf1][sdf2-1]!='~'&&sl[sdf1][sdf2-1]!='w'){
sl[sdf1][sdf2-1]=' ';
wplgs[1]++;
nj--;
}else if(fx=='d'&&sl[sdf1][sdf2+1]!='~'&&sl[sdf1][sdf2+1]!='w'){
sl[sdf1][sdf2+1]=' ';
wplgs[1]++;
nj--;
}
}
if(nj==0){
nj=100;
wplgs[2]--;
}//sdhfuhfueihfudsgugfsdgfhsg
}
sdf1%=15;
sdf2%=30;
system("cls");
sc();
}else if(KEY_DOWN('f')||KEY_DOWN('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]='@';
}
wplgs[1]--;
system("cls");
sc();
}else if(KEY_DOWN('k')||KEY_DOWN('K')){
for(int i=0;i<=15;i++){
for(int j=0;j<=30;j++){
dt[i][j]=' ';
}
}
system("cls");
sc();
}else if(KEY_DOWN('c')||KEY_DOWN('C')){
czms();
system("cls");
sc();
}else if(KEY_DOWN('j')||KEY_DOWN('J')){
sj+=120;
system("cls");
sc();
}else if(KEY_DOWN('g')||KEY_DOWN('G')){
fj_main();
sc();
}else if(KEY_DOWN('q')||KEY_DOWN('Q')){
shijie="森林";
sc();
}else if(KEY_DOWN('p')||KEY_DOWN('P')){
shijie="平坦世界";
sc();//wo
}else if(KEY_DOWN('H')){
hc();
}
sj++;
sj%=240;
gzt++;gzt%=125000;
}
}
沙盒.cpp
#include"game.h"
int main(){m();}
运行效果如下:
下期更新:背包、合成
还有游戏大改革