#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
#include <time.h>
#include <stdio.h>
#include <limits>
#define MAX 100
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#define MOVING 5
#define STOP 0
HANDLE hMain_Out = NULL;
HANDLE hMain_In = NULL;
struct Pos {
int x;
int y;
};
struct Body {
int state;
int len;
int Direction;
Pos pos[MAX];
};
Pos NewPos[MAX];
Pos Food;
SMALL_RECT Wall;
int count = 0;
int grade = 0;
int level = 1;
int amount = 0;
int speed = 200;
bool isPaused = false;
void basic();
void game();
void out();
bool login();
void registerUser();
void gameIntroduction();
void Init(Body& b);
void Print(const Body& b);
void Print(int x, int y);
void Move(Body& b);
void Clean(int x, int y);
void Clean(const Body& b);
void ShowInfo();
int GetDirection(Body& b);
void TurnRound(int Direction, Body& b);
void PosCopy(Body& b, Pos NewPos[]);
void MoveBody(Body& b);
void HideCursor();
void CreateWall();
void CreateFood();
bool IsKnock_Food(const Body& b);
bool IsKnock_Wall(const Body& b);
void AddBody(Body& b);
void HideTheCursor();
void basic() {
HideTheCursor();
system("cls");
int choice;
std::cout << "1. 登录" << std::endl;
std::cout << "2. 注册" << std::endl;
std::cout << "3. 游戏介绍" << std::endl;
std::cout << "4. 退出" << std::endl;
std::cout << "请选择: ";
std::cin >> choice;
while (true) {
switch (choice) {
case 1:
if (login()) {
// 登录成功后执行的代码
for (int i = 5; i > 0; i--) {
system("cls");
std::cout << "登录成功,即将进入游戏!" << std::endl;
std::cout << "还有" << i << "秒即将开始游戏";
Sleep(1000);
}
game();
}
break;
case 2:
registerUser();
break;
case 3:
gameIntroduction();
break;
case 4:
std::cout << "请按ESC键退出游戏 ";
while (true) {
if (GetAsyncKeyState(VK_ESCAPE)) {
out();
}
}
return;
default:
std::cout << "\n无效选择,请重新输入!" << std::endl;
std::cin >> choice;
break;
}
system("cls");
std::cout << "1. 登录" << std::endl;
std::cout << "2. 注册" << std::endl;
std::cout << "3. 游戏介绍" << std::endl;
std::cout << "4. 退出" << std::endl;
std::cout << "请重新选择: ";
std::cin >> choice;
}
return;
}
void game() {
system("cls");
Body b;
Init(b);
Print(b);
HideCursor();
while (TRUE) {
if (GetAsyncKeyState(VK_ESCAPE)) {
out();
}
if (GetAsyncKeyState(VK_SPACE)) {
isPaused = !isPaused;