Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
On dead player can now watch the game
  • Loading branch information
restylianos committed Jun 13, 2020
1 parent 3c30971 commit 148af2f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CSSRC = $(wildcard server/*.c)
CC = gcc

game.bin: $(CGSRC)
$(CC) $(CGSRC) -g -Wall -lpthread -lcrypto -lssl -o game.bin
$(CC) $(CGSRC) -g -Wall -lpthread -lcrypto -lssl -Os -o game.bin

server.bin: $(CSSRC)
$(CC) $(CSSRC) src/events_handler.c src/mode_handle.c src/net_protocol.c src/custom_effects.c src/player.c src/client.c src/util.c src/login.c src/chest.c src/map.c src/game_logic.c src/monster.c -g -Wall -lpthread -lcrypto -lssl -o server.bin
Binary file added game.bin
Binary file not shown.
5 changes: 2 additions & 3 deletions saves/8.rpg
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
7
8,18,48,100,100,100,100,6,0
8,12,37,100,100,100,100,6,0
7
0,0,0,0,0,0,0
10
9
0,0
20,1
20,2
20,3
20,4
20,5
20,6
20,7
20,8
Expand Down
Binary file added server.bin
Binary file not shown.
5 changes: 3 additions & 2 deletions src/events_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ int decode_on_player_update_stats(player_t players_arr[], char *buffer_to_decode
}
for (int i = 0; i < 3; i++)
{
map_set(map, PSYMBOL, players_arr[i].y, players_arr[i].x);
if(players_arr[i].isDead != TRUE) map_set(map, PSYMBOL, players_arr[i].y, players_arr[i].x);
if(players_arr[i].prev_x != players_arr[i].x || players_arr[i].prev_y != players_arr[i].y){
map_set(map, MAP_P_SYMBOL,players_arr[i].prev_y, players_arr[i].prev_x);
}
Expand All @@ -374,7 +374,7 @@ int decode_on_player_update_stats(player_t players_arr[], char *buffer_to_decode
return 0;
}

int decode_on_player_death(player_t players_arr[], char *buffer_to_decode)
int decode_on_player_death(map_t *map,player_t players_arr[], char *buffer_to_decode)
{
char *token;
int i;
Expand All @@ -389,6 +389,7 @@ int decode_on_player_death(player_t players_arr[], char *buffer_to_decode)
token = strtok(NULL, NET_DELIM);
//get the second number which is 1 -> force player to die
players_arr[i].isDead = atoi(token); //kill player
map_set(map,MAP_P_SYMBOL,players_arr[i].y, players_arr[i].x);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/events_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ char *on_player_update_stats(player_t *player, map_t* map);

//Decoding funcs
int decode_on_chest_open(chest_t chests_arr[], char *buffer_to_decode, map_t *map); //checked
int decode_on_player_death(player_t players_arr[], char *buffer_to_decode); // checked
int decode_on_player_death(map_t *map,player_t players_arr[], char *buffer_to_decode); // checked
int decode_on_player_update_stats(player_t players_arr[], char *buffer_to_decode, map_t *map); //checked
int decode_on_monster_update_stats(monster_t mons_arr[], char *buffer_to_decode, map_t *map); //check later
int decode_on_monster_death(monster_t mons_arr[], char *buffer_to_decode, map_t *map); //checked
Expand Down
11 changes: 7 additions & 4 deletions src/mode_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,17 @@ void *multi_game_handler(void *args)
{
while (1)
{

key_press = key_input(key);
if (key_press == LEFT_C ||
if ((key_press == LEFT_C ||
key_press == LEFT_S ||
key_press == RIGHT_C ||
key_press == RIGHT_S ||
key_press == UP_C ||
key_press == UP_S ||
key_press == DOWN_C ||
key_press == DOWN_S)
key_press == DOWN_S) &&
game->players[game->client->uid].isDead == FALSE)
{
game->players[game->client->uid].prev_direction = game->players[game->client->uid].direction;
game->players[game->client->uid].direction = key_press;
Expand All @@ -315,6 +317,7 @@ void *multi_game_handler(void *args)
net_buffer = on_player_update_stats(&game->players[game->client->uid],&game->map);
send(game->client->sockfd, net_buffer, SOCK_BUFF_SZ, 0);
}


/**
* Save the game press #
Expand Down Expand Up @@ -356,7 +359,7 @@ void *multi_game_handler(void *args)
update_objects(&game->map, game->mons_arr, game->chest_arr);
to_print_multi(&game->map, game->players, game->mons_arr, game->chest_arr,game->client->uid);

usleep(10000);
usleep(100000);
fflush(stderr);
fflush(stdin);
fflush(stdout);
Expand Down Expand Up @@ -408,7 +411,7 @@ void *multi_recv_handler(void *args)
itoa(PLR_DEATH_ID_P, comp, 10);
if (!strcmp(response_id, comp))
{
if (decode_on_player_death(game->players, net_buffer) != 0)
if (decode_on_player_death(&game->map,game->players, net_buffer) != 0)
{
// send message to server for message loss
}
Expand Down
19 changes: 17 additions & 2 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,17 @@ void get_stats_multi(player_t players[], monster_t monsters[], map_t *map, int m
printf("\033[0m");

printf("\033[1;36m");
printf("AT: %d \n", players[i].attack);
printf("AT: %d ", players[i].attack);
printf("\033[0m");

if(players[i].isDead == TRUE)
{
printf("\033[1;31m");
printf(" *DEAD* ");
printf("\033[0m\n");
}
else printf("\n");

printf("\033[1;32m");
printf("Wins: ");
printf("%d", players[i].wins);
Expand All @@ -207,6 +215,8 @@ void get_stats_multi(player_t players[], monster_t monsters[], map_t *map, int m
printf(" Level: ");
printf("%d\n", map->level);
printf("\033[0m");


}
printf("Monsters left: [");

Expand Down Expand Up @@ -329,8 +339,13 @@ void object_found_multi(client_t *client, map_t *map, player_t *player, char key
{
player_attack = attack((float)mons_arr[i].accuracy, (float)mons_arr[i].attack, (float)player->armor);
player->health -= player_attack;
if (player->health <= 0)
if (player->health <= 0){
player_die(player); //second check for life after health so the player can t have negative hp
net_buffer = on_player_death(player);
send(client->sockfd, net_buffer, SOCK_BUFF_SZ, 0);
net_buffer = NULL;
}

}
else
{
Expand Down

0 comments on commit 148af2f

Please sign in to comment.