Новичок
Профиль
Группа: Участник
Сообщений: 1
Регистрация: 13.11.2012
Репутация: нет Всего: нет
|
Здравствуйте. Тут в руки попал код скрипта, но при копилирование он выдает ошибки. Просьба подсказать, что сделать что бы он скомпилировался. У меня XP sp3 и VS 2010. Мб автор специально ошибки допустил. Прошу помощи. | Скрытый текст |
| Код | #if _WIN32_WINNT < 0x0500 #define _WIN32_WINNT 0x0500 #endif #include <windows.h> #include <time.h> #include <list> #include <mmsystem.h> #include "resource.h" #pragma comment(lib, "winmm.lib")
#define processId #define realmlist #define server #define rate #define name #define memory 256 #define name #define fraction #define type #define mapId autodetect #define place #define coords autodetect #define cell 1x1 #define valueOf 1 #define currentHealth #define curentMana #define currentRage #define money #define allsloth clear #define good #define serverdelay autodetect #define interfaceUI get.alldataOfInterface(); #define stats_power get.character.stats.power(); #define honor get.character.stats.honor(); #define tallent get.character.stats.allTallent(); #define tallent_value #define profession get.data.professoon ();
typedef struct _Ship { COORD pos; DWORD mtime; int type; // 1 - shipA, 2 - shipB int cnt; int life; } Ship, *PShip;
DWORD WINAPI ThreadInputDevice(LPVOID param); DWORD WINAPI ThreadSpikerSound(LPVOID param); BOOL ParemtersConsole(const WCHAR* caption); void InitGame(void); int DrawStatus(BOOL reset, int plife, int pbonus, int pmimo, int pkill); BOOL IsQuitGame(void); void DrawSpaceshipA(PShip ship, DWORD tick); void DrawSpaceshipB(PShip ship, DWORD tick); void DrawUser(void); void DrawBullet(PCOORD pos, BOOL redraw); void MoveBullet(void); void GeneratePosition(PShip ship); void CrushShip(PShip ship); bool IsCollisionShip(PCOORD pos); void CollisionBullet(PCOORD pos); void OutputText(const CHAR* str, SHORT x, SHORT y, SHORT width = 0, WORD color = 0); void CleanConsole(CHAR ch = ' ', WORD color = 0); void BeginGame(void); void EndGame(void); CHAR* SaveStatus(int bonus, int kill, int mimo);
HANDLE hout = NULL; HANDLE hin = NULL; HANDLE thread = NULL; HANDLE sthread = NULL; HGLOBAL sound = NULL; PShip ships = NULL; BOOL restart = FALSE; BOOL gameover = FALSE; DWORD idsound = 0uL; COORD screen; COORD upos; COORD utmp; DWORD speed[2];
CRITICAL_SECTION section; std::list<COORD> bullets;
int main(void) {
DWORD tick = 0uL; DWORD tmove = 0uL;
if(! ParemtersConsole(L"Космический одиночка")) return 1;
sthread = CreateThread(NULL, 0uL, (LPTHREAD_START_ROUTINE)ThreadSpikerSound, (LPVOID)NULL, 0uL, &idsound); if(sthread == NULL) return 2;
thread = CreateThread(NULL, 0uL, (LPTHREAD_START_ROUTINE)ThreadInputDevice, (LPVOID)NULL, CREATE_SUSPENDED, NULL); if(thread == NULL) { TerminateThread(sthread, 0uL); return 3; }
BeginGame(); ResumeThread(thread); srand(time(NULL)); InitializeCriticalSection(§ion);
prev: InitGame();
while( IsQuitGame() ) {
if(restart) { restart = FALSE; goto prev; }
if(gameover) continue; tick = GetTickCount();
for(int i = 0; i < MAX_SHIPS; i++) { if(ships[i].type & SHIP_A) DrawSpaceshipA(&ships[i], tick); else if(ships[i].type & SHIP_B) DrawSpaceshipB(&ships[i], tick);
if(IsCollisionShip(&ships[i].pos)) { if(DrawStatus(FALSE, 1, ships[i].type * 10, 0, 1) < 0) { EndGame(); break; } PostThreadMessage(idsound, WM_COMMAND, SPIK_CRUSH, 0); CrushShip(&ships[i]); } }
if((tick - tmove) > 10uL) { tmove = tick; MoveBullet(); }
Sleep(0uL); }
WaitForMultipleObjects(1uL, &sthread, TRUE, INFINITE); CloseHandle(sthread); CloseHandle(thread); DeleteCriticalSection(§ion);
if(bullets.size() > 0u) bullets.clear();
delete[] ships;
if(sound) { GlobalUnlock(sound); #ifdef _WIN32 FreeResource(sound); #endif sound = NULL; } return ERROR_SUCCESS; } BOOL ParemtersConsole(const WCHAR* caption) {
CONSOLE_SCREEN_BUFFER_INFO sinfo; CONSOLE_CURSOR_INFO cinfo;
if((hin = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE || (hout = GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) return FALSE;
ZeroMemory(&sinfo, sizeof(CONSOLE_SCREEN_BUFFER_INFO)); GetConsoleScreenBufferInfo(hout, &sinfo);
sinfo.dwSize.Y /= 7; SetConsoleScreenBufferSize(hout, sinfo.dwSize);
sinfo.srWindow.Bottom = sinfo.dwSize.Y - 1; SetConsoleWindowInfo(hout, TRUE, &sinfo.srWindow); CopyMemory(&screen, &sinfo, sizeof(COORD));
SetConsoleTitleW(caption); SetConsoleMode(hin, ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT);
ZeroMemory(&cinfo, sizeof(CONSOLE_CURSOR_INFO)); GetConsoleCursorInfo(hout, &cinfo); cinfo.bVisible = FALSE; SetConsoleCursorInfo(hout, &cinfo); return TRUE; }
DWORD WINAPI ThreadInputDevice(LPVOID param) { INPUT_RECORD records[128] = {0}; DWORD size = sizeof(records) / sizeof(INPUT_RECORD); DWORD dread = 0u; COORD pos;
while(TRUE) { if(! ReadConsoleInput(hin, records, size, &dread)) break; for(DWORD i = 0u; i < dread; i++) { switch(records[i].EventType) { case MOUSE_EVENT: if(gameover) continue;
pos = records[i].Event.MouseEvent.dwMousePosition; if((records[i].Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED) && (records[i].Event.MouseEvent.dwEventFlags == 0)) { if(TryEnterCriticalSection(§ion)) { pos.X = upos.X + 3 + SHORT(rand() % 2); pos.Y = upos.Y; bullets.push_back(pos); LeaveCriticalSection(§ion); PostThreadMessage(idsound, WM_COMMAND, SPIK_FIRE, 0); }
} else { pos.X -= 4; pos.Y -= 3; if((pos.X > BORDER_HORZ) && (pos.X <= (screen.X - BORDER_HORZ*2 + 1))) { utmp = upos; upos = pos; DrawUser(); } } break; case KEY_EVENT: if(records[i].Event.KeyEvent.bKeyDown) { switch(records[i].Event.KeyEvent.wVirtualKeyCode) { case VK_RETURN: / restart = TRUE; break; case VK_ESCAPE: / PostThreadMessage(idsound, WM_CLOSE, 0, 0); return 1uL; } } break; } } Sleep(0uL); } return 0uL; }
DWORD WINAPI ThreadSpikerSound(LPVOID param) { MSG msg;
ZeroMemory(&msg, sizeof(MSG)); while(TRUE) {
if(PeekMessage(&msg, NULL, 0u, 0u, PM_REMOVE)) { switch(msg.message) { / case WM_COMMAND: switch(msg.wParam) { case SPIK_FIRE: Beep(7800uL, 20uL); break; case SPIK_CRUSH: Beep(97uL, 200uL); break; case SPIK_CRUSH2: Beep(234uL, 200uL); break; } break; case WM_CLOSE: ExitThread(0uL); break; } } Sleep(0uL); } return 0uL; }
void InitGame(void) { DWORD dwrite = 0uL; COORD pos = { 0, 0 }; gameover = FALSE; speed[0] = 45uL; speed[1] = 55uL; upos.X = screen.X / 2 - 4; upos.Y = screen.Y - 10; FillMemory(&utmp, 0, sizeof(COORD));
if(ships == NULL) { ships = new Ship[MAX_SHIPS]; HRSRC res = FindResourceW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDR_SBACKGROUND), L"WAVE"); if(res != NULL) { if((sound = LoadResource(GetModuleHandle(NULL), res)) != NULL) sndPlaySound((LPCTSTR)GlobalLock(sound), SND_MEMORY | SND_ASYNC | SND_LOOP); } }
for(int i = 0; i < MAX_SHIPS; i++) { ships[i].cnt = 0; ships[i].mtime = 0uL; ships[i].type = 1 + rand() % 2; ships[i].pos.X = BORDER_HORZ + (rand() % (screen.X - BORDER_HORZ*2 - 5)); ships[i].pos.Y = -5 * SHORT(i); ships[i].life = (ships[i].type & SHIP_A) ? 0 : 1; }
if(bullets.size() > 0u) bullets.clear();
CleanConsole();
for(SHORT r = 0; r < screen.Y; r++, pos.Y++) { pos.X = 0; FillConsoleOutputCharacterA(hout, ' ', BORDER_HORZ, pos, &dwrite); FillConsoleOutputAttribute(hout, 18, BORDER_HORZ, pos, &dwrite);
pos.X = screen.X - BORDER_HORZ; FillConsoleOutputCharacterA(hout, ' ', BORDER_HORZ, pos, &dwrite); FillConsoleOutputAttribute(hout, 22, BORDER_HORZ, pos, &dwrite); }
OutputText("Заново", 2, screen.Y - 6); OutputText(" Enter", 2, screen.Y - 5, 0, 5); OutputText("Выход", 2, screen.Y - 3); OutputText(" Esc ", 2, screen.Y - 2, 0, 5);
pos.X = screen.X - BORDER_HORZ + 1;
OutputText("Очки", pos.X, 1); OutputText("Сбито", pos.X, 7); OutputText("Пропуск", pos.X, 14); OutputText("Жизни", pos.X, 21); DrawStatus(TRUE, 0, 0, 0, 0); DrawUser(); }
void BeginGame(void) {
const CHAR* str[4] = { };
BOOL fullscreen = FALSE; DWORD dwrite = 0uL; COORD pos = { 0, 0 }; int r; CleanConsole(-6, 46);
for(pos.X = screen.X / 2 - screen.X / 4, pos.Y = 5, r = 0; r < 5; r++, pos.Y++) { FillConsoleOutputCharacterA(hout, ' ', DWORD(screen.X / 2), pos, &dwrite); FillConsoleOutputAttribute(hout, 27, DWORD(screen.X / 2), pos, &dwrite); } OutputText(str[0], screen.X / 2 - SHORT(lstrlenA(str[0]) / 2), 7, 0, 0); for(pos.X = screen.X / 2 - screen.X / 3, pos.Y = 14, r = 0; r < 9; r++, pos.Y++) { FillConsoleOutputCharacterA(hout, ' ', DWORD(screen.X / 2 + screen.X / 7), pos, &dwrite); FillConsoleOutputAttribute(hout, 90, DWORD(screen.X / 2 + screen.X / 7), pos, &dwrite); } OutputText(str[1], screen.X / 2 - SHORT(lstrlenA(str[1]) / 2), 17, 0, 0); OutputText(str[2], screen.X / 2 - SHORT(lstrlenA(str[2]) / 2), 19, 0, 0);
CHAR* ptr = SaveStatus(0, 0, 0); if(ptr) { r = (int)lstrlenA(ptr); OutputText(" screen.X / 2 - SHORT(r / 2 + r % 2), 26, SHORT(r + r % 2), 248); OutputText(ptr, screen.X / 2 - SHORT(r / 2 + r % 2), 27, SHORT(r + r % 2), 249); } OutputText(str[3], screen.X / 2 - SHORT(lstrlenA(str[3]) / 2), 35, SHORT(lstrlenA(str[3])), 47); OutputText(, 1, screen.Y - 2, 0, 0);
for(dwrite = 0uL, r = 0; TRUE; ++r %= 50) {
if(GetKeyState(VK_RETURN) & 0x80) break; else if(GetKeyState(VK_SPACE) & 0x80) { fullscreen = TRUE; break; }
if(r == 25) OutputText(str[0], screen.X / 2 - SHORT(lstrlenA(str[0]) / 2), 7, SHORT(lstrlenA(str[0])), (++dwrite & 1uL) ? 62 : 27);
Sleep(5uL); }
if(fullscreen) { keybd_event(VK_MENU, 0x38, 0uL, 0uL); keybd_event(VK_RETURN, 0x1C, 0uL, 0uL); keybd_event(VK_RETURN, 0x1C, KEYEVENTF_KEYUP, 0uL); keybd_event(VK_MENU, 0x38, KEYEVENTF_KEYUP, 0uL); } else MessageBeep(MB_ICONINFORMATION); }
void EndGame(void) { DWORD dwrite = 0uL; COORD pos = { 0, 0 }; const CHAR* str = ; SHORT len = (SHORT)lstrlenA(str);
gameover = TRUE; Sleep(100uL); CleanConsole(-70, 189);
pos.X = screen.X / 2 - screen.X / 4; pos.Y = screen.Y / 2 - 5; for(int r = 0; r < 5; r++, pos.Y++) { FillConsoleOutputCharacterA(hout, ' ', DWORD(screen.X / 2), pos, &dwrite); FillConsoleOutputAttribute(hout, 233, DWORD(screen.X / 2), pos, &dwrite); } OutputText(str, screen.X / 2 - len / 2, screen.Y / 2 - 3, 0, 0); MessageBeep(MB_ICONEXCLAMATION); }
/ int DrawStatus(BOOL reset, int plife, int pbonus, int pmimo, int pkill) { static int bonus = 0; static int life = 0; static int mimo = 0; static int kill = 0;
DWORD dwrite = 0uL; CHAR buf[16]; COORD pos;
if(reset) { bonus = 0; life = 17; mimo = 0; kill = 0; }
bonus += pbonus; life -= plife; mimo += pmimo; kill += pkill;
pos.X = screen.X - BORDER_HORZ + 1; wsprintfA(buf, "%d", bonus); OutputText(buf, pos.X, 2, 8, 7);
wsprintfA(buf, "%d", kill); OutputText(buf, pos.X, 8, 8, 4);
wsprintfA(buf, "%d", mimo); OutputText(buf, pos.X, 15, 8, 2);
wsprintfA(buf, "%d", life); OutputText(buf, pos.X, 22, 8, 12);
if(pkill > 0uL) { if(speed[0] > 5uL) --speed[0]; if(speed[1] > 10uL) --speed[1]; }
if(life < 0) SaveStatus(bonus, kill, mimo);
return life; }
void OutputText(const CHAR* str, SHORT x, SHORT y, SHORT width, WORD color) { DWORD dwrite = 0uL; SHORT len = (SHORT)lstrlenA(str); COORD pos = { x, y }; CHAR buf[128]; CharToOemA(str, buf); if(width > 0) { FillConsoleOutputCharacterA(hout, ' ', DWORD(width), pos, &dwrite); x = pos.X; pos.X += width / 2 - SHORT(len / 2) - len % 2; } WriteConsoleOutputCharacterA(hout, buf, DWORD(len), pos, &dwrite); if(color > 0) { pos.X = x; FillConsoleOutputAttribute(hout, color, DWORD(width), pos, &dwrite); } }
BOOL IsQuitGame(void) { DWORD res = 0uL; if(GetExitCodeThread(thread, &res)) { if(res == 1uL) return FALSE; } return TRUE; }
void DrawBullet(PCOORD pos, BOOL redraw) { DWORD dwrite = 0uL; if(redraw) FillConsoleOutputCharacterA(hout, ' ', 1uL, *pos, &dwrite); else { FillConsoleOutputAttribute(hout, 12, 1uL, *pos, &dwrite); FillConsoleOutputCharacterA(hout, -3, 1uL, *pos, &dwrite); } }
void MoveBullet(void) { for(std::list<COORD>::iterator iter = bullets.begin(); iter != bullets.end(); ++iter) { DrawBullet(&(*iter), TRUE); iter->Y--; CollisionBullet(&(*iter)); DrawBullet(&(*iter), FALSE);
if(iter->Y <= 0) { DrawBullet(&(*iter), TRUE); EnterCriticalSection(§ion); bullets.erase(iter); LeaveCriticalSection(§ion); break; } } }
void GeneratePosition(PShip ship) { if((rand() % 2)) ship->pos.X = BORDER_HORZ + (rand() % (screen.X - BORDER_HORZ*2 - 5)); else ship->pos.X = upos.X;
ship->pos.Y = -5; for(PShip p = ships; p != ships + MAX_SHIPS; ++p) { if(p == ship) continue; if((p->pos.Y + ship->pos.Y) <= 6) ship->pos.Y -= 7; } ship->life = (ship->type & SHIP_A) ? 0 : 1; }
void CrushShip(PShip ship) { DWORD dwrite = 0uL; COORD pos = ship->pos; for(int r = 0; r < 4; r++, pos.Y++) FillConsoleOutputCharacterA(hout, ' ', 6uL, pos, &dwrite);
ship->type ^= SHIP_A + SHIP_B;
GeneratePosition(ship); }
bool IsCollisionShip(PCOORD pos) { SHORT x = pos->X - upos.X; SHORT y = pos->Y - upos.Y; if((x <= 6 && x >= -6) && (y <= 3 && y >= -3)) return true; return false; }
void CollisionBullet(PCOORD pos) { SHORT x, y; for(PShip p = ships; p != ships + MAX_SHIPS; *p++) { x = pos->X - p->pos.X; y = pos->Y - p->pos.Y; if((x < 6 && x > -2) && (y <= 3 && y >= -3)) { pos->Y = -5; if(--p->life < 0) { PostThreadMessage(idsound, WM_COMMAND, SPIK_CRUSH2, 0); DrawStatus(FALSE, 0, p->type * 10, 0, 1); CrushShip(p); return; } p->pos.Y -= 1; } } }
void DrawSpaceshipA(PShip pship, DWORD tick) {
const CHAR ship[3][6] = { { ' ', -55, -51, -51, -69, ' ' }, { 17, -37, -79, -79, -37, 16 }, { ' ', -41, -37, -37, -41, ' ' } };
const WORD color[3][6] = { { 0, 11, 11, 11, 11, 0 }, { 2, 2, 12, 12, 2, 2 }, { 0, 11, 2, 2, 11, 0 } };
WORD colors[2]; DWORD dwrite = 0uL; COORD pt = pship->pos; CHAR head[] = { 31, 31 }; int r;
if((tick - pship->mtime) > speed[0]) pship->mtime = tick; else return;
for(r = 0; r < 3; r++, pt.Y++) FillConsoleOutputCharacterA(hout, ' ', 6uL, pt, &dwrite);
if(++pship->pos.Y >= screen.Y) { DrawStatus(FALSE, 0, 0, 1, 0); GeneratePosition(pship); }
for(pt = pship->pos, r = 0; r < 3; r++, pt.Y++) { WriteConsoleOutputCharacterA(hout, ship[r], 6uL, pt, &dwrite); WriteConsoleOutputAttribute(hout, color[r], 6uL, pt, &dwrite); }
if(pship->cnt < 5) { colors[0] = 4; colors[1] = 12; } else { colors[0] = 12; colors[1] = 4; } ++pship->cnt %= 10;
pt.X = pship->pos.X + 2; pt.Y = pship->pos.Y + 3; WriteConsoleOutputCharacterA(hout, head, 2uL, pt, &dwrite); WriteConsoleOutputAttribute(hout, colors, 2uL, pt, &dwrite); }
void DrawSpaceshipB(PShip pship, DWORD tick) {
const CHAR ship[4][6] = { // { -36, 30, ' ', ' ', 30, -36 }, { -37, -37, -37, -37, -37, -37 }, { -58, -37, -78, -78, -37, -75 }, { ' ', -11, -34, -35, -11, ' ' } };
const WORD color[4][6] = { // { 6, 14, 0, 0, 14, 6 }, { 6, 6, 14, 14, 6, 6 }, { 15, 14, 13, 13, 14, 15 }, { 0, 10, 6, 6, 10, 0 } };
DWORD dwrite = 0uL; COORD pt = pship->pos; int r;
if((tick - pship->mtime) > speed[1]) pship->mtime = tick; else return;
for(r = 0; r < 4; r++, pt.Y++) / FillConsoleOutputCharacterA(hout, ' ', 6uL, pt, &dwrite);
if(++pship->pos.Y >= screen.Y) { DrawStatus(FALSE, 0, 0, 1, 0); GeneratePosition(pship); }
for(pt = pship->pos, r = 0; r < 4; r++, pt.Y++) { WriteConsoleOutputCharacterA(hout, ship[r], 6uL, pt, &dwrite); WriteConsoleOutputAttribute(hout, color[r], 6uL, pt, &dwrite); }
if(pship->cnt < 5) { pt.X = pship->pos.X; pt.Y = pship->pos.Y + 2; FillConsoleOutputAttribute(hout, 11, 1uL, pt, &dwrite); pt.X = pship->pos.X + 5; FillConsoleOutputAttribute(hout, 11, 1uL, pt, &dwrite); } ++pship->cnt %= 10; }
void DrawUser(void) {
const CHAR ship[6][8] = { { -55, 4, ' ', -47, -47, ' ', 4, -69 }, { -70, ' ', -46, -37, -37, -46, ' ', -70 }, { -37, -75, -37, -37, -37, -37, -58, -37 }, { -70, -77, -37, -80, -80, -37, -77, -70 }, { -70, -37, -37, -37, -37, -37, -37, -70 }, { -56, -54, -75, -63, -63, -58, -54, -68 } };
const WORD color[6][8] = { // { 11, 12, 0, 14, 14, 0, 12, 11 }, { 11, 0, 15, 8, 8, 15, 0, 11 }, { 9, 14, 7, 7, 7, 7, 14, 9 }, { 11, 14, 15, 13, 13, 15, 14, 11 }, { 11, 9, 15, 15, 15, 15, 9, 11 }, { 11, 11, 11, 14, 14, 11, 11, 11 } };
DWORD dwrite = 0uL; COORD pt = upos; int r;
for(pt = utmp, r = 0; r < 6; r++, pt.Y++) FillConsoleOutputCharacterA(hout, ' ', 8uL, pt, &dwrite);
for(pt = upos, r = 0; r < 6; r++, pt.Y++) { WriteConsoleOutputCharacterA(hout, ship[r], 8uL, pt, &dwrite); WriteConsoleOutputAttribute(hout, color[r], 8uL, pt, &dwrite); } }
void CleanConsole(CHAR ch, WORD color) { DWORD dwrite = 0uL; COORD pos = { 0, 0 }; for(int r = 0; r < screen.Y; r++, pos.Y++) { FillConsoleOutputCharacterA(hout, ch, DWORD(screen.X), pos, &dwrite); FillConsoleOutputAttribute(hout, color, DWORD(screen.X), pos, &dwrite); } }
CHAR* SaveStatus(int pbonus, int pkill, int pmimo) { static CHAR buf[64]; static int bonus = 0; static int kill = 0; static int mimo = 0;
if(! pbonus) {
if(GetProfileSectionA("OneSpace", buf, sizeof(buf) - 1u) != 0u) { int k = 0, i = 0, n = 0; for(const CHAR* p = buf; *p; p += n, ++k) { if(sscanf(p, "%*[^0123456789]%d%n", &i, &n) != 1) break; switch(k) { case 0: bonus = i; break; case 1: kill = i; break; case 2: mimo = i; break; } } return buf; }
return NULL; }
if(pbonus > bonus) { bonus = pbonus; kill = pkill; mimo = pmimo; wsprintfA(buf, "Очки: %d Сбито: %d Пропущено: %d", bonus, kill, mimo); WriteProfileSectionA("OneSpace", buf); return buf; } return buf; }
|
|
|