-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse hunt source code
62 lines (46 loc) · 1.28 KB
/
mouse hunt source code
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
#!/bin/bash
echo "simple mouse hunt"
echo "made by stuffbymax"
echo "==================="
# Print a message
echo "Press enter to continue"
read
# Do something else
echo "Continuing the script"
# Define the track length
track_length=200
# Define the starting positions of the cat and mouse
cat_pos=0
mouse_pos=$(($track_length - 2)) # Initial mouse position (2 units away from the end)
# Define the characters for the cat and mouse
cat_char="C"
mouse_char="M"
# Define the dice roll function
function roll_dice {
echo $((1 + RANDOM % 6))
}
# Define the main game loop
while true; do
# Clear the screen
clear
# Print the track
printf "%${track_length}s\n" "Track"
printf "%${track_length}s\n" "|"
# Print the cat and mouse
printf "%${cat_pos}s" "$cat_char"
printf "%$(($mouse_pos - $cat_pos - 1))s" "$mouse_char"
printf "%$(($track_length - $mouse_pos))s\n" "|"
# Check if the cat has caught the mouse
if [ $cat_pos -ge $mouse_pos ]; then
echo "The cat caught the mouse!"
break # End the game
fi
# Wait for input from the user
read -n 1 -s -r -p "Press any key to roll the dice..."
# Roll the dice
roll=$(roll_dice)
# Update the cat's position
cat_pos=$(($cat_pos + $roll))
# Update the mouse's position
mouse_pos=$(($mouse_pos - $roll))
done