connect_four_2301 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: a9773a767de66c3b76bee7bea6e39862ab2ab99b42f2e15db2616c2d46525652
4
- data.tar.gz: a77e8bdbaa6ffb4aa8fb136bb910f0f0d650ff90a58ef9e637155b2d1a43fbdf
3
+ metadata.gz: f7808b77c5bd080bae1a9e91714f39186c942cac807a97182d216106af8bbeff
4
+ data.tar.gz: 34b72faec9a286346b11c3511ba860bbc5de54e3190040d75f2eec3273a649dd
5
5
  SHA512:
6
- metadata.gz: e6dd6940b97e52561eac37bbd71782e83c91ec3b1c80e4d50a05fe69b0a5d407a7d83c5b5ade1a105dd233181433155cce671851753f00422a2e740d7e157a48
7
- data.tar.gz: d41178b66342d0ed3f7f1009ede23c5dde181cdfb2063c8358b6a7d3c16f6bb71f1af8a2d29e05406972536e9a76f0e0cda63e7b1a51765429b77f350494ef03
6
+ metadata.gz: 36108ffdffd9db2fa5d4609eb55d1ec532769e42aa8084a53265553faac555098f4230ca8c40e04eef1d0d990da7060bddb9ec0f78e8fd90249a10d3d2c0f207
7
+ data.tar.gz: 312b50f4258ef500a9fd29638d3d44408003475754cb5f778e008159180498ebf9bb0534f2597b0d90e5ccf28104c3e84e30ec7f38a618d3493a817bb85725cf
@@ -12,6 +12,7 @@ class Board
12
12
  end
13
13
 
14
14
  def initialize_board
15
+ @turns = []
15
16
  @slots = [*(1..6)].map do |row|
16
17
  [*(1..7)].map { |col| :white }
17
18
  end
@@ -91,7 +92,6 @@ class Board
91
92
  end
92
93
 
93
94
  def update
94
- initialize_board
95
95
  @turns.each { |turn| @slots[turn.row][turn.col] = turn.color }
96
96
  nil
97
97
  end
@@ -14,6 +14,9 @@ class Game
14
14
  Player.new('Player 2', :red, false)
15
15
  ]
16
16
  @board = Board.new
17
+ @starting_time = 0
18
+ @ending_time = 0
19
+ @recorded_times = []
17
20
  end
18
21
 
19
22
  def start
@@ -22,7 +25,9 @@ class Game
22
25
  end
23
26
 
24
27
  def play_game
28
+ @board.initialize_board
25
29
  @board.render
30
+ starting_time
26
31
  until game_over?
27
32
  @players.each do |player|
28
33
  break if game_over?
@@ -35,12 +40,26 @@ class Game
35
40
  end
36
41
  @board.next_turn(player.name, player.color, player.is_human?)
37
42
  @board.update
43
+ puts `clear`
38
44
  @board.render
39
45
  end
40
46
  end
47
+ ending_time
41
48
  game_over
42
49
  end
43
50
 
51
+ def play_2_player_game
52
+
53
+ end
54
+
55
+ def starting_time
56
+ @starting_time += Process.clock_gettime(Process::CLOCK_MONOTONIC)
57
+ end
58
+
59
+ def ending_time
60
+ @ending_time += Process.clock_gettime(Process::CLOCK_MONOTONIC)
61
+ end
62
+
44
63
  def game_over?
45
64
  @board.winner || @board.valid_columns.empty?
46
65
  end
@@ -52,19 +71,28 @@ class Game
52
71
  end
53
72
 
54
73
  def game_menu
55
- puts GAME_PLAY_PROMPT
74
+ puts " Please enter '1' for a 1 person game against the computer, or press '2' for a two person game, or pres 'Q' to exit out of the program."
56
75
  user_input = gets.chomp
57
- until user_input == 'p' || user_input == 'q'
58
- puts "Please enter one of the following: p or q"
76
+ until user_input == '1' || user_input == '2' || user_input == 'q'
77
+ puts " Please enter one of the following: 1, 2, or q"
59
78
  user_input = gets.chomp
60
79
  end
61
- if user_input == "p"
62
- puts " ...\n\n"
80
+ if user_input == '1'
81
+ puts " ...\n\n\n\n"
63
82
  sleep(1)
64
- puts " Ok. You will be the Blue block. Good luck!"
83
+ puts " Ok. You will be the Blue block. Good luck!"
65
84
  sleep(3)
66
85
  play_game
67
- elsif user_input == "q"
86
+ elsif user_input == '2'
87
+ puts " Player 1, please enter your name:"
88
+ player_1_name = gets.chomp.capitalize
89
+ puts " Player 2, please enter your name:"
90
+ player_2_name = gets.chomp.capitalize
91
+ player_1 = Player.new(player_1_name, :blue )
92
+ player_2 = Player.new(player_2_name, :red )
93
+ @players = [player_1, player_2]
94
+ play_game
95
+ else user_input == 'q'
68
96
  Process.exit!
69
97
  end
70
98
  end
@@ -78,10 +106,81 @@ class Game
78
106
  sleep(1)
79
107
  if @board.valid_columns.empty?
80
108
  puts DRAW_MESSAGE
109
+ sleep(1)
110
+ puts "\n\n\n\n\n"
111
+ puts elapsed_time
112
+ puts "\n\n\n\n\n"
113
+ play_again?
81
114
  elsif @players.find { |player| player.color == @board.winner }.is_human?
82
115
  puts HUMAN_WIN_MESSAGE
116
+ sleep(1)
117
+ puts "\n\n\n\n\n\n\n"
118
+ puts elapsed_time
119
+ puts "\n\n\n\n\n\n\n"
120
+ play_again?
83
121
  else
84
122
  puts COMPUTER_WIN_MESSAGE
123
+ sleep(1)
124
+ puts "\n\n\n\n\n\n\n"
125
+ puts elapsed_time
126
+ puts "\n\n\n\n\n\n\n"
127
+ play_again?
128
+ end
129
+ end
130
+
131
+ def play_again?
132
+ puts "Thanks for playing!"
133
+ puts "\n\n\n\n"
134
+ puts "If you would like to play again, enter 'Y'. If you would like to exit the game, enter 'Q'. "
135
+ user_input = gets.chomp.capitalize
136
+ if user_input == 'Y'
137
+ play_game
138
+ elsif user_input == 'Q'
139
+ Process.exit!
140
+ end
141
+ end
142
+
143
+ def elapsed_time
144
+ elapsed_time = @ending_time - @starting_time
145
+ if elapsed_time >= 60.00
146
+ time_in_minutes = elapsed_time.fdiv(60)
147
+ @recorded_times << time_in_minutes
148
+ puts "Wow, you finished the game in #{time_in_minutes.round(2)} minutes!"
149
+ puts "\n\n"
150
+ fastest_elapsed__time
151
+ puts "\n\n"
152
+ average_elapsed_time
153
+ elsif elapsed_time < 60.00
154
+ time_in_seconds = elapsed_time.round(2)
155
+ @recorded_times << time_in_seconds
156
+ puts "Wow that was fast! You finished the game in #{time_in_seconds} seconds!"
157
+ puts "\n\n"
158
+ fastest_elapsed__time
159
+ puts "\n\n"
160
+ average_elapsed_time
161
+ end
162
+ end
163
+
164
+ def average_elapsed_time
165
+ sum_of_times = @recorded_times.sum
166
+ num_of_times = @recorded_times.length
167
+ long_average_time = sum_of_times.fdiv(num_of_times)
168
+ average_time = long_average_time.round(2)
169
+ if average_time >= 60.00
170
+ puts "On average it took you #{average_time} minutes to finish a game."
171
+ end
172
+ if average_time < 60.00
173
+ puts "On average it took you #{average_time} seconds to finish a game."
174
+ end
175
+ end
176
+
177
+ def fastest_elapsed__time
178
+ fastest_time = @recorded_times.sort.first.round(2)
179
+ if fastest_time >= 60.00
180
+ puts "So far, your fastest time to finish the game is #{fastest_time} minutes."
181
+ end
182
+ if fastest_time < 60.00
183
+ puts "So far, your fastest time to finish the game is #{fastest_time} seconds."
85
184
  end
86
185
  end
87
186
  end
@@ -116,38 +116,8 @@ module Messages
116
116
  ╚═╝░░╚═╝  ╚═════╝░  ░╚════╝░  ╚═════╝░  ╚══════╝  ╚═╝░░░░░  ░╚═════╝░
117
117
  COLUMN
118
118
 
119
- GAME_PLAY_PROMPT = <<-PLAY_PROMPT
120
-
121
- ███████╗███╗░░██╗████████╗███████╗██████╗░  ██╗██████╗░██╗  ████████╗░█████╗░  ██████╗░██╗░░░░░░█████╗░██╗░░░██╗
122
- ██╔════╝████╗░██║╚══██╔══╝██╔════╝██╔══██╗  ╚█║██╔══██╗╚█║  ╚══██╔══╝██╔══██╗  ██╔══██╗██║░░░░░██╔══██╗╚██╗░██╔╝
123
- █████╗░░██╔██╗██║░░░██║░░░█████╗░░██████╔╝  ░╚╝██████╔╝░╚╝  ░░░██║░░░██║░░██║  ██████╔╝██║░░░░░███████║░╚████╔╝░
124
- ██╔══╝░░██║╚████║░░░██║░░░██╔══╝░░██╔══██╗  ░░░██╔═══╝░░░░  ░░░██║░░░██║░░██║  ██╔═══╝░██║░░░░░██╔══██║░░╚██╔╝░░
125
- ███████╗██║░╚███║░░░██║░░░███████╗██║░░██║  ░░░██║░░░░░░░░  ░░░██║░░░╚█████╔╝  ██║░░░░░███████╗██║░░██║░░░██║░░░
126
- ╚══════╝╚═╝░░╚══╝░░░╚═╝░░░╚══════╝╚═╝░░╚═╝  ░░░╚═╝░░░░░░░░  ░░░╚═╝░░░░╚════╝░  ╚═╝░░░░░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░
127
-
128
- ░█████╗░██████╗░
129
- ██╔══██╗██╔══██╗
130
- ██║░░██║██████╔╝
131
- ██║░░██║██╔══██╗
132
- ╚█████╔╝██║░░██║
133
- ░╚════╝░╚═╝░░╚═╝
134
-
135
-
136
- ███████╗███╗░░██╗████████╗███████╗██████╗░  ██╗░██████╗░██╗  ████████╗░█████╗░
137
- ██╔════╝████╗░██║╚══██╔══╝██╔════╝██╔══██╗  ╚█║██╔═══██╗╚█║  ╚══██╔══╝██╔══██╗
138
- █████╗░░██╔██╗██║░░░██║░░░█████╗░░██████╔╝  ░╚╝██║██╗██║░╚╝  ░░░██║░░░██║░░██║
139
- ██╔══╝░░██║╚████║░░░██║░░░██╔══╝░░██╔══██╗  ░░░╚██████╔╝░░░  ░░░██║░░░██║░░██║
140
- ███████╗██║░╚███║░░░██║░░░███████╗██║░░██║  ░░░░╚═██╔═╝░░░░  ░░░██║░░░╚█████╔╝
141
- ╚══════╝╚═╝░░╚══╝░░░╚═╝░░░╚══════╝╚═╝░░╚═╝  ░░░░░░╚═╝░░░░░░  ░░░╚═╝░░░░╚════╝░
142
-
143
- ░██████╗░██╗░░░██╗██╗████████╗
144
- ██╔═══██╗██║░░░██║██║╚══██╔══╝
145
- ██║██╗██║██║░░░██║██║░░░██║░░░
146
- ╚██████╔╝██║░░░██║██║░░░██║░░░
147
- ░╚═██╔═╝░╚██████╔╝██║░░░██║░░░
148
- ░░░╚═╝░░░░╚═════╝░╚═╝░░░╚═╝░░░
149
-
150
- PLAY_PROMPT
119
+
120
+
151
121
 
152
122
  BEEP_BOOP_BOP = <<-BEEP
153
123
  █▄▄ █▀▀ █▀▀ █▀█   █▄▄ █▀█ █▀█ █▀█   █▄▄ █▀█ █▀█
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConnectFour2301
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connect_four_2301
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Branden Ge