-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.rb
44 lines (36 loc) · 874 Bytes
/
player.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true
class Player
attr_reader :hp, :position
def initialize position:, hp: 2
@hp = hp
@position = position
@mines = 0
end
def alive?
@hp.positive?
end
def collect_mine
@mines += 1
end
def damage
@hp -= 1
alive?
end
def draw
puts "🪖 #{alive? ? '🛡' : '☠'} #{@hp}"
puts "🗃 inventory\n 💣: #{@mines}"
puts "⚑ objective: #{@goal}"
# 🛠 - tools to disasemble mines
end
def set_goal mines_total:
@goal ||= mines_total - @hp + 3
end
def check_goal
if @mines >= @goal
puts 'You have found enough mines. It is time to return to return to the flagship!'
else
puts 'You briefly looked into your backpack, there are not enough mines yet...'
puts ' but you cowardly flew away on the jetpack back to your spacecraft'
end
end
end