Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- using namespace System;
- using namespace std;
- struct posc
- {
- int x;
- int y;
- int delx;
- int dely;
- };
- void genera_muestra_matriz(int m1[20][23])
- {
- int xx, yy;
- Console::BackgroundColor = ConsoleColor::Black;
- for (int f = 0; f < 20; f++)
- {
- Console::SetCursorPosition(xx, yy);
- for(int c = 0; c < 23; c++)
- {
- switch (m1[f][c])
- {
- case 0:
- Console::ForegroundColor = ConsoleColor::DarkRed;
- cout << char(177);break;
- case 1:
- Console::ForegroundColor = ConsoleColor::Gray;
- cout << char(219);break;
- }
- }
- yy++;
- }
- }
- void Dez_Player_Enem(int m1[20][23])
- {
- int tecla;
- posc * obj = new posc[2];
- obj[0].x = 19;
- obj[0].y = 4;
- obj[0].dely = 1;
- obj[1].x = 10;
- obj[1].y = 8;
- Console::BackgroundColor = ConsoleColor::Gray;
- Console::SetCursorPosition(obj[0].x, obj[0].y);
- cout << char(1);
- Console::SetCursorPosition(obj[1].x, obj[1].y);
- Console::BackgroundColor = ConsoleColor::Gray;
- cout << "*";
- while (1)
- {
- _sleep(50);
- if (kbhit)
- {
- tecla = _getch();
- if (tecla == 224)
- {
- tecla = _getch();
- Console::SetCursorPosition(obj[1].x, obj[1].y);
- cout << " ";
- switch (tecla)
- {
- case 72: obj[1].y--;if (m1[obj[1].y][obj[1].x]==0)obj[1].x=10; obj[1].y=8;break;
- case 75: obj[1].x--;if (m1[obj[1].y][obj[1].x]==0)obj[1].x=10; obj[1].y=8;break;
- case 77: obj[1].x++;if (m1[obj[1].y][obj[1].x]==0)obj[1].x=10; obj[1].y=8;break;
- case 80: obj[1].y++;if (m1[obj[1].y][obj[1].x]==0)obj[1].x=10; obj[1].y=8;break;
- }
- Console::SetCursorPosition(obj[1].x, obj[1].y);
- Console::BackgroundColor = ConsoleColor::Gray;
- cout << "*";
- }
- }
- Console::SetCursorPosition(obj[0].x, obj[0].y);
- cout << " ";
- if (obj[0].y == 3)
- obj[0].dely = 1;
- if (obj[0].y == 8)
- obj[0].dely = -1;
- obj[0].y = obj[0].y + obj[0].dely;
- Console::SetCursorPosition(obj[0].x, obj[0].y);
- cout << char(1);
- }
- }
- int main()
- {
- int Mapa1[20][23]=
- {
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
- };
- genera_muestra_matriz(Mapa1);
- Dez_Player_Enem(Mapa1);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment