-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.c
83 lines (76 loc) · 1.64 KB
/
display.c
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
83
/*
** display.c for tetris in /home/thibrex/Dropbox/delivery/PSU/PSU_2016_tetris
**
** Made by Thibaut Cornolti
** Login <[email protected]>
**
** Started on Tue Feb 28 17:12:32 2017 Thibaut Cornolti
** Last update Fri Mar 17 18:01:43 2017 Thibaut Cornolti
*/
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <fcntl.h>
#include "tetris.h"
static void init_pair_color()
{
init_pair(8, 1, 1);
init_pair(9, 2, 2);
init_pair(10, 3, 3);
init_pair(11, 4, 4);
init_pair(12, 5, 5);
init_pair(13, 6, 6);
init_pair(14, 7, 7);
}
static void draw_shape(t_pos *pos)
{
int i;
int j;
i = -1;
attron(COLOR_PAIR(pos->color % 7 + 8));
while (pos->map[++i])
{
j = -1;
while (pos->map[i][++j])
if (pos->map[i][j] != -1)
mvprintw(16 + pos->y + i, 33 + pos->x + j, "*");
}
attroff(COLOR_PAIR(pos->color % 7 + 8));
}
static void draw_board(t_pos *pos, t_pars *p, char **board)
{
int i;
int j;
init_pair_color();
create_box(15, 32, p->row + 2, p->col + 2);
i = -1;
while (board[++i])
{
j = -1;
while (board[i][++j])
{
attron(COLOR_PAIR(board[i][j] % 7 + 8));
mvprintw(16 + i, 33 + j,
(board[i][j] == -1) ? " " : "*");
attroff(COLOR_PAIR(board[i][j] % 8));
}
}
draw_shape(pos);
}
int display(char **board, t_pos *pos, t_game *g, t_pars *p)
{
clear();
if (COLS > 78 && LINES > 25 &&
LINES - 16 > p->row &&
COLS - 32 > p->col)
{
draw_stats(g);
draw_title(pos, p);
draw_board(pos, p, board);
draw_next(NULL, p);
}
else
mvprintw(LINES / 2, COLS / 2 - 10, "ENLARGE THE TERMINAL");
refresh();
return (0);
}