Linux

All about Linux kernel and operating systems that are based on it.
[Random post]

 tags  gallery  RSS

16.5.2022 19:04:17

A quick fight game made in bash

#!/bin/bash
health=10
enemy=10
while [[ $health > 0 && $enemy > 0 ]]
do
echo You: $health
echo Enemy: $enemy
input=
while [[ $input != 0 && $input != 1 ]]
do
echo "Pick a number (0-1)"
read input
if [[ $input != 0 && $input != 1 ]]; then
echo "Wrong input"
fi
done
hit=$(( $RANDOM % 2 ))
if [[ $input == $hit ]]; then
((enemy--))
else
((health--))
fi
done
if [[ $health == 0 ]]; then
echo "You Died"
else
echo "You defeated the beast"
fi

Save this as a file named fight.sh onto any linux system, chmod +x it, run it and have fun

 

Timeline speed: 1.00 posts per hour

 

You have reached the end...

THE END

login