Skip to content

Instantly share code, notes, and snippets.

@elderica
Created May 22, 2023 12:39
Show Gist options
  • Save elderica/bab50e31ad0242fa866371621cbb82be to your computer and use it in GitHub Desktop.
Save elderica/bab50e31ad0242fa866371621cbb82be to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eux
player_hand=$(
zenity --list \
--title "あなたの手は?" \
--column="手" \
"グー" \
"チョキ" \
"パー"
)
cpu_candidates=("グー" "チョキ" "パー")
h=$((RANDOM % 3))
cpu_hand="${cpu_candidates[h]}"
if [[ "${player_hand}" = "${cpu_hand}" ]]
then
zenity --error --text="あいこです"
else
if [[ "${player_hand}" = "グー" && "${cpu_hand}" = "チョキ" ]] || [[ "${player_hand}" = "チョキ" && "${cpu_hand}" = "パー" ]] || [[ "${player_hand}" = "パー" && "${cpu_hand}" = "グー" ]]
then
zenity --info --text="あなたは${player_hand}、CPUは${cpu_hand}。あなたの勝ちです!"
else
zenity --warning --text="あなたは${player_hand}、CPUは${cpu_hand}。あなたの負けです..."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment