一.前言
这是一个拼手速的贪吃蛇,你能玩到多少分呢?快来邀请你的朋友玩一玩吧!
二.代码
#include <windows.h>
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <ctime>
using namespace std;
#define random( x ) rand ( ) % ( x )
HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE );
COORD coord;
void SetPosition ( int x, int y ) {
coord.X = x; coord.Y = y; SetConsoleCursorPosition ( handle, coord ); }
class Data {
public:
struct strRect {
int x; int y; int width; int height; int color; };
struct strButton {
int x; int y; int width; int color; string text [ 2 ]; };
struct strText {
int x; int y; int color; string text; };
struct strNumber {
int x; int y; int color; int number; };
struct strXY {
int x; int y; };
strButton button_start, button_set, button_exit, button_size, button_size_min,
button_level, button_level_n, button_level_h, button_level_vh, button_gameover;
strRect area_main, area_play, area_score, area_option, area_attribute, area_size;
strText text_pass, text_level, text_score, text_time, text_multiple, text_gametime;
strNumber number_score, number_speed, number_pass;
strXY xy_snake, xy_food [ 2 ];
int id_window, id_button, id_snake, id_food;
int isfood_score [ 2 ], isfood_random [ 2 ];
Data ( ) {
button_start = {
40, 10, 20, 0x8f, {
"开始游戏","开 始 游 戏"} };
button_set = {
40, 14, 20, 0x8f, {
"设置", "设 置" } };
button_exit = {
40, 18, 20, 0x8f, {
"退出游戏", "退 出 游 戏" } };
button_size = {
10, 5, 20, 0x8f, {
"分辨率", "分 辨 率" } };
button_size_min = {
30, 5, 60, 0x70, {
"100 X 31", "100 X 31" } };
button_level = {
10, 8, 20, 0x8f, {
"游戏难度", "游 戏 难 度" } };
button_level_n = {
30, 5, 60, 0x70, {
"简单", "简 单" } };
button_level_h = {
30, 8, 60, 0x70, {
"困难", "困 难" } };
button_level_vh = {
30, 11, 60, 0x70, {
"地狱", "地 狱" } };
button_gameover = {
10, 14, 56, 0xcf, {
"GAME\tOVER", "\0" } };
area_main = {
10, 0, 80, 31, 0xf0 };
area_play = {
10, 0, 56, 31, 0x7f };
area_score = {
66, 0, 24, 31, 0x8f };
area_option = {
10, 0, 20, 31, 0x8f };
area_attribute = {
30, 0, 60, 31, 0x7f };
area_size = {
30, 8, 60, 6, 0x7f };
text_pass = {
75, 2, 0x8f, "第 1 关" };
text_level = {
68, 5, 0x8f, "游戏难度:简单" };
text_score = {
68, 7, 0x8f, "得分:" };
text_time = {
68, 15, 0x8f