-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.c
More file actions
139 lines (114 loc) · 3.73 KB
/
function.c
File metadata and controls
139 lines (114 loc) · 3.73 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "header.h"
//Funzione principale che racchiude tutto il gioco
int spaceInvadersGame ()
{
int direzioneGlobale=1;
pid_t p_cannone; //Processo del cannone terrestre
pid_t p_navicelleAliene[NUMERO_ALIENI];
pid_t p_navicelleAlieneLivello2[NUMERO_ALIENI];
int w, h, i, j;
//Inizializzo le pipe
int pTutto[2];
int pAlieni[NUMERO_ALIENI][2];
initscr();
noecho(); //Nascondo i caratteri da tastiera
keypad(stdscr, true);
getmaxyx(stdscr, h, w);
curs_set(0); //Nascondo il cursore
srand(time(NULL));
//Inizializzo con la funzione pipe la pipe
if(pipe(pTutto) == -1){
exit(EXIT_FAILURE);
}
for (j = 0; j < NUMERO_ALIENI; ++j) {
if(pipe(pAlieni[j]) == -1){
exit(EXIT_FAILURE);
}
}
//Implementazione 1 ad 1
//Avvio il processo del cannone che dovrò comandare
p_cannone = fork();
switch (p_cannone) {
case -1:
exit(EXIT_FAILURE);
case 0:
close(pTutto[LETTURA]);
cannoneTerrestre(pTutto[SCRITTURA]);
break;
default:
break;
}
generoProcessiAlieni(p_navicelleAliene, NUMERO_ALIENI, pTutto, pAlieni, &direzioneGlobale);
close(pTutto[SCRITTURA]);
terraControllo(pTutto[LETTURA], p_navicelleAliene, pTutto[SCRITTURA], p_navicelleAlieneLivello2, &direzioneGlobale);
clear();
//Uccido i processi dei due nemici e del personaggio controllato dall'utente
kill(p_cannone,SIGKILL);
killerProcessiAlieni(p_navicelleAliene, NUMERO_ALIENI);
// endwin();
gameOver();
return 0;
}
int mainMenu (){
int h,w; //Dichiaro altezza e larghezza dello schermo
int tasto;
initscr();
noecho(); //Nascondo i caratteri da tastiera
keypad(stdscr, true);
getmaxyx(stdscr, h, w);
curs_set(0); //Nascondo il cursore
srand(time(NULL));
start_color();
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2, COLOR_BLUE, COLOR_BLACK);
init_pair(3, COLOR_WHITE, COLOR_BLACK);
attron(COLOR_PAIR(1));
mvprintw(h/4, w/2-30, "BENVENUTO SU SPACE INVADERS by Fabio Piscitelli e Lorenzo Giua");
mvprintw(h/2-2, w/2-12, "Per giocare premi SPAZIO");
mvprintw(h/2, w/2-12, "Per USCIRE premi Q");
while(true){
switch (tasto = getch()) {
case TASTO_USCIRE:
endwin();
exit(-1);
break;
case KEY_SPACE:
endwin();
return EXIT_SUCCESS;
}
}
}
//Gestisco la stampa del messaggio alla fine del gioco
int gameOver(){
int i, h, w;
char gameOverWrite[GAME_OVER_ALTEZZA][GAME_OVER_LARGHEZZA] = {" ____ _ __ __ _____ _____ _______ ____",
" / ___| / \\ | \\/ | ____| / _ \\ \\ / / ____| _ \\",
" | | _ / _ \\ | |\\/| | _| | | | \\ \\ / /| _| | |_) |",
" | |_| |/ ___ \\| | | | |___ | |_| |\\ V / | |___| _ <",
" \\____/_/ \\_\\_| |_|_____| \\___/ \\_/ |_____|_| \\_\\"};
getmaxyx(stdscr, h, w);
for (i = 0; i < GAME_OVER_ALTEZZA; i++) {
mvprintw(h / 2 - GAME_OVER_ALTEZZA - 1 + i, (w / 2) - (GAME_OVER_LARGHEZZA / 2), gameOverWrite[i]);
}
mvprintw(h / 2 + 1, (w / 2) - 8, "(press %c to quit)", TASTO_USCIRE);
refresh();
while (getch() != TASTO_USCIRE);
endwin();
return EXIT_SUCCESS;
}
//Funzione che restituisce il valore massimo tra i due inseriti
int max(int num1, int num2)
{
if(num1 >= num2)
return num1;
else
return num2;
}
//Funzione che restituisce il valore minimo tra i due inseriti
int min(int num1, int num2)
{
if(num1 <= num2)
return num1;
else
return num2;
}