c++小游戏
更新时间:2023-08-18 04:02:01 阅读量: 资格考试认证 文档下载
c++小游戏
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<Windows.h>
/********函数变量声明********/
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade = 1, C_Gold = 0, C_Ag = 0, Score = 0, Delay_time = 1000, Max_blank = 9, Distance = 18;
typedef struct Birds {
int x, y;
int condition;
}Birds;
Birds * Bird;
typedef struct Bg {
int x, y;
int l_blank;
int reward[9];
struct Bg * pri;
struct Bg * next;
}Bg;
Bg * Bg1;
void Position(int x, int y) {
COORD pos = {
x - 1, y - 1
};
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
void CreatBird() {
Bird -> x = 41;
Bird -> y = 10;
Bird -> condition = 0;
}
void CreatBg() {
Bg * Bg2 = (Bg * ) malloc(sizeof(Bg));
Bg1 -> x = 90;
Bg1 -> y = 8;
Bg2 -> x = Bg1 -> x + Distance;
Bg2 -> y = 9;
Bg1 -> l_blank = Max_blank - Grade;
Bg2 -> l_blank = Max_blank - Grade;
Bg1 -> next = Bg2;
Bg1 -> pri = Bg2;
Bg2 -> next = Bg1;
Bg2 -> pri = Bg1;
}
void InsertBg(Bg * p) {
int temp;
Bg * Bgs = (Bg * ) malloc(sizeof(Bg));
Bgs -> x = p -> pri -> x + Distance;
Bgs -> l_blank = Max_blank - Grade;
srand((int) time(0));
temp = rand();
if (temp % 2 == 0) //++
{
if ((temp % 4 + p -> pri -> y + Max_blank - Grade) < 21)
Bgs -> y = p -> pri -> y + temp % 4;
else
Bgs -> y = p -> pri -> y;
} else {
if ((p -> pri -> y - temp % 4) > 2)
Bgs -> y = p -> pri -> y - temp % 4;
else
Bgs -> y = p -> pri -> y;
}
Bgs -> pri = p -> pri;
Bgs -> next = p;
p -> pri -> next = Bgs;
p -> pri = Bgs;
}
void Check_Bg(Bg * q) {
Bg * p = q;
int i = 0, temp;
while (++i <= 5) {
if (p -> x > -4)
p = p -> next;
else {
srand((int) time(0));
temp = rand();
if (temp % 2 == 0) //++
{
if ((temp % 4 + p -> y + Max_blank - Grade) < 21)
p -> y = p -> y + temp % 4;
else
p -> y = p -> y;
p -> x = p -> pri -> x + Distance;
p -> l_blank = Max_blank - Grade;
} else {
if ((p -> y - temp % 4) > 2)
p -&
gt; y = p -> y - temp % 4;
else
p -> y = p -> y;
p -> x = p -> pri -> x + Distance;
p -> l_blank = Max_blank - Grade;
c++小游戏
}
}
}
}
void Loop_Bg(Bg * q) {
Bg * p = q;
int i = 0;
while (++i <= 5) {
p -> x = p -> x - 1;
p = p -> next;
if (Bird -> x == p -> x) {
Score += 1;
if (Score % 4 == 0 && Grade < 4)
Grade++;
}
}
}
void Prt_Bg(Bg * q) {
Bg * p = q;
int i = 0, k, j;
while (++i <= 5) {
if (p -> x > 0 && p -> x <= 78) {
for (k = 2; k < p -> y; k++) {
Position(p -> x + 1, k);
PR_Box;
PR_Box;
PR_Blank
}
Position(p -> x, p -> y);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
Position(p -> x, p -> y + p -> l_blank);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
k = k + p -> l_blank + 1;
for (k; k <= 22; k++) {
Position(p -> x + 1, k);
PR_Box;
PR_Box;
PR_Blank;
}
Position(p -> x, 23);
for (k = 1; k < Distance / 3 - 2; k++)
PR_Land;
}
p = p -> next;
if (p -> x == 0) {
for (j = 2; j < p -> y; j++) {
Position(p -> x + 1, j);
PR_Blank;
PR_Blank;
}
Position(p -> x + 1, p -> y);
PR_Blank;
PR_Blank;
PR_Blank;
Position(p -> x + 1, p -> y + Max_blank - Grade);
PR_Blank;
PR_Blank;
PR_Blank;
j = j + Max_blank - Grade + 1;
for (j; j <= 22; j++) {
Position(p -> x + 1, j);
PR_Blank;
PR_Blank;
}
}
}
}
void PrtBg() {
int i;
Position(1, 1);
PR_Bg_TL;
Position(79, 1);
PR_Bg_TR;
Position(1, 24);
PR_Bg_DL;
Position(79, 24);
PR_Bg_DR;
for (i = 3; i <= 78; i += 2) {
Position(i, 1);
PR_Bg_X;
Position(i, 24);
PR_Bg_X;
}
}
void PrtBird() {
Position(Bird -> x, Bird -> y - 1);
PR_Blank;
Position(Bird -> x, Bird -> y);
PR_FBird;
Position(38, 2);
printf("Score:%d", Score);
}
int CheckYN(Bg * q) {
Bg * p = q;
int i = 0;
while (++i <= 5) {
if (Bird -> y > 23)
return 0;
if (Bird -> x == p -> x && Bird -> y <= p -> y)
return 0;
if ((Bird -> x == p -> x || Bird -> x == p -> x + 1 || Bird -> x == p -> x + 2) && Bird -> y == p -> y)
return 0;
if (Bird -> x == p -> x && Bird -> y > p -> y + p -> l_blank)
return 0;
if ((Bird -> x == p -&
gt; x || Bird -> x == p -> x + 1 || Bird -> x == p -> x + 2) && Bird -> y == p -> y +
p -> l_blank)
return 0;
p
c++小游戏
= p -> next;
}
return 1;
}
void Prtfirst() {
printf("══════════════════════════════════════\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■ C语言版 Flappy Bird\n");
printf(" ■■ ■■ 瞎搞人:yyposs\n");
printf(" ■■ ■■ 瞎搞日期:2014.2\n");
printf(" ■■ ■■ 耗时:4小时\n");
printf(" ■■■ ■■ 游戏说明:\n");
printf(" ■■ 1-按上箭头使鸟起飞\n");
printf(" ■■ 2-等级越高,难度越大!\n");
printf(" Ю ■■■\n");
printf("\n");
printf(" ■■■ 欢迎各路大神一起探讨\n");
printf(" ■■\n");
printf(" ■■\n");
printf(" ■■ ■■■ 【无版权,随意修改】\n");
printf(" ■■ ■■\n");
printf(" ■■ Ф ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳\n");
system("pause");
Position(1, 1);
int i = 0;
while (i++ < 40 * 25)
PR_Blank;
}
int main(void) {
int i = 0;
char ch;
Bird = (Birds * ) malloc(sizeof(Birds));
Bg1 = (Bg * ) malloc(sizeof(Bg));
Prtfirst();
PrtBg();
CreatBg();
InsertBg(Bg1);
InsertBg(Bg1);
InsertBg(Bg1);
CreatBird();
while (1) {
if (!CheckYN(Bg1))
break;
Check_Bg(Bg1);
Prt_Bg(Bg1);
PrtBird();
Loop_Bg(Bg1);
Bird -> y = Bird -> y + 1;
if (GetAsyncKeyState(VK_UP)) {
Position(Bird -> x, Bird -> y - 1);
PR_Blank;
Bird -> y = Bird -> y - 4;
}
while
(i++ < 500); {
Sleep(100);
}
i = 0;
}
Position(38, 10);
printf("You Lost!");
Position(1, 25);
system("pause");
}
正在阅读:
c++小游戏08-18
历史观摩课教学设计与反思05-23
酒吧服务员基本培训05-07
八匹马拉不开歇后语02-12
妈妈对宝宝成长寄语02-11
浅谈企业税收筹划-所得税06-19
电子万年历毕业设计(基于AT89C51单片机和DS1302时钟芯片)09-15
扶贫攻坚驻村联户帮扶动员大会讲话稿11-13
这就是我作文女孩06-20
- 梳理《史记》素材,为作文添彩
- 2012呼和浩特驾照模拟考试B2车型试题
- 关于全面推进施工现场标准化管理实施的通知(红头文件)
- 江西省房屋建筑和市政基础设施工程施工招标文件范本
- 律师与公证制度第2阶段练习题
- 2019-2020年最新人教版PEP初三英语九年级上册精编单元练习unit6训练测试卷内含听力文件及听力原文
- 小升初数学模拟试卷(十四) 北京版 Word版,含答案
- 认识创新思维特点 探讨创新教育方法-精选教育文档
- 00266 自考 社会心理学一(复习题大全)
- 多媒体在语文教学中的运用效果
- 派出所派出所教导员述职报告
- 低压电工作业考试B
- 18秋福建师范大学《管理心理学》在线作业一4
- 中国铝业公司职工违规违纪处分暂行规定
- 13建筑力学复习题(答案)
- 2008年新密市师德征文获奖名单 - 图文
- 保安员培训考试题库(附答案)
- 银川市贺兰一中一模试卷
- 2011—2017年新课标全国卷2文科数学试题分类汇编 - 1.集合
- 湖北省襄阳市第五中学届高三生物五月模拟考试试题一
- c++
- 小游戏