-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserInterface.h
74 lines (61 loc) · 1.81 KB
/
UserInterface.h
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef USERINTERFACE_INCLUDED
#define USERINTERFACE_INCLUDED
#include <string>
const char ARROW_UP = '8';
const char ARROW_DOWN = '2';
const char ARROW_LEFT = '4';
const char ARROW_RIGHT = '6';
///////////////////////////////////////////////////////////
// Screen -- Visual Output
///////////////////////////////////////////////////////////
class ScreenImpl;
class Screen
{
public:
Screen(int width, int height);
~Screen();
void clear();
void gotoXY(int x, int y);
void printChar(char ch);
void printString(std::string s);
void printStringClearLine(std::string s);
void refresh();
private:
ScreenImpl* m_impl;
};
///////////////////////////////////////////////////////////
// Functions for Keyboard Input
///////////////////////////////////////////////////////////
bool getCharIfAny(char& ch);
void waitForEnter();
void discardPendingKeys();
///////////////////////////////////////////////////////////
// Class for Timing
///////////////////////////////////////////////////////////
//========================================================================
// Timer t; // create and start a timer
// t.start(); // restart the timer
// double d = t.elapsed(); // milliseconds since timer was last started
//========================================================================
#include <chrono>
class Timer
{
public:
Timer()
{
start();
}
void start()
{
m_time = std::chrono::high_resolution_clock::now();
}
double elapsed() const
{
std::chrono::duration<double,std::milli> diff =
std::chrono::high_resolution_clock::now() - m_time;
return diff.count();
}
private:
std::chrono::high_resolution_clock::time_point m_time;
};
#endif // USERINTERFACE_INCLUDED