0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

簡単なジャンケン

Posted at

puts "最初はグー!じゃんけん。。。"
puts "【0】グー【1】ちょき【2】パー"

user_input = gets.to_i #ユーザーに選んでもらう(整数)to_i
computer = rand(3) #コンピュータの選択をランダムで0~2

if user_input >= 3 #3以上の数字が選ばれた際に出力して、以降の処理をストップする
    puts "0~2の数字を入力してください"
exit
end

puts "あなたは #{user_input}"
puts "computerは #{computer}"



if user_input == computer
    puts "あいこです。"

elsif (user_input == 0 && computer == 1) ||
 (user_input == 1 && computer == 2) ||
 (user_input == 2 && computer == 0) 
    puts "あなたの勝ちです"
#ジャンケン勝敗の3パターンを記載 &&(and) ||(or)の使い方

else
    puts "あなたの負けです"
    

end

#ユーザーが0~2を入力する
#判定する

#1.user_input == computer_input => あいこ
#2.user_input (勝ちパターン)
#3.

#結果を表示する



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?