Advertisement
KDOXG

Graphics

Oct 21st, 2019 (edited)
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.02 KB | None | 0 0
  1. // Graphics.cpp : Este arquivo contém a função 'main'. A execução do programa começa e termina ali.
  2. //
  3.  
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <Windows.h>
  7. #include <conio.h>
  8. #define PLAY_SIZE 20
  9.  
  10. struct control {
  11.     unsigned x;
  12.     unsigned y;
  13.     COLORREF color;
  14.     int move;
  15.     /*
  16.     control(unsigned x, unsigned y, COLORREF color, int action)
  17.     {
  18.         this->x = x;
  19.         this->y = y;
  20.         this->color = color;
  21.         move = action;
  22.     }
  23.     */
  24. };
  25.  
  26. void createSquare(COLORREF point, unsigned length, int start_x, int start_y);
  27. void playGame(COLORREF point, unsigned length, int start_x, int start_y);
  28.  
  29. int main()
  30. {
  31.     COLORREF White = RGB(255, 255, 255);
  32.     //createSquare(White, 512, 20, 20);
  33.     playGame(White, 512, 20, 20);
  34.     system("pause");
  35.     return 0;
  36. }
  37.  
  38. void createSquare(COLORREF point, unsigned length, int start_x, int start_y)
  39. {
  40.     HDC hdc = GetDC(NULL);
  41.     for (unsigned i = 0; i < length; i++)
  42.         for (unsigned j = 0; j < length; j++)
  43.             SetPixel(hdc,start_x + i, start_y + j, point);
  44.     ReleaseDC(NULL, hdc);
  45. }
  46.  
  47. void playGame(COLORREF point, unsigned length, int start_x, int start_y)
  48. {
  49.     control c;
  50.     c.x = start_x;
  51.     c.y = start_y;
  52.     c.color = RGB(0, 0, 0);
  53.     c.move = 0;
  54.     HDC hdc = GetDC(NULL);
  55.     for (unsigned i = 0; i < length; i++)
  56.         for (unsigned j = 0; j < length; j++)
  57.             SetPixel(hdc, start_x + i, start_y + j, point);
  58.     for (unsigned i = 0; i < PLAY_SIZE; i++)
  59.         for (unsigned j = 0; j < PLAY_SIZE; j++)
  60.             SetPixel(hdc, c.x + i, c.y + j, c.color);
  61.     do {
  62.         if ((c.move = _getch()) == '\n')
  63.             break;
  64.         switch (c.move)
  65.         {
  66.         case 'w':
  67.             if (c.y != PLAY_SIZE)
  68.             {
  69.                 for (unsigned j = PLAY_SIZE - 1 - 8; j < PLAY_SIZE - 1; j++)
  70.                 for (unsigned i = 0; i < PLAY_SIZE; i++)
  71.                     SetPixel(hdc, c.x + i, c.y + j, point);
  72.                 c.y -= 8;
  73.                 for (unsigned j = 0; j < 8; j++)
  74.                 for (unsigned i = 0; i < PLAY_SIZE; i++)
  75.                     SetPixel(hdc, c.x + i, c.y + j, c.color);
  76.             }
  77.             break;
  78.         case 'a':
  79.             if (c.x != PLAY_SIZE)
  80.             {
  81.                 for (unsigned i = PLAY_SIZE - 1 - 8; i < PLAY_SIZE - 1; i++)
  82.                 for (unsigned j = 0; j < PLAY_SIZE; j++)
  83.                     SetPixel(hdc, c.x + i, c.y + j, point);
  84.                 c.x -= 8;
  85.                 for (unsigned i = 0; i < 8; i++)
  86.                 for (unsigned j = 0; j < PLAY_SIZE; j++)
  87.                     SetPixel(hdc, c.x + i, c.y + j, c.color);
  88.             }
  89.             break;
  90.         case 's':
  91.             if (c.y != 500)
  92.             {
  93.                 for (unsigned j = 0; j < 8; j++)
  94.                 for (unsigned i = 0; i < PLAY_SIZE; i++)
  95.                     SetPixel(hdc, c.x + i, c.y + j, point);
  96.                 c.y += 8;
  97.                 for (unsigned j = PLAY_SIZE - 1 - 8; j < PLAY_SIZE - 1; j++)
  98.                 for (unsigned i = 0; i < PLAY_SIZE; i++)
  99.                     SetPixel(hdc, c.x + i, c.y + j, c.color);
  100.             }
  101.             break;
  102.         case 'd':
  103.             if (c.x != 500)
  104.             {
  105.                 for (unsigned i = 0; i < 8; i++)
  106.                 for (unsigned j = 0; j < PLAY_SIZE; j++)
  107.                     SetPixel(hdc, c.x + i, c.y + j, point);
  108.                 c.x += 8;
  109.                 for (unsigned i = PLAY_SIZE - 1 - 8; i < PLAY_SIZE - 1; i++)
  110.                 for (unsigned j = 0; j < PLAY_SIZE; j++)
  111.                     SetPixel(hdc, c.x + i, c.y + j, c.color);
  112.             }
  113.             break;
  114.         default:
  115.             break;
  116.         }
  117.     } while (1);
  118.     ReleaseDC(NULL, hdc);
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement