C++贪吃蛇分数版(非本人创作)

这篇博客介绍了一个基于C++编写的贪吃蛇游戏,玩家可以通过这个游戏测试自己的反应速度,博主邀请大家与朋友一起比拼高分。
摘要由CSDN通过智能技术生成

C++分数版贪吃蛇

一.前言

这是一个拼手速的贪吃蛇,你能玩到多少分呢?快来邀请你的朋友玩一玩吧!

二.代码

#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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值