Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <conio.h>
- #include <windows.h>
- void gotoxy(int x, int y)
- {
- COORD coord;
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- void mapa(int x, int z, int (*map)[z])
- {
- for (int i = 0; i < x; i++)
- for (int y = 0; y < z; y++)
- {
- if ((i == 0) || (y == 0) || (i == x - 1) || (y == z - 1))
- map[i][y] = 219;
- else
- map[i][y] = ' ';
- }
- }
- void printm(int x, int z, int (*map)[z])
- {
- system("cls");
- for (int i = 0; i < x; i++)
- {
- if (i != 0) printf("\n");
- for (int y = 0; y < z; y++)
- printf ("%c", map[i][y]);
- }
- }
- int key_move_logic(int x, int z, int (*map)[z])
- {
- int a = x/2;
- int b = z/2;
- int _42 = 0;
- int key = 0;
- gotoxy(b,a);
- for(;;)
- {
- loop:
- key = getch();
- if (key == 119) //nahoru
- {
- a--;
- _42 = 1;
- }
- else if (key == 115) //dolu
- {
- a++;
- _42 = 2;
- }
- else if (key == 100) //doprava
- {
- b++;
- _42 = 3;
- }
- else if (key == 97) //doleva
- {
- b--;
- _42 = 4;
- }
- else if (key == 27) //konec filmu
- {
- return 0;
- }
- while (!kbhit())
- {
- gotoxy(b,a);
- if (_42 == 1)
- {
- gotoxy(b,a + 1);
- printf(" ");
- gotoxy(b,a - 1);
- a--;
- Sleep(150);
- }
- else if (_42 == 2)
- {
- gotoxy(b,a - 1);
- printf(" ");
- gotoxy(b,a + 1);
- a++;
- Sleep(150);
- }
- else if (_42 == 3)
- {
- gotoxy(b - 1,a);
- printf(" ");
- gotoxy(b + 1,a);
- b++;
- Sleep(200);
- }
- else if (_42 == 4)
- {
- gotoxy(b + 1,a);
- printf(" ");
- gotoxy(b - 1,a);
- b--;
- Sleep(200);
- }
- }
- goto loop;
- }
- }
- int main(void)
- {
- int map [25][50];
- mapa(25, 50, map);
- printm(25, 50, map);
- key_move_logic(25, 50, map);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement