c++贪吃蛇 DEV
DEV-C++
#include <iostream>
#include <list>
#include <cstdio>
#include <string>
#include <vector>
#include <ctime>
#include <algorithm>
#include <conio.h>
#include <windows.h>
using namespace std;
class Node {
public:
int x, y;
Node(int x1, int y1);
};
class UserData {
public:
string name;
long long score;
int gt;
int gr;
UserData(string s, long long sc,int gametime,int grade);
friend bool operator < (UserData a, UserData b);
};
#define RIGHT 0x4d
#define LEFT 0x4b
#define UP 0x48
#define DOWN 0x50
#define YELLOW FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define CYAN FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define ORANGE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define PURPLE FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY
#define RED FOREGROUND_RED | FOREGROUND_INTENSITY
const int STARTX = 8;
const int STARTY = 4;
const int RANGEX = 60;
const int RANGEY = 20;
int point=10;
const int ENDX = STARTX + RANGEX;
const int ENDY = STARTY + RANGEY;
bool isSnake[RANGEY + 10 ][RANGEX + 10];
int speed;
int sysj;
int gametime;
list<Node> snake;
int curDiraction;
int score;
int grade;
int snakeLen;
int foodx, foody;
int gox, goy;
int mj;
void GoTo(short x, short y);
void DrawBoard();
void ShowInformation();
void Init();
void RunSnake(int x, int y);
void Try(int& x, int& y);
bool IsGoodCoord(int x, int y);
void AddFood();
void EartFood();
void InitSnake();
bool EndGame();
bool StartGame();
bool GameMenu();
void ShowRanking();
void ShowAbout();
void InputData();
int main() {
system("title 贪吃蛇小游戏v.1.5.5.3 by 赖以凡");
while (true) {
if (!GameMenu()) return 0;
}
return 0;
}
Node::Node(int x1, int y1) {
x = x1; y = y1;
}
int SuiJi()
{
srand((unsigned)time(NULL));
return (rand()*rand()+rand()*rand())%14;
}
bool operator < (UserData a, UserData b) {
if(a.score != b.score)
return a.score > b.score;
if(a.gt !=b.gt)
return a.gt > b.gt;
else
return a.gr > b.gr;
}
UserData::UserData(string s, long long sc,int gametime_,int _grade) {
name = s; score = sc; gt=gametime_; gr=_grade;
}
void color(WORD A)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), A);
}
void Color(int a)
{
switch (a%4)
{
case 0:color(RED);break;
case 1:color(CYAN);break;
case 2:color(YELLOW);break;
case 3:color(PURPLE);break;
}
}
void GoTo