Class: TriviaCrack::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/triviacrack/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, opponent: nil, game_status: nil, language: nil, created: nil, last_turn: nil, type: nil, expiration_date: nil, my_turn: nil, round_number: nil, is_random: nil, unread_messages: nil, status_version: nil, available_crowns: nil, questions: nil, my_statistics: nil, opponent_statistics: nil) ⇒ Game

Returns a new instance of Game.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/triviacrack/game.rb', line 61

def initialize(id:, opponent: nil, game_status: nil, language: nil,
               created: nil, last_turn: nil, type: nil,
               expiration_date: nil, my_turn: nil, round_number: nil,
               is_random: nil, unread_messages: nil, status_version: nil,
               available_crowns: nil, questions: nil, my_statistics: nil,
               opponent_statistics: nil)
  @id                   = id
  @opponent             = opponent
  @game_status          = game_status
  @language             = language
  @created              = created
  @last_turn            = last_turn
  @type                 = type
  @expiration_date      = expiration_date
  @my_turn              = my_turn
  @round_number         = round_number
  @is_random            = is_random
  @unread_messages      = unread_messages
  @status_version       = status_version
  @available_crowns     = available_crowns
  @questions            = questions
  @my_statistics        = my_statistics
  @opponent_statistics  = opponent_statistics
end

Instance Attribute Details

#available_crownsObject (readonly)

Public: Array of available crowns that can be won by the user.



49
50
51
# File 'lib/triviacrack/game.rb', line 49

def available_crowns
  @available_crowns
end

#createdObject (readonly)

Public: The datetime on which the game was created.



21
22
23
# File 'lib/triviacrack/game.rb', line 21

def created
  @created
end

#expiration_dateObject (readonly)

Public: The datetime on which the game will expire.



30
31
32
# File 'lib/triviacrack/game.rb', line 30

def expiration_date
  @expiration_date
end

#game_statusObject (readonly)

Public: The current status of the game (e.g. :active, :ended, :pending_approval).



15
16
17
# File 'lib/triviacrack/game.rb', line 15

def game_status
  @game_status
end

#idObject (readonly)

Public: The unique identifier of the game.



8
9
10
# File 'lib/triviacrack/game.rb', line 8

def id
  @id
end

#is_randomObject (readonly)

Public: Boolean indicating whether the game was created with a random opponent.



40
41
42
# File 'lib/triviacrack/game.rb', line 40

def is_random
  @is_random
end

#languageObject (readonly)

Public: The language used for the game (e.g. :en).



18
19
20
# File 'lib/triviacrack/game.rb', line 18

def language
  @language
end

#last_turnObject (readonly)

Public: The datetime on which the last turn was taken.



24
25
26
# File 'lib/triviacrack/game.rb', line 24

def last_turn
  @last_turn
end

#my_statisticsObject (readonly)

Public: TriviaCrack::GameStatistics for the user.



56
57
58
# File 'lib/triviacrack/game.rb', line 56

def my_statistics
  @my_statistics
end

#my_turnObject (readonly)

Public: Boolean indicating whether it is the user’s turn.



33
34
35
# File 'lib/triviacrack/game.rb', line 33

def my_turn
  @my_turn
end

#opponentObject (readonly)

Public: The TriviaCrack::User information for the opponent.



11
12
13
# File 'lib/triviacrack/game.rb', line 11

def opponent
  @opponent
end

#opponent_statisticsObject (readonly)

Public: TriviaCrack::GameStatistics for the opponent.



59
60
61
# File 'lib/triviacrack/game.rb', line 59

def opponent_statistics
  @opponent_statistics
end

#questionsObject (readonly)

Public: Array of questions that can be answered by the user. This array will be empty if the user is unable to play (i.e. not their turn).



53
54
55
# File 'lib/triviacrack/game.rb', line 53

def questions
  @questions
end

#round_numberObject (readonly)

Public: The number of the current round.



36
37
38
# File 'lib/triviacrack/game.rb', line 36

def round_number
  @round_number
end

#status_versionObject (readonly)

Public: The status version.



46
47
48
# File 'lib/triviacrack/game.rb', line 46

def status_version
  @status_version
end

#typeObject (readonly)

Public: The type of the game (:normal, :duel)



27
28
29
# File 'lib/triviacrack/game.rb', line 27

def type
  @type
end

#unread_messagesObject (readonly)

Public: Number of unread messages.



43
44
45
# File 'lib/triviacrack/game.rb', line 43

def unread_messages
  @unread_messages
end

Instance Method Details

#playable?Boolean

Public: Returns true if the game has not ended and it is the user’s turn.

Examples

if game.playable?
  ... do something ...
end

Returns a boolean indicating if the game is playable.

Returns:

  • (Boolean)


95
96
97
# File 'lib/triviacrack/game.rb', line 95

def playable?
  @my_turn && @game_status != :ended
end