xTetris-Game
Loading...
Searching...
No Matches
printGame.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <wchar.h>
3
4#include "printGame.h"
5#include "common.h"
6#include "definitions.h"
7#include "struct.h"
8
9
11
12 int i;
13
14 for (i=0; i<SPACING; i++)
15 wprintf(L" ");
16}
17
18void printPlayersName(int points_1, int points_2, int mode){
19
20 int i, length, n;
21
22 n = intLen(points_1);
23
24 wprintf(PLAYER_1);
25 wprintf(L": %d", points_1);
26 length = wcslen(PLAYER_1) + wcslen(L": ") + n;
27 for (i=0; i<12*2-length; i++)
28 wprintf(L" ");
30 if (mode == MULTIPLAYER)
31 wprintf(PLAYER_2);
32 else
33 wprintf(BOT);
34 wprintf(L": %d", points_2);
35 wprintf(L"\r\n");
36}
37
38void printBoard(BoardPtr mat_1, BoardPtr mat_2, int points_1, int points_2, int mode){
39
40 int i, j, k;
41
42 clearCLI();
43
44 for (i=0; i<HEIGHT+2; i++){
45 if (i==0 || i==HEIGHT+1){
46 if (i==0)
47 printPlayersName(points_1, points_2, mode);
48 for (k=0; k<2; k++){
49 for (j=0; j<WIDTH+2; j++)
50 wprintf(L"%lc", fSq);
52 }
53 wprintf(L"\r\n");
54 }
55 else{
56 for (j=0; j<WIDTH+2; j++){
57 if (j==0 || j==WIDTH+1){
58 wprintf(L"%lc", fSq);
59 if (j==WIDTH+1)
61 }
62 else if (mat_1[i-1][j-1].status > EMPTY_BOX)
63 wprintf(L"%lc", fSq);
64 else
65 wprintf(L"%lc", eSq);
66 }
67 for (j=0; j<WIDTH+2; j++){
68 if (j==0 || j==WIDTH+1)
69 wprintf(L"%lc", fSq);
70 else if (mat_2[i-1][j-1].status > EMPTY_BOX)
71 wprintf(L"%lc", fSq);
72 else
73 wprintf(L"%lc", eSq);
74 }
75 wprintf(L"\r\n");
76 }
77 }
78}
79
80void gameOver(int points_1, int points_2, int mode){
81
82 clearCLI();
83
84 if(points_1 != points_2){
85
87
88 printCentered(L"WINNER:");
89
90 wprintf(L"\r\n");
91
92 if (points_1>points_2 && mode==SINGLEPLAYER)
94 else if (points_2>points_1 && mode==SINGLEPLAYER)
96 else if (points_1>points_2 && mode==MULTIPLAYER)
98 else if (points_2>points_1 && mode==MULTIPLAYER)
100 }
101 else if(points_1 == points_2){
102 heightSpacing(6);
103 printCentered(L"TIE!!!");
104 }
105
106 wprintf(L"\r\n\r\n");
107
108 printCentered(L"🕹 Press ENTER to continue...");
109
110 waitUser();
111
112}
113
115
116 int i, j, k, l;
117
118 clearCLI();
119
120 for(i=0; i<N_PIECES; i++){
121 wprintf(L"Piece: %d\r\n", i);
122 for(j=0; j<TETRO_ROT; j++){
123 wprintf(L"Rotation: %d\r\n", j);
124 for(k=0; k<TETRO_DIM; k++){
125 for(l=0; l<TETRO_DIM; l++){
126 if (parts[i][j][k][l].status>EMPTY_BOX)
127 wprintf(L"%lc", fSq);
128 else
129 wprintf(L"%lc", eSq);
130 }
131 wprintf(L"\r\n");
132 }
133 wprintf(L"\r\n");
134 }
135 wprintf(L"\r\n");
136 }
137}
void printCentered(wchar_t *text)
Print text centered horizontally based on string length.
Definition common.c:71
int intLen(int value)
Calculate the length of a given number.
Definition common.c:47
void heightSpacing(int filledHeight)
Apply a vertical spacing based on window heigth and what need to be printed.
Definition common.c:76
const wchar_t fSq
Assign unicode character (black square) to this global variable.
Definition common.c:17
const wchar_t eSq
Assign unicode character (white square) to this global variable.
Definition common.c:16
void waitUser(void)
Wait until Enter key is pressed.
Definition common.c:146
void clearCLI(void)
Call the system function to clear the cli.
Definition common.c:25
#define WIDTH
Definition definitions.h:6
#define PLAYER_1
Definition definitions.h:37
#define TETRO_ROT
Definition definitions.h:9
#define N_PIECES
Definition definitions.h:8
#define TETRO_DIM
Definition definitions.h:10
#define MULTIPLAYER
Definition definitions.h:36
#define EMPTY_BOX
Definition definitions.h:14
#define SINGLEPLAYER
Definition definitions.h:35
#define BOT
Definition definitions.h:39
#define SPACING
Definition definitions.h:7
#define HEIGHT
Definition definitions.h:5
#define PLAYER_2
Definition definitions.h:38
void printPlayersName(int points_1, int points_2, int mode)
Print players' name.
Definition printGame.c:18
void gameOver(int points_1, int points_2, int mode)
Print end screen result.
Definition printGame.c:80
void printSpacing()
Print spaces between the two boards.
Definition printGame.c:10
void printTetrominoes(TetrominoPtr parts)
Print all tetrominoes shapes.
Definition printGame.c:114
void printBoard(BoardPtr mat_1, BoardPtr mat_2, int points_1, int points_2, int mode)
Print the game with object in the terminal.
Definition printGame.c:38
Definition struct.h:5