197 lines
5.6 KiB
GDScript
197 lines
5.6 KiB
GDScript
extends Node2D
|
|
|
|
@onready var card_manager = $CardManager
|
|
@onready var deck = $CardManager/deck
|
|
@onready var player_1_hand = $CardManager/Player1Hand
|
|
@onready var player_1_pile = $CardManager/Player1PlayPile
|
|
@onready var player_2_hand = $CardManager/Player2Hand
|
|
@onready var player_2_pile = $CardManager/Player2PlayPile
|
|
@onready var player_3_hand = $CardManager/Player3Hand
|
|
@onready var player_3_pile = $CardManager/Player3PlayPile
|
|
@onready var player_4_hand = $CardManager/Player4Hand
|
|
@onready var player_4_pile = $CardManager/Player4PlayPile
|
|
@onready var trumpbuttons = $ButtonsTrumpSelect
|
|
@onready var first_player = $CardManager/Player1PlayPile
|
|
var trump : String
|
|
|
|
signal dealt
|
|
|
|
func _ready():
|
|
trumpbuttons.trump.connect(define_trump.bind())
|
|
player_1_pile.enable_drop_zone = false
|
|
player_1_pile.sensor_visibility = false
|
|
setup_game()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setup_game():
|
|
# Create a deck of cards
|
|
create_standard_deck()
|
|
deck._held_cards.shuffle()
|
|
|
|
# Deal initial hand
|
|
const DEAL_PAUSE = 0.1
|
|
var deal_r: int =1
|
|
while true:
|
|
deal_cards_to_hand(3, player_1_hand)
|
|
await get_tree().create_timer(DEAL_PAUSE).timeout
|
|
deal_cards_to_hand(3, player_2_hand)
|
|
await get_tree().create_timer(DEAL_PAUSE).timeout
|
|
deal_cards_to_hand(3, player_3_hand)
|
|
await get_tree().create_timer(DEAL_PAUSE).timeout
|
|
deal_cards_to_hand(3, player_4_hand)
|
|
if deal_r == 3:
|
|
dealt.emit()
|
|
break
|
|
else:
|
|
await get_tree().create_timer(DEAL_PAUSE).timeout
|
|
deal_r += 1
|
|
await get_tree().create_timer(DEAL_PAUSE).timeout
|
|
trumpbuttons.visible = true
|
|
|
|
func define_trump(suit : String):
|
|
trump = suit
|
|
turn(first_player)
|
|
|
|
func turn(first):
|
|
first.sensor_visibility = true
|
|
first.enable_drop_zone = true
|
|
first._redraw_drop_zone()
|
|
await first.played
|
|
first.enable_drop_zone = false
|
|
first._redraw_drop_zone()
|
|
match first:
|
|
player_1_pile:
|
|
|
|
player_2_pile.sensor_visibility = true
|
|
player_2_pile.enable_drop_zone = true
|
|
player_2_pile._redraw_drop_zone()
|
|
await player_2_pile.played
|
|
player_2_pile.enable_drop_zone = false
|
|
player_2_pile._redraw_drop_zone()
|
|
|
|
player_3_pile.sensor_visibility = true
|
|
player_3_pile.enable_drop_zone = true
|
|
player_3_pile._redraw_drop_zone()
|
|
await player_3_pile.played
|
|
player_3_pile.enable_drop_zone = false
|
|
player_3_pile._redraw_drop_zone()
|
|
|
|
player_4_pile.sensor_visibility = true
|
|
player_4_pile.enable_drop_zone = true
|
|
player_4_pile._redraw_drop_zone()
|
|
await player_4_pile.played
|
|
player_4_pile.enable_drop_zone = false
|
|
player_4_pile._redraw_drop_zone()
|
|
|
|
player_2_pile:
|
|
|
|
player_3_pile.sensor_visibility = true
|
|
player_3_pile.enable_drop_zone = true
|
|
player_3_pile._redraw_drop_zone()
|
|
await player_3_pile.played
|
|
player_3_pile.enable_drop_zone = false
|
|
player_3_pile._redraw_drop_zone()
|
|
|
|
player_4_pile.sensor_visibility = true
|
|
player_4_pile.enable_drop_zone = true
|
|
player_4_pile._redraw_drop_zone()
|
|
await player_4_pile.played
|
|
player_4_pile.enable_drop_zone = false
|
|
player_4_pile._redraw_drop_zone()
|
|
|
|
player_1_pile.sensor_visibility = true
|
|
player_1_pile.enable_drop_zone = true
|
|
player_1_pile._redraw_drop_zone()
|
|
await player_1_pile.played
|
|
player_1_pile.enable_drop_zone = false
|
|
player_1_pile._redraw_drop_zone()
|
|
|
|
player_3_pile:
|
|
|
|
player_4_pile.sensor_visibility = true
|
|
player_4_pile.enable_drop_zone = true
|
|
player_4_pile._redraw_drop_zone()
|
|
await player_4_pile.played
|
|
player_4_pile.enable_drop_zone = false
|
|
player_4_pile._redraw_drop_zone()
|
|
|
|
player_1_pile.sensor_visibility = true
|
|
player_1_pile.enable_drop_zone = true
|
|
player_1_pile._redraw_drop_zone()
|
|
await player_1_pile.played
|
|
player_1_pile.enable_drop_zone = false
|
|
player_1_pile._redraw_drop_zone()
|
|
|
|
player_2_pile.sensor_visibility = true
|
|
player_2_pile.enable_drop_zone = true
|
|
player_2_pile._redraw_drop_zone()
|
|
await player_2_pile.played
|
|
player_2_pile.enable_drop_zone = false
|
|
player_2_pile._redraw_drop_zone()
|
|
|
|
player_4_pile:
|
|
player_1_pile.sensor_visibility = true
|
|
player_1_pile.enable_drop_zone = true
|
|
player_1_pile._redraw_drop_zone()
|
|
await player_1_pile.played
|
|
player_1_pile.enable_drop_zone = false
|
|
player_1_pile._redraw_drop_zone()
|
|
|
|
player_2_pile.sensor_visibility = true
|
|
player_2_pile.enable_drop_zone = true
|
|
player_2_pile._redraw_drop_zone()
|
|
await player_2_pile.played
|
|
player_2_pile.enable_drop_zone = false
|
|
player_2_pile._redraw_drop_zone()
|
|
|
|
player_3_pile.sensor_visibility = true
|
|
player_3_pile.enable_drop_zone = true
|
|
player_3_pile._redraw_drop_zone()
|
|
await player_3_pile.played
|
|
player_3_pile.enable_drop_zone = false
|
|
player_3_pile._redraw_drop_zone()
|
|
get_turn_winner()
|
|
|
|
|
|
|
|
|
|
func get_turn_winner():
|
|
var card_1 = player_1_pile.get_top_cards(1)[0]
|
|
var card_2 = player_2_pile.get_top_cards(1)[0]
|
|
var card_3 = player_3_pile.get_top_cards(1)[0]
|
|
var card_4 = player_4_pile.get_top_cards(1)[0]
|
|
var value_1 = card_1.card_info.value
|
|
var value_2 = card_2.card_info.value
|
|
var value_3 = card_3.card_info.value
|
|
var value_4 = card_4.card_info.value
|
|
|
|
if trump == card_1.card_info.suit:
|
|
match value_1:
|
|
11:
|
|
value_1 += 40
|
|
9:
|
|
value_1 += 30
|
|
|
|
func move_to_stiche(team: int):
|
|
pass
|
|
|
|
func create_standard_deck():
|
|
var suits = ["Club", "Diamond", "Heart", "Spade"]
|
|
var values = ["A", "6", "7", "8", "9", "10", "B", "Q", "K"]
|
|
|
|
for suit in suits:
|
|
for value in values:
|
|
var card_name = "%s_%s" % [suit, value]
|
|
var card = card_manager.card_factory.create_card(card_name, deck)
|
|
deck.add_card(card)
|
|
|
|
func deal_cards_to_hand(count: int, player):
|
|
for i in count:
|
|
if deck.get_card_count() > 0:
|
|
var card = deck.get_top_cards(1).front()
|
|
player.move_cards([card])
|