#pragma warning(disable: 4996)
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
#include <conio.h>
#include "iostream"
#include"unistd.h"
#include"pthread.h"
using namespace std;
#define M 50
#define N 23
char ch;
int xxx=10,yyy=10;
void* getMsg(void *f) {
while (1) {
ch = getch();
xxx=(ch=='1'||ch=='4'||ch=='7')?0:(ch=='2'||ch=='5'||ch=='8')?1:2;
yyy=(ch=='1'||ch=='2'||ch=='3')?0:(ch=='4'||ch=='5'||ch=='6')?1:2;
}
return NULL;
}
void* xc(void *f) {
while (1) {
usleep(500000);
if(!isdigit(ch)){
xxx=10;
yyy=10;
}
}
return NULL;
}
int main()
{
begining:;
int start;
start = clock();
system("color 57");
char a[M][M] = {"*|******************************|*",
"*|------------------------------|*",
"*|###########打三角树###########|*",
"*|##############################|*",
"*| 菜单 |*",//5
"*|##############################|*",
"*|##############################|*",
"*| 开始游戏 |*",//8
"*|##############################|*",
"*|##############################|*",
"*|########请按键盘回车键########|*",
"*|##############################|*",
"*|##############################|*",
"*|------------------------------|*",
"*|******************************|*",//15
};
char b[M][M] = { "*|******************************|*",
"*|------------------------------|*",
"*| are |*",
"*|##############################|*",
"*| you |*",//5
"*|##############################|*",
"*|##############################|*",
"*| ready!!! |*",
"*|##############################|*",
"*|##############################|*",//10
"*|############哈哈哈############|*",
"*|##############################|*",
"*|##########按任意键开始########|*",
"*| ----zwt---|*",
"*|******************************|*",//15
}; //设置一个34*23的迷宫地图
char c[31][60] = { "*|******************************************************|*",
"*| * * |*",
"*| * * |*",//2
"*| # * ##### * ##### |*",
"*| # * # * # |*",
"*| # * ##### * ##### |*",//5
"*| # * # * # |*",
"*| # * ##### * ##### |*",
"*| * * |*",
"*| * * |*",//8
"*|******************************************************|*",
"*| * * |*",//9
"*| * * |*",//10
"*| # # * ##### * ##### |*",
"*| # # * # * # |*",
"*| #### * ##### * ##### |*",
"*| # * # * # # |*",
"*| # * ##### * ##### |*",//15
"*| * * |*",
"*| * * |*",
"*|******************************************************|*",
"*| * * |*",
"*| * * |*",//18
"*| ##### * ##### * ##### |*",
"*| # * # # * # # |*",//20
"*| # * ##### * ##### |*",
"*| # * # # * # |*",
"*| # * ##### * ##### |*",
"*| * * |*",
"*| * * |*",
"*|******************************************************|*",//25
};
char d[8][13] = { " # ",
" ### ",
" ##### ",
" ####### ",
" ######### ",
" * ",
" * ",
"<<<<< >>>>>",
};
char dd[8][13] = {
" ",
"###### ",
"###### ",
"###### ",
"###### ",
" * ",
" * ",
" * ",
};
/* char d[6][13] = { " ##### #### ",
" # # # # ",
" ##### # # ",
" # # # # ",
" # # # # ",
" # # # ",
};
*/
char xx[31][60] = { "*|******************************************************|*",
"*| * * |*",
"*| * * |*",//2
"*| # * ##### * ##### |*",
"*| # * # * # |*",
"*| # * ##### * ##### |*",//5
"*| # * # * # |*",
"*| # * ##### * ##### |*",
"*| * * |*",
"*| * * |*",//8
"*|******************************************************|*",
"*| * * |*",//9
"*| * * |*",//10
"*| # # * ##### * ##### |*",
"*| # # * # * # |*",
"*| #### * ##### * ##### |*",
"*| # * # * # # |*",
"*| # * ##### * ##### |*",//15
"*| * * |*",
"*| * * |*",
"*|******************************************************|*",
"*| * * |*",
"*| * * |*",//18
"*| ##### * ##### * ##### |*",
"*| # * # # * # # |*",//20
"*| # * ##### * ##### |*",
"*| # * # # * # |*",
"*| # * ##### * ##### |*",
"*| * * |*",
"*| * * |*",
"*|******************************************************|*",//25
};
begin:;
int i;
for (i = 0; i <= 14; i++)
{
puts(a[i]);
}
getchar();
system("cls");
for (i = 0; i <= 14; i++)
{
puts(b[i]);
}
getchar();
cout<<endl<<endl<<" 请输入困难等级"<<endl<<"一为容易 二为一般 三为困难"<<endl;
int qq=1,sudu;
cin>>qq;
if(qq==1) sudu=990000;
if(qq==2) sudu=500000;
if(qq==3) sudu=20000;
pthread_t as,kj;
pthread_create(&as,NULL, getMsg, NULL);
pthread_create(&kj,NULL, xc, NULL);
int tt=5;
while(tt--){
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<" 全屏游戏更爽哦 "<<endl<<" 游戏将在"<<tt<<"秒后开始";
sleep(1);
}
cout<<endl<<endl<<endl<<endl<<endl<<"《《《《《《《游戏开始》》》》》》》";
sleep(1);
int x = 1, y = 1;
int sx,sy;
//屏幕输出移动前的情况
while (1)
{
input:;
srand((unsigned)time(NULL));
while(x==sx&&y==sy){
x = rand() % 3;
y = rand() % 3;
}//设置一变量来储存键盘所输入的方向大写字符
sx=x;
sy=y;
for (int j = 0; j < 31; j++) {
for (int k = 0; k < 58; k++) {
xx[j][k] = c[j][k];
};
}
/* for (int j = 0; j < 6; j++) {
for (int k = 0; k < 13; k++) {
xx[y * 8 + 1 + j][x * 18 + 2 + k] = d[j][k];
}
}*/
int j = 0, k = 0;
for (; j < 8; j++) {
for (k = 0; k < 11; k++) {
xx[y * 10 + 1 + j][x * 18 + 2+3 + k] = d[j][k];
}
}
if(x>=0&&x<=2&&y>=0&&y<=2){
j = 0, k = 0;
for (; j < 8; j++) {
for (k = 0; k < 11; k++) {
xx[yyy * 10 + 1 + j][xxx * 18 + 2+3 + k] = dd[j][k];
}
}
}
/* for (j = 0; j < 6; j++) {
for (k=13; x * 18 + 2 + k <59; k++) {
xx[y * 8 + 1 + j][x * 18 + 2 + k] = c[y * 8 + 1 + j][x * 18 + 2 + k];
}
}
*/
xx[y * 8 + 1 + 6][x * 18 + 2 + 13] = ' ';
system("cls");
for (int j = 0; j < 31; j++) {
puts(xx[j]);
}
usleep(sudu);
if (ch - '0' == y * 3 + 1 + x){
break;
}
ch='k';
//屏幕输出移动后的情况
}
system("cls");
printf("\n\n\n\n 恭喜你把三角树打扁了!!!!!!!!!!!\n");
printf(" 恭喜你把三角树打扁了!!!!!!!!!!!\n");
printf(" 恭喜你把三角树打扁了!!!!!!!!!!!\n");
printf(" 重要事 说三遍!!!\n");
printf(" 还想再锤三角么? \n");
printf(" input you answer!n"); //是否再次进行游戏
printf(" 请输入 Y or N\n");
char answer = '\0';
getchar();
scanf("%c", &answer);
if (answer == 'Y')
{
goto begining; //利用goto函数在执行一次游戏
}
else
{
goto end; //利用goto函数结束游戏的运行
}
end:
printf("Thanks for you play!!!");
system("pause");
return 0;
}
打地鼠 --- 树 game
猜你喜欢
转载自blog.csdn.net/qq_14989799/article/details/105550991
今日推荐
周排行