-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·59 lines (51 loc) · 1.3 KB
/
start.sh
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
#!/bin/bash
GAME_EXECUTABLE="./cub3D"
MAPS_DIRECTORY="maps"
MAP_PATH=""
EXIT_CODE=0
choose_map() {
echo "Available maps:"
map_files=($(ls -1 "$MAPS_DIRECTORY"))
# Print each map file on a new line
for i in "${!map_files[@]}"; do
echo "$((i + 1)). ${map_files[$i]}"
done
echo ""
# Select a map
while true; do
read -p "Select a map by number: " selection
if [[ $selection -gt 0 && $selection -le ${#map_files[@]} ]]; then
map_file="${map_files[$((selection - 1))]}"
echo "You selected the map: $map_file"
MAP_PATH="$MAPS_DIRECTORY/$map_file"
break
else
echo "Invalid selection. Please try again."
fi
done
}
compile_game() {
echo "Compiling the game..."
make
if [ $? -ne 0 ]; then
echo "Compilation failed. Exiting."
exit 1
fi
echo "Compilation successful."
}
main() {
compile_game
clear
while true; do
choose_map
echo "Starting the game with the selected map: $MAP_PATH"
$GAME_EXECUTABLE "$MAP_PATH"
EXIT_CODE=$?
if [ $EXIT_CODE -ne 42 ]; then
echo "Game has terminated with exit code: $EXIT_CODE"
break
fi
done
echo "Game has completely terminated."
}
main