Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
victorgrt authored Feb 19, 2023
1 parent fb3a049 commit 0a13cbc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 158 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: victor <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/02/18 13:40:35 by victor #+# #+# #
# Updated: 2023/02/18 17:47:51 by victor ### ########.fr #
# Updated: 2023/02/19 21:38:56 by victor ### ########.fr #
# #
# **************************************************************************** #

Expand All @@ -20,18 +20,18 @@ CC = gcc
################################################################################
# * SRC * #

SRC = hangman.c ft_words.c ft_printer.c ft_error_handler.c ./gnl/get_next_line.c \
SRC = hangman.c ft_words.c ft_printer.c ./gnl/get_next_line.c \
./gnl/get_next_line_utils.c ft_utils.c\

OBJ = ${SRC:.c=.o}

################################################################################
# ? RULES ? #

all: ${NAME} ok_util
all: ${NAME} hangman_logo

${NAME} : ${OBJ}
${CC} ${OBJ}
@${CC} ${OBJ}


%.o : %.c
Expand Down Expand Up @@ -59,6 +59,7 @@ fclean_util :
@${foreach value, $(NAME), echo "\\033[1;31m >> \\033[0;39m" ${value};}
@echo "⢀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⣠⣤⣶⣶\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⢰⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣀⣀⣾⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⡏⠉⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿\n⣿⣿⣿⣿⣿⣿⠀⠀⠀⠈⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠉⠁⠀⣿\n⣿⣿⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠙⠿⠿⠿⠻⠿⠿⠟⠿⠛⠉⠀⠀⠀⠀⠀⣸⣿\n⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⣴⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⢰⣹⡆⠀⠀⠀⠀⠀⠀⣭⣷⠀⠀⠀⠸⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠈⠉⠀⠀⠤⠄⠀⠀⠀⠉⠁⠀⠀⠀⠀⢿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⢾⣿⣷⠀⠀⠀⠀⡠⠤⢄⠀⠀⠀⠠⣿⣿⣷⠀⢸⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⡀⠉⠀⠀⠀⠀⠀⢄⠀⢀⠀⠀⠀⠀⠉⠉⠁⠀⠀⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿"

ok_util :
@echo "\
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀⢠⠞⠉⠙⠲⡀⠀\n ⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀ ⡏⠀⠀⠀⠀⠀⢷ \n ⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀⢸⠀⠀⠀⠀⠀ ⡇ \n ⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀⣸ OK ⡇ \n ⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀⢹⠀⠀⠀⠀⠀ ⡇ \n ⠀⠀⠙⢿⣯⠄ ⠘⠤⣄⣠⠞⠀⡿⠀⠀⡇⠀⠀⠀⠀⡼ \n ⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀⠘⠤⣄⣠⠞⠀ \n ⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ \n ⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀ \n ⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀ \n ⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀ \n ⣿⣿⣧⣀⣿………⣀⣰⣏⣘⣆⣀⠀⠀ \n"
hangman_logo :
@echo "__ __ ____ ____ ____ ___ ___ ____ ____\n| | | / || \ / || | | / || \\n| | || o || _ || __|| _ _ || o || _ |\n| _ || || | || | || \_/ || || | |\n| | || _ || | || |_ || | || _ || | |\n| | || | || | || || | || | || | |\n|__|__||__|__||__|__||___,_||___|___||__|__||__|__|"


21 changes: 11 additions & 10 deletions ft_printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: victor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/18 13:40:32 by victor #+# #+# */
/* Updated: 2023/02/19 18:25:32 by victor ### ########.fr */
/* Updated: 2023/02/19 21:34:24 by victor ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -42,33 +42,34 @@ void ft_print_echaffau(int tries)
else if (tries == 1)
printf(" |====||\n | ||\n o || TRIES : %d\n -|- ||\n / /__\\\n", tries);
else if (tries == 0)
printf(" |====||\n | ||\n o || TRIES : %d\n -|- ||\n / \\ /__\\\n", tries);
printf(" |====||\n | ||\n o || TRIES : \033[1m\033[31m%d\033[0m\n -|- ||\n / \\ /__\\\n", tries);
printf("\n");
}

void ft_print_used(char *used_letters)
void ft_print_used(char *used_letters, char *mot)
{
int i = 0;

if(!used_letters)
return ;
printf("Lettres essayées : ");
while (used_letters[i])
{
printf(" %c ", used_letters[i]);
if (ft_check(mot, used_letters[i]) == 1)
printf(" \033[32m%c\033[0m", used_letters[i]);
else
printf("\033[1m\033[31m%c\033[0m", used_letters[i]);
i++;
}
printf("\n");
}

void ft_print_all(char *mot, char *hidden, char *used, int life)
{
printf("#======== \033[31mHungman\033[0m =========#\n\n");
ft_print_echaffau(life);
ft_print_mot(mot, hidden);
if (used)
{
write(1, "\n", 1);
ft_print_used(used);
write(1, "\n", 1);
}
ft_print_used(used, mot);
}

// int main(void)
Expand Down
40 changes: 4 additions & 36 deletions ft_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,19 @@
/* By: victor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/18 17:46:17 by victor #+# #+# */
/* Updated: 2023/02/19 14:41:07 by victor ### ########.fr */
/* Updated: 2023/02/19 21:36:24 by victor ### ########.fr */
/* */
/* ************************************************************************** */

#include "hangman.h"

int ft_victory(char *mot, char *hidden)
{
int i = 0;

while (mot[i])
{
if (mot[i] != hidden[i])
return (0);
i++;
}
return (1);
}

void ft_reponse(char *mot, char *hidden, char c)
{
int i = 0;
int j;

if (!hidden)
return ;
while (hidden[i])
{
if (mot[i] == c)
Expand All @@ -45,28 +34,7 @@ void ft_reponse(char *mot, char *hidden, char c)
}
i++;
}
}

char ft_get_letter()
{
char lettre;

printf("Enter a letter : \n");
lettre = scanf("%c", &lettre);
return (lettre);
}

int ft_win(char *mot, char *hidden)
{
int i = 0;

while (hidden[i] && mot[i])
{
if (hidden[i] == mot[i])
i++;
return (0);
}
return (1);
hidden[i] = '\0';
}

int ft_cmp(char *s1, char *s2)
Expand Down
99 changes: 3 additions & 96 deletions hangman.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,12 @@
/* By: victor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/18 18:59:11 by victor #+# #+# */
/* Updated: 2023/02/19 18:30:01 by victor ### ########.fr */
/* Updated: 2023/02/19 21:39:13 by victor ### ########.fr */
/* */
/* ************************************************************************** */

#include "hangman.h"

void ft_setup_used(char *used)
{
int i = 0;

while (used[i])
{
used[i] = '0';
i++;
}
}

// void hangman(char *mot, char *hidden)
// {
// int life = 6;
// int pos = 0;
// int i = 0;
// char letter;
// static char *used;

// used = malloc(sizeof(char) * (ft_strlen(mot) + 6));
// if(!used)
// return ;
// ft_setup_used(used);
// printf("ici%s\n", used);
// if (i == 0)
// {
// ft_print_echaffau(life);
// ft_print_mot(mot, hidden);
// letter = ft_get_letter();
// used[i] = letter;
// if (ft_check(mot, letter) == 1)
// ft_reponse(mot, hidden, letter);
// else
// life--;
// }
// while (i < life)
// {
// if (ft_cmp(mot, hidden) == 1)
// {
// printf("▓██ ██▓ ▒█████ █ ██ █ █░ ██▓ ███▄ █\n ▒██ ██▒▒██▒ ██▒ ██ ▓██▒ ▓█░ █ ░█░▓██▒ ██ ▀█ █ \n ▒██ ██░▒██░ ██▒▓██ ▒██░ ▒█░ █ ░█ ▒██▒▓██ ▀█ ██▒\n ░ ▐██▓░▒██ ██░▓▓█ ░██░ ░█░ █ ░█ ░██░▓██▒ ▐▌██▒\n ░ ██▒▓░░ ████▓▒░▒▒█████▓ ░░██▒██▓ ░██░▒██░ ▓██░\n ██▒▒▒ ░ ▒░▒░▒░ ░▒▓▒ ▒ ▒ ░ ▓░▒ ▒ ░▓ ░ ▒░ ▒ ▒ \n ▓██ ░▒░ ░ ▒ ▒░ ░░▒░ ░ ░ ▒ ░ ░ ▒ ░░ ░░ ░ ▒░\n ▒ ▒ ░░ ░ ░ ░ ▒ ░░░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ \n ░ ░ ░ ░ ░ ░ ░ ░ \nBravo tu as trouvé le mot : \033[4m %s \033[0\n", mot);
// return;
// }
// ft_print_echaffau(life);
// ft_print_mot(mot, hidden);
// ft_print_used(mot, pos);
// letter = ft_get_letter();
// used[i] = letter;
// if (ft_check(mot, letter) == 1)
// ft_reponse(mot, hidden, letter);
// else
// life--;
// pos++;
// }
// printf(" ▄████ ▄▄▄ ███▄ ▄███▓▓█████ ▒█████ ██▒ █▓▓█████ ██▀███\n ██▒ ▀█▒▒████▄ ▓██▒▀█▀ ██▒▓█ ▀ ▒██▒ ██▒▓██░ █▒▓█ ▀ ▓██ ▒ ██▒\n▒██░▄▄▄░▒██ ▀█▄ ▓██ ▓██░▒███ ▒██░ ██▒ ▓██ █▒░▒███ ▓██ ░▄█ ▒\n░▓█ ██▓░██▄▄▄▄██▒██ ▒██ ▒▓█ ▄ ▒██ ██░ ▒██ █░░▒▓█ ▄ ▒██▀▀█▄ \n░▒▓███▀▒ ▓█ ▓██▒██▒ ░██▒░▒████▒ ░ ████▓▒░ ▒▀█░ ░▒████▒░██▓ ▒██▒\n ░▒ ▒ ▒▒ ▓▒█░ ▒░ ░ ░░░ ▒░ ░ ░ ▒░▒░▒░ ░ ▐░ ░░ ▒░ ░░ ▒▓ ░▒▓░\n ░ ░ ▒ ▒▒ ░ ░ ░ ░ ░ ░ ░ ▒ ▒░ ░ ░░ ░ ░ ░ ░▒ ░ ▒░\n░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░░ ░ \n ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ \n ░ \n\nTon mot était : \033[4m%s\033[0", mot);
// }

int hangman()
{
char *mot;
Expand All @@ -82,7 +26,7 @@ int hangman()
if (!used)
return 0;
mot = ft_select_word(1, 1830);
printf("Mot : %s\n", mot);
//printf("Mot : %s\n", mot);
hidden = ft_hidden_word(mot);
ft_print_all(mot, hidden, NULL, 6);
while (ft_cmp(mot, hidden) == 0)
Expand All @@ -100,7 +44,7 @@ int hangman()
{
ft_reponse(mot, hidden, letter);
used[i] = letter;
used[i+1] = '\0';
//used[i+1] = '\0';
ft_print_all(mot, hidden, used, life);
i++;
printed = 1;
Expand All @@ -119,45 +63,8 @@ int hangman()
return (1);
}

//j'ai besoin de quoi? Un mot généré, un hidden, un used et
// Deroulement du jeu : - generation du mot, affichage de l'echaffau et du hidden.
// - jusqu'a que hidden == mot || life = 0 -> scanf lettre, si lettre dans mot -> on remplace dans hidden toutes les occurences et
// on ajoute lettre dans used; On affiche echaffau, hidden et used. Sinon (lettre pas dans mot), on enleve une vie, on actualise used
// et on affiche echaffau hidden et used.
//Si life == 0 printf (game over)
//Si hidden == mot printf (you win);


/* !!TODO!! */

int main()
{
hangman();
//tried = ft_tried_letters(lettre, 0);
// ft_print_echaffau(tries);
//ft_print_mot(mot, hidden, NULL);
// printf("Mot : %s\nHidden : %s\n", mot, hidden);
// ft_print_echaffau(tries);
// ft_print_mot(mot, hidden, test);
// while (tries != 0 || ft_win(mot, hidden) == 0)
// {
// if (ft_cmp(mot, hidden) == 0) //si c pas pareil, on print echaffau et
// {
// if (ft_check(mot, test[i]) == 1)
// ft_reponse(mot, hidden, test[i]);
// ft_print_echaffau(tries);
// ft_print_mot(mot, hidden, NULL);
// test[i] = ft_get_letter();
//
// }
// else if (ft_cmp(mot, hidden) == 1) //si les deux son pareils alors win
// {
// printf("\nBravo tu as trouvé le mot : \033[4m%s\033[0m\n", mot);
// return (0);
// }
// else
// tries--;
// }
// printf(" Game Over\nLe mot était : %s\n%s", mot, test);
return 0;
}
18 changes: 9 additions & 9 deletions hangman.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: victor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/18 13:40:40 by victor #+# #+# */
/* Updated: 2023/02/19 18:07:21 by victor ### ########.fr */
/* Updated: 2023/02/19 21:29:47 by victor ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,17 +20,17 @@
#include "./gnl/get_next_line.h"

char *ft_select_word(int min, int max);
int ft_victory(char *mot, char *hidden);
int random_generator(int min, int max);
char *ft_hidden_word(char *mot);
void ft_print_echaffau(int tries);
void ft_print_mot(char *mot, char *hidden);

char *ft_tried_letters(char c, int tries);
int ft_cmp(char *s1, char *s2);
int ft_check(char *mot, char c);
void ft_reponse(char *mot, char *hidden, char c);
char ft_get_letter();
int ft_win(char *mot, char *hidden);
int ft_cmp(char *s1, char *s2);
int ft_check(char *mot, char c);
void ft_print_used(char *mot);

void ft_print_echaffau(int tries);
void ft_print_mot(char *mot, char *hidden);
void ft_print_used(char *used, char *mot);
void ft_print_all(char *mot, char *hidden, char *used, int life);

#endif

0 comments on commit 0a13cbc

Please sign in to comment.