| Home/Info (English) | Startseite (Deutsch) | Posts | Links |

Bash Game Update!

(Dieser Post enthält Deutsch und Englisch zusammen!)

(This post contains both English and German Text!)

I remembered I made a bash game not too long ago, and decided to look through the code again - and it wasnt very good :/ so I redid it!

Ich habe mich erinnert, dass ich ein Bash-Spiel gemacht habe, und dann sah ich das Code wieder - und es war nicht sehr gut :/ darum habe ich ein neues Skript gemacht! :D

#!/bin/bash #choose random x to be the question number- make sure x is factorable initloop () { x=$((RANDOM)) factor $x | grep -qE '^(.*): \1$' && initloop || echo "Your number is: $x" } #keep dividing x by n until you factor down x to a prime, which is a win, and the game is over #selecting a number that is not a factor of your current x is a loss, and also exits the game gameloop () { #First Question read -p "Find a unique factor to divide $x by - " n remainder=$(($x%$n)) #Unique factor requirement (([ $n == $x ] || [ $n == 1 ]) && (read -p " Too easy, no cheating! Find a unique factor to divide $x by - " n))|| #the actual game loop case $remainder in 0) x=$(($x/$n));factor $x | grep -qE '^(.*): \1$' && (echo "Awesome job! You factored the number down to a prime and won! :D ";sleep 1;exit) || gameloop ;; *) (echo "Sorry, you just lost... $n was not a factor of $x. D:";sleep 1;exit) ;; esac } initloop gameloop