Skip to content

Commit

Permalink
Merge pull request #11284 from tobymao/hex-market-dividend
Browse files Browse the repository at this point in the history
[Core] Add support for hex market movement to dividends
  • Loading branch information
crericha authored Oct 17, 2024
2 parents 011ed24 + 1047406 commit 51b327d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
4 changes: 2 additions & 2 deletions assets/app/view/game/dividend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def render
end
next if real_moves.zero?

"#{real_moves} #{dir}"
"#{real_moves} #{dir.tr('_', ' ')}"
end.compact.join(', ')

movement_str.empty? ? 'None' : movement_str
Expand Down Expand Up @@ -98,7 +98,7 @@ def render
textAlign: 'left',
},
}
share_props = { style: { width: '2.7rem' } }
share_props = { style: { width: '3rem' } }

if corporation_interest_penalty?(entity)
corporation_penalty = "#{entity.name} has " +
Expand Down
8 changes: 8 additions & 0 deletions lib/engine/step/dividend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ def change_share_price(entity, payout)
@game.stock_market.move_up(entity)
when :down
@game.stock_market.move_down(entity)
when :diagonally_up_left
@game.stock_market.move_diagonally_up_left(entity)
when :diagonally_up_right
@game.stock_market.move_diagonally_up_right(entity)
when :diagonally_down_left
@game.stock_market.move_diagonally_down_left(entity)
when :diagonally_down_right
@game.stock_market.move_diagonally_down_right(entity)
end
end
end
Expand Down
40 changes: 24 additions & 16 deletions lib/engine/stock_market.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,36 +122,36 @@ def left(corporation, coordinates)
@movement.left(corporation, coordinates)
end

def move_up_left_hex(corporation)
move(corporation, up_left_hex(corporation, corporation.share_price.coordinates))
def move_diagonally_up_left(corporation)
move(corporation, diagonally_up_left(corporation, corporation.share_price.coordinates))
end

def up_left_hex(corporation, coordinates)
@movement.up_left_hex(corporation, coordinates)
def diagonally_up_left(corporation, coordinates)
@movement.diagonally_up_left(corporation, coordinates)
end

def move_down_left_hex(corporation)
move(corporation, down_left_hex(corporation, corporation.share_price.coordinates))
def move_diagonally_down_left(corporation)
move(corporation, diagonally_down_left(corporation, corporation.share_price.coordinates))
end

def down_left_hex(corporation, coordinates)
@movement.down_left_hex(corporation, coordinates)
def diagonally_down_left(corporation, coordinates)
@movement.diagonally_down_left(corporation, coordinates)
end

def move_up_right_hex(corporation)
move(corporation, up_right_hex(corporation, corporation.share_price.coordinates))
def move_diagonally_up_right(corporation)
move(corporation, diagonally_up_right(corporation, corporation.share_price.coordinates))
end

def up_right_hex(corporation, coordinates)
@movement.up_right_hex(corporation, coordinates)
def diagonally_up_right(corporation, coordinates)
@movement.diagonally_up_right(corporation, coordinates)
end

def move_down_right_hex(corporation)
move(corporation, down_right_hex(corporation, corporation.share_price.coordinates))
def move_diagonally_down_right(corporation)
move(corporation, diagonally_down_right(corporation, corporation.share_price.coordinates))
end

def down_right_hex(corporation, coordinates)
@movement.down_right_hex(corporation, coordinates)
def diagonally_down_right(corporation, coordinates)
@movement.diagonally_down_right(corporation, coordinates)
end

def find_share_price(corporation, directions)
Expand All @@ -173,6 +173,14 @@ def find_relative_share_price(share, corporation, directions)
coordinates = down(corporation, coordinates)
when :up
coordinates = up(corporation, coordinates)
when :diagonally_up_left
coordinates = diagonally_up_left(corporation, coordinates)
when :diagonally_up_right
coordinates = diagonally_up_right(corporation, coordinates)
when :diagonally_down_left
coordinates = diagonally_down_left(corporation, coordinates)
when :diagonally_down_right
coordinates = diagonally_down_right(corporation, coordinates)
end
price = share_price(coordinates) || price
end
Expand Down
28 changes: 14 additions & 14 deletions lib/engine/stock_movement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ def up(corporation, coordinates)
raise NotImplementedError
end

def down_left_hex(_corporation, coordinates)
def diagonally_down_left(_corporation, coordinates)
raise NotImplementedError
end

def up_left_hex(_corporation, coordinates)
def diagonally_up_left(_corporation, coordinates)
raise NotImplementedError
end

def down_right_hex(_corporation, coordinates)
def diagonally_down_right(_corporation, coordinates)
raise NotImplementedError
end

def up_right_hex(_corporation, coordinates)
def diagnonally_up_right(_corporation, coordinates)
raise NotImplementedError
end
end
Expand Down Expand Up @@ -101,48 +101,48 @@ def up(corporation, coordinates)
class HexMovement < BaseMovement
def left(corporation, coordinates)
r, c = coordinates
new_coords = [r, c - 2]
new_coords = [r, c - 1]
return new_coords if share_price(new_coords)

@market.down_left_hex(corporation, coordinates)
@market.diagonally_down_left(corporation, coordinates)
end

def right(corporation, coordinates)
r, c = coordinates
new_coords = [r, c + 2]
new_coords = [r, c + 1]
return new_coords if share_price(new_coords)

@market.up_right_hex(corporation, coordinates)
@market.diagonally_up_right(corporation, coordinates)
end

def down_left_hex(_corporation, coordinates)
def diagonally_down_left(_corporation, coordinates)
r, c = coordinates
new_coords = [r + 1, c - 1]
new_coords = [r + 1, c]
x = share_price(new_coords)
return new_coords if x

coordinates
end

def up_left_hex(_corporation, coordinates)
def diagonally_up_left(_corporation, coordinates)
r, c = coordinates
new_coords = [r - 1, c - 1]
return new_coords if share_price(new_coords)

coordinates
end

def down_right_hex(_corporation, coordinates)
def diagonally_down_right(_corporation, coordinates)
r, c = coordinates
new_coords = [r + 1, c + 1]
return new_coords if share_price(new_coords)

coordinates
end

def up_right_hex(_corporation, coordinates)
def diagnonally_up_right(_corporation, coordinates)
r, c = coordinates
new_coords = [r - 1, c + 1]
new_coords = [r - 1, c]
return new_coords if share_price(new_coords)

coordinates
Expand Down
2 changes: 1 addition & 1 deletion public/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ text.number {

@media only screen and (min-width: 421px) {
#left {
width: 20rem;
width: 22rem;
margin-right: 1rem;
}
}
Expand Down

0 comments on commit 51b327d

Please sign in to comment.