glimmer-dsl-swt 4.20.13.14 → 4.20.13.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e7f58c70a78eb8867dd0116be71fb75a3a369deeb7f5676c673dde098304d55
4
- data.tar.gz: '078a62bf56f74b1e156ef520d39c37e15b2324367bd813d0dd6a2a3f66e52e2d'
3
+ metadata.gz: 41658f842e145c053d12a6b5b07d93607523a2400092aa2fe0d1017d2683fa93
4
+ data.tar.gz: c5fc77baf99b69ebe8f06f7550feed02a47adcb2417cca0e205be0182f4a22c6
5
5
  SHA512:
6
- metadata.gz: 4bb4fc88a86497ce00a50735ee2c189d9fdfb1698e8fa568e1ddad2565809d40e8602bf309fd29efc933481fe3f7d142c50ba80ee7d571dd2eb7c6d0e4dba405
7
- data.tar.gz: c43f3edbc949886f21029c429229b73b4f5c08a89af9f7ad42a02539de8a8bc842eff606ccd090609fe05802cc9685499390bd1997f813be714e730ba2f8f801
6
+ metadata.gz: bd12243a6229d64c56dc1a7fd18717b50f02e873d3d3e3c0088e6c95f86791d2f0f719efc4f02769097eceaa3e0c791044c2e0ec85d1d85ee6ec3f6edc4b612d
7
+ data.tar.gz: f25ea6a7597d29aa16d095b886ce6d0a5d367a4523c9fadd726c093f7f5ec7d2e4aed18f9666d9871b3b5403c0250502e8c6178545166ceedd10c5c663d2a1c5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.20.14.0
4
+
5
+ - Change `arrow` widget default SWT style to include `:down`
6
+ - Hello, Arrow! sample
7
+
8
+ ### 4.20.13.17
9
+
10
+ - Hello, Slider! sample
11
+
12
+ ### 4.20.13.16
13
+
14
+ - Fix issue with setting app name (via `Display.app_name=`) when app is not packaged (always gets set to Glimmer)
15
+ - Fix Hello, Custom Shell! sample
16
+
17
+ ### 4.20.13.15
18
+
19
+ - Battleship elaborate sample
20
+
3
21
  ### 4.20.13.14
4
22
 
5
23
  - Connect 4 elaborate sample
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.20.13.14
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.20.14.0
2
2
  ## JRuby Desktop Development GUI Framework
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
4
4
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
@@ -15,7 +15,7 @@
15
15
  [<img src="https://covers.oreillystatic.com/images/9780596519650/lrg.jpg" width=105 /><br />
16
16
  Featured in JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do) and [Chalmers/Gothenburg University Software Engineering Master's Lecture Material](http://www.cse.chalmers.se/~bergert/slides/guest_lecture_DSLs.pdf)
17
17
 
18
- [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.13.14 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
18
+ [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.14.0 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (please report any issues you may encounter).
19
19
 
20
20
  **Starting in version 4.20.0.0, [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) comes with the new [***Shine***](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax** for highly intuitive and visually expressive View/Model Attribute Mapping, relying on `<=>` for bidirectional (two-way) data-binding and `<=` for unidirectional (one-way) data-binding, providing an alternative to the `bind` keyword (keep in mind that it is still a beta, so default back to `bind` whenever needed).
21
21
 
@@ -199,11 +199,6 @@ Glimmer app:
199
199
 
200
200
  [![Math Bowling App Screenshot](https://raw.githubusercontent.com/AndyObtiva/MathBowling/master/Math-Bowling-Screenshot.png)](https://github.com/AndyObtiva/MathBowling)
201
201
 
202
- **Note:** I offer Glimmer DSL for SWT as a free and open-source [Ruby Gem](https://rubygems.org/gems/glimmer-dsl-swt) that represents my interests in Ruby Programming, Desktop GUI application development with SWT, Object Oriented Design, Design Patterns, and Software Architecture.
203
- Additionally, I am sharing my professional experience and expertise in Eclipse SWT given that I am an [EclipseCon](http://andymaleh.blogspot.com/2007/03/eclipsecon-2007-day-3.html)/[EclipseWorld](http://andymaleh.blogspot.com/2008/11/eclipseworld-2008-highlights.html) presenter and have built professional applications in SWT/JFace/RCP for Obtiva and the Pampered Chef in the past. This is also done in the hopes that it would indirectly bring me work in a field I am extremely passionate about.
204
- That said, please keep in mind that I myself am learning topics in Software Engineering too everyday, including newer editions of SWT and JRuby, which seem to pop up every quarter.
205
- If you see anything that needs to be improved, please do not hesitate to contact me on [Gitter](https://gitter.im/AndyObtiva/glimmer) or submit [Issues](https://github.com/AndyObtiva/glimmer-dsl-swt/issues)/[Pull-Requests](https://github.com/AndyObtiva/glimmer-dsl-swt/pulls).
206
-
207
202
  ## Table of contents
208
203
 
209
204
  - [Glimmer (JRuby Desktop Development GUI Framework)](#jruby-desktop-development-gui-framework)
@@ -326,7 +321,7 @@ jgem install glimmer-dsl-swt
326
321
 
327
322
  Or this command if you want a specific version:
328
323
  ```
329
- jgem install glimmer-dsl-swt -v 4.20.13.14
324
+ jgem install glimmer-dsl-swt -v 4.20.14.0
330
325
  ```
331
326
 
332
327
  `jgem` is JRuby's version of `gem` command.
@@ -354,7 +349,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
354
349
 
355
350
  Add the following to `Gemfile`:
356
351
  ```
357
- gem 'glimmer-dsl-swt', '~> 4.20.13.14'
352
+ gem 'glimmer-dsl-swt', '~> 4.20.14.0'
358
353
  ```
359
354
 
360
355
  And, then run:
@@ -375,7 +370,7 @@ glimmer
375
370
  ```
376
371
 
377
372
  ```
378
- Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.13.14
373
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.14.0
379
374
 
380
375
  Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
381
376
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.20.13.14
1
+ 4.20.13.18
@@ -19,6 +19,7 @@
19
19
  - [Hello, Drag and Drop!](#hello-drag-and-drop)
20
20
  - [Hello, Menu Bar!](#hello-menu-bar)
21
21
  - [Hello, Pop Up Context Menu!](#hello-pop-up-context-menu)
22
+ - [Hello, Arrow!](#hello-arrow)
22
23
  - [Hello, Custom Widget!](#hello-custom-widget)
23
24
  - [Hello, Custom Shell!](#hello-custom-shell)
24
25
  - [Hello, Sash Form!](#hello-sash-form)
@@ -33,6 +34,7 @@
33
34
  - [Hello, File Dialog!](#hello-file-dialog)
34
35
  - [Hello, Date Time!](#hello-date-time)
35
36
  - [Hello, Scale!](#hello-scale)
37
+ - [Hello, Slider!](#hello-slider)
36
38
  - [Hello, Spinner!](#hello-spinner)
37
39
  - [Hello, Table!](#hello-table)
38
40
  - [Hello, Link!](#hello-link)
@@ -65,6 +67,7 @@
65
67
  - [Game of Life](#game-of-life)
66
68
  - [Glimmer Tetris](#glimmer-tetris)
67
69
  - [Klondike Solitaire](#klondike-solitaire)
70
+ - [Battleship](#battleship)
68
71
  - [Mandelbrot Fractal](#mandelbrot-fractal)
69
72
  - [Parking](#parking)
70
73
  - [Stock Ticker](#stock-ticker)
@@ -74,6 +77,7 @@
74
77
  - [Glimmer Calculator](#glimmer-calculator)
75
78
  - [Gladiator](#gladiator)
76
79
  - [Timer](#timer)
80
+ - [Glimmer Klondike Solitaire](#glimmer-klondike-solitaire)
77
81
  - [License](#license)
78
82
 
79
83
  ## Samples
@@ -397,6 +401,20 @@ Code:
397
401
  ![Hello Pop Up Context Menu](/images/glimmer-hello-pop-up-context-menu.png)
398
402
  ![Hello Pop Up Context Menu Popped Up](/images/glimmer-hello-pop-up-context-menu-popped-up.png)
399
403
 
404
+ #### Hello, Arrow!
405
+
406
+ This sample demonstrates `arrow` button (aka `button(:arrow)`).
407
+
408
+ Code:
409
+
410
+ [samples/hello/hello_arrow.rb](/samples/hello/hello_arrow.rb)
411
+
412
+ ![Hello Arrow](/images/glimmer-hello-arrow.png)
413
+
414
+ ![Hello Arrow Menu](/images/glimmer-hello-arrow-menu.png)
415
+
416
+ ![Hello Arrow Item Selected](/images/glimmer-hello-arrow-item-selected.png)
417
+
400
418
  #### Hello, Custom Widget!
401
419
 
402
420
  This sample demonstrates the use of a custom widget in Glimmer.
@@ -612,6 +630,18 @@ Hello, Scale!
612
630
 
613
631
  ![Hello Scale](/images/glimmer-hello-scale.png)
614
632
 
633
+ #### Hello, Slider!
634
+
635
+ This sample demonstrates the use of `slider` widget in Glimmer
636
+
637
+ Code:
638
+
639
+ [samples/hello/hello_slider.rb](/samples/hello/hello_slider.rb)
640
+
641
+ Hello, Slider!
642
+
643
+ ![Hello Slider](/images/glimmer-hello-slider.png)
644
+
615
645
  #### Hello, Spinner!
616
646
 
617
647
  This sample demonstrates the use of `spinner` widget in Glimmer
@@ -1066,7 +1096,7 @@ Connect 4 - Dropped Coin
1066
1096
 
1067
1097
  ![Connect 4 Dropped Coin](/images/glimmer-connect4-dropped-coin.png)
1068
1098
 
1069
- Connect 4 - Player 1 Wins
1099
+ Connect 4 - Player 1 Wins (keeps the coin about to drop visual cue)
1070
1100
 
1071
1101
  ![Connect 4 Player 1 Wins](/images/glimmer-connect4-player1-wins.png)
1072
1102
 
@@ -1142,7 +1172,7 @@ Code:
1142
1172
 
1143
1173
  #### Klondike Solitaire
1144
1174
 
1145
- This sample demonstrates how to build an interactive card game with MVC architecture, canvas, custom-shapes, data-binding, observers, and drag & drop.
1175
+ This sample demonstrates how to build an interactive card game with MVC architecture, canvas, custom-shapes, data-binding, observers, and canvas shape drag & drop.
1146
1176
 
1147
1177
  Code:
1148
1178
 
@@ -1152,6 +1182,26 @@ Code:
1152
1182
 
1153
1183
  ![Klondike Solitaire Played](/images/glimmer-klondike-solitaire-played.png)
1154
1184
 
1185
+ Check out a souped up large-card-size packaged version of the game in the [Glimmer Klondike Solitaire](#glimmer-klondike-solitaire) external sample.
1186
+
1187
+ #### Battleship
1188
+
1189
+ This sample demonstrates how to build an interactive board game with A.I., MVC architecture, hybrid canvas widget/shape approach, custom-widgets, data-binding, observers, and widget drag & drop.
1190
+
1191
+ Code:
1192
+
1193
+ [samples/elaborate/battleship.rb](/samples/elaborate/battleship.rb)
1194
+
1195
+ ![Battleship](/images/glimmer-battleship.png)
1196
+
1197
+ ![Battleship Placement](/images/glimmer-battleship-placement.png)
1198
+
1199
+ ![Battleship Ready for Battle](/images/glimmer-battleship-ready-for-battle.png)
1200
+
1201
+ ![Battleship Won](/images/glimmer-battleship-won.png)
1202
+
1203
+ ![Battleship Game Over](/images/glimmer-battleship-game-over.png)
1204
+
1155
1205
  #### Mandelbrot Fractal
1156
1206
 
1157
1207
  This sample demonstrates how to render canvas graphics with multi-threaded processing taking advantage of all CPU cores and doing background processing of images.
@@ -1275,6 +1325,14 @@ Gladiator is a good demonstration of:
1275
1325
 
1276
1326
  [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-timer/master/glimmer-timer-screenshot.png" />](https://github.com/AndyObtiva/glimmer-cs-timer)
1277
1327
 
1328
+ #### Glimmer Klondike Solitaire
1329
+
1330
+ This is a souped up version of the Klondike Solitaire elaborate sample, which is built as an external application to enable packaging as a native executable installer. Enjoy!
1331
+
1332
+ [<img alt="Glimmer Klondike Solitaire Icon" src="https://raw.githubusercontent.com/AndyObtiva/glimmer_klondike_solitaire/master/package/linux/Glimmer%20Klondike%20Solitaire.png" height=40 /> Glimmer Klondike Solitaire](https://github.com/AndyObtiva/glimmer_klondike_solitaire)
1333
+
1334
+ ![Glimmer Klondike Solitaire](https://raw.githubusercontent.com/AndyObtiva/glimmer_klondike_solitaire/master/images/glimmer-klondike-solitaire.png)
1335
+
1278
1336
  ## License
1279
1337
 
1280
1338
  [MIT](LICENSE.txt)
Binary file
@@ -200,12 +200,14 @@ module Glimmer
200
200
  elsif observation_request.start_with?('on_')
201
201
  event_name = observation_request.sub(/^on_/, '')
202
202
  if OBSERVED_MENU_ITEMS.include?(event_name) && OS.mac?
203
- system_menu = swt_display.getSystemMenu
204
- menu_item = system_menu.getItems.find {|menu_item| menu_item.getID == SWTProxy["ID_#{event_name.upcase}"]}
205
- listener = ConcreteListener.new(&block)
206
- display_mac_event_registration = menu_item.addListener(SWTProxy[:Selection], listener)
207
- Glimmer::UI::CustomWidget.current_custom_widgets.last&.observer_registrations&.push(display_mac_event_registration)
208
- display_mac_event_registration
203
+ auto_exec do
204
+ system_menu = swt_display.getSystemMenu
205
+ menu_item = system_menu.getItems.find {|menu_item| menu_item.getID == SWTProxy["ID_#{event_name.upcase}"]}
206
+ listener = ConcreteListener.new(&block)
207
+ display_mac_event_registration = menu_item.addListener(SWTProxy[:Selection], listener)
208
+ Glimmer::UI::CustomWidget.current_custom_widgets.last&.observer_registrations&.push(display_mac_event_registration)
209
+ display_mac_event_registration
210
+ end
209
211
  end
210
212
  end
211
213
  end
@@ -48,7 +48,7 @@ module Glimmer
48
48
  include Custom::Drawable
49
49
 
50
50
  DEFAULT_STYLES = {
51
- 'arrow' => [:arrow],
51
+ 'arrow' => [:arrow, :down],
52
52
  'button' => [:push],
53
53
  'canvas' => ([:double_buffered] unless OS.mac?),
54
54
  'ccombo' => [:border],
@@ -30,8 +30,8 @@ module Glimmer
30
30
 
31
31
  class << self
32
32
  def launch(*args, &content)
33
+ launched_custom_shell = send(keyword, *args, &content)
33
34
  auto_exec do
34
- launched_custom_shell = send(keyword, *args, &content)
35
35
  launched_custom_shell.swt_widget.set_data('launched', true)
36
36
  launched_custom_shell.open
37
37
  end
@@ -176,16 +176,16 @@ module Glimmer
176
176
  options ||= {}
177
177
  @options = self.class.options.merge(options)
178
178
  @content = Util::ProcTracker.new(content) if content
179
- execute_hook('before_body')
179
+ auto_exec { execute_hook('before_body') }
180
180
  body_block = self.class.instance_variable_get("@body_block")
181
181
  raise Glimmer::Error, 'Invalid custom widget for having no body! Please define body block!' if body_block.nil?
182
- @body_root = instance_exec(&body_block)
182
+ @body_root = auto_exec { instance_exec(&body_block) }
183
183
  raise Glimmer::Error, 'Invalid custom widget for having an empty body! Please fill body block!' if @body_root.nil?
184
184
  @swt_widget = @body_root.swt_widget
185
185
  auto_exec do
186
186
  @swt_widget.set_data('custom_widget', self)
187
187
  end
188
- execute_hook('after_body')
188
+ auto_exec { execute_hook('after_body') }
189
189
  auto_exec do
190
190
  @dispose_listener_registration = @body_root.on_widget_disposed do
191
191
  observer_registrations.compact.each(&:deregister)
@@ -0,0 +1,79 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer-dsl-swt'
23
+ require 'facets/string/titlecase'
24
+ require 'facets/string/underscore'
25
+
26
+ require_relative 'battleship/model/game'
27
+
28
+ require_relative 'battleship/view/grid'
29
+ require_relative 'battleship/view/ship_collection'
30
+ require_relative 'battleship/view/action_panel'
31
+
32
+ class Battleship
33
+ include Glimmer::UI::CustomShell
34
+
35
+ COLOR_WATER = rgb(156, 211, 219)
36
+ COLOR_SHIP = :dark_gray
37
+
38
+ before_body do
39
+ @game = Model::Game.new
40
+ end
41
+
42
+ after_body do
43
+ observe(@game, :over) do |game_over_value|
44
+ if game_over_value
45
+ game_over_message = if game_over_value == :you
46
+ "Game over!\nYou Won!"
47
+ else
48
+ "Game over!\nYou Lost!"
49
+ end
50
+
51
+ message_box {
52
+ text 'Game Over!'
53
+ message game_over_message
54
+ }.open
55
+ end
56
+ end
57
+ end
58
+
59
+ body {
60
+ shell(:no_resize) {
61
+ grid_layout(2, false) {
62
+ horizontal_spacing 15
63
+ vertical_spacing 15
64
+ }
65
+
66
+ text 'Glimmer Battleship'
67
+
68
+ @enemy_grid = grid(game: @game, player: :enemy)
69
+ @enemy_ship_collection = ship_collection(game: @game, player: :enemy)
70
+
71
+ @player_grid = grid(game: @game, player: :you)
72
+ @player_ship_collection = ship_collection(game: @game, player: :you)
73
+
74
+ action_panel(game: @game)
75
+ }
76
+ }
77
+ end
78
+
79
+ Battleship.launch
@@ -0,0 +1,84 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Battleship
23
+ module Model
24
+ class Cell
25
+ attr_reader :grid, :row_index, :column_index
26
+ attr_accessor :hit, :ship, :ship_index
27
+ alias hit? hit
28
+
29
+ def initialize(grid, row_index, column_index)
30
+ @grid = grid
31
+ @row_index = row_index
32
+ @column_index = column_index
33
+ end
34
+
35
+ def reset!
36
+ self.hit = nil
37
+ self.ship = nil
38
+ self.ship_index = nil
39
+ end
40
+
41
+ # Places ship horizontally so that its top left cell is self,
42
+ # automatically figuring out the rest of the cells
43
+ def place_ship!(ship)
44
+ begin
45
+ old_ship_top_left_cell = ship.top_left_cell
46
+ old_ship_orientation = ship.orientation
47
+ ship.top_left_cell = self
48
+ if old_ship_top_left_cell
49
+ ship.cells(old_ship_orientation).each(&:reset!)
50
+ ship.length.times do |index|
51
+ if ship.orientation == :horizontal
52
+ old_cell = grid.cell_rows[old_ship_top_left_cell.row_index][old_ship_top_left_cell.column_index + index]
53
+ else
54
+ old_cell = grid.cell_rows[old_ship_top_left_cell.row_index + index][old_ship_top_left_cell.column_index]
55
+ end
56
+ old_cell.reset!
57
+ end
58
+ end
59
+ ship.length.times do |index|
60
+ if ship.orientation == :horizontal
61
+ cell = grid.cell_rows[row_index][column_index + index]
62
+ else
63
+ cell = grid.cell_rows[row_index + index][column_index]
64
+ end
65
+ cell.ship = ship
66
+ cell.ship_index = index
67
+ end
68
+ rescue => e
69
+ Glimmer::Config.logger.debug(e.full_message)
70
+ end
71
+ end
72
+
73
+ def hit=(value)
74
+ @hit = value
75
+ ship&.sunk = true if ship&.all_cells_hit?
76
+ grid.game.over = grid.game.opposite_player(grid.player) if grid.game.started? && grid.game.ship_collections[grid.player].ships.values.map(&:sunk).all?
77
+ end
78
+
79
+ def to_s
80
+ "#{(Grid::ROW_ALPHABETS[row_index])}#{(column_index + 1)}"
81
+ end
82
+ end
83
+ end
84
+ end