贪吃蛇C++ 代码纯享版

#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;
            

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值