-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Valentin Simeonov
committed
Mar 17, 2022
1 parent
e9d1383
commit b9e11c5
Showing
8 changed files
with
433 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* checkers.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: vsimeono <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/03/17 13:44:38 by vsimeono #+# #+# */ | ||
/* Updated: 2022/03/17 15:58:07 by vsimeono ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "so_long.h" | ||
|
||
|
||
/* Checking if P, E, C is in Map */ | ||
int check_P_E_C_in_map(t_long *arch, t_list **lines) | ||
{ | ||
t_list *temp; | ||
int i; | ||
int len_line; | ||
int flag[255]; | ||
|
||
temp = *lines; | ||
len_line = ft_strlen_line(lines); | ||
i = 0; | ||
while (i > 255) | ||
{ | ||
flag[i] = 0; | ||
i++; | ||
} | ||
while (temp->next != NULL) | ||
{ | ||
if (ft_strchr(temp->line, 'P')) | ||
{ | ||
flag[80] = 1; | ||
arch->player++; | ||
} | ||
if (ft_strchr(temp->line, 'E')) | ||
{ | ||
flag[69] = 1; | ||
arch->exit++; | ||
} | ||
if (ft_strchr(temp->line, 'C')) | ||
{ | ||
flag[67] = 1; | ||
arch->collect++; | ||
printf("%d\n", arch->collect); | ||
printf("%d\n", arch->collect); | ||
printf("%d\n", arch->collected); | ||
} | ||
temp = temp->next; | ||
} | ||
if (flag[80] != 1 || flag[69] != 1 || flag[67] != 1) | ||
return (0); | ||
return (1); | ||
} | ||
|
||
/* Check that there are not any other Characters except P,C,E, 1 and 0 */ | ||
int is_only__P_C_E_1_0_in_map(t_list **lines) | ||
{ | ||
t_list *temp; | ||
int i; | ||
int len_line; | ||
|
||
temp = (*lines); | ||
len_line = ft_strlen_line(lines); | ||
while (temp->next != NULL) | ||
{ | ||
i = 0; | ||
while (i < len_line) | ||
{ | ||
if (temp->line[i] != '0' && temp->line[i] != '1' && temp->line[i] != 'P' && temp->line[i] != 'E' && temp->line[i] != 'C' && temp->line[i] != '\n') | ||
return (0); | ||
i++; | ||
} | ||
temp = temp->next; | ||
} | ||
return (1); | ||
} | ||
|
||
/* Checking the Length of the Lines are the Same */ | ||
int is_length_of_lines_the_same(t_list **lines) | ||
{ | ||
t_list *temp; | ||
int len_line; | ||
|
||
temp = (*lines); | ||
len_line = ft_strlen_line(lines); | ||
while (temp->next != NULL) | ||
{ | ||
temp = temp->next; | ||
if (len_line != ft_strlen_line_1(temp->line)) | ||
return (0); | ||
} | ||
return (1); | ||
} | ||
|
||
/* Checking if first Line and Last Line is Made from 1s */ | ||
int is_first_and_last_line_is_one(t_list **lines) | ||
{ | ||
t_list *temp; | ||
|
||
temp = (*lines); | ||
if (!ft_strchr_first_line(temp->line, '1')) | ||
return (0); | ||
while (temp->next != NULL) | ||
temp = temp->next; | ||
if (!ft_strchr_second_line(temp->line, '1')) | ||
return (0); | ||
return (1); | ||
} | ||
|
||
/* Check if First Char and Last Char is 1 */ | ||
int is_first_char_and_last_char_one(t_list **lines) | ||
{ | ||
t_list *temp; | ||
int len_line; | ||
int j; | ||
|
||
temp = (*lines); | ||
len_line = ft_strlen_line(lines); | ||
while (temp->next != NULL) | ||
{ | ||
j = 0; | ||
if (temp->line[j] != 49) | ||
return (0); | ||
j = len_line - 1; | ||
if (temp->line[j] != 49) | ||
return (0); | ||
temp = temp->next; | ||
} | ||
return (1); | ||
} | ||
|
||
/* Checking if the Map has Extension .ber*/ | ||
int is_map(char *argv) | ||
{ | ||
int len; | ||
|
||
len = ft_strlen(argv); | ||
if (argv[len - 4] == '.' && argv[len - 3] == 'b' && \ | ||
argv[len - 2] == 'e' && argv[len - 1] == 'r') | ||
return (1); | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* create_destroy_map.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: vsimeono <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/03/17 14:04:00 by vsimeono #+# #+# */ | ||
/* Updated: 2022/03/17 14:04:31 by vsimeono ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "so_long.h" | ||
|
||
int loop(t_long *arch) | ||
{ | ||
char *moves; | ||
|
||
moves = ft_itoa(arch->moves); | ||
mlx_string_put(arch->mlx, arch->mlx_win, 30, 30, 0xffff00, moves); | ||
return (0); | ||
} | ||
|
||
/* Freeing the Allocated Memory for Linked List and for Graphical Interface */ | ||
int finish(t_long *arch) | ||
{ | ||
free_list(&arch->lines); | ||
mlx_destroy_window(arch->mlx, arch->mlx_win); | ||
write(1, "You have Closed the Game!\n", 26); | ||
exit(0); | ||
} | ||
|
||
/* Creating the Visual Map */ | ||
void create_visual_map(t_long *arch) | ||
{ | ||
t_list *temp; | ||
char *line; | ||
int i; | ||
|
||
i = 0; | ||
arch->img.point_x = 0; | ||
arch->img.point_y = 0; | ||
temp = arch->lines; | ||
while (temp) | ||
{ | ||
line = temp->line; | ||
while (line[i] && line[i] != '\n') | ||
{ | ||
load_assests(arch, line[i], arch->img.point_x, arch->img.point_y); | ||
i++; | ||
arch->img.point_x += 48; | ||
} | ||
temp = temp->next; | ||
arch->img.point_x = 0; | ||
arch->img.point_y += 48; | ||
i = 0; | ||
} | ||
} | ||
|
||
/* Loading Pictures as the Pixels for the Graphical Map according to their Corresponding Lettter or Number */ | ||
void load_assests(t_long *arch, char c, int x, int y) | ||
{ | ||
if (c == '1') | ||
arch->img.img = mlx_xpm_file_to_image(arch->mlx, "./data/red_walls.xpm", &arch->img.size_x, &arch->img.size_y); | ||
else if (c == 'P') | ||
{ | ||
arch->img.img = mlx_xpm_file_to_image(arch->mlx, "./data/space.xpm", &arch->img.size_x, &arch->img.size_y); | ||
arch->img.img = mlx_xpm_file_to_image(arch->mlx, "./data/sun_resized.xpm", &arch->img.size_x, &arch->img.size_y); | ||
} | ||
else if (c == 'E') | ||
arch->img.img = mlx_xpm_file_to_image(arch->mlx, "./data/exit_x.xpm", &arch->img.size_x, &arch->img.size_y); | ||
else if (c == 'C') | ||
{ | ||
arch->img.img = mlx_xpm_file_to_image(arch->mlx, "./data/space.xpm", &arch->img.size_x, &arch->img.size_y); | ||
arch->img.img = mlx_xpm_file_to_image(arch->mlx, "./data/heart.xpm", &arch->img.size_x, &arch->img.size_y); | ||
} | ||
else | ||
arch->img.img = mlx_xpm_file_to_image(arch->mlx, "./data/space.xpm", &arch->img.size_x, &arch->img.size_y); | ||
mlx_put_image_to_window(arch->mlx, arch->mlx_win, arch->img.img, x, y); | ||
mlx_destroy_image(arch->mlx, arch->img.img); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* hooks_and_rules.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: vsimeono <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/03/17 14:02:28 by vsimeono #+# #+# */ | ||
/* Updated: 2022/03/17 17:02:47 by vsimeono ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "so_long.h" | ||
|
||
/* Determining where the Key Pressed Takes the Player and what Action it Determines */ | ||
int key_hook(int keycode, t_long *arch) | ||
{ | ||
if (keycode == UP || keycode == DOWN \ | ||
|| keycode == LEFT || keycode == RIGHT) | ||
{ | ||
p_position_and_counting_objects(arch, keycode); | ||
create_visual_map(arch); | ||
} | ||
if (keycode == ESC) | ||
finish(arch); | ||
return (0); | ||
} | ||
|
||
/* Using Player's Position and Next Move to Determine what Happens to the Objects in the Map and Finishes the Game */ | ||
void p_position_and_counting_objects(t_long *arch, int keycode) | ||
{ | ||
t_list *temp; | ||
char *next; | ||
|
||
temp = player_position(arch, arch->lines); | ||
next = player_next_move(temp, arch, keycode); | ||
if (*next != '1') | ||
{ | ||
if (*next == 'C' || *next == '0') | ||
{ | ||
if (*next == 'C') | ||
arch->collected++; | ||
arch->moves++; | ||
} | ||
else if (*next == 'E' && arch->collected == arch->collect) | ||
{ | ||
printf("%d\n", arch->collect); | ||
printf("%d\n", arch->collected); | ||
arch->moves++; | ||
finish(arch); | ||
} | ||
else if (*next == 'E') | ||
// finish(arch); | ||
return ; | ||
*next = 'P'; | ||
*(char *)(temp->next->line + arch->pos_x) = '0'; | ||
} | ||
return ; | ||
} | ||
|
||
/* Determining the Player's Position in the Map */ | ||
t_list *player_position(t_long *arch, t_list *lines) | ||
{ | ||
t_list *temp; | ||
|
||
temp = lines->next; | ||
// print_list(&lines); | ||
while (temp) | ||
{ | ||
arch->pos_x = 0; | ||
while (*(char *)(temp->line + arch->pos_x) \ | ||
&& *(char *)(temp->line + arch->pos_x) != 'P' \ | ||
&& *(char *)(temp->line + arch->pos_x) != '\n' ) | ||
arch->pos_x++; | ||
if (*(char *)(temp->line + arch->pos_x) == 'P') | ||
break; | ||
lines = temp; | ||
temp = temp->next; | ||
} | ||
return (lines); | ||
} | ||
|
||
/* Determining where the Next Player Move would Arrive the Player*/ | ||
char *player_next_move(t_list *temp, t_long *arch, int keycode) | ||
{ | ||
char *next; | ||
|
||
next = (char *)temp->line; | ||
if (keycode == UP) | ||
next = (char *)temp->line + arch->pos_x; | ||
if (keycode == DOWN) | ||
next = (char *)temp->next->next->line + arch->pos_x; | ||
if (keycode == LEFT) | ||
next = (char *)temp->next->line + arch->pos_x - 1; | ||
if (keycode == RIGHT) | ||
next = (char *)temp->next->line + arch->pos_x + 1; | ||
return (next); | ||
} |
Oops, something went wrong.