-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
93 lines (83 loc) · 1.48 KB
/
utils.c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
** utils.c for navy in /home/thibrex/Dropbox/delivery/PSU/PSU_2016_navy
**
** Made by Thibaut Cornolti
** Login <[email protected]>
**
** Started on Mon Jan 30 10:18:04 2017 Thibaut Cornolti
** Last update Sun Feb 5 22:07:47 2017 Thibaut Cornolti
*/
#include <signal.h>
#include "navy.h"
char *format_it(char *str)
{
int i;
char c;
i = -1;
if (str == NULL)
return (str);
while (str[++i])
if (str[i] >= 'a' && str[i] <= 'z')
str[i] -= 32;
if (str[0] >= '0' && str[0] <= '9')
{
c = str[0];
str[0] = str[1];
str[1] = c;
}
return (str);
}
static void my_memclean(void *v, int n)
{
int i;
unsigned char *ptr;
ptr = v;
i = -1;
while (++i < n)
{
*ptr = 0;
ptr += 1;
}
}
void init_sig()
{
struct sigaction act;
my_memclean(&act, sizeof(act));
act.sa_sigaction = &receive_signal;
act.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &act, NULL);
sigaction(SIGUSR2, &act, NULL);
}
static void init_var()
{
GAME.me.pid = getpid();
GAME.enemy.pid = 0;
GAME.receive_x = 0;
GAME.receive_y = 0;
GAME.receive_nbr = 0;
GAME.send_x = 100;
GAME.send_y = 100;
GAME.me.hit = 0;
GAME.enemy.hit = 0;
}
void init_game()
{
int i;
int j;
init_sig();
init_var();
i = 0;
while (i <= 7)
{
j = 0;
while (j <= 7)
{
GAME.me.map[i][j] = '.';
GAME.enemy.map[i][j] = '.';
j += 1;
}
GAME.me.map[i][j] = 0;
GAME.enemy.map[i][j] = 0;
i += 1;
}
}