Class: Player

Inherits:
Object
  • Object
show all
Defined in:
lib/software_challenge_client/player.rb

Overview

A player, participating in a game

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color, name) ⇒ Player

Initializer

Parameters:

  • color (PlayerColor)

    the new player’s color

  • name (String)

    the new player’s name (for displaying)



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

def initialize(color, name)
  @color = color
  @name = name
  @points = 0
  @velocity = 1
  @movement = 1
  @coal = 6
  @passengers = 0
  @direction = Direction::RIGHT
end

Instance Attribute Details

#coalInteger

Returns the player’s current coal supply.

Returns:

  • (Integer)

    the player’s current coal supply



23
24
25
# File 'lib/software_challenge_client/player.rb', line 23

def coal
  @coal
end

#colorPlayerColor (readonly)

Returns the player’s color.

Returns:



11
12
13
# File 'lib/software_challenge_client/player.rb', line 11

def color
  @color
end

#directionDirection

Returns the player’s current direction.

Returns:

  • (Direction)

    the player’s current direction



27
28
29
# File 'lib/software_challenge_client/player.rb', line 27

def direction
  @direction
end

#movementDirection

Returns the player’s current movement points.

Returns:

  • (Direction)

    the player’s current movement points



39
40
41
# File 'lib/software_challenge_client/player.rb', line 39

def movement
  @movement
end

#nameString (readonly)

Returns the player’s name.

Returns:

  • (String)

    the player’s name



7
8
9
# File 'lib/software_challenge_client/player.rb', line 7

def name
  @name
end

#passengersInteger

Returns how many passengers the player’s has picked up.

Returns:

  • (Integer)

    how many passengers the player’s has picked up



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

def passengers
  @passengers
end

#pointsInteger

Returns the player’s points.

Returns:

  • (Integer)

    the player’s points



15
16
17
# File 'lib/software_challenge_client/player.rb', line 15

def points
  @points
end

#velocityInteger

Returns the player’s current velocity.

Returns:

  • (Integer)

    the player’s current velocity



19
20
21
# File 'lib/software_challenge_client/player.rb', line 19

def velocity
  @velocity
end

#xInteger

Returns the player’s current x-position.

Returns:

  • (Integer)

    the player’s current x-position



31
32
33
# File 'lib/software_challenge_client/player.rb', line 31

def x
  @x
end

#yInteger

Returns the player’s current y-position.

Returns:

  • (Integer)

    the player’s current y-position



35
36
37
# File 'lib/software_challenge_client/player.rb', line 35

def y
  @y
end

Instance Method Details

#==(other) ⇒ Object



59
60
61
# File 'lib/software_challenge_client/player.rb', line 59

def ==(other)
  color == other.color
end