看你有多色(看你有多色)

2023-03-29 15:52:23 游戏资讯 lvseyouxi

你这个问题好像是在对中国男生的道德调查哦!

色的更高境界是——不动声色!就像礼于表面的日本人那样,如果这个问题你去问日本人,一定有你最标准的答案!

C++ 游戏 (看你有多色) 代码

/* 看你有多色小游戏

 *

 * 曙光 2014年11月19日16:18

*/

#include stdlib.h

#include string.h

#include Windows.h

#ifndef _T

#ifdef UNICODE

#define _T(str)   L ## str

#else

#define _T(str)     str

#endif  // UNICODE

#endif  // _T

#if ! __STDC_WANT_SECURE_LIB__

#define strcpy_s(DstText, TextLen, SrcText)         strcpy(DstText, SrcText) 

#define strcat_s(DstText, TextLen, SrcText)         strcat(DstText, SrcText) 

#define _itoa_s(Val, Text, TextLen, Radix)          itoa(Val, Text, Radix)

#endif

// 全局变量

HWND MainWindow;              // 主窗口

int  TruthX, TruthY;          // 正确答案坐标

int  ArraySize, Level;        // 颜色块矩阵边长、级别

COLORREF ColorDef, ColorTruth;// 默认颜色与正确答案颜色

// 画矩形

BOOL PolyRect(HDC hdc, LONG left, LONG top, LONG width, LONG hight) {

POINT point[4];

point[0].x = left;

point[0].y = top;

point[1].x = left + width;

point[1].y = top;

point[2].x = left + width;

point[2].y = top + hight;

point[3].x = left;

point[3].y = top + hight;

return Polygon(hdc, point, 4);

}

// 重绘窗口事件

void PaintWindow(void) {

HBRUSH hBrush, hOldBrush;

PAINTSTRUCT ps;

HDC hdc;

RECT rect;

int x, y;

double w, h;

ArraySize = ArraySize  2 ? 2 : ArraySize;

GetClientRect(MainWindow, rect);

hdc = BeginPaint(MainWindow, ps);

hBrush = CreateSolidBrush(ColorDef);

hOldBrush = (HBRUSH) SelectObject(hdc, hBrush);

w = (double) (rect.right - rect.left) / ArraySize;

h = (double) (rect.bottom - rect.top) / ArraySize;

for (x = 0; x  ArraySize; ++x) {

for (y = 0; y  ArraySize; ++y) {

PolyRect(hdc, (LONG) w * x, (LONG) h * y, (LONG) w - 1, (LONG) h - 1);

}

}

hBrush = CreateSolidBrush(ColorTruth);

DeleteObject(SelectObject(hdc, hBrush));

PolyRect(hdc, (LONG) w * TruthX, (LONG) h * TruthY, (LONG) w - 1, (LONG) h - 1);

SelectObject(hdc, hOldBrush);

DeleteObject(hBrush);

EndPaint(MainWindow, ps);

}

// 新游戏

void NewGame(int lev) {

BYTE r, g, b;

char text[1024];

if (lev  100) {

MessageBox(MainWindow, _T("您已经通关了,在下佩服!"), _T("通关提示"), 0);

}

lev = lev  1 || lev  100 ? 1 : lev;

ArraySize = lev / 10 + 2;

Level = lev;

TruthX = rand() % ArraySize;

TruthY = rand() % ArraySize;

r = rand()  0x7f;

g = rand()  0x7f;

b = rand()  0x7f;

ColorDef = RGB(r, g, b);

ColorTruth = RGB(r + 51 - lev / 2, g + 51 - lev / 2, b + 51 - lev / 2);

InvalidateRect(MainWindow, NULL, TRUE);

strcpy_s(text, sizeof(text), "看你有多色 - 第");

_itoa_s(lev, text + strlen(text), 4, 10);

strcat_s(text, sizeof(text), "关");

SetWindowTextA(MainWindow, text);

}

// 点击事件响应

void WindowClick(int x, int y) {

char text[1024];

RECT rect;

double w, h;

GetClientRect(MainWindow, rect);

w = (double) (rect.right - rect.left) / ArraySize;

h = (double) (rect.bottom - rect.top) / ArraySize;

x = x / (int) w;

y = y / (int) h;

if (x == TruthX  y == TruthY) {

NewGame(Level + 1);

} else {

strcpy_s(text, sizeof(text), "你点错了哦,正确答案:");

_itoa_s(TruthX + 1, text + strlen(text), 3, 10);

strcat_s(text, sizeof(text), ",");

_itoa_s(TruthY + 1, text + strlen(text), 3, 10);

MessageBoxA(MainWindow, text, "重新开始", 0);

NewGame(1);

}

}

// 窗口消息响应

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

switch (uMsg) {

case WM_DESTROY:      // 窗口销毁

PostQuitMessage(0);

break;

case WM_SIZE:         // 窗口大小被改变

InvalidateRect(hWnd, NULL, TRUE);

break;

case WM_PAINT:        // 重绘窗口

PaintWindow();

break;

case WM_LBUTTONDOWN:  // 鼠标左键按下

WindowClick(LOWORD(lParam), HIWORD(lParam));

break;

default:

return DefWindowProc(hWnd, uMsg, wParam, lParam);

}

return 0;

}

// 入口函数

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow) {

WNDCLASSEX wce;

MSG msg;

// 注册窗口类

wce.cbSize = sizeof(wce);

wce.style = 0;

wce.lpfnWndProc = (WNDPROC) WndProc;  // 窗口消息处理函数

wce.cbClsExtra = wce.cbWndExtra = 0;

wce.hInstance = hInstance;

wce.hCursor = LoadCursor(NULL,IDC_ARROW);

wce.hbrBackground = (HBRUSH) COLOR_ *** NSHADOW;

wce.hIcon = wce.hIconSm = LoadIcon(NULL,IDI_APPLICATION);

wce.lpszClassName = _T("ShuGuang");

wce.lpszMenuName = NULL;

RegisterClassEx(wce);

MainWindow = CreateWindowEx(0, _T("ShuGuang"), _T("看你有多色"), WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, CW_USEDEFAULT, 600, 400, NULL, NULL, hInstance, NULL);

ShowWindow(MainWindow, nCmdShow);

UpdateWindow(MainWindow);

srand(GetTickCount());

NewGame(1);

// 消息循环

while (GetMessage(msg, NULL, 0, 0)) {

TranslateMessage(msg);

DispatchMessage(msg);

}

return msg.wParam;

}

水平有限,可以参考 呵呵

微信小游戏看你有多色用c++写出来,这段代码是什么意思?

这个是对类成员的初始化。具体有设定的意思要看成员类型及起的作用才行,不知道你是什么游戏,只能根据变量猜测一下其作用

rect_diff = NULL; //这个是一个指针,让其等于NULL,是防止出现错误操作。一般指针都要初始化为NULL

count = 2; //count变量设置为2,从变量名可以知道,它应该是统计游戏里的什么东西,可能是游戏的得分吧

level = 1; //level变量设置为1,从变量名可以知道,它应该是游戏的级别

timeWork = 60; //timeWork变量设置为60,可能是调用SetTimer()函数里的nElapse

isWorking = false; //isWorking变量设置为false,表示没有在游戏

indent_X =20; //indent_X变量设置为20,可能是X方向缩进20。

indent_Y =20; //indent_Y变量设置为20,可能是Y方向缩进20。

TIMERID = 100001; //TIMERID 变量设置为100001,可能是调用SetTimer()函数里的nIDEvent

diffX = 0; //diffX变量设置为0,可能是rect_diff的X方向的大小

diffY = 0; //diffY变量设置为0,可能是rect_diff的Y方向的大小

看你有多色(看你有多色宅男神器下载) 第1张