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
|
#include <stdlib.h>
#include <curses.h>
#include "game.h"
#include "player.h"
static void draw_paddles(struct game *g);
struct game *
new_game(void)
{
struct game *g;
g = malloc(sizeof(*g));
if (g == NULL) {
return NULL;
}
g->players[0] = new_player();
g->players[1] = new_player();
return g;
}
void
free_game(struct game *g)
{
free_player(g->players[0]);
free_player(g->players[1]);
free(g);
}
void
draw_game(struct game *g)
{
draw_paddles(g);
}
static void
draw_paddles(struct game *g)
{
int off;
int pos;
/* Player 1 horizontal paddle */
off = g->players[0]->paddle_h.pos;
off -= g->players[0]->paddle_h.size / 2;
for (pos = 0; pos < g->players[0]->paddle_h.size; ++pos) {
attr_on(WA_REVERSE, NULL);
mvprintw(23, off + pos, " ");
attr_off(WA_REVERSE, NULL);
}
/* Player 1 vertical paddle */
off = g->players[0]->paddle_v.pos;
off -= g->players[0]->paddle_v.size / 2;
for (pos = 0; pos < g->players[0]->paddle_v.size; ++pos) {
attr_on(WA_REVERSE, NULL);
mvprintw(off + pos, 1, " ");
attr_off(WA_REVERSE, NULL);
}
/* Player 2 horizontal paddle */
off = g->players[1]->paddle_h.pos;
off -= g->players[1]->paddle_h.size / 2;
for (pos = 0; pos < g->players[1]->paddle_h.size; ++pos) {
attr_on(WA_REVERSE, NULL);
mvprintw(1, off + pos, " ");
attr_off(WA_REVERSE, NULL);
}
/* Player 2 vertical paddle */
off = g->players[1]->paddle_v.pos;
off -= g->players[1]->paddle_v.size / 2;
for (pos = 0; pos < g->players[1]->paddle_v.size; ++pos) {
attr_on(WA_REVERSE, NULL);
mvprintw(off + pos, 78, " ");
attr_off(WA_REVERSE, NULL);
}
}
|