#include<time.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<Windows.h>
/**************************/
const int PreSetMapHei=25;
const int PreSetMapLen=25;
const float PreSetJumpRef1=6;
const float PreSetJumpRef2=0.6;
const int PreSetMonPosi=10;
const int PreSetMonHei=5;
const int PreSetMonBan=7;
const int PreSetSleep=20;
/**************************/
void back_move();
void jump_func();
int monst_create();
void check();
void print();
void main_process();
void enter_process();
/**************************/
/* main time line */
int TIME;
/* map */
const int MAP_HEI=PreSetMapHei,MAP_LEN=PreSetMapLen;
char map[MAP_LEN];
void back_move() {
memcpy(map,map+1,sizeof(map)-1);
map[MAP_LEN-1]=monst_create();
}
/* ground line */
const char roll[]={"yyk is so strong "};
int rolen=strlen(roll),front_r;
void ground_init() {
front_r=0;
}
void ground_move() {
front_r=(front_r+1)%rolen;
}
void ground_print() {
for(int i=0;i<MAP_LEN;i++) {
putchar(roll[(front_r+i)%rolen]);
}
}
/* player */
int player;
int dead;
/* jump */
const float J1=PreSetJumpRef1,J2=PreSetJumpRef2;
int jump_v;
void jump_func() {
if(kbhit()) {
while(kbhit()) getch();
if(jump_v==-1) jump_v=0;
}
if(jump_v!=-1) {
player=(J1-J2*(++jump_v))*(jump_v);
if(player<0) {
player=0;
jump_v=-1;
}
}
}
/* monsters */
const int M_POSSI=PreSetMonPosi,M_HEI=PreSetMonHei,M_BAN=PreSetMonBan;
int monst_create() {
struct timeb timeSeed;
ftime(&timeSeed);
srand(timeSeed.time*1000+timeSeed.millitm);
for(int i=1;i<=M_BAN;i++) {
if(map[MAP_LEN-i]) return 0;
}
int tmp=rand()%M_POSSI;
if(!tmp) return rand()%M_HEI+1;
return 0;
}
void check() {
if(player<map[0]) dead=1;
}
/* print */
void print() {
printf("SCORES : %d\n",TIME);
for(int i=MAP_HEI-1;i>=0;i--) {
if(i==player+2) putchar(player>=map[0] ? 1 : 2);
else {
if(i==player+1) putchar(21);
else {
if(i==player) putchar(TIME&1 ? 47 : 20);
else putchar(i>=map[0] ? 0 : '#');
}
}
putchar((i==player)&&(TIME&1) ? 92 : (i>=map[1] ? 0 : '#') );
for(int j=2;j<MAP_LEN;j++)
putchar(i>=map[j] ? 0 : '#');
putchar('\n');
}
ground_move();
ground_print();
putchar('\n');
}
/* main */
void main_process() {
HANDLE hOutput;
COORD coord={0,0};
hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
memset(map,0,sizeof map);
for(TIME=0,dead=0,ground_init();!dead;TIME++) {
SetConsoleCursorPosition(hOutput, coord);
Sleep(PreSetSleep);
back_move();
jump_func();
check();
print();
}
}
void enter_process() {
for(int i=MAP_HEI-1;i>=0;i--) {
puts(i==MAP_HEI/2 ? " ENTER" : "");
}
getch();
for(char c='r';c=='r';c=getch()){
main_process();
puts(" GAME OVER");
puts("press R to play again");
}
}
int main() {
enter_process();
}
jump_1.1
最新推荐文章于 2025-07-10 21:00:03 发布