Class: PlayerClass

Inherits:
GridLayout show all
Defined in:
lib/games_paradise/schiffe_versenken/schiffe_versenken.rb

Overview

#

Nimmt die PlayerClass

#

Constant Summary

Constants inherited from GridLayout

GridLayout::N

Instance Attribute Summary collapse

Attributes inherited from GridLayout

#hash_grid, #owner

Instance Method Summary collapse

Methods inherited from GridLayout

#calculate_grid, #debug, #output_grid, #owner?, #randomly_place_ship, #randomly_shoot_at, #reset, #shoot_at, #win_the_game

Constructor Details

#initialize(name) ⇒ PlayerClass

initialize



219
220
221
222
223
224
225
226
227
228
# File 'lib/games_paradise/schiffe_versenken/schiffe_versenken.rb', line 219

def initialize(name)
  super()
  @player_name = name
  if @player_name.nil?
    @player_name = "TestPlayer" 
  else
    @player_name = name.my_cap
  end
  @computer = ''
end

Instance Attribute Details

#computerObject

Returns the value of attribute computer.



217
218
219
# File 'lib/games_paradise/schiffe_versenken/schiffe_versenken.rb', line 217

def computer
  @computer
end

Instance Method Details

#infoObject

#

info

#


243
244
245
# File 'lib/games_paradise/schiffe_versenken/schiffe_versenken.rb', line 243

def info
  puts "You are #{@player_name}."
end

#play_against_computerObject

#

lay_against_computer

#


250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/games_paradise/schiffe_versenken/schiffe_versenken.rb', line 250

def play_against_computer
  puts "Der Computer"
  @computer=GridLayout.new
  @computer.randomly_place_ship
  @computer.calculate_grid
  @computer.owner = 'Computer'
  puts @computer.owner?
  5.times { randomly_shoot_at(@computer) }
  # neu berechnen des grid
  @computer.calculate_grid
  puts "Der Computer Grid"    
  @computer.display_grid
end

#prepare_gameObject

#

Prepares the game. Right now it only randomly places a ship somewhere and calculates the grid. And starts the play_against_computer method.

#


234
235
236
237
238
# File 'lib/games_paradise/schiffe_versenken/schiffe_versenken.rb', line 234

def prepare_game
  randomly_place_ship
  calculate_grid
  play_against_computer
end