目录
游戏介绍
在学习了一个大佬的贪吃蛇后,收获很大,所以我就想我的简易版马里奥进行了升级
实现了超级马里奥的移动、跳跃
w 跳跃 a 向左 d 向右
做了一个粗糙的地图
游戏效果
游戏代码
代码有点长,主要是地图代码
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
#include<conio.h>
#define KONG 0
#define WALL 1
#define ROLE 2
#define DIE 3
#define FLAG 4
#define ROW 15
#define COL 90
char board[ROW][COL];
struct Role//人物
{
int x;
int y;
}role;
void menu()//菜单
{
printf("\n\n\n\n 1 PLAY 2 EXIT \n");
}
void WIN()
{
printf("\n\n\n\n YOU WIN! \n");
printf("\n\n\n PRESS ANY KEY TO CONTINUE \n");
}
void END()
{
printf("\n\n\n\n GAME OVER! \n");
printf("\n\n\n PRESS ANY KEY TO CONTINUE \n");
}
void HideCursor()//隐藏光标
{
CONSOLE_CURSOR_INFO cursorInfo;
cursorInfo.dwSize = 1;
cursorInfo.bVisible = FALSE;
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cursorInfo);
}
void CursorJump(int x,int y)//光标跳跃
{
COORD pos;
pos.X = x;
pos.Y = y;
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(handle, pos);
}
void color(int c)//颜色函数
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
void InitInterBoard()//初始化地图
{
color(7);
int i = 0, j = 0,k = 0;;
for (i = 0; i < ROW; i++)
{
if (i == 0)
{
for (j = 0; j < COL; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
printf("\n");
}
else if (i == 3)
{
for (j = 89; j < 90; j++)
{
board[i][j] = FLAG;
CursorJump(2 * j, i);
printf("|");
}
printf("\n");
}
else if (i == 4)
{
for (j = 89; j < 90; j++)
{
board[i][j] = FLAG;
CursorJump(2 * j, i);
printf("|");
}
printf("\n");
}
else if (i == 5)
{
for (j = 7; j < 8; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 28; j < 32; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 34; j < 37; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 45; j < 46; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 51; j < 54; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 55; j < 58; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 89; j < 90; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("|");
}
printf("\n");
}
else if (i == 6)
{
for (j = 86; j < 87; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 89; j < 90; j++)
{
board[0][j] = FLAG;
CursorJump(2 * j, i);
printf("|");
}
printf("\n");
}
else if (i == 7)
{
for (j = 85; j < 87; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 89; j < 90; j++)
{
board[0][j] = FLAG;
CursorJump(2 * j, i);
printf("|");
}
printf("\n");
}
else if (i == 8)
{
for (j = 3; j < 4; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 6; j < 9; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 14; j < 15; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 17; j < 18; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 21; j < 22; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}
for (j = 26; j < 28; j++)
{
board[i][j] = WALL;
CursorJump(2 * j, i);
printf("■");
}