别踩白块

///*----------------------------------------别踩白块--------------------------------------------------*/

#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include<easyx.h>
#include<time.h>
#include<string.h>
#pragma comment(lib,"winmm.lib")

using namespace std;

IMAGE pict;
//随机数
int arr[4];
void ramd() 
{
	srand((unsigned)time(NULL));    //以时间为随机数
	for (size_t i = 0; i < 4; i++)arr[i] = rand() % 4;   //产生的随机数组值。
}
//创建游戏窗口
void init_map()
{
	initgraph(400, 480);
    loadimage(&pict,100,120); //设置图片的格式。
}
//初始化窗口
void init_wind()
{
	BeginBatchDraw();
	cleardevice();
	setlinecolor(GREEN);
	setfillcolor(WHITE);
	for (size_t i = 0; i <4; i++)
	{
		for (size_t j = 0; j < 4; j++)
		{
			fillrectangle(i * 100, j * 120, (i + 1) * 100, (j + 1) * 120);    //绘制4*4的白块。
		}
	}
	setfillcolor(RED);    //随机红块
	for (size_t i = 0; i < 4; i++)
	{
		//fillrectangle(arr[i] * 100, i * 120, (arr[i] + 1) * 100, (i + 1) * 120);   //每行随机生产1个红块。
        putimage(arr[i] * 100, i * 120, &pict);  //放入图片
	}

	EndBatchDraw();
}
int score;

//鼠标操作
bool opera()
{
	
	MOUSEMSG msg = GetMouseMsg();//获取鼠标信息
	int m = msg.x;
	int n = msg.y;
	if (n >= 360 && n <= 480)
	{
		switch (msg.uMsg)    //当前接收到的信息
		{
		case WM_LBUTTONDOWN:
		case WM_RBUTTONDOWN:

			if (arr[3] * 100 < m && m < (arr[3] + 1) * 100)
			{
				for (size_t i = 3; i > 0; i--)	arr[i] = arr[i - 1];
				arr[0] = rand() % 4;
				init_wind();
				score += 10;

			}
			else return false;
			break;

		default:return true;
			break;
		}
	}

}

//游戏积分
void play()
{	
	char s[50];
	sprintf(s, "当前得分:%d", score);
	outtextxy(10, 60, s);    //用于在指定位置输出字符串
	if (opera() == false)
	{
		TCHAR txt[50];
		wsprintf(txt, "游戏失败,得分:%d", score);
		if (MessageBox(GetHWnd(), txt, "是否要继续", MB_YESNO) == IDYES)
		{
			ramd();
			init_wind();
			score = 0;
		}
		else exit(0);
	}
	if (score == 100)
	{
		TCHAR txt[50];
		wsprintf(txt, "游戏过关,得分:%d", score);
		if (MessageBox(GetHWnd(),txt, "是否要继续", MB_YESNO) == IDYES)
		{
			ramd();
			init_wind();
			score = 0;
		}
		else exit(0);
	}
}


int main()
{
	init_map();
	ramd();
	init_wind();
	while (true)play();
	
	system("pause");
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值