Class: AI
- Inherits:
-
Object
- Object
- AI
- Defined in:
- lib/ruby-ai/ai.rb
Overview
Add your own AI code here. You have two methods at your disposal:
look(direction)
use :up, :down, :left, :right, or nothing as your direction
returns the tile in the specified direction, or the tile the player is currently standing on
move(direction)
use :up, :down, :left, or :right as your direction
moves the player in the specified direction
You can cheat pretty easily if you like, but it’s not as fun that way.
Instance Attribute Summary collapse
-
#player ⇒ Object
readonly
Returns the value of attribute player.
Instance Method Summary collapse
-
#initialize(player) ⇒ AI
constructor
A new instance of AI.
- #level(num) ⇒ Object
Constructor Details
#initialize(player) ⇒ AI
Returns a new instance of AI.
16 17 18 |
# File 'lib/ruby-ai/ai.rb', line 16 def initialize(player) @player = player end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object (private)
this method is required to allow method calls directly to player object exa. move(:up) vs player.move(:up)
28 29 30 |
# File 'lib/ruby-ai/ai.rb', line 28 def method_missing(m, *args) player.send(m, *args) end |
Instance Attribute Details
#player ⇒ Object (readonly)
Returns the value of attribute player.
14 15 16 |
# File 'lib/ruby-ai/ai.rb', line 14 def player @player end |
Instance Method Details
#level(num) ⇒ Object
20 21 22 |
# File 'lib/ruby-ai/ai.rb', line 20 def level(num) puts 'Add your own code to ai.rb' end |