Class: GamesParadise::Godmode::Player

Inherits:
Base
  • Object
show all
Defined in:
lib/games_paradise/godmode/player.rb

Overview

GamesParadise::Godmode::Player

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
MAXIMUM_NUMBER_OF_GLADIATORS =
#

MAXIMUM_NUMBER_OF_GLADIATORS

#
5
MAXIMUM_NUMBER_SIDE_GLADIATORS =
#

MAXIMUM_NUMBER_SIDE_GLADIATORS

#
12

Constants inherited from Base

Base::CONTROL_C_CODE, Base::N

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cat, #commandline_arguments?, #efancy, #eparse, #first_argument?, #forestgreen, #gold, #lightblue, #lightgreen, #mediumorchid, #mediumslateblue, #opnn, #peru, #register_sigint, #rev, #royalblue, #set_commandline_arguments, #sfile, #steelblue, #teal, #tomato, #yellow

Methods included from BaseModule

#cliner, #commandline_arguments?, #first_argument?, #infer_the_namespace, #namespace?, #rename_file, #reset_the_internal_hash, #return_pwd, #set_commandline_arguments

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ Player

#

initialize

#


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/games_paradise/godmode/player.rb', line 48

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  set_name(first_argument?)
  run if run_already
end

Instance Attribute Details

#array_storing_gladiatorsObject

Returns the value of attribute array_storing_gladiators.



41
42
43
# File 'lib/games_paradise/godmode/player.rb', line 41

def array_storing_gladiators
  @array_storing_gladiators
end

#n_gold_coinsObject

Returns the value of attribute n_gold_coins.



43
44
45
# File 'lib/games_paradise/godmode/player.rb', line 43

def n_gold_coins
  @n_gold_coins
end

#n_slavesObject

Returns the value of attribute n_slaves.



42
43
44
# File 'lib/games_paradise/godmode/player.rb', line 42

def n_slaves
  @n_slaves
end

#player_nameObject

Returns the value of attribute player_name.



40
41
42
# File 'lib/games_paradise/godmode/player.rb', line 40

def player_name
  @player_name
end

Class Method Details

.[](i = '') ⇒ Object

#

GamesParadise::Godmode::Player[]

#


173
174
175
# File 'lib/games_paradise/godmode/player.rb', line 173

def self.[](i = '')
  new(i)
end

Instance Method Details

#add_main_gladiator(i = Gladiator.new) ⇒ Object

#

add_main_gladiator

Use only this method when appending to @array_storing_gladiators Reason for this constraint is that we disallow to have more than MAXIMUM_NUMBER_OF_GLADIATORS.

#


148
149
150
151
152
153
154
155
# File 'lib/games_paradise/godmode/player.rb', line 148

def add_main_gladiator(i = Gladiator.new)
  if @array_storing_main_gladiators.size == MAXIMUM_NUMBER_OF_GLADIATORS
    warn 'You can not add any more Gladiator as the limit of '+
          MAXIMUM_NUMBER_OF_GLADIATORS.to_s+' was already reached.'
  else
    @array_storing_main_gladiators << i
  end
end

#add_side_gladiator(i = Gladiator.new) ⇒ Object

#

add_side_gladiator

#


113
114
115
116
117
118
119
120
121
122
# File 'lib/games_paradise/godmode/player.rb', line 113

def add_side_gladiator(
    i = Gladiator.new
  )
  if @array_storing_side_gladiators.size == MAXIMUM_NUMBER_SIDE_GLADIATORS
    ewarn 'You can not add any more Gladiator as the limit of '+
           MAXIMUM_NUMBER_SIDE_GLADIATORS.to_s+' was already reached.'
  else
    @array_storing_side_gladiators << i
  end
end

#deduct_n_gold_coins(i) ⇒ Object

#

decut_n_gold_coins

This method will deduct some gold coins.

#


96
97
98
99
100
101
# File 'lib/games_paradise/godmode/player.rb', line 96

def deduct_n_gold_coins(i)
  @n_gold_coins -= i.to_i
  if @n_gold_coins < 0
    @n_gold_coins = 0
  end
end

#get_nameObject

#

get_name

this gets player name.

#


129
130
131
132
# File 'lib/games_paradise/godmode/player.rb', line 129

def get_name
  e 'Input your name now please:'
  @player_name = STDIN.gets.chomp.my_cap
end

#n_gladiators?Boolean

#

n_gladiators?

#

Returns:

  • (Boolean)


137
138
139
# File 'lib/games_paradise/godmode/player.rb', line 137

def n_gladiators?
  e "You have #{@array_storing_gladiators.size} Gladiators."
end

#name?Boolean

#

name?

#

Returns:

  • (Boolean)


160
161
162
# File 'lib/games_paradise/godmode/player.rb', line 160

def name?
  @name
end

#resetObject

#

reset (reset tag)

#


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/games_paradise/godmode/player.rb', line 63

def reset
  super()
  # ======================================================================= #
  # === @n_gold_coins
  #
  # This variable keeps track as to how many gold coins a given player
  # has.
  # ======================================================================= #
  @n_gold_coins = 1000+rand(101)
  # ======================================================================= #
  # === @n_slaves
  #
  # How many slaves this player (the merchant) owns. This has to be 0
  # initially, for a clean game state.
  # ======================================================================= #
  @n_slaves = 0
  # ======================================================================= #
  # === @array_storing_main_gladiators
  # ======================================================================= #
  @array_storing_main_gladiators = []
  # ======================================================================= #
  # === @array_storing_side_gladiators
  # ======================================================================= #
  @array_storing_side_gladiators = []
  add_main_gladiator
  add_side_gladiator
end

#runObject

#

run (run tag)

#


167
168
# File 'lib/games_paradise/godmode/player.rb', line 167

def run
end

#set_name(i) ⇒ Object

#

set_name

#


106
107
108
# File 'lib/games_paradise/godmode/player.rb', line 106

def set_name(i)
  @name = i
end