Skip to content

Commit

Permalink
rename location to tile
Browse files Browse the repository at this point in the history
  • Loading branch information
David Henry committed Feb 13, 2012
1 parent a8388af commit adf501a
Show file tree
Hide file tree
Showing 42 changed files with 284 additions and 284 deletions.
2 changes: 1 addition & 1 deletion lib/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'lib/game/input'
require 'lib/game/player'
require 'lib/game/map'
require 'lib/game/location'
require 'lib/game/tile'
require 'lib/game/object'

require 'json'
Expand Down
11 changes: 0 additions & 11 deletions lib/game/location/empty.rb

This file was deleted.

23 changes: 0 additions & 23 deletions lib/game/location/movement.rb

This file was deleted.

8 changes: 4 additions & 4 deletions lib/game/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ def method_missing(method, *args, &blk)
super
end

def start_location
def start_tile
at(0, 0)
end

private
def build_data
Game::Location.clear
Game::Tile.clear
map = []
@map_data['data'].each_with_index do |row, x|
row_items = []
row.each_with_index do |location, y|
row_items << Game::Location.build(location, x, y)
row.each_with_index do |tile, y|
row_items << Game::Tile.build(tile, x, y)
end
map << row_items
end
Expand Down
2 changes: 1 addition & 1 deletion lib/game/modules/object_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Game
module Modules
module ObjectManagement
def add(object)
object.location = self
object.tile = self
@objects << object
end

Expand Down
2 changes: 1 addition & 1 deletion lib/game/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'lib/game/object/exit'
require 'lib/game/object/healer'
require 'lib/game/object/inventry_item'
require 'lib/game/object/location_modifier'
require 'lib/game/object/tile_modifier'
require 'lib/game/object/passage'
require 'lib/game/object/switcher'
require 'lib/game/object/setter'
Expand Down
2 changes: 1 addition & 1 deletion lib/game/object/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Game
class Object
module Default
def self.included(base)
base.send :attr_accessor, :location
base.send :attr_accessor, :tile
end

def initialize(options)
Expand Down
4 changes: 2 additions & 2 deletions lib/game/object/exit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Exit
def auto_process
if @options['next_map']
skip_to next_map
move_to if @options["exit_location"]
move_to if @options["exit_tile"]
else
Game::Engine.instance.end('Congratulations you have Won.')
end
Expand All @@ -21,7 +21,7 @@ def skip_to(name)
end

def move_to
Game::Player.instance.move_to(Game::Location.at(*exit_location))
Game::Player.instance.move_to(Game::Tile.at(*exit_tile))
end
private :move_to
end
Expand Down
2 changes: 1 addition & 1 deletion lib/game/object/healer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Object
module Healer
def auto_process
self.health -= Game::Player.instance.heal(health)
self.location.remove(self) if self.health == 0
self.tile.remove(self) if self.health == 0
end

def health
Expand Down
9 changes: 0 additions & 9 deletions lib/game/object/location_modifier.rb

This file was deleted.

9 changes: 9 additions & 0 deletions lib/game/object/tile_modifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Game
class Object
module TileModifier
def end_point
@options['end_point'] || raise('No end point set for tile modifier')
end
end
end
end
2 changes: 1 addition & 1 deletion lib/game/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Player
include Game::Player::Movements
include Game::Modules::InstanceSetter

attr_accessor :location
attr_accessor :tile
attr_reader :objects
attr_reader :hp

Expand Down
6 changes: 3 additions & 3 deletions lib/game/player/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Player
module Actions
def take_action
objects_to_pick_up.each do |obj|
location.remove(obj)
tile.remove(obj)
add(obj)
end
objects_to_responding_to(:process).each do |obj|
Expand All @@ -18,12 +18,12 @@ def take_auto_action
end

def objects_to_pick_up
location.objects.select {|obj| obj.is_a?(Game::Object::InventryItem) }
tile.objects.select {|obj| obj.is_a?(Game::Object::InventryItem) }
end
private :objects_to_pick_up

def objects_to_responding_to(method)
location.objects.select {|obj| obj.respond_to?(method) }
tile.objects.select {|obj| obj.respond_to?(method) }
end
private :objects_to_responding_to
end
Expand Down
18 changes: 9 additions & 9 deletions lib/game/player/movements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ def self.included(base)

def load_map(map)
@map = map
@location = @map.start_location
@location.add(self)
@tile = @map.start_tile
@tile.add(self)
end

def move(direction)
@direction = direction
new_location = @location.at(direction)
if new_location.passible?(objects)
move_to new_location
new_tile = @tile.at(direction)
if new_tile.passible?(objects)
move_to new_tile
take_auto_action
else
# beep or something here
print "\a"
end
end

def move_to(location)
@location.remove(self)
@location = location
@location.add(self)
def move_to(tile)
@tile.remove(self)
@tile = tile
@tile.add(self)
end
end
end
Expand Down
22 changes: 11 additions & 11 deletions lib/game/location.rb → lib/game/tile.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'lib/game/location/modules'
require 'lib/game/location/movement'
require 'lib/game/location/passible'
require 'lib/game/tile/modules'
require 'lib/game/tile/movement'
require 'lib/game/tile/passible'

require 'lib/game/location/edge'
require 'lib/game/location/empty'
require 'lib/game/location/wall'
require 'lib/game/tile/edge'
require 'lib/game/tile/empty'
require 'lib/game/tile/wall'

class Game
class Location
class Tile
EMPTY_CELL = 0
WALL_90 = 1
WALL_CORNER_LEFT = 4
Expand All @@ -16,13 +16,13 @@ class Location
WALL_0 = 3

class << self
def build(location_type, x, y)
def build(tile_type, x, y)
@board ||= {}
@board[[x, y]] = class_for(location_type).new(location_type, x, y)
@board[[x, y]] = class_for(tile_type).new(tile_type, x, y)
end

def class_for(location_type)
case location_type
def class_for(tile_type)
case tile_type
when WALL_0, WALL_90, WALL_CORNER_RIGHT,
WALL_CORNER_LEFT, WALL_CORNER
Wall
Expand Down
6 changes: 3 additions & 3 deletions lib/game/location/edge.rb → lib/game/tile/edge.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class Game
class Location
class Tile
class Edge
include Game::Location::Base
include Game::Location::Impassible
include Game::Tile::Base
include Game::Tile::Impassible

def self.instance
@self ||= new
Expand Down
11 changes: 11 additions & 0 deletions lib/game/tile/empty.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Game
class Tile
class Empty
include Game::Modules::ObjectManagement
include Game::Tile::Base
include Game::Tile::Passible
include Game::Tile::Movement

end
end
end
10 changes: 5 additions & 5 deletions lib/game/location/modules.rb → lib/game/tile/modules.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Game
class Location
class Tile
module Impassible
def passible?(player_objects)
false
Expand All @@ -14,19 +14,19 @@ def passible?(player_objects)

module Base
def self.included(base)
base.send :attr_accessor, :location_type
base.send :attr_accessor, :tile_type
base.send :attr_reader, :objects, :x, :y
end

def initialize(location_type, x, y)
@location_type = location_type
def initialize(tile_type, x, y)
@tile_type = tile_type
@x = x
@y = y
@objects = []
end

def ==(val)
location_type == val.location_type &&
tile_type == val.tile_type &&
x == val.x &&
y == val.y
end
Expand Down
23 changes: 23 additions & 0 deletions lib/game/tile/movement.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Game
class Tile
module Movement
def at(direction)
tile = Game::Tile.at(@x - 1, @y) if direction == :up
tile = Game::Tile.at(@x + 1, @y) if direction == :down
tile = Game::Tile.at(@x, @y - 1) if direction == :left
tile = Game::Tile.at(@x, @y + 1) if direction == :right

tile.try(:end_point) || Game::Tile::Edge.instance
end

def end_point
if has_object?(Game::Object::TileModifier)
Game::Tile.at(*get_object(Game::Object::TileModifier).end_point)
else
self
end
end
private :end_point
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Game
class Location
class Tile
module Passible
def passible?(player_objects)
objects.all?(&:passible?)
Expand Down
6 changes: 3 additions & 3 deletions lib/game/location/wall.rb → lib/game/tile/wall.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Game
class Location
class Tile
class Wall
include Game::Modules::ObjectManagement
include Game::Location::Base
include Game::Location::Movement
include Game::Tile::Base
include Game::Tile::Movement

def passible?(player_objects)
return false unless has_object?(Game::Object::Passage)
Expand Down
4 changes: 2 additions & 2 deletions lib/render/console/draw_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def draw_map(engine)
draw_board(engine.map.data)
draw_stats(engine.player)
draw_player(engine.player)
draw_tile(engine.player.location)
draw_tile(engine.player.tile)

system('clear')
@io.puts @output
Expand Down Expand Up @@ -66,7 +66,7 @@ def draw_player(player)

def draw_tile(tile)
objects = tile.objects.dup
append "Location: "
append "Tile: "
append " ", tile.class
append "Items: "
objects.each do |obj|
Expand Down
Loading

0 comments on commit adf501a

Please sign in to comment.