c++益智小游戏《十步万度》

1鼠标点击哪个圆圈,那个圆圈就转90度,

2指针指向哪个圆圈,哪个圆圈就转90度,

3共有10次机会,每转一圈加90分。

代码:

       

// 十步万度.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define PI 3.14159
struct  Round {
	float x, y;
	float r;
	int anglenum;
}rounds[5][5];
int step, score;
void startup() {
	step = 10, score = 0;
	initgraph(600, 700);
	setbkcolor(RGB(50, 50, 50));
	setlinestyle(PS_SOLID, 3);
	cleardevice();
	BeginBatchDraw();
	int i, j;
	for (i = 0; i < 5; i++) {
		for (j = 0; j < 5; j++) {
			rounds[i][j].r = 30;
			rounds[i][j].x = 100 + j * 100;
			rounds[i][j].y = 200 + i * 100;
			rounds[i][j].anglenum = 1;
		}
	}
}
void show() {
	cleardevice();
	float angle;
	int i, j;
	for (i = 0; i < 5; i++) {
		for (j = 0; j < 5; j++) {
			setlinecolor(RGB(200, 201, 202));
			circle(rounds[i][j].x, rounds[i][j].y, rounds[i][j].r);
			angle = rounds[i][j].anglenum * PI / 2;
			setlinecolor(RGB(255, 0, 0));
			line(rounds[i][j].x, rounds[i][j].y, rounds[i][j].x + cos(-angle) * rounds[i][j].r, rounds[i][j].y +sin(-angle) * rounds[i][j].r);
		}
	}
	TCHAR s[20];
	setbkmode(TRANSPARENT);
	_stprintf(s, _T("% d 步 % d 度"), step, score);
	settextstyle(50, 0, _T("宋体"));
	outtextxy(150, 20, s);
	settextstyle(20, 0, _T("宋体"));
	outtextxy(15, 100, _T("点击一个圆圈,其指针顺时针旋转90度后 指向的针依次旋转"));
	FlushBatchDraw();
	FlushBatchDraw();
	
}
void rotateround(int i, int j) {
	rounds[i][j] .anglenum-= 1;
	if (rounds[i][j].anglenum == -1) {
		rounds[i][j].anglenum = 3;
	}
	score += 90;
}

int Getindexes(int indexes[2]) {
	int i = indexes[0];
	int j = indexes[1];
	if (rounds[i][j].anglenum == 1) {
		i--;
	}
	else if (rounds[i][j].anglenum == 2) {
		j--;
	}
	else if (rounds[i][j].anglenum == 3) {
		i++;
	}
	else {
		j++;
	}
	indexes[0] = i;
	indexes[1] = j;
	if (i >= 0 && i < 5 && j >= 0 && j < 5) {
		return 1;
	}
	else
		return 0;
}


void update() {
	MOUSEMSG  m;
	if (MouseHit()) {
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN&&step>0) {
			int ci = int(m.y - 150) / 100;
			int cj = int(m.x - 50) / 100;
			rotateround(ci, cj);
			step--;
			show();
			Sleep(300);
			int indexes[2] = { ci,cj };
			while (Getindexes(indexes)) {
				rotateround(indexes[0], indexes[1]);
				show();
				Sleep(300);
			}
		}
	}
}


int main() {
	startup();
	while (step>0) {
		show();
		update();
	}
	getch();
	return 0;
}

 最开始:

 第一步:

第二步:

 最后

  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学徒在修行

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值