4
已解决
吴庞茂旭
资深光能
资深光能
还记得BW吗?NY未了继承BW的部分操作重磅来袭!
NY是一款平面单机无目标游戏,目前仍然处于测试阶段,暂定版本号为-1,本次是把基本操作和大体框架搞好了,后期再搞渲染。欢迎大家提出意见!
/*
NAME:Not yet
NODE/TIPS:NONE
*/
//std
#include <bits/stdc++.h>
#include <windows.h>
#define int long long
using namespace std;
const int MAXN=20;//A map of 20*20
int picture[MAXN][MAXN];
int x,y;//Player's point
map<int,string> meanings;
/*
Meanings of numbers in picture:
0----Null----
1----Half blood "me"----m
2----"me"----me
10----shoot to right----→
11----shoot to left---- ↑
12----shoot to down----←
13----shoot to up----↓
249----Half blood box----H
250----Fine box----He
255----Wall----XX
*/
void init();//Initialize picture and meanings
void shoot();//Dealing with bullets
void output();//Output the picture
void cls();//Just like "system("cls")"
void HideCursor();//Hide Cursor
int gotoxy(int y, int x);//Position cursor
signed main(){
srand(time(NULL));
HideCursor();
init();
while(true){
output();
shoot();
cls();
static int last;//Record the keys of the previous step
if(GetAsyncKeyState('D')&&y<MAXN-1&&picture[x][y+1]!=255&&picture[x][y+1]!=250){
picture[x][y+1]=picture[x][y];
picture[x][y]=0;
y++;
Sleep(100);
last=1;
}
if(GetAsyncKeyState('A')&&y>0&&picture[x][y-1]!=255&&picture[x][y-1]!=250){
picture[x][y-1]=picture[x][y];
picture[x][y]=0;
y--;
Sleep(100);
last=2;
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&picture[x+1][y]!=255&&picture[x+1][y]!=250){
picture[x+1][y]=picture[x][y];
picture[x][y]=0;
x++;
Sleep(100);
last=3;
}
if(GetAsyncKeyState('W')&&x>0&&picture[x-1][y]!=255&&picture[x-1][y]!=250){
picture[x-1][y]=picture[x][y];
picture[x][y]=0;
x--;
Sleep(100);
last=4;
}
if(GetAsyncKeyState('D')&&y<MAXN-1&&picture[x][y+1]==250){
picture[x][y+1]=249;
Sleep(100);
last=1;
}
if(GetAsyncKeyState('A')&&y>0&&picture[x][y-1]==250){
picture[x][y-1]=249;
Sleep(100);
last=2;
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&picture[x+1][y]==250){
picture[x+1][y]=249;
Sleep(100);
last=3;
}
if(GetAsyncKeyState('W')&&x>0&&picture[x-1][y]==250){
picture[x-1][y]=249;
Sleep(100);
last=4;
}
if(GetAsyncKeyState('X')){
if(last==1){//D
if(picture[x][y+1]!=255){
picture[x][y+1]=250;
}
} else if(last==2){//A
if(picture[x][y-1]!=255){
picture[x][y-1]=250;
}
} else if(last==3){//S
if(picture[x+1][y]!=255){
picture[x+1][y]=250;
}
} else{//W
if(picture[x-1][y]!=255){
picture[x-1][y]=250;
}
}
Sleep(100);
}
if(GetAsyncKeyState('P')){
if(last==1){//D
if(picture[x][y+1]!=255&&picture[x][y+1]!=250){
picture[x][y+1]=10;
}
} else if(last==2){//A
if(picture[x][y-1]!=255&&picture[x][y-1]!=250){
picture[x][y-1]=11;
}
} else if(last==3){//S
if(picture[x+1][y]!=255&&picture[x+1][y]!=250){
picture[x+1][y]=12;
}
} else{//W
if(picture[x-1][y]!=255&&picture[x-1][y]!=250){
picture[x-1][y]=13;
}
}
Sleep(100);
}
}
return 0;
}
void init(){
for(int i=0;i<MAXN;i++)picture[0][i]=255;//Initialize the upper fence
for(int i=0;i<MAXN;i++)picture[MAXN-1][i]=255;//Initialize the lower fence
for(int j=0;j<MAXN;j++)picture[j][0]=255;//Initialize left fence
for(int j=0;j<MAXN;j++)picture[j][MAXN-1]=255;//Initialize right fence
x=rand()%(MAXN-2)+1,y=rand()%(MAXN-2)+1;
int z=rand()%1000;
picture[x][y]=(z==522?1:2);
//Initialize the meanings
meanings[0]=" ";
meanings[1]="m ";
meanings[2]="me";
meanings[10]="→";
meanings[11]="←";
meanings[12]="↓";
meanings[13]="↑";
meanings[249]="H ";
meanings[250]="He";
meanings[255]="XX";
//Put Box
z=rand()%((MAXN/2)*(MAXN/2));
while(z--){
int xx=rand()%(MAXN-2)+1,yy=rand()%(MAXN-2)+1;
if(picture[xx][yy]==0){
int c=rand()%100+1;
picture[xx][yy]=(c%5==0?249:250);
}
}
}
void shoot(){
for(int i=0;i<MAXN;i++){
for(int j=0;j<MAXN;j++){
if(picture[i][j]==11){//A
if(picture[i][j-1]!=255&&picture[i][j-1]!=250){
picture[i][j-1]=11;
}
picture[i][j]=0;
} else if(picture[i][j]==13){//W
if(picture[i-1][j]!=255&&picture[i-1][j]!=250){
picture[i-1][j]=13;
}
picture[i][j]=0;
}
}
}
for(int i=MAXN-1;i>=0;i--){
for(int j=MAXN-1;j>=0;j--){
if(picture[i][j]==10){//D
if(picture[i][j+1]!=255&&picture[i][j+1]!=250){
picture[i][j+1]=10;
}
picture[i][j]=0;
} else if(picture[i][j]==12){//S
if(picture[i+1][j]!=255&&picture[i+1][j]!=250){
picture[i+1][j]=12;
}
picture[i][j]=0;
}
}
}
}
void output(){
for(int i=0;i<MAXN;i++){
for(int j=0;j<MAXN;j++){
cout<<meanings[picture[i][j]];
}
puts("");
}
}
void cls(){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 }; // home for the cursor
SetConsoleCursorPosition( hConsole, coordScreen );
}
void HideCursor(){
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
CursorInfo.bVisible = false; //隐藏控制台光标
SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
}
int gotoxy(int y, int x){
HANDLE handle; //Define handle variable handle
COORD coord; //Define structure coord (coordinate system coord)
coord.X = x; //Abscissa x
coord.Y = y; //Ordinate y
handle = GetStdHandle(STD_OUTPUT_HANDLE); //Get console output handle (value - 11)
SetConsoleCursorPosition(handle, coord); //Move Cursor
}
教程:
WSAD----上下左右
X----放箱子
P----射击
有些基本设定需要大家自己发现,本帖持续更新,也希望大家同时关注关注Cc++的发展。
吴庞茂旭在2022-03-20 21:11:54追加了内容
-2版本推出了!
主要让代码优美了一些。
本次除了优化了射击以外,增设了一个能攻击玩家的道具——陷阱地刺,踩上去之后会掉一个命,且子弹无法打破!
踩上地刺后,地刺会消失哦。
【啐啐念:子弹说不定可以当近战武器……】
/*
NAME:Not yet
NODE/TIPS:NONE
*/
//std
#include <bits/stdc++.h>
#include <windows.h>
#define int long long
using namespace std;
const int MAXN=25;//A map of MAXN*MAXN
int picture[MAXN][MAXN];
int x,y;//Player's point
map<int,string> meanings;
/*
Meanings of numbers in picture:
0----Null----
1----Half blood "me"----m
2----"me"----me
10----shoot to right----→
11----shoot to left---- ↑
12----shoot to down----←
13----shoot to up----↓
200----Ground thorn----AA
249----Half blood box----H
250----Fine box----He
255----Wall----XX
*/
void init();//Initialize picture and meanings
void shoot();//Dealing with bullets
void output();//Output the picture
void cls();//Just like "system("cls")"
void HideCursor();//Hide Cursor
int gotoxy(int y, int x);//Position cursor
signed main(){
srand(time(NULL));
HideCursor();
init();
double dur;
clock_t start,end;
start = clock();
while(picture[x][y]){
output();
shoot();
cls();
static int last;//Record the keys of the previous step
if(GetAsyncKeyState('D')){
last=1;
}
if(GetAsyncKeyState('A')){
last=2;
}
if(GetAsyncKeyState('S')){
last=3;
}
if(GetAsyncKeyState('W')){
last=4;
}
if(GetAsyncKeyState('D')&&y<MAXN-1&&(picture[x][y+1]==0||picture[x][y+1]==249)){
picture[x][y+1]=picture[x][y];
picture[x][y]=0;
y++;
Sleep(100);
}
if(GetAsyncKeyState('A')&&y>0&&(picture[x][y-1]==0||picture[x][y-1]==249)){
picture[x][y-1]=picture[x][y];
picture[x][y]=0;
y--;
Sleep(100);
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&(picture[x+1][y]==0||picture[x+1][y]==249)){
picture[x+1][y]=picture[x][y];
picture[x][y]=0;
x++;
Sleep(100);
}
if(GetAsyncKeyState('W')&&x>0&&(picture[x-1][y]==0||picture[x-1][y]==249)){
picture[x-1][y]=picture[x][y];
picture[x][y]=0;
x--;
Sleep(100);
}
if(GetAsyncKeyState('D')&&y<MAXN-1&&picture[x][y+1]==250){
picture[x][y+1]=249;
Sleep(100);
}
if(GetAsyncKeyState('A')&&y>0&&picture[x][y-1]==250){
picture[x][y-1]=249;
Sleep(100);
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&picture[x+1][y]==250){
picture[x+1][y]=249;
Sleep(100);
}
if(GetAsyncKeyState('W')&&x>0&&picture[x-1][y]==250){
picture[x-1][y]=249;
Sleep(100);
}
if(GetAsyncKeyState('D')&&y<MAXN-1&&picture[x][y+1]==200){
picture[x][y+1]=picture[x][y]-1;
picture[x][y]=0;
y++;
Sleep(100);
}
if(GetAsyncKeyState('A')&&y>0&&picture[x][y-1]==200){
picture[x][y-1]=picture[x][y]-1;
picture[x][y]=0;
y--;
Sleep(100);
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&picture[x+1][y]==200){
picture[x+1][y]=picture[x][y]-1;
picture[x][y]=0;
x++;
Sleep(100);
}
if(GetAsyncKeyState('W')&&x>0&&picture[x-1][y]==200){
picture[x-1][y]=picture[x][y]-1;
picture[x][y]=0;
x--;
Sleep(100);
}
if(GetAsyncKeyState('X')){
int z=rand()%50;
z=(z%25==0);
if(last==1){//D
if(picture[x][y+1]!=255){
picture[x][y+1]=250-z;
}
} else if(last==2){//A
if(picture[x][y-1]!=255){
picture[x][y-1]=250-z;
}
} else if(last==3){//S
if(picture[x+1][y]!=255){
picture[x+1][y]=250-z;
}
} else{//W
if(picture[x-1][y]!=255){
picture[x-1][y]=250-z;
}
}
Sleep(100);
}
if(GetAsyncKeyState('P')){
if(last==1){//D
if(picture[x][y+1]==0){
picture[x][y+1]=10;
} else if(picture[x][y+1]==200||picture[x][y+1]==249||picture[x][y+1]==250){
picture[x][y+1]=0;
}
} else if(last==2){//A
if(picture[x][y-1]==0){
picture[x][y-1]=11;
} else if(picture[x][y-1]==200||picture[x][y-1]==249||picture[x][y-1]==250){
picture[x][y-1]=0;
}
} else if(last==3){//S
if(picture[x+1][y]==0){
picture[x+1][y]=12;
} else if(picture[x+1][y]==200||picture[x+1][y]==249||picture[x+1][y]==250){
picture[x+1][y]=0;
}
} else{//W
if(picture[x-1][y]==0){
picture[x-1][y]=13;
} else if(picture[x-1][y]==200||picture[x-1][y]==249||picture[x-1][y]==250){
picture[x-1][y]=0;
}
}
Sleep(100);
}
}
end = clock();
dur = (double)(end - start);
system("cls");
output();
MessageBox(NULL,"GameOver","Tips",MB_OK);
system("cls");
printf("You lived for %f seconds\n",(dur/CLOCKS_PER_SEC));
return 0;
}
void init(){
for(int i=0;i<MAXN;i++)picture[0][i]=255;//Initialize the upper fence
for(int i=0;i<MAXN;i++)picture[MAXN-1][i]=255;//Initialize the lower fence
for(int j=0;j<MAXN;j++)picture[j][0]=255;//Initialize left fence
for(int j=0;j<MAXN;j++)picture[j][MAXN-1]=255;//Initialize right fence
x=rand()%(MAXN-2)+1,y=rand()%(MAXN-2)+1;
int z=rand()%1000;
picture[x][y]=(z==522?1:2);
//Initialize the meanings
meanings[0]=" ";
meanings[1]="m ";
meanings[2]="me";
meanings[10]="→";
meanings[11]="←";
meanings[12]="↓";
meanings[13]="↑";
meanings[200]="AA";
meanings[249]="H ";
meanings[250]="He";
meanings[255]="XX";
//Put Box
z=rand()%((MAXN/2)*(MAXN/2));
while(z--){
int xx=rand()%(MAXN-2)+1,yy=rand()%(MAXN-2)+1;
if(picture[xx][yy]==0){
int c=rand()%100+1;
picture[xx][yy]=(c%5==0?249:250);
}
}
//Put Ground thorn
z=rand()%((MAXN/5)*(MAXN/5));
while(z--){
int xx=rand()%(MAXN-2)+1,yy=rand()%(MAXN-2)+1;
if(picture[xx][yy]==0){
picture[xx][yy]=200;
}
}
}
void shoot(){
for(int i=0;i<MAXN;i++){
for(int j=0;j<MAXN;j++){
if(picture[i][j]==11){//A
if(picture[i][j-1]==0){
picture[i][j-1]=11;
} else if(picture[i][j-1]==250){
picture[i][j-1]=249;
} else if(picture[i][j-1]==249){
picture[i][j-1]=0;
}
picture[i][j]=0;
} else if(picture[i][j]==13){//W
if(picture[i-1][j]==0){
picture[i-1][j]=13;
} else if(picture[i-1][j]==250){
picture[i-1][j]=249;
} else if(picture[i-1][j]==249){
picture[i-1][j]=0;
}
picture[i][j]=0;
}
}
}
for(int i=MAXN-1;i>=0;i--){
for(int j=MAXN-1;j>=0;j--){
if(picture[i][j]==10){//D
if(picture[i][j+1]==0){
picture[i][j+1]=10;
} else if(picture[i][j+1]==250){
picture[i][j+1]=249;
} else if(picture[i][j+1]==249){
picture[i][j+1]=0;
}
picture[i][j]=0;
} else if(picture[i][j]==12){//S
if(picture[i+1][j]==0){
picture[i+1][j]=12;
} else if(picture[i+1][j]==250){
picture[i+1][j]=249;
} else if(picture[i+1][j]==249){
picture[i+1][j]=0;
}
picture[i][j]=0;
}
}
}
}
void output(){
for(int i=0;i<MAXN;i++){
for(int j=0;j<MAXN;j++){
cout<<meanings[picture[i][j]];
}
puts("");
}
}
void cls(){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 }; // home for the cursor
SetConsoleCursorPosition( hConsole, coordScreen );
}
void HideCursor(){
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
CursorInfo.bVisible = false; //隐藏控制台光标
SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
}
int gotoxy(int y, int x){
HANDLE handle; //Define handle variable handle
COORD coord; //Define structure coord (coordinate system coord)
coord.X = x; //Abscissa x
coord.Y = y; //Ordinate y
handle = GetStdHandle(STD_OUTPUT_HANDLE); //Get console output handle (value - 11)
SetConsoleCursorPosition(handle, coord); //Move Cursor
}
吴庞茂旭在2022-03-27 21:31:17追加了内容
/*
NAME:Not yet
NODE/TIPS:NONE
*/
//std
#include <bits/stdc++.h>
#include <windows.h>
#define int long long
using namespace std;
const int MAXN=25;//A map of MAXN*MAXN
const string help[]={
"Meanings of numbers in picture:",
"0----Null---- ",
"1----Half blood \"me\"----m ",
"2----\"me\"----me",
"10----shoot to right---- ==",
"11----shoot to left---- ==",
"12----shoot to down----||",
"13----shoot to up----||",
"200----Ground thorn----AA",
"249----Half blood box----H ",
"250----Fine box----He",
"255----Wall----XX"
};
int picture[MAXN][MAXN];
int x,y;//Player's point
map<int,string> meanings;
map<int,int> colors;
/*
Meanings of numbers in picture:
0----Null----
1----Half blood "me"----m
2----"me"----me
10----shoot to right---- ==
11----shoot to left---- ==
12----shoot to down----||
13----shoot to up----||
200----Ground thorn----AA
249----Half blood box----H
250----Fine box----He
255----Wall----XX
*/
void init();//Initialize picture and meanings
void shoot();//Dealing with bullets
void output();//Output the picture
void cls();//Just like "system("cls")"
void HideCursor();//Hide Cursor
int gotoxy(int y, int x);//Position cursor
void color(int x);//Change the color
/*
How to make a color:
0 black
1 Blue
2 green
3 light blue
4 red
5 Purple
6 orange
7 white
8 ash
9 sky blue
10 green
11 bright blue
12 light red
13 light purple
14 flesh color
15 bright white
1024 upper dash
2048 spacing line
3072 1024+2048
6144 thick spacing line
7169 thick 1024 + 2048
*/
signed main(){
system("title NotYet -3 By CodersClub");
system("color 00");
srand(time(NULL));
HideCursor();
init();
double dur;
clock_t start,end;
start = clock();
while(picture[x][y]){
output();
shoot();
cls();
static int last;//Record the keys of the previous step
if(GetAsyncKeyState('D')){
last=1;
}
if(GetAsyncKeyState('A')){
last=2;
}
if(GetAsyncKeyState('S')){
last=3;
}
if(GetAsyncKeyState('W')){
last=4;
}
if(GetAsyncKeyState('D')&&y<MAXN-1&&(picture[x][y+1]==0||picture[x][y+1]==249)){
picture[x][y+1]=picture[x][y];
picture[x][y]=0;
y++;
Sleep(100);
}
if(GetAsyncKeyState('A')&&y>0&&(picture[x][y-1]==0||picture[x][y-1]==249)){
picture[x][y-1]=picture[x][y];
picture[x][y]=0;
y--;
Sleep(100);
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&(picture[x+1][y]==0||picture[x+1][y]==249)){
picture[x+1][y]=picture[x][y];
picture[x][y]=0;
x++;
Sleep(100);
}
if(GetAsyncKeyState('W')&&x>0&&(picture[x-1][y]==0||picture[x-1][y]==249)){
picture[x-1][y]=picture[x][y];
picture[x][y]=0;
x--;
Sleep(100);
}
if(GetAsyncKeyState('D')&&y<MAXN-1&&picture[x][y+1]==250){
picture[x][y+1]=249;
Sleep(100);
}
if(GetAsyncKeyState('A')&&y>0&&picture[x][y-1]==250){
picture[x][y-1]=249;
Sleep(100);
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&picture[x+1][y]==250){
picture[x+1][y]=249;
Sleep(100);
}
if(GetAsyncKeyState('W')&&x>0&&picture[x-1][y]==250){
picture[x-1][y]=249;
Sleep(100);
}
if(GetAsyncKeyState('D')&&y<MAXN-1&&picture[x][y+1]==200){
picture[x][y+1]=picture[x][y]-1;
picture[x][y]=0;
y++;
Sleep(100);
}
if(GetAsyncKeyState('A')&&y>0&&picture[x][y-1]==200){
picture[x][y-1]=picture[x][y]-1;
picture[x][y]=0;
y--;
Sleep(100);
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&picture[x+1][y]==200){
picture[x+1][y]=picture[x][y]-1;
picture[x][y]=0;
x++;
Sleep(100);
}
if(GetAsyncKeyState('W')&&x>0&&picture[x-1][y]==200){
picture[x-1][y]=picture[x][y]-1;
picture[x][y]=0;
x--;
Sleep(100);
}
if(GetAsyncKeyState('X')){
int z=rand()%50;
z=(z%25==0);
if(last==1){//D
if(picture[x][y+1]!=255){
picture[x][y+1]=250-z;
}
} else if(last==2){//A
if(picture[x][y-1]!=255){
picture[x][y-1]=250-z;
}
} else if(last==3){//S
if(picture[x+1][y]!=255){
picture[x+1][y]=250-z;
}
} else{//W
if(picture[x-1][y]!=255){
picture[x-1][y]=250-z;
}
}
Sleep(100);
}
if(GetAsyncKeyState('P')){
if(last==1){//D
if(picture[x][y+1]==0){
picture[x][y+1]=10;
} else if(picture[x][y+1]==200||picture[x][y+1]==249||picture[x][y+1]==250){
picture[x][y+1]=0;
}
} else if(last==2){//A
if(picture[x][y-1]==0){
picture[x][y-1]=11;
} else if(picture[x][y-1]==200||picture[x][y-1]==249||picture[x][y-1]==250){
picture[x][y-1]=0;
}
} else if(last==3){//S
if(picture[x+1][y]==0){
picture[x+1][y]=12;
} else if(picture[x+1][y]==200||picture[x+1][y]==249||picture[x+1][y]==250){
picture[x+1][y]=0;
}
} else{//W
if(picture[x-1][y]==0){
picture[x-1][y]=13;
} else if(picture[x-1][y]==200||picture[x-1][y]==249||picture[x-1][y]==250){
picture[x-1][y]=0;
}
}
Sleep(100);
}
}
end = clock();
dur = (double)(end - start);
system("cls");
output();
MessageBox(NULL,"GameOver","Tips",MB_OK);
system("cls");
printf("You lived for %f seconds\n",(dur/CLOCKS_PER_SEC));
return 0;
}
void init(){
for(int i=0;i<MAXN;i++)picture[0][i]=255;//Initialize the upper fence
for(int i=0;i<MAXN;i++)picture[MAXN-1][i]=255;//Initialize the lower fence
for(int j=0;j<MAXN;j++)picture[j][0]=255;//Initialize left fence
for(int j=0;j<MAXN;j++)picture[j][MAXN-1]=255;//Initialize right fence
x=rand()%(MAXN-2)+1,y=rand()%(MAXN-2)+1;
int z=rand()%1000;
picture[x][y]=(z==522?1:2);
//Initialize the meanings
meanings[0]=" ",colors[0]=255;
meanings[1]="m ",colors[1]=244;
meanings[2]="me",colors[2]=240;
meanings[10]="==",colors[10]=242;
meanings[11]="==",colors[11]=242;
meanings[12]="||",colors[12]=242;
meanings[13]="||",colors[13]=242;
meanings[200]="AA",colors[200]=199;
meanings[249]="H ",colors[249]=128;
meanings[250]="He",colors[250]=128;
meanings[255]="XX",colors[255]=15;
//Put Box
z=rand()%((MAXN/2)*(MAXN/2));
while(z--){
int xx=rand()%(MAXN-2)+1,yy=rand()%(MAXN-2)+1;
if(picture[xx][yy]==0){
int c=rand()%100+1;
picture[xx][yy]=(c%5==0?249:250);
}
}
//Put Ground thorn
z=rand()%((MAXN/5)*(MAXN/5));
while(z--){
int xx=rand()%(MAXN-2)+1,yy=rand()%(MAXN-2)+1;
if(picture[xx][yy]==0){
picture[xx][yy]=200;
}
}
}
void shoot(){
for(int i=0;i<MAXN;i++){
for(int j=0;j<MAXN;j++){
if(picture[i][j]==11){//A
if(picture[i][j-1]==0){
picture[i][j-1]=11;
} else if(picture[i][j-1]==250){
picture[i][j-1]=249;
} else if(picture[i][j-1]==249){
picture[i][j-1]=0;
}
picture[i][j]=0;
} else if(picture[i][j]==13){//W
if(picture[i-1][j]==0){
picture[i-1][j]=13;
} else if(picture[i-1][j]==250){
picture[i-1][j]=249;
} else if(picture[i-1][j]==249){
picture[i-1][j]=0;
}
picture[i][j]=0;
}
}
}
for(int i=MAXN-1;i>=0;i--){
for(int j=MAXN-1;j>=0;j--){
if(picture[i][j]==10){//D
if(picture[i][j+1]==0){
picture[i][j+1]=10;
} else if(picture[i][j+1]==250){
picture[i][j+1]=249;
} else if(picture[i][j+1]==249){
picture[i][j+1]=0;
}
picture[i][j]=0;
} else if(picture[i][j]==12){//S
if(picture[i+1][j]==0){
picture[i+1][j]=12;
} else if(picture[i+1][j]==250){
picture[i+1][j]=249;
} else if(picture[i+1][j]==249){
picture[i+1][j]=0;
}
picture[i][j]=0;
}
}
}
}
void output(){
for(int i=0;i<MAXN;i++){
for(int j=0;j<MAXN;j++){
color(colors[picture[i][j]]);
cout<<meanings[picture[i][j]];
}
puts("");
}
// color(240);
// gotoxy(0,MAXN*2);
// for(int i=1;i<=20;i++)putchar('*');
// for(int i=1;i<MAXN-1;i++){
// gotoxy(i,MAXN*2+19);
// putchar('*');
// }
// gotoxy(MAXN-1,MAXN*2);
// for(int i=1;i<=20;i++)putchar('*');
}
void cls(){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 }; // home for the cursor
SetConsoleCursorPosition( hConsole, coordScreen );
}
void HideCursor(){
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
CursorInfo.bVisible = false; //隐藏控制台光标
SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
}
int gotoxy(int y, int x){
HANDLE handle; //Define handle variable handle
COORD coord; //Define structure coord (coordinate system coord)
coord.X = x; //Abscissa x
coord.Y = y; //Ordinate y
handle = GetStdHandle(STD_OUTPUT_HANDLE); //Get console output handle (value - 11)
SetConsoleCursorPosition(handle, coord); //Move Cursor
}
void color(int x){
HANDLE h = GetStdHandle (-11);
SetConsoleTextAttribute(h,x);
}
主要更新了控制台的可观**。
吴庞茂旭在2022-05-15 21:49:21追加了内容
/*
NAME:Not yet
NODE/TIPS:NONE
*/
//std
#include <bits/stdc++.h>
#include <windows.h>
#define int long long
using namespace std;
const int M=26;
const string Ttips[M]={
"Game tips",
"Null---- ",
"Half blood \"me\"----m ",
"\"me\"----me",
"shoot to left or right----==",
"shoot to up or down----||",
"Ground thorn----AA",
"Half blood box----H ",
"Fine box----He",
"Wall----XX",
"",
"Play Tips",
"Up and down keys----Adjust the prompt bar",
"W----up",
"S----down",
"A----left",
"D----down",
"X----put boxes",
"P----shoot",
"",
"Update Log",
"1. In the name of our Lord Nully, add tips for new adventurers;",
"2. Start recording updates;",
"3. Expand the map with the power of gemstones;",
"4. The ground spike has become active. Be careful!",
"5. My Lord said: set an ending for you: resist 100 ground stab attacks!"
};
const int MAXN=30;//A map of MAXN*MAXN
const int TIME=0x7fffffff;
const int N=MAXN;
int picture[MAXN][MAXN];
int kill;
int x,y;//Player's point
int timecnt;//clocktime
map<int,string> meanings;
map<int,int> colors;
string tips[M*5];
int head,tail,len;
/*
Meanings of numbers in picture:
0----Null----
1----Half blood "me"----m
2----"me"----me
10----shoot to right---- ==
11----shoot to left---- ==
12----shoot to down----||
13----shoot to up----||
200----Ground thorn----AA
249----Half blood box----H
250----Fine box----He
255----Wall----XX
*/
void init();//Initialize picture and meanings
void shoot();//Dealing with bullets
bool make_thorn();//Make some new thorn
void output();//Output the picture
void cls();//Just like "system("cls")"
void HideCursor();//Hide Cursor
int gotoxy(int y, int x);//Position cursor
void color(int x);//Change the color
/*
How to make a color:
0 black
1 Blue
2 green
3 light blue
4 red
5 Purple
6 orange
7 white
8 ash
9 sky blue
10 green
11 bright blue
12 light red
13 light purple
14 flesh color
15 bright white
1024 upper dash
2048 spacing line
3072 1024+2048
6144 thick spacing line
7169 thick 1024 + 2048
*/
/*
VK_SHIFT Shift键
VK_LSHIFT 左Shift键
VK_RSHIFT 右Shift键
VK_CONTROL Ctrl键
VK_LCONTROL 左Ctrl键
VK_RCONTROL 右Ctril键
VK_MENU Alt键
VK_LMENU 左Alt键
VK_RMENU 右Alt键
VK_LBUTTON 鼠标左键
VK_RBUTTON 鼠标右键
VK_ESCAPE ESC键
VK_RETURN回车键
VK_TABTAB键
VK_SPACE空格键
VK_UP↑键
VK_DOWN↓键
VK_LEFT←键
VK_RIGHT→键
*/
signed main(){
system("title NotYet -4 By CodersClub*William.Wupang");
system("color 00");
srand(time(NULL));
HideCursor();
init();
MessageBox(NULL,"If you have any questions or ideas,plaese send me email at William.wupang@\
qq.com","Caption",MB_OK);
while(picture[x][y]){
timecnt++;//clock count add one
if(timecnt==TIME){
timecnt--;
}
if(make_thorn()){
system("cls");
output();
MessageBox(NULL,"You win!","Tips",MB_OK);
system("cls");
printf("You lived for %f seconds\n",timecnt/100.0);
}
output();
shoot();
cls();
static int last;//Record the keys of the previous step
if(GetAsyncKeyState('D')){
last=1;
}
if(GetAsyncKeyState('A')){
last=2;
}
if(GetAsyncKeyState('S')){
last=3;
}
if(GetAsyncKeyState('W')){
last=4;
}
if(GetAsyncKeyState('D')&&y<MAXN-1&&(picture[x][y+1]==0||picture[x][y+1]==249)){
picture[x][y+1]=picture[x][y];
picture[x][y]=0;
y++;
Sleep(100);
}
if(GetAsyncKeyState('A')&&y>0&&(picture[x][y-1]==0||picture[x][y-1]==249)){
picture[x][y-1]=picture[x][y];
picture[x][y]=0;
y--;
Sleep(100);
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&(picture[x+1][y]==0||picture[x+1][y]==249)){
picture[x+1][y]=picture[x][y];
picture[x][y]=0;
x++;
Sleep(100);
}
if(GetAsyncKeyState('W')&&x>0&&(picture[x-1][y]==0||picture[x-1][y]==249)){
picture[x-1][y]=picture[x][y];
picture[x][y]=0;
x--;
Sleep(100);
}
if(GetAsyncKeyState('D')&&y<MAXN-1&&picture[x][y+1]==250){
picture[x][y+1]=249;
Sleep(100);
}
if(GetAsyncKeyState('A')&&y>0&&picture[x][y-1]==250){
picture[x][y-1]=249;
Sleep(100);
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&picture[x+1][y]==250){
picture[x+1][y]=249;
Sleep(100);
}
if(GetAsyncKeyState('W')&&x>0&&picture[x-1][y]==250){
picture[x-1][y]=249;
Sleep(100);
}
if(GetAsyncKeyState('D')&&y<MAXN-1&&picture[x][y+1]==200){
picture[x][y+1]=picture[x][y]-1;
picture[x][y]=0;
y++;
Sleep(100);
kill=3;
}
if(GetAsyncKeyState('A')&&y>0&&picture[x][y-1]==200){
picture[x][y-1]=picture[x][y]-1;
picture[x][y]=0;
y--;
Sleep(100);
kill=3;
}
if(GetAsyncKeyState('S')&&x<MAXN-1&&picture[x+1][y]==200){
picture[x+1][y]=picture[x][y]-1;
picture[x][y]=0;
x++;
Sleep(100);
kill=3;
}
if(GetAsyncKeyState('W')&&x>0&&picture[x-1][y]==200){
picture[x-1][y]=picture[x][y]-1;
picture[x][y]=0;
x--;
Sleep(100);
kill=3;
}
if(GetAsyncKeyState('X')){
int z=rand()%50;
z=(z%25==0);
if(last==1){//D
if(picture[x][y+1]!=255){
picture[x][y+1]=250-z;
}
} else if(last==2){//A
if(picture[x][y-1]!=255){
picture[x][y-1]=250-z;
}
} else if(last==3){//S
if(picture[x+1][y]!=255){
picture[x+1][y]=250-z;
}
} else{//W
if(picture[x-1][y]!=255){
picture[x-1][y]=250-z;
}
}
Sleep(100);
}
if(GetAsyncKeyState('P')){
if(last==1){//D
if(picture[x][y+1]==0){
picture[x][y+1]=10;
} else if(picture[x][y+1]==200||picture[x][y+1]==249||picture[x][y+1]==250){
picture[x][y+1]=0;
}
} else if(last==2){//A
if(picture[x][y-1]==0){
picture[x][y-1]=11;
} else if(picture[x][y-1]==200||picture[x][y-1]==249||picture[x][y-1]==250){
picture[x][y-1]=0;
}
} else if(last==3){//S
if(picture[x+1][y]==0){
picture[x+1][y]=12;
} else if(picture[x+1][y]==200||picture[x+1][y]==249||picture[x+1][y]==250){
picture[x+1][y]=0;
}
} else{//W
if(picture[x-1][y]==0){
picture[x-1][y]=13;
} else if(picture[x-1][y]==200||picture[x-1][y]==249||picture[x-1][y]==250){
picture[x-1][y]=0;
}
}
Sleep(100);
}
if(GetAsyncKeyState(VK_UP)&&head>1){//go up
head--,tail--;
}
if(GetAsyncKeyState(VK_DOWN)&&tail<len){//go down
head++,tail++;
}
}
system("cls");
output();
MessageBox(NULL,"GameOver","Tips",MB_OK);
system("cls");
printf("You lived for %f seconds\n",timecnt/100.0);
return 0;
}
void init(){
for(int i=0;i<MAXN;i++)picture[0][i]=255;//Initialize the upper fence
for(int i=0;i<MAXN;i++)picture[MAXN-1][i]=255;//Initialize the lower fence
for(int j=0;j<MAXN;j++)picture[j][0]=255;//Initialize left fence
for(int j=0;j<MAXN;j++)picture[j][MAXN-1]=255;//Initialize right fence
x=rand()%(MAXN-2)+1,y=rand()%(MAXN-2)+1;
int z=rand()%1000;
picture[x][y]=(z==522?1:2);
//Initialize the meanings
meanings[0]=" ",colors[0]=255;
meanings[1]="m ",colors[1]=244;
meanings[2]="me",colors[2]=240;
meanings[10]="==",colors[10]=242;
meanings[11]="==",colors[11]=242;
meanings[12]="||",colors[12]=242;
meanings[13]="||",colors[13]=242;
meanings[200]="AA",colors[200]=199;
meanings[249]="H ",colors[249]=128;
meanings[250]="He",colors[250]=128;
meanings[255]="XX",colors[255]=15;
//Put Box
z=rand()%((MAXN/2)*(MAXN/2));
while(z--){
int xx=rand()%(MAXN-2)+1,yy=rand()%(MAXN-2)+1;
if(picture[xx][yy]==0){
int c=rand()%100+1;
picture[xx][yy]=(c%5==0?249:250);
}
}
//make tips
head=1,tail=MAXN,len=1;
for(int i=0;i<M;i++){
for(int j=0;j<Ttips[i].size();j++){
tips[len]+=Ttips[i][j];
if(j>=N&&j%N==0){
len++;
}
}
while(tips[len].size()<=N)tips[len]+=" ";
len++;
}
len--;
tail=min(tail,MAXN-2);
}
void shoot(){
for(int i=0;i<MAXN;i++){
for(int j=0;j<MAXN;j++){
if(picture[i][j]==11){//A
if(picture[i][j-1]==0){
picture[i][j-1]=11;
} else if(picture[i][j-1]==250){
picture[i][j-1]=249;
} else if(picture[i][j-1]==249){
picture[i][j-1]=0;
}
picture[i][j]=0;
} else if(picture[i][j]==13){//W
if(picture[i-1][j]==0){
picture[i-1][j]=13;
} else if(picture[i-1][j]==250){
picture[i-1][j]=249;
} else if(picture[i-1][j]==249){
picture[i-1][j]=0;
}
picture[i][j]=0;
}
}
}
for(int i=MAXN-1;i>=0;i--){
for(int j=MAXN-1;j>=0;j--){
if(picture[i][j]==10){//D
if(picture[i][j+1]==0){
picture[i][j+1]=10;
} else if(picture[i][j+1]==250){
picture[i][j+1]=249;
} else if(picture[i][j+1]==249){
picture[i][j+1]=0;
}
picture[i][j]=0;
} else if(picture[i][j]==12){//S
if(picture[i+1][j]==0){
picture[i+1][j]=12;
} else if(picture[i+1][j]==250){
picture[i+1][j]=249;
} else if(picture[i+1][j]==249){
picture[i+1][j]=0;
}
picture[i][j]=0;
}
}
}
}
bool make_thorn(){
static int timeclock,number,cnt;
//Put Ground thorn
if(!timeclock){//It's time to put the thorns
int z;
for(int i=0;i<MAXN;i++){
for(int j=0;j<MAXN;j++){
if(picture[i][j]==200){
z=rand()%200+1;
picture[i][j]=(z>=50&&z<=60?250:0);
number++;
}
}
}
number=number+rand()%5+1;
while(number--){
int xx=rand()%(MAXN-2)+1,yy=rand()%(MAXN-2)+1;
z=rand()%200+1;
if(picture[xx][yy]==0||picture[xx][yy]!=2&&picture[xx][yy]!=1&&z>=50&&z<=60){
picture[xx][yy]=200;
}
}
timeclock=rand()%100+50;
cnt++;
}
timeclock--;
if(cnt==100)return true;
else return false;
}
void output(){
for(int i=0;i<MAXN;i++){
for(int j=0;j<MAXN;j++){
if(!kill)color(colors[picture[i][j]]);
if(kill)color(76);
cout<<meanings[picture[i][j]];
}
puts("");
}
if(kill)kill--;
color(240);
gotoxy(0,MAXN*2);
for(int i=1;i<=N+1;i++){
putchar('*');
}
for(int i=0;i<MAXN;i++){
gotoxy(i,MAXN*2+1+N);
putchar('*');
}
gotoxy(MAXN-1,MAXN*2);
for(int i=1;i<=N+1;i++){
putchar('*');
}
for(int i=head;i<=tail;i++){
gotoxy(i-head+1,MAXN*2);
cout<<tips[i];
}
}
void cls(){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 }; // home for the cursor
SetConsoleCursorPosition( hConsole, coordScreen );
}
void HideCursor(){
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
CursorInfo.bVisible = false; //隐藏控制台光标
SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
}
int gotoxy(int y, int x){
HANDLE handle; //Define handle variable handle
COORD coord; //Define structure coord (coordinate system coord)
coord.X = x; //Abscissa x
coord.Y = y; //Ordinate y
handle = GetStdHandle(STD_OUTPUT_HANDLE); //Get console output handle (value - 11)
SetConsoleCursorPosition(handle, coord); //Move Cursor
}
void color(int x){
HANDLE h = GetStdHandle (-11);
SetConsoleTextAttribute(h,x);
}
我不学了,此号废弃,我共有3552个酷町豆,1500个给@陈曦,1500个给@陈振轩,剩下550个由@刘宇航分发。
0
已采纳
薛乘志
初级启示者
初级启示者
一个建议:
最好不要使用数字ID存东西,不然开 发到后面就会开始抓狂(然后弃坑),可以使用有意义的字符串ID
薛乘志在2022-03-21 19:33:14追加了内容
但是到后面就会发现东西多了根本记不住,用有意义的字符串id更好记些
如果非要使用数字ID的话最好定义个宏存储,不然后面改了ID就要全代码寻找修改特别麻烦
薛乘志在2022-03-21 19:35:29追加了内容
还有就是可以考虑使用一下代码格式化工具如clang-format或astyle等等(直接一键排版!)
0
0
0
吴庞茂旭
资深光能
资深光能
目前是全英文注释版本,别问我为什么,因为我想英特耐雄纳尔化程序。
吴庞茂旭在2022-03-19 20:51:32追加了内容
基本上后期会更新一些新障碍、小怪、BOSS什么的,看你们的建议咯。
0
0
0
0