Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Graphics.cpp : Este arquivo contém a função 'main'. A execução do programa começa e termina ali.
- //
- #include <iostream>
- #include <cstdlib>
- #include <Windows.h>
- #include <conio.h>
- #define PLAY_SIZE 20
- struct control {
- unsigned x;
- unsigned y;
- COLORREF color;
- int move;
- /*
- control(unsigned x, unsigned y, COLORREF color, int action)
- {
- this->x = x;
- this->y = y;
- this->color = color;
- move = action;
- }
- */
- };
- void createSquare(COLORREF point, unsigned length, int start_x, int start_y);
- void playGame(COLORREF point, unsigned length, int start_x, int start_y);
- int main()
- {
- COLORREF White = RGB(255, 255, 255);
- //createSquare(White, 512, 20, 20);
- playGame(White, 512, 20, 20);
- system("pause");
- return 0;
- }
- void createSquare(COLORREF point, unsigned length, int start_x, int start_y)
- {
- HDC hdc = GetDC(NULL);
- for (unsigned i = 0; i < length; i++)
- for (unsigned j = 0; j < length; j++)
- SetPixel(hdc,start_x + i, start_y + j, point);
- ReleaseDC(NULL, hdc);
- }
- void playGame(COLORREF point, unsigned length, int start_x, int start_y)
- {
- control c;
- c.x = start_x;
- c.y = start_y;
- c.color = RGB(0, 0, 0);
- c.move = 0;
- HDC hdc = GetDC(NULL);
- for (unsigned i = 0; i < length; i++)
- for (unsigned j = 0; j < length; j++)
- SetPixel(hdc, start_x + i, start_y + j, point);
- for (unsigned i = 0; i < PLAY_SIZE; i++)
- for (unsigned j = 0; j < PLAY_SIZE; j++)
- SetPixel(hdc, c.x + i, c.y + j, c.color);
- do {
- if ((c.move = _getch()) == '\n')
- break;
- switch (c.move)
- {
- case 'w':
- if (c.y != PLAY_SIZE)
- {
- for (unsigned j = PLAY_SIZE - 1 - 8; j < PLAY_SIZE - 1; j++)
- for (unsigned i = 0; i < PLAY_SIZE; i++)
- SetPixel(hdc, c.x + i, c.y + j, point);
- c.y -= 8;
- for (unsigned j = 0; j < 8; j++)
- for (unsigned i = 0; i < PLAY_SIZE; i++)
- SetPixel(hdc, c.x + i, c.y + j, c.color);
- }
- break;
- case 'a':
- if (c.x != PLAY_SIZE)
- {
- for (unsigned i = PLAY_SIZE - 1 - 8; i < PLAY_SIZE - 1; i++)
- for (unsigned j = 0; j < PLAY_SIZE; j++)
- SetPixel(hdc, c.x + i, c.y + j, point);
- c.x -= 8;
- for (unsigned i = 0; i < 8; i++)
- for (unsigned j = 0; j < PLAY_SIZE; j++)
- SetPixel(hdc, c.x + i, c.y + j, c.color);
- }
- break;
- case 's':
- if (c.y != 500)
- {
- for (unsigned j = 0; j < 8; j++)
- for (unsigned i = 0; i < PLAY_SIZE; i++)
- SetPixel(hdc, c.x + i, c.y + j, point);
- c.y += 8;
- for (unsigned j = PLAY_SIZE - 1 - 8; j < PLAY_SIZE - 1; j++)
- for (unsigned i = 0; i < PLAY_SIZE; i++)
- SetPixel(hdc, c.x + i, c.y + j, c.color);
- }
- break;
- case 'd':
- if (c.x != 500)
- {
- for (unsigned i = 0; i < 8; i++)
- for (unsigned j = 0; j < PLAY_SIZE; j++)
- SetPixel(hdc, c.x + i, c.y + j, point);
- c.x += 8;
- for (unsigned i = PLAY_SIZE - 1 - 8; i < PLAY_SIZE - 1; i++)
- for (unsigned j = 0; j < PLAY_SIZE; j++)
- SetPixel(hdc, c.x + i, c.y + j, c.color);
- }
- break;
- default:
- break;
- }
- } while (1);
- ReleaseDC(NULL, hdc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement