xTetris-Game
Loading...
Searching...
No Matches
Functions
printGame.c File Reference
#include <stdio.h>
#include <wchar.h>
#include "printGame.h"
#include "common.h"
#include "definitions.h"
#include "struct.h"

Go to the source code of this file.

Functions

void printSpacing ()
 Print spaces between the two boards.
 
void printPlayersName (int points_1, int points_2, int mode)
 Print players' name.
 
void printBoard (BoardPtr mat_1, BoardPtr mat_2, int points_1, int points_2, int mode)
 Print the game with object in the terminal.
 
void gameOver (int points_1, int points_2, int mode)
 Print end screen result.
 
void printTetrominoes (TetrominoPtr parts)
 Print all tetrominoes shapes.
 

Function Documentation

◆ gameOver()

void gameOver ( int points_1,
int points_2,
int mode )

Print end screen result.

Parameters
[in]points_1Points value of player 1.
[in]points_2Points value of player 2 ( or bot, depending on match mode).
[in]modeSingleplayer or Multiplayer (0 or 1).

Definition at line 80 of file printGame.c.

80 {
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}
void printCentered(wchar_t *text)
Print text centered horizontally based on string length.
Definition common.c:71
void heightSpacing(int filledHeight)
Apply a vertical spacing based on window heigth and what need to be printed.
Definition common.c:76
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 PLAYER_1
Definition definitions.h:37
#define MULTIPLAYER
Definition definitions.h:36
#define SINGLEPLAYER
Definition definitions.h:35
#define BOT
Definition definitions.h:39
#define PLAYER_2
Definition definitions.h:38

◆ printBoard()

void printBoard ( BoardPtr mat_1,
BoardPtr mat_2,
int points_1,
int points_2,
int mode )

Print the game with object in the terminal.

Parameters
[in]mat_1Pointer of struct board of player 1.
[in]mat_2Pointer of struct board of player 2.
[in]points_1Points value of player 1.
[in]points_2Points value of player 2 ( or bot, depending on match mode).
[in]modeSingleplayer or Multiplayer (0 or 1).

Definition at line 38 of file printGame.c.

38 {
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}
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
#define WIDTH
Definition definitions.h:6
#define EMPTY_BOX
Definition definitions.h:14
#define HEIGHT
Definition definitions.h:5
void printPlayersName(int points_1, int points_2, int mode)
Print players' name.
Definition printGame.c:18
void printSpacing()
Print spaces between the two boards.
Definition printGame.c:10

◆ printPlayersName()

void printPlayersName ( int points_1,
int points_2,
int mode )

Print players' name.

Parameters
[in]points_1Points value of player 1.
[in]points_2Points value of player 2 ( or bot, depending on match mode).
[in]modeSingleplayer or Multiplayer (0 or 1).

Definition at line 18 of file printGame.c.

18 {
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}
int intLen(int value)
Calculate the length of a given number.
Definition common.c:47

◆ printSpacing()

void printSpacing ( )

Print spaces between the two boards.

Definition at line 10 of file printGame.c.

10 {
11
12 int i;
13
14 for (i=0; i<SPACING; i++)
15 wprintf(L" ");
16}
#define SPACING
Definition definitions.h:7

◆ printTetrominoes()

void printTetrominoes ( TetrominoPtr parts)

Print all tetrominoes shapes.

Parameters
[in]partsStruct containing all possible tetrominoes' shapes.

Definition at line 114 of file printGame.c.

114 {
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}
#define TETRO_ROT
Definition definitions.h:9
#define N_PIECES
Definition definitions.h:8
#define TETRO_DIM
Definition definitions.h:10