質問編集履歴

4

your_hand→you_hand

2019/06/26 12:48

投稿

tai_chi
tai_chi

スコア15

test CHANGED
File without changes
test CHANGED
@@ -76,7 +76,7 @@
76
76
 
77
77
 
78
78
 
79
- if your_hand == program_hand
79
+ if you_hand == program_hand
80
80
 
81
81
  puts "あいこで"
82
82
 

3

前提の編集

2019/06/26 12:48

投稿

tai_chi
tai_chi

スコア15

test CHANGED
File without changes
test CHANGED
@@ -8,11 +8,9 @@
8
8
 
9
9
  Rubyを勉強し始め、じゃんけんアプリを作っております。
10
10
 
11
+ classを使用しての書き換えです。
12
+
11
13
  通常の関数によるじゃんけんアプリの作成は、ネットの記事で理解しました。(https://qiita.com/aiorange19/items/dff465f9e7af5e996f13)
12
-
13
- classを使用して作成しておりますが、どうしてもわからないです。
14
-
15
- 他のクラスへのアクセス自体ができていない、もしくは設計自体がおかしいのか。。
16
14
 
17
15
 
18
16
 
@@ -41,8 +39,6 @@
41
39
  class You
42
40
 
43
41
  def hand
44
-
45
-
46
42
 
47
43
  puts "[0]グー\n[1]チョキ\n[2]パー"
48
44
 

2

you_handに統一

2019/06/26 12:44

投稿

tai_chi
tai_chi

スコア15

test CHANGED
File without changes
test CHANGED
@@ -46,7 +46,7 @@
46
46
 
47
47
  puts "[0]グー\n[1]チョキ\n[2]パー"
48
48
 
49
- your_hand = gets.to_i
49
+ you_hand = gets.to_i
50
50
 
51
51
 
52
52
 
@@ -70,11 +70,11 @@
70
70
 
71
71
  class Janken
72
72
 
73
- def pon(your_hand, program_hand)
73
+ def pon(you_hand, program_hand)
74
74
 
75
75
  jankens = ["グー", "チョキ", "パー"]
76
76
 
77
- puts "あなたの手:#{jankens[your_hand]}, プログラムの手:#{jankens[program_hand]}"
77
+ puts "あなたの手:#{jankens[you_hand]}, プログラムの手:#{jankens[program_hand]}"
78
78
 
79
79
 
80
80
 
@@ -86,11 +86,11 @@
86
86
 
87
87
  return true
88
88
 
89
- elsif (your_hand == 0 && program_hand == 1) ||
89
+ elsif (you_hand == 0 && program_hand == 1) ||
90
90
 
91
- (your_hand == 1 && program_hand == 2) ||
91
+ (you_hand == 1 && program_hand == 2) ||
92
92
 
93
- (your_hand == 2 && program_hand == 0)
93
+ (you_hand == 2 && program_hand == 0)
94
94
 
95
95
  puts "あなたの勝ちです"
96
96
 

1

your_hand, program_handに変数名を修正し、統一しました。

2019/06/26 12:40

投稿

tai_chi
tai_chi

スコア15

test CHANGED
File without changes
test CHANGED
@@ -46,7 +46,7 @@
46
46
 
47
47
  puts "[0]グー\n[1]チョキ\n[2]パー"
48
48
 
49
- player_hand = gets.to_i
49
+ your_hand = gets.to_i
50
50
 
51
51
 
52
52
 
@@ -70,23 +70,27 @@
70
70
 
71
71
  class Janken
72
72
 
73
- def pon(player_hand, enemy_hand)
73
+ def pon(your_hand, program_hand)
74
74
 
75
75
  jankens = ["グー", "チョキ", "パー"]
76
76
 
77
- puts "あなたの手:#{jankens[player_hand]}, プログラムの手:#{jankens[program_hand]}"
77
+ puts "あなたの手:#{jankens[your_hand]}, プログラムの手:#{jankens[program_hand]}"
78
78
 
79
79
 
80
80
 
81
81
 
82
82
 
83
- if player_hand == program_hand
83
+ if your_hand == program_hand
84
84
 
85
85
  puts "あいこで"
86
86
 
87
87
  return true
88
88
 
89
- elsif (player_hand == 0 && program_hand == 1) || (player_hand == 1 && program_hand == 2) || (player_hand == 2 && program_hand == 0)
89
+ elsif (your_hand == 0 && program_hand == 1) ||
90
+
91
+ (your_hand == 1 && program_hand == 2) ||
92
+
93
+ (your_hand == 2 && program_hand == 0)
90
94
 
91
95
  puts "あなたの勝ちです"
92
96