-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPad.cpp
More file actions
82 lines (73 loc) · 1.69 KB
/
Pad.cpp
File metadata and controls
82 lines (73 loc) · 1.69 KB
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
75
76
77
78
79
80
81
82
// Copyright Milan Oberkirch
// <oberkirm@tf.uni-freiburg.de>
#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#include "./Pong.h"
// ____________________________________________________________________________
Pad::Pad()
{
_xMax = _yMax = 0;
_counterLeft = _counterRight = 0;
}
// ____________________________________________________________________________
Pad::~Pad()
{
endwin();
}
// ____________________________________________________________________________
void Pad::Init()
{
// Initiate screen, see "man 3 ncurses" for more details
initscr();
cbreak();
noecho();
nonl();
nodelay(stdscr, true);
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
curs_set(false);
// Set all maximum values
getmaxyx(stdscr, _yMax, _xMax);
// All borders are inclusive
_xMax--;
_yMax--;
_xMaxPlay = _xMax;
_yMaxPlay = _yMax - 1;
_xMinPlay = 0;
_yMinPlay = 2;
_xMid = ((_xMaxPlay - _xMinPlay) / 2) + _xMinPlay;
_yMid = ((_yMaxPlay - _yMinPlay) / 2) + _yMinPlay;
// Initialice counter
_counterLeft = _counterRight = 0;
}
// ____________________________________________________________________________
void Pad::CountUp(bool left)
{
left?_counterLeft++:_counterRight++;
Draw();
}
// ____________________________________________________________________________
void Pad::Draw()
{
mvprintw(0, (_xMax / 2) - 5,
"%.3d | %.3d",
_counterLeft, _counterRight);
move(_yMinPlay - 1, 0);
for (int i = 0; i <= _xMax; ++i)
{
printw("_");
}
move(_yMax, 0);
for (int i = 0; i <= _xMax; ++i)
{
printw("_");
}
}
// ____________________________________________________________________________
void Pad::Clear()
{
refresh();
clear();
move(0, 0);
}