Class: Yahtzee::Controller

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

Overview

class API < Grape::API

version 'v1.1', using: :header, vendor: :yahtzee

end

Instance Method Summary collapse

Constructor Details

#initializeController

Returns a new instance of Controller



9
10
11
12
13
14
15
# File 'lib/yahtzee.rb', line 9

def initialize
  @message = ""
  
  @sc = Scorecard.new
  
  @turn = Turn.new
end

Instance Method Details

#get_dataObject



50
51
52
# File 'lib/yahtzee.rb', line 50

def get_data
  return @sc.get_cats
end

#get_diceObject



42
43
44
# File 'lib/yahtzee.rb', line 42

def get_dice
  return @turn.get_dice
end

#get_potentialObject



54
55
56
# File 'lib/yahtzee.rb', line 54

def get_potential
  return sc.calculate_dice @turn.get_dice
end

#next_turnObject



38
39
40
# File 'lib/yahtzee.rb', line 38

def next_turn
  @turn = Turn.new
end

#reroll(a) ⇒ Object



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

def reroll a
  @turn.reroll a
end

#rollObject



17
18
19
# File 'lib/yahtzee.rb', line 17

def roll
  @turn = Turn.new
end

#score(a) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/yahtzee.rb', line 25

def score a 
  case @sc.score a, @turn.get_dice, @turn.joker?
  when -1
    return -1
  when 0
    @turn.set_joker true
    return 0
  else
    next_turn
    return 1
  end
end

#set_dice(a) ⇒ Object



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

def set_dice a
  @turn.set_dice a
end