专栏文章
(3)TGLXJ-666-hungry
休闲·娱乐参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mipubrtb
- 此快照首次捕获于
- 2025/12/03 18:04 3 个月前
- 此快照最后确认于
- 2025/12/03 18:04 3 个月前
CPP
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
#define kd(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
map<pair<int,int>,char> mp;
const int winx=666,winy=666;
bool win=1,run=0;
struct player{
int x,y,hungry;
char foot;
}you;
char square(){
int x=rand()%1000+1;
if(x>=1 && x<=800) return '.';
else if(x>=801 && x<=950) return '#';
else if(x>=951 && x<=1000) return 'F';
}
void init(){
srand(time(0));
you.x=you.y=0;
win=1;
run=0;
you.hungry=10;
you.foot='.';
mp.clear();
int x1=you.x-5,y1=you.y-5,x2=you.x+5,y2=you.y+5;
for(int i=x1;i<=x2;i++){
for(int j=y1;j<=y2;j++){
mp[{i,j}]=square();
}
}
mp[{0,0}]='Y';
mp[{winx,winy}]='H';
mp[{-winx,winy}]='H';
mp[{winx,-winy}]='H';
mp[{-winx,-winy}]='H';
}
bool check(int x,int y){
if(mp[{x,y}]=='#') return 0;
return 1;
}
void run_you(){
if(kd(VK_LEFT) && check(you.x,you.y-1)){
mp[{you.x,you.y}]=you.foot;
swap(you.foot,mp[{you.x,you.y-1}]);
you.y--;
mp[{you.x,you.y}]='Y';
run=1;
}
if(kd(VK_UP) && check(you.x-1,you.y)){
mp[{you.x,you.y}]=you.foot;
swap(you.foot,mp[{you.x-1,you.y}]);
you.x--;
mp[{you.x,you.y}]='Y';
run=1;
}
if(kd(VK_RIGHT) && check(you.x,you.y+1)){
mp[{you.x,you.y}]=you.foot;
swap(you.foot,mp[{you.x,you.y+1}]);
you.y++;
mp[{you.x,you.y}]='Y';
run=1;
}
if(kd(VK_DOWN) && check(you.x+1,you.y)){
mp[{you.x,you.y}]=you.foot;
swap(you.foot,mp[{you.x+1,you.y}]);
you.x++;
mp[{you.x,you.y}]='Y';
run=1;
}
}
void change(){
int x1=you.x-5,y1=you.y-5,x2=you.x+5,y2=you.y+5;
for(int i=x1;i<=x2;i++){
for(int j=y1;j<=y2;j++){
if(mp.find({i,j})==mp.end()) mp[{i,j}]=square();
}
}
if(you.foot=='F'){
you.foot='.';
you.hungry+=10;
}else if(run){
you.hungry--;
run=0;
}
}
void gotoxy(short x,short y){
COORD pos={x,y};
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
return ;
}
void print(){
gotoxy(0,0);
int x1=you.x-5,y1=you.y-5,x2=you.x+5,y2=you.y+5;
for(int i=x1;i<=x2;i++){
for(int j=y1;j<=y2;j++){
printf("%c",mp[{i,j}]);
}
printf("\n");
}
printf("x=%-10dy=%-10dhungry=%-10d",you.x,you.y,you.hungry);
}
bool you_win_or_no(){
if(you.foot=='H'){
return 0;
}else if(you.hungry==0){
win=0;
return 0;
}
return 1;
}
int main(){
cl:
init();
while(you_win_or_no()){
run_you();
change();
print();
Sleep(75);
}
system("cls");
if(win){
printf("YOU ARE 666");
Sleep(1000);
system("cls");
}else{
printf("YOU ARE NOT 666");
Sleep(1000);
system("cls");
goto cl;
}
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...