forked from mendicant-original/s6-e2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Massive patch. This is an example of how not to do revision control
- Loading branch information
1 parent
2c02a37
commit afa4970
Showing
22 changed files
with
274 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- IvoryTower::Map is poorly tested. | ||
- IvoryTower::Map has several opportunities for refactoring. | ||
- Most tiles are only lightly tested. | ||
- Text based UI is horrible | ||
- IvoryTower::Monsters::BlindMouse completely untested | ||
- IvoryTower::Towers::ArrowTower limited testing | ||
- Many missing features and validations in core engine | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
require "mocha" | ||
|
||
require_relative "ivory_tower/errors" | ||
require_relative "ivory_tower/allowed_units" | ||
require_relative "ivory_tower/tile" | ||
require_relative "ivory_tower/map" | ||
require_relative "ivory_tower/towers" | ||
require_relative "ivory_tower/monsters" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require_relative "monsters/blind_mouse" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module IvoryTower | ||
module Monsters | ||
class BlindMouse | ||
MOVE_FREQUENCY = 2 | ||
|
||
def initialize(map) | ||
@map = map | ||
@health = 5 | ||
end | ||
|
||
attr_reader :map | ||
attr_accessor :location, :health | ||
|
||
def defend_against(tower) | ||
self.health = [0, health - tower.weapon_power].max | ||
|
||
die if health == 0 | ||
end | ||
|
||
def move_on_tick?(tick) | ||
(tick % MOVE_FREQUENCY) == 0 | ||
end | ||
|
||
def move(params) | ||
return unless move_on_tick?(params[:tick]) | ||
|
||
remove_from_current_tile | ||
|
||
neighbors = map.neighbors_of(location, distance: 1) | ||
next_tile = neighbors.select { |e| e.allows?(:ground_units) }.sample | ||
|
||
map[*next_tile.location] << self | ||
end | ||
|
||
def remove_from_current_tile | ||
@map[*location].occupants.delete(self) | ||
end | ||
|
||
alias_method :die, :remove_from_current_tile | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ module Tile | |
class Sea | ||
include AllowedUnits | ||
allows :sea_units | ||
attr_accessor :map_symbol, :location | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require_relative "towers/arrow_tower" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module IvoryTower | ||
module Towers | ||
class ArrowTower | ||
FIRE_FREQUENCY = 3 | ||
WEAPON_POWER = 1 | ||
|
||
def initialize(map) | ||
@map = map | ||
end | ||
|
||
attr_reader :map | ||
attr_accessor :location | ||
|
||
def fire(params) | ||
return unless fire_on_tick?(params[:tick]) | ||
|
||
monster = target_monster | ||
return unless monster | ||
|
||
monster.defend_against(self) | ||
end | ||
|
||
def fire_on_tick?(tick) | ||
(tick % FIRE_FREQUENCY) == 0 | ||
end | ||
|
||
def weapon_power | ||
WEAPON_POWER | ||
end | ||
|
||
def target_monster | ||
tile = target_tile | ||
return unless tile | ||
|
||
tile.occupants.sample | ||
end | ||
|
||
def target_tile | ||
neighbors = map.neighbors_of(location, distance: 1) | ||
neighbors.find { |t| t.occupied? } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,6 @@ | |
|
||
# hack to replace later | ||
def new_monster | ||
Object.new | ||
mock(:die => nil) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,6 @@ | |
|
||
# hack to be replaced later | ||
def new_monster | ||
Object.new | ||
mock(:location= => nil) | ||
end | ||
end |
Oops, something went wrong.