Class: Gamefic::Tty::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic-tty/engine.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plot: Gamefic::Plot.new, user: Gamefic::Tty::User.new) ⇒ Engine

Returns a new instance of Engine.



8
9
10
11
12
13
14
# File 'lib/gamefic-tty/engine.rb', line 8

def initialize(plot: Gamefic::Plot.new, user: Gamefic::Tty::User.new)
  @plot = plot
  @user = user
  @character = @plot.get_player_character
  @plot.introduce @character
  @plot.ready
end

Instance Attribute Details

#characterObject (readonly)

Returns the value of attribute character.



6
7
8
# File 'lib/gamefic-tty/engine.rb', line 6

def character
  @character
end

#plotObject (readonly)

Returns the value of attribute plot.



4
5
6
# File 'lib/gamefic-tty/engine.rb', line 4

def plot
  @plot
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'lib/gamefic-tty/engine.rb', line 5

def user
  @user
end

Class Method Details

.run(**args) ⇒ Object



21
22
23
24
25
# File 'lib/gamefic-tty/engine.rb', line 21

def self.run **args
  engine = new(**args)
  engine.run
  engine
end

Instance Method Details

#runObject



16
17
18
19
# File 'lib/gamefic-tty/engine.rb', line 16

def run
  turn until @character.concluded?
  @user.update @character.output
end

#turnObject



27
28
29
30
31
# File 'lib/gamefic-tty/engine.rb', line 27

def turn
  send_and_receive
  @plot.update
  @plot.ready
end