#include <bits/stdc++.h>
#include <windows.h>
#include <cstdlib>
#include <conio.h>
using namespace std;
int foodnum=0;
char a[22][42];
char qw;
struct node1{
string name;
int x=10,y=20;
double tili=100;
}pp;
void csh(){
for(int i=0;i<20;i++)
for(int j=0;j<40;j++){
if(i==0||i==19||j==0||j==39)
a[i][j]='#';
else if(a[i][j]=='*')
continue;
else
a[i][j]=' ';
}
}
void duru(){
qw=_getch();
if((qw=='w'||qw=='W')&&pp.x>1)
pp.x-=1;
else if((qw=='s'||qw=='S')&&pp.x<18)
pp.x+=1;
else if((qw=='a'||qw=='A')&&pp.y>1)
pp.y-=1;
else if((qw=='d'||qw=='D')&&pp.y<38)
pp.y+=1;
}
void shuchu(){
for(int i=0;i<20;i++){
for(int j=0;j<40;j++){
if(pp.x==i&&pp.y==j)
cout<<"@";
else
cout<<a[i][j];
}
cout<<"\n";
}
}
void loadfood(int n){
for(int i=0;i<=n;i++){
a[rand()%(20-1)][rand()%(40-1)]='*';
}
}
void shuruxingming(){
cout<<"输入你的id:";
getline(cin,pp.name);
}
void shushu(){
foodnum=0;
for(int i=0;i<20;i++)
for(int j=0;j<40;j++)
if(a[i][j]=='*')
foodnum++;
}
int main(){
shuruxingming();
loadfood(30);
while(true){
if(foodnum<=0){
loadfood(30);
}
shushu();
csh();
if(qw=='z'){
cout<<"end";
return 0;
}
system("cls");
cout<<"注意看,@是你,*是食物。"<<"\n";
cout<<"走一步体力减0.5,吃食物时体力加4。"<<"\n";
cout<<"食物数量归0时会刷新食物。"<<"\n";
cout<<"不要让体力归0。"<<"\n";
cout<<"按wasd控制行走。"<<"\n";
cout<<"不想玩了就按z。"<<"\n";
shuchu();
cout<<pp.name<<"\n";
cout<<"体力值:"<<pp.tili<<"\n";
if(a[pp.x][pp.y]=='*'){
a[pp.x][pp.y]=' ';
pp.tili+=4;
foodnum--;
}
cout<<"食物数量:"<<foodnum<<"\n";
duru();
pp.tili-=0.5;
if(pp.tili<=0){
cout<<"你因能量耗尽而死";
Sleep(10000);
return 0;
}
}
return 0;
}
4 个赞
建议:每次更新难度增大,食物减少,初始能量 100->90->80->70->60->55->:50->50…
函数封装使用英文 如input,output等等
做的好好!先赞后看,养成习惯!!!
1 个赞
谢谢!!!
会闪屏,给你一个函数
void gotoxy(int x, int y) {
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
return ;
}
把system(“cls”)换成gotoxy(0,0)
1 个赞
我试试
哇塞,真的不闪频
我做的游戏(星际迷途1.5以上)(2047-极限求生 PS:还没出)都用了这个函数,☆*: .。. o(≧▽≦)o .。.:*☆
1 个赞
哈哈,我昨天还玩了
666╰(°▽°)╯
1 个赞
我的同学希望有一个人能做一个二维的我的世界
这要求太高了。。。(转战scratch吧,那里有)
2 个赞
我有一个朋友(许睿则)用的是这个函数,希望对你的极限求生 PS,有所帮助
这个函数是甚么意思???φ(* ̄0 ̄)ヾ(•ω•`)o
1 个赞
如果没看到看这个
void dy()
{
Sleep(50);
system("cls");
for(int i=0;i<xxx;i++)
{
puts(dt[i]);
}
}
我也不知道
这是他做的贪吃蛇
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<ctime>
#include<cstdlib>
using namespace std;
const int xxx=20,yyy=50;
char dt[xxx][yyy+1];
struct sn
{
int x,y;
}s[(xxx-1)*(yyy-1)*2],ne;
int h=0,t=0;
void chushihua()
{
for(int i=0;i<xxx;i++)
{
for(int j=0;j<yyy;j++)
{
if((i==0||i==xxx-1) || (j==0||j==yyy-1))
{
dt[i][j]='#';
}
else
{
dt[i][j]=' ';
}
}
}
for(int i=2;i<=4;i++)
{
dt[i][2]='O';
s[t].x=i;
s[t++].y=2;
}
}
void dy()
{
Sleep(50);
system("cls");
for(int i=0;i<xxx;i++)
{
puts(dt[i]);
}
}
void food()
{
srand(time(0));
int nx,ny;
do
{
nx=rand()%(xxx-2);
ny=rand()%(yyy-2);
}while(dt[nx][ny]=='#' || dt[nx][ny]=='O');
dt[nx][ny]='*';
}
int main()
{
chushihua();
food();
dy();
char dir='s',ls;
int cnt=3;
while(cnt<=14)
{
if(kbhit())
{
ls=getch();
if((ls=='a'||ls=='d')&&(dir=='w'||dir=='s'))
{
dir=ls;
}
else if((dir=='a'||dir=='d')&&(ls=='w'||ls=='s'))
{
dir=ls;
}
}
ne.x=s[t-1].x;
ne.y=s[t-1].y;
if(dir=='s')
{
ne.x++;
}
else if(dir=='w')
{
ne.x--;
}
else if(dir=='a')
{
ne.y--;
}
else if(dir=='d')
{
ne.y++;
}
if(dt[ne.x][ne.y]=='O' || dt[ne.x][ne.y]=='#')
{
cout<<"you lost"<<" "<<cnt;
}
else if(dt[ne.x][ne.y]==' ')
{
s[t].x=ne.x;
s[t++].y=ne.y;
dt[s[h].x][s[h].y]=' ';
h++;
dt[ne.x][ne.y]='O';
}
else if(dt[ne.x][ne.y]=='*')
{
s[t].x=ne.x;
s[t++].y=ne.y;
dt[ne.x][ne.y]='O';
food();
cnt++;
}
dy();
}
cout<<"you win!"<<" "<<"长度为" <<cnt;
return 0;
}
6(●’◡’●)
1 个赞
是这个???我玩过!!(你是一高集训的吗ヾ(•ω•`)o)
1 个赞
先退了,下次聊╰(°▽°)╯
1 个赞
一初东