1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| #include <iostream> #include <easyx.h> #include <conio.h> #include <time.h> #include <mmsystem.h> #pragma comment(lib, "winmm.lib") using namespace std;
struct round_rec { int left; int top; int right; int bottom; int ew; int eh; };
void BGM() { mciSendString(L"open ./music/1.mp3 alias bgm", 0, 0, 0); mciSendString(L"play bgm repeat", 0, 0, 0); }
void Change_Caption() { HWND hnd = GetHWnd(); SetWindowText(hnd, L"欢迎来到DQY&WYの小窝~"); }
void SetText() { settextcolor(BLACK);
settextstyle(20, 0, L"楷体");
setbkmode(TRANSPARENT); }
void Set_Graphics() { setlinestyle(PS_DASH, 5);
setlinecolor(BROWN);
setfillcolor(YELLOW); }
void Start() { while (MessageBox(GetHWnd(), L"欢迎来到欢迎来到DQY&WYの小窝~要开始游戏嘛?", L"提示", MB_YESNO) != IDYES) { MessageBox(GetHWnd(), L"不开始游戏就无法继续噢!", L"警告", MB_OK); } }
void KeyHit(int &x, int &y) { if (_kbhit()) { if (GetAsyncKeyState(VK_UP)) { y--; } if (GetAsyncKeyState(VK_DOWN)) { y++; } if (GetAsyncKeyState(VK_LEFT)) { x--; } if (GetAsyncKeyState(VK_RIGHT)) { x++; } Sleep(5); } }
void MouseHit(struct round_rec fill_roundrec, ExMessage &msg) { if (peekmessage(&msg, EM_MOUSE)) { switch (msg.message) { case WM_LBUTTONDOWN: if (msg.x >= fill_roundrec.left && msg.x <= fill_roundrec.right && msg.y >= fill_roundrec.top && msg.y <= fill_roundrec.bottom) { MessageBox(GetHWnd(), L"我只是个摆设噢~", L"阿巴阿巴", MB_OK); } break; default: break; } } }
int main() {
initgraph(720, 480);
Change_Caption();
BGM();
Start();
SetText(); Set_Graphics();
IMAGE img; loadimage(&img, L"./images/1.jpg", 720, 480);
struct round_rec fill_roundrec = { 50, 150, 150, 200, 10, 50 };
wchar_t str[] = L"Button"; int width = textwidth(str); int height = textheight(str); int tx = fill_roundrec.left + (fill_roundrec.right - fill_roundrec.left - width) / 2; int ty = fill_roundrec.top + (fill_roundrec.bottom - fill_roundrec.top - height) / 2;
int x = 50, y = 50; ExMessage msg; while (true) { BeginBatchDraw(); cleardevice(); putimage(0, 0, &img); fillcircle(x, y, 50); fillroundrect(fill_roundrec.left, fill_roundrec.top, fill_roundrec.right, fill_roundrec.bottom, fill_roundrec.ew, fill_roundrec.eh); outtextxy(tx, ty, str); EndBatchDraw();
MouseHit(fill_roundrec, msg);
KeyHit(x, y); }
getchar(); closegraph();
return 0; }
|