Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : main project file.
- #include "stdafx.h"
- #include <conio.h>
- #include <iostream>
- using namespace std;
- using namespace System;
- void DibujaTablero(char Matriz[][5])
- {
- Console::ForegroundColor= ConsoleColor::White;
- Console::BackgroundColor = ConsoleColor::Black;
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- cout << Matriz[i][j];
- }cout << endl;
- }
- }
- void Juega(char Matriz[][5])
- {
- int tecla;
- int px, py;
- px = 40; py = 20;
- Console::SetCursorPosition(px, py);
- while (1)
- {
- if (kbhit())
- {
- tecla = _getch();
- if (tecla == 224)
- {
- Console::SetCursorPosition(px, py);
- cout << " ";
- tecla = _getch();
- switch (tecla)
- {
- case 77: if (Matriz[py][px + 1] != 'M')px++; break;
- case 75: if (Matriz[py][px - 1] != 'M')px--; break;
- case 72: if (Matriz[py - 1][px] != 'M')py--; break;
- case 80: if (Matriz[py + 1][px] != 'M')py++; break;
- }
- }Console::SetCursorPosition(px, py);
- cout << "*";
- }
- }
- }
- int main()
- {
- char Matriz[5][5] = { {'M','M','M','M','M'},{'M',' ',' ',' ','M'},{'M',' ',' ',' ','M'},{'M',' ',' ',' ','M'},{'M','M','M',' ','M'} };
- DibujaTablero(Matriz);
- Juega(Matriz);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment