rpsalvin 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e5dc87069efaf563725fbc2c2dd7c4e5d56b91b
4
- data.tar.gz: 9e9e350d7b8c3032ea05ac6240abe420262c2ff5
3
+ metadata.gz: 7e708f2af0ab08c4aa0cb3766c7ab98c7a802c62
4
+ data.tar.gz: 3e1049e8d3eb625b9d7410ceba7651d63d138d22
5
5
  SHA512:
6
- metadata.gz: 72f799bda726d530054487b66c29f42989aa3a2572beb379c193c30306be81c51220515d3d36662745928a25b3a2c429e84724f97eb32efb9b41c7e4563c0f87
7
- data.tar.gz: eb05777d9ccd0abf10411786bcef879275397cd7959dc38fbecc930ab8bfec7373e67b878d784d66b6dddc633f2088af11085e16b796fe2e6dfd2328c4c8c627
6
+ metadata.gz: 88d08fa11f760f3689ee99764c743a828d7189db6185cc49f6049df9ef954aadc439e1a63de4d9f2cf86b80e3fddf967ff684e31d5e81c97248321622f1df44a
7
+ data.tar.gz: 56371a4329bb4132f3711b90dcd4a29adc9030ab5d93df46a12282cdaf67ba414567f06e7d5fb7bb34e5a322e7c6f26ee4b7d874bae2795d2dcb1d422f819aa0
data/game.rb ADDED
@@ -0,0 +1,79 @@
1
+ module Rpsalvin
2
+ class Game
3
+
4
+ def compute_winner
5
+ if @p_one.move == 1
6
+
7
+ if @p_two.move == 2
8
+ puts "#{@p_two.name} wins!!"
9
+ elsif @p_two.move == 3
10
+ puts "#{@p_one.name} wins!!"
11
+ else
12
+ puts "It's a tie."
13
+ end
14
+
15
+ elsif @p_one.move == 2
16
+
17
+ if @p_two.move == 1
18
+ puts "#{@p_one.name} wins!!"
19
+ elsif @p_two.move == 3
20
+ puts "#{@p_two.name} wins!!"
21
+ else
22
+ puts "It's a tie."
23
+ end
24
+
25
+ elsif @p_one.move == 3
26
+
27
+ if @p_two.move == 1
28
+ puts "#{@p_two.name} wins!!"
29
+ elsif @p_two.move == 2
30
+ puts "#{@p_one.name} wins!!"
31
+ else
32
+ puts "It's a tie."
33
+ end
34
+ end
35
+ end
36
+
37
+
38
+ def initialize(player_one)
39
+ @p_one = Player.new(player_one)
40
+ @p_two = Player.new("CPU")
41
+ @mode = 1
42
+ end
43
+
44
+ def initialize(player_one, player_two)
45
+ @p_one = Player.new(player_one)
46
+ @p_two = Player.new(player_two)
47
+ @mode = 2
48
+ end
49
+
50
+ def start_game()
51
+ if @mode == 1
52
+ while 1 do
53
+ puts "Type Q to quit, or A to play SINGLE PLAYER"
54
+ choice = gets.chomp
55
+ if choice == "Q"
56
+ break
57
+ end
58
+ print "#{@p_one.name()}, "
59
+ @p_one.make_move()
60
+ @p_two.set_move(rand(1..3))
61
+ self.compute_winner()
62
+ end
63
+ elsif @mode == 2
64
+ while 1 do
65
+ puts "Type Q to quit, or A to play TWO PLAYER"
66
+ choice = gets.chomp
67
+ if choice == "Q"
68
+ break
69
+ end
70
+ print "#{@p_one.name()}, "
71
+ @p_one.make_move()
72
+ print "#{@p_two.name()}, "
73
+ @p_two.make_move()
74
+ self.compute_winner()
75
+ end
76
+ end
77
+ end
78
+
79
+ end
@@ -1,5 +1,8 @@
1
1
  require "rpsalvin/version"
2
+ require "rpsalvin/player"
3
+ require "rpsalvin/game"
2
4
 
3
5
  module Rpsalvin
4
- # Your code goes here...
6
+ new_game = Game.new("Alvin", "Noob")
7
+ new_game.start_game()
5
8
  end
@@ -0,0 +1,29 @@
1
+ module Rpsalvin
2
+ class Player
3
+
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+
8
+ def make_move()
9
+ puts "Choose from the following options:"
10
+ puts "1. Rock"
11
+ puts "2. Paper"
12
+ puts "3. Scissors"
13
+ self.set_move(gets.chomp)
14
+ end
15
+
16
+ def set_move(move)
17
+ @move = move.to_i
18
+ end
19
+
20
+ def name()
21
+ @name
22
+ end
23
+
24
+ def move()
25
+ @move
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Rpsalvin
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpsalvin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alvin Li
@@ -69,7 +69,9 @@ files:
69
69
  - Rakefile
70
70
  - bin/console
71
71
  - bin/setup
72
+ - game.rb
72
73
  - lib/rpsalvin.rb
74
+ - lib/rpsalvin/player.rb
73
75
  - lib/rpsalvin/version.rb
74
76
  - rpsalvin.gemspec
75
77
  homepage: ''