-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutilities.cpp
55 lines (46 loc) · 1.35 KB
/
utilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "Game.h"
#include "Arena.h"
#include "Player.h"
#include "Robot.h"
#include "globals.h"
#include "History.h"
#include <iostream>
#include <cstdlib>
using namespace std;
int decodeDirection(char dir)
{
switch (dir)
{
case 'u': return UP;
case 'd': return DOWN;
case 'l': return LEFT;
case 'r': return RIGHT;
}
return -1; // bad argument passed in!
}
#ifdef _MSC_VER // Microsoft Visual C++
#include <windows.h>
void clearScreen()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
COORD upperLeft = { 0, 0 };
DWORD dwCharsWritten;
FillConsoleOutputCharacter(hConsole, TCHAR(' '), dwConSize, upperLeft,
&dwCharsWritten);
SetConsoleCursorPosition(hConsole, upperLeft);
}
#else // not Microsoft Visual C++, so assume UNIX interface
#include <cstring>
void clearScreen()
{
static const char* term = getenv("TERM");
static const char* ESC_SEQ = "\x1B["; // ANSI Terminal esc seq: ESC [
if (term == NULL || strcmp(term, "dumb") == 0)
cout << endl;
else
cout << ESC_SEQ << "2J" << ESC_SEQ << "H" << flush;
}
#endif