-
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.
Add Trap and concept of health points Location specification when changing levels - simulate multi level map
- Loading branch information
David Henry
committed
Feb 12, 2012
1 parent
8b77e20
commit 78809b6
Showing
51 changed files
with
1,504 additions
and
348 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
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,38 +1,35 @@ | ||
class Game | ||
class Engine | ||
attr_reader :state, :player | ||
include Game::Modules::InstanceSetter | ||
|
||
attr_reader :state, :player, :message | ||
|
||
def initialize | ||
@map = Game::Map.load_map('maps/level1') | ||
super | ||
@state = 'Running' | ||
@player = Player.new | ||
@player.load_map(@map) | ||
load_map Game::Map.load_map('maps/level1') | ||
end | ||
|
||
def load_map(map) | ||
@map = map | ||
@player.load_map @map | ||
end | ||
|
||
def map | ||
@map | ||
end | ||
|
||
def take_turn | ||
if @player.location.has_object?(Game::Object::Exit) | ||
begin | ||
@map = Game::Map.load_map("maps/#{@map.next}") | ||
@player.load_map(@map) | ||
rescue NoMethodError | ||
@ended = true | ||
end | ||
end | ||
end | ||
|
||
def skip_to(name) | ||
@map = Game::Map.load_map("maps/#{name}") | ||
@player.load_map(@map) | ||
rescue NoMethodError | ||
@ended = true | ||
end | ||
|
||
def ended? | ||
!!@ended | ||
end | ||
|
||
def end(message) | ||
@ended = true | ||
@message = message | ||
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Game | ||
class Location | ||
class Edge | ||
include Game::Location::Base | ||
include Game::Location::Impassible | ||
|
||
def self.instance | ||
@self ||= new | ||
end | ||
|
||
def initialize; 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class Game | ||
class Location | ||
module Movement | ||
def at(direction) | ||
tile = Game::Location.at(@x - 1, @y) if direction == :up | ||
tile = Game::Location.at(@x + 1, @y) if direction == :down | ||
tile = Game::Location.at(@x, @y - 1) if direction == :left | ||
tile = Game::Location.at(@x, @y + 1) if direction == :right | ||
|
||
tile.try(:end_point) || Game::Location::Edge.instance | ||
end | ||
|
||
def end_point | ||
if has_object?(Game::Object::LocationModifier) | ||
Game::Location.at(*get_object(Game::Object::LocationModifier).end_point) | ||
else | ||
self | ||
end | ||
end | ||
private :end_point | ||
end | ||
|
||
module Impassible | ||
def passible?(player_objects) | ||
false | ||
end | ||
end | ||
|
||
module Passible | ||
def passible?(player_objects) | ||
true | ||
end | ||
end | ||
|
||
module Base | ||
def self.included(base) | ||
base.send :attr_accessor, :location_type | ||
base.send :attr_reader, :objects, :x, :y | ||
end | ||
|
||
def initialize(location_type, x, y) | ||
@location_type = location_type | ||
@x = x | ||
@y = y | ||
@objects = [] | ||
end | ||
|
||
def ==(val) | ||
location_type == val.location_type && | ||
x == val.x && | ||
y == val.y | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Game | ||
class Location | ||
class Wall | ||
include Game::Modules::ObjectManagement | ||
include Game::Location::Base | ||
include Game::Location::Movement | ||
|
||
def passible?(player_objects) | ||
return false unless has_object?(Game::Object::Passage) | ||
passage = get_object(Game::Object::Passage) | ||
return true if passage.passible? | ||
key = player_objects.detect{|obj| obj.id == passage.id} | ||
passage.open if key | ||
key.try(:use) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'lib/game/modules/object_management' | ||
require 'lib/game/modules/try_helper' | ||
require 'lib/game/modules/instance_setter' |
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,23 @@ | ||
class Game | ||
module Modules | ||
module InstanceSetter | ||
def self.included(base) | ||
base.extend ClassMethods | ||
end | ||
|
||
def initialize(*args) | ||
self.class.set(self) | ||
end | ||
|
||
module ClassMethods | ||
def set(instance) | ||
@instance = instance | ||
end | ||
|
||
def instance | ||
@instance | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Game | ||
module Modules | ||
module ObjectManagement | ||
def add(object) | ||
@objects << object | ||
end | ||
|
||
def remove(object) | ||
@objects.delete(object) | ||
end | ||
|
||
def has_object?(object_class) | ||
!!@objects.detect { |object| object.is_a?(object_class) } | ||
end | ||
|
||
def get_object(object_class) | ||
@objects.detect { |object| object.is_a?(object_class) } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Game | ||
module Modules | ||
module TryHelper | ||
def try(method, *args, &block) | ||
return nil if self.nil? | ||
send(method, *args, &block) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Object.send :include, Game::Modules::TryHelper |
Oops, something went wrong.