-
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.
move life force processing out of player class
- Loading branch information
David Henry
committed
Feb 15, 2012
1 parent
30ea64e
commit 030f1de
Showing
6 changed files
with
69 additions
and
26 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
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,17 @@ | ||
require 'lib/game/player/actions' | ||
require 'lib/game/player/life_force' | ||
require 'lib/game/player/movements' | ||
|
||
class Game | ||
class Player | ||
include Game::Modules::ObjectManagement | ||
include Game::Player::Actions | ||
include Game::Player::Movements | ||
include Game::Player::LifeForce | ||
include Game::Modules::InstanceSetter | ||
|
||
attr_accessor :tile | ||
attr_reader :objects | ||
attr_reader :hp | ||
|
||
def initialize(*args) | ||
super(*args) | ||
@objects = [] | ||
@hp = 100 | ||
end | ||
|
||
def damage(hp) | ||
if hp >= @hp | ||
@hp = 0 | ||
Game::Engine.instance.end('Unfortunately you died.') | ||
else | ||
@hp -= hp | ||
end | ||
end | ||
|
||
def heal(hp) | ||
@hp += hp | ||
return hp if @hp <= 100 | ||
used = hp - (@hp - 100) | ||
@hp = 100 | ||
used | ||
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,32 @@ | ||
class Game | ||
class Player | ||
module LifeForce | ||
|
||
def self.included(base) | ||
base.send :attr_reader, :hp | ||
end | ||
|
||
def initialize(*args) | ||
super | ||
@hp = 100 | ||
end | ||
|
||
def damage(hp) | ||
if hp >= @hp | ||
@hp = 0 | ||
Game::Engine.instance.end('Unfortunately you died.') | ||
else | ||
@hp -= hp | ||
end | ||
end | ||
|
||
def heal(hp) | ||
@hp += hp | ||
return hp if @hp <= 100 | ||
used = hp - (@hp - 100) | ||
@hp = 100 | ||
used | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Game | ||
class Tile | ||
module Base | ||
def self.included(base) | ||
base.send :attr_accessor, :tile_type | ||
base.send :attr_reader, :objects, :x, :y | ||
end | ||
|
||
def initialize(tile_type, x, y) | ||
super | ||
@tile_type = tile_type | ||
@x = x | ||
@y = y | ||
@objects = [] | ||
end | ||
|
||
def ==(val) | ||
tile_type == val.tile_type && | ||
x == val.x && | ||
y == val.y | ||
end | ||
end | ||
end | ||
end |