Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
迷宫生成完成
Browse files Browse the repository at this point in the history
  • Loading branch information
Rratic committed Mar 14, 2021
1 parent 276a5d2 commit 4aead75
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions cpp11/maze-base.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "maze-base.h"
block::block() { id = blank; }
void block::setdirect(unsigned short iid,unsigned short iinfo){id=iid;info=iinfo;}
char block::push_block(PAINT &color)
{
auto te=id/100;
Expand Down
1 change: 1 addition & 0 deletions cpp11/maze-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class block{
public:
unsigned short id,info;
block();
void setdirect(unsigned short iid,unsigned short iinfo=0);
void set(char in);
char push_block(PAINT &color);
void settext(char in);
Expand Down
1 change: 1 addition & 0 deletions cpp11/maze-chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ bool chunk::toline(string s,unsigned short line){
player->y=c;
player->health=10;
player->id=0;
player->name=setting.tag["user-name"];
blocks[line][c].id=air;
}
else{
Expand Down
29 changes: 25 additions & 4 deletions cpp11/maze-game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void menu(){
if(input=="0")exit(0);
cls;
if(input=="1")world_menu();
else if(input=="0")rand_game();
else if(input=="2")rand_game();
else if(input=="s")set_game();
}
void game::clear(){
Expand Down Expand Up @@ -205,10 +205,31 @@ void show_story(string s){
cin>>input;
}
void rand_game(){
array<array<unsigned short,15>,15>a;
unsigned short x=rand();
prim<15U,15U>(15U,15U,a);
unsigned short m=rand()%6+11,n=rand()%6+11;
array<array<unsigned short,16>,16>a;
prim(m,n,a);
game all;
all.help_words="";
all.focusing=0;
chunk temp;
temp.l=m;temp.w=n;
for(size_t i=0;i<m;++i){
for(size_t j=0;j<n;++j){
switch(a[i][j]){
case '#':temp.blocks[i][j].setdirect(unbreakable_wall);break;
case '@':{
temp.player=new entity;
temp.player->x=i;
temp.player->y=j;
temp.player->health=10;
temp.player->id=0;
temp.player->name=setting.tag["user-name"];
}
case '.':temp.blocks[i][j].setdirect(air);break;
case '%':temp.blocks[i][j].setdirect(exitb);break;
}
}
}
all.chunks.push_back(temp);
all.work();
}
3 changes: 1 addition & 2 deletions cpp11/maze-game.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ using std::rand;
using std::srand;
extern string input;
class game{
private:
public:
unsigned short focusing;
vector<chunk>chunks;
public:
string name,help_words;
bool set(string filename,string find);
unsigned short work();
Expand Down
3 changes: 1 addition & 2 deletions cpp11/maze-generate.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "maze-generate.h"
#define isin(x,y) (x>=0&&y>=0&&x<m&&y<n)
template<unsigned short l=15,unsigned short w=15>
void prim(unsigned short maze_len,unsigned short maze_wid,array<array<unsigned short,l>,w>&a){
void prim(unsigned short maze_len,unsigned short maze_wid,array<array<unsigned short,16>,16>&a){
int m=maze_len,n=maze_wid;
short mox[4]={0,0,1,-1},moy[4]={1,-1,0,0};
vector<pair<unsigned short,unsigned short>>li;
Expand Down
3 changes: 1 addition & 2 deletions cpp11/maze-generate.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#ifndef rra_maze_generate
#define rra_maze_generate
#include "maze-chunk.h"
template<unsigned short l=15,unsigned short w=15>
void prim(unsigned short maze_len,unsigned short maze_wid,array<array<unsigned short,l>,w>&a);
void prim(unsigned short maze_len,unsigned short maze_wid,array<array<unsigned short,16>,16>&a);
#endif

0 comments on commit 4aead75

Please sign in to comment.