没有合适的资源?快使用搜索试试~ 我知道了~
贪吃蛇完美版
需积分: 10 3 下载量 16 浏览量
2018-06-25
17:25:42
上传
评论
收藏 7KB TXT 举报
温馨提示
试读
10页
C++贪吃蛇小游戏。是学习C++来开发游戏的好实例。本人正在学习,拿出来与大家分享,共同学习。
资源推荐
资源详情
资源评论
#include "iostream"
#include <graphics.h>
#include "stdlib.h"//rand的头文件
#include "time.h"//srand的头文件
#include <conio.h>//kbhit的头文件
using namespace std;
int speed=250;
int fenshu=0;
char str[1000];
struct Food
{
int yes;//yes等于0表示没有食物,等于1有食物
int x;
int y;
} food;
struct Snake
{
int x[200];//蛇最长为200
int y[200];
int node;//蛇的长度
int dir;//蛇的方向
} snake;
void init ();
void chanfood();
void move ();
void snakelife ();
void chansnake();
void jieshu ();
void eatfood ();
void pfenshu ();
#include <graphics.h>
#include "stdlib.h"//rand的头文件
#include "time.h"//srand的头文件
#include <conio.h>//kbhit的头文件
using namespace std;
int speed=250;
int fenshu=0;
char str[1000];
struct Food
{
int yes;//yes等于0表示没有食物,等于1有食物
int x;
int y;
} food;
struct Snake
{
int x[200];//蛇最长为200
int y[200];
int node;//蛇的长度
int dir;//蛇的方向
} snake;
void init ();
void chanfood();
void move ();
void snakelife ();
void chansnake();
void jieshu ();
void eatfood ();
void pfenshu ();
void init ()//初始化
{
initgraph(800,600); //初始化绘图环境
loadimage(NULL,"D:\\1.jpg",800,600);
setbkmode(TRANSPARENT); //设置图案填充和文字输出时的背景模式
{
setcolor(GREEN);
setfont(64, 0, "方正舒体");
outtextxy(300, 150, "贪吃蛇");
setcolor(GREEN);
setfont(16, 0, "仿宋_GB2312");
outtextxy(300, 250, " 制作成员:陶小方 杨皓迪");
outtextxy(300, 300, "控制方向: W 是上、 S 是下");
outtextxy(380, 350, " A 是向左、D 是向右");
outtextxy(380, 400, " O 是加速、P 是减速");
outtextxy(380,450," L 是暂停");
while(!kbhit()){ //检查是否有输入,若没有就返回0;
setcolor(GREEN);
setfont(20, 0, "仿宋_GB2312");
outtextxy(150, 450, "任意键开始游戏");
}
getch();
}
cleardevice();
snake.x[0]=60;
snake.y[0]=60;
snake.x[1]=40;
snake.y[1]=40;
snake.node=2;
snake.dir=1;
{
initgraph(800,600); //初始化绘图环境
loadimage(NULL,"D:\\1.jpg",800,600);
setbkmode(TRANSPARENT); //设置图案填充和文字输出时的背景模式
{
setcolor(GREEN);
setfont(64, 0, "方正舒体");
outtextxy(300, 150, "贪吃蛇");
setcolor(GREEN);
setfont(16, 0, "仿宋_GB2312");
outtextxy(300, 250, " 制作成员:陶小方 杨皓迪");
outtextxy(300, 300, "控制方向: W 是上、 S 是下");
outtextxy(380, 350, " A 是向左、D 是向右");
outtextxy(380, 400, " O 是加速、P 是减速");
outtextxy(380,450," L 是暂停");
while(!kbhit()){ //检查是否有输入,若没有就返回0;
setcolor(GREEN);
setfont(20, 0, "仿宋_GB2312");
outtextxy(150, 450, "任意键开始游戏");
}
getch();
}
cleardevice();
snake.x[0]=60;
snake.y[0]=60;
snake.x[1]=40;
snake.y[1]=40;
snake.node=2;
snake.dir=1;
剩余9页未读,继续阅读
资源评论
weixin_42543014
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功