-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.c
More file actions
80 lines (76 loc) · 2.56 KB
/
functions.c
File metadata and controls
80 lines (76 loc) · 2.56 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
#include "mastermind.h"
/**
* masterMind - function to start the game
* Return: void
*/
void masterMind(void)
{
title();
instructions();
}
/**
* initializeBoard - function to initialize the board
* Return: void
*/
void initializeBoard(void)
{
int i, j;
for (j = 0; j < 4; j++)
hiden[j] = '?';
for (i = 0; i < 8; i++)
{
for (j = 0; j < 4; j++)
{
rows[i][j] = '_';
tries[i][j] = '_';
}
}
}
/**
* startGame - function with the main loop to game
* Return: void
*/
void startGame(void)
{
int chances = 7;
generateSecretCode();
initializeBoard();
while (1 && chances >= 0)
{
system("clear");
title();
printBoard();
motor(chances);
chances--;
}
lose();
}
/**
* congratulations - function to congrats the player when guess the secret code
* Return: void
*/
void congratulations(void)
{
char *cgrts1 = ANSI_COLOR_RED "\t ______ ______ .__ __. _______ .______ ___ .___________. __ __ __ ___ .___________. __ ______ .__ __. _______.\n" ANSI_COLOR_RESET;
char *cgrts2 = ANSI_COLOR_RED "\t / | / __ \\ | \\ | | / _____|| _ \\ / \\ | || | | | | | / \\ | || | / __ \\ | \\ | | / |\n" ANSI_COLOR_RESET;
char *cgrts3 = ANSI_COLOR_RED "\t| ,----'| | | | | \\| | | | __ | |_) | / ^ \\ `---| |----`| | | | | | / ^ \\ `---| |----`| | | | | | | \\| | | (----`\n" ANSI_COLOR_RESET;
char *cgrts4 = ANSI_COLOR_RED "\t| | | | | | | . ` | | | |_ | | / / /_\\ \\ | | | | | | | | / /_\\ \\ | | | | | | | | | . ` | \\ \\ \n" ANSI_COLOR_RESET;
char *cgrts5 = ANSI_COLOR_RED "\t| `----.| `--' | | |\\ | | |__| | | |\\ \\----. / _____ \\ | | | `--' | | `----. / _____ \\ | | | | | `--' | | |\\ | .----) | \n" ANSI_COLOR_RESET;
char *cgrts6 = ANSI_COLOR_RED "\t \\______| \\______/ |__| \\__| \\______| | _| `._____|/__/ \\__\\ |__| \\______/ |_______|/__/ \\__\\ |__| |__| \\______/ |__| \\__| |_______/ \n" ANSI_COLOR_RESET;
system("clear");
printf("%s%s%s%s%s%s", cgrts1, cgrts2, cgrts3, cgrts4, cgrts5, cgrts6);
exit(EXIT_SUCCESS);
}
/**
* check_input - function to avoid no numeric characters as input
* @number: the number from the input of the player
* Return: 0 if all the characters are numbers, otherwise -1
*/
int check_input(char *number)
{
int i;
for (i = 0; i < 4; i++)
if (!isdigit(number[i]))
return (0);
return (1);
}