Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Die Funktionsweise des Skripts muss nicht geändert werden, nur outputs und inputs sind von Dialog betroffen
- array=(0 0 0 0)
- wantedarray=(0 0 0 0)
- is=0
- r=0
- for ((s=0; s<4; s++))
- do
- wantedarray[s]=$(($RANDOM % 10))
- for ((o=s-1; o>=0; o--))
- do
- if ((${wantedarray[s]}==${wantedarray[o]}))
- then
- let s=$s-1
- fi
- done
- done
- for ((i=0; i<8; i++))
- do
- let v=$i+1
- is=0
- r=0
- dialog --msgbox "\033[33mVersuch $v\033[0m" 20 50
- dialog --clear
- number=$(dialog --inputbox "Bitte gib deinen naechsten Versuch ein:" 20 50 ""\ 3>&1 1>&2 2>&3)
- dialog --clear
- for ((j=0; j<4; j++))
- do
- array[j]=${number:j:1}
- done
- for ((k=0; k<4; k++))
- do
- if ((array[k]==wantedarray[k]))
- then
- ((r++))
- fi
- for ((l=0; l<4; l++))
- do
- if ((wantedarray[k]==array[l]))
- then
- ((is++))
- break
- fi
- done
- done
- dialog --msgbox "There are $is numbers in the wanted number" 20 50
- dialog --msgbox "There are $r numbers at the right place" 20 50
- dialog --clear
- if (($r==4))
- then
- dialog --msgbox "\033[32mCongratulations, you won\033[0m" 20 50
- dialog --msgbox "\033[31mThe right number is ${wantedarray[*]}\033[0m" 20 50
- dialog --clear
- break
- else
- dialog --msgbox "\033[31mSorry, try again\033[0m" 20 50
- dialog --clear
- fi
- done
- if (($r!=4))
- then
- dialog --msgbox "\033[31mSorry you lose\033[0m" 20 50
- dialog --msgbox "\033[31mThe right number is ${wantedarray[*]}\033[0m" 20 50
- dialog --clear
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement