Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- using namespace System;
- #define UP 72
- #define LEFT 75
- #define DOWN 80
- #define RIGHT 77
- void dibuja(int x, int y, ConsoleColor color) {
- Console::ForegroundColor = color;
- Console::SetCursorPosition(x, y);
- cout << (char)1;
- }
- int main() {
- int c, x=5, y=7;
- dibuja(x, y, ConsoleColor::Yellow);
- while (true) {
- if (_kbhit()) {
- c = _getch();
- c = toupper(c);
- switch (c) {
- case 'W':
- case UP:
- y--;
- break;
- case 'S':
- case DOWN:
- y++;
- break;
- case 'A':
- case LEFT:
- x--;
- break;
- case 'D':
- case RIGHT:
- x++;
- break;
- }
- Console::Clear();
- dibuja(x, y, ConsoleColor::Yellow);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement