-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.rb
59 lines (55 loc) · 1.33 KB
/
player.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require './scopa.rb'
class Player
def initialize
@hand = []
@scopas = []
end
def give_a_card card
@hand << card
end
def number_the_cards_in_the_hand
@hand.count
end
def take_a_card_of_hand position
card = @hand[position]
@hand.delete_at position
card
end
def give_back_the_card card
take_a_card_of_hand card
end
def scopa(card,mesa, cartas)
soma = @hand[card].value_for_escopa
cartas.each { |card| the_card = mesa.look_card(card); the_card_value = the_card.value_for_escopa; soma = soma + the_card_value }
if soma == 15
my_card = take_a_card_of_hand card
cards_for_scopa = [my_card]
cards_from_board = []
cartas.each { |card| the_card = mesa.look_card(card); cards_from_board << the_card ;}
cards_from_board.each { |card| mesa.give_a_card card }
cards_for_scopa << cards_from_board
cards_for_scopa.flatten!
scopa = Scopa.new(cards_for_scopa)
@scopas << scopa
end
end
def number_of_scopas
@scopas.count
end
def score
pontos = 0
@scopas.each{|scopa| pontos += 1}
if number_of_seven() == 4
pontos += 3
end
pontos
end
def number_of_seven
sevens = 0
@hand.each{|card| sevens +=1 if card.value_for_escopa == 7}
@scopas.each { |scopa_list| cards = scopa_list.cards();
cards.each { |card| sevens +=1 if card.value_for_escopa == 7 }
}
sevens
end
end