278 lines
8.3 KiB
GDScript
278 lines
8.3 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 team_1_stiche = $CardManager/Team1Stiche
|
|
@onready var team_2_stiche = $CardManager/Team2Stiche
|
|
@onready var trumpbuttons = $ButtonsTrumpSelect
|
|
@onready var first_player = $CardManager/Player1PlayPile
|
|
var trump : String
|
|
var rounds_played: int
|
|
|
|
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()
|
|
|
|
player_1_hand.allow_movement = true
|
|
player_2_hand.allow_movement = true
|
|
player_3_hand.allow_movement = true
|
|
player_4_hand.allow_movement = true
|
|
|
|
# Deal initial hand
|
|
const DEAL_PAUSE = 0.5
|
|
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):
|
|
rounds_played += 1
|
|
if rounds_played == 10:
|
|
count_points()
|
|
return
|
|
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:
|
|
await get_tree().create_timer(0.2).timeout
|
|
player_1_hand.enable_drop_zone = false
|
|
|
|
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()
|
|
await get_tree().create_timer(0.2).timeout
|
|
player_2_hand.allow_movement = false
|
|
|
|
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()
|
|
await get_tree().create_timer(0.2).timeout
|
|
player_3_hand.allow_movement = false
|
|
|
|
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()
|
|
await get_tree().create_timer(0.2).timeout
|
|
player_4_hand.allow_movement = false
|
|
player_2_pile:
|
|
player_2_hand.allow_movement = false
|
|
|
|
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_3_hand.allow_movement = false
|
|
|
|
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_4_hand.allow_movement = false
|
|
|
|
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_1_hand.allow_movement = false
|
|
player_3_pile:
|
|
player_3_hand.allow_movement = false
|
|
|
|
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_4_hand.allow_movement = false
|
|
|
|
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_1_hand.allow_movement = false
|
|
|
|
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_2_hand.allow_movement = false
|
|
player_4_pile:
|
|
player_4_hand.allow_movement = false
|
|
|
|
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_1_hand.allow_movement = false
|
|
|
|
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_2_hand.allow_movement = false
|
|
|
|
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_3_hand.allow_movement = false
|
|
get_turn_winner()
|
|
|
|
func count_points():
|
|
print("end of round")
|
|
|
|
|
|
func get_turn_winner():
|
|
var cards = {
|
|
1: {"value": int(player_1_pile.get_top_cards(1)[0].card_info.value), "suit": player_1_pile.get_top_cards(1)[0].card_info.suit},
|
|
2: {"value": int(player_2_pile.get_top_cards(1)[0].card_info.value), "suit": player_2_pile.get_top_cards(1)[0].card_info.suit},
|
|
3: {"value": int(player_3_pile.get_top_cards(1)[0].card_info.value), "suit": player_3_pile.get_top_cards(1)[0].card_info.suit},
|
|
4: {"value": int(player_4_pile.get_top_cards(1)[0].card_info.value), "suit": player_4_pile.get_top_cards(1)[0].card_info.suit}
|
|
}
|
|
print(trump)
|
|
if trump != "Top" and trump != "Down":
|
|
print("pass")
|
|
for card in cards:
|
|
if trump == cards[card]["suit"]:
|
|
match cards[card]["value"]:
|
|
11:
|
|
cards[card]["value"] += 40
|
|
9:
|
|
cards[card]["value"] += 30
|
|
_:
|
|
cards[card]["value"] += 14
|
|
print(cards[card]["value"])
|
|
elif trump == "Down":
|
|
for card in cards:
|
|
cards[card]["value"] = cards[card]["value"] * (-1)
|
|
print(cards[card]["value"])
|
|
|
|
var played_suit = first_player.get_top_cards(1)[0].card_info.suit
|
|
var highest_card: int
|
|
var highest_value: int
|
|
for i in cards:
|
|
var card = cards[i]
|
|
if card["suit"] == played_suit and card["value"] > highest_value:
|
|
highest_value = card["value"]
|
|
highest_card = i
|
|
|
|
match highest_card:
|
|
1:
|
|
first_player = player_1_pile
|
|
move_to_stiche(1)
|
|
2:
|
|
first_player = player_2_pile
|
|
move_to_stiche(2)
|
|
3:
|
|
first_player = player_3_pile
|
|
move_to_stiche(1)
|
|
4:
|
|
first_player = player_4_pile
|
|
move_to_stiche(2)
|
|
|
|
func move_to_stiche(team: int):
|
|
if team == 1:
|
|
team_1_stiche.move_cards(player_1_pile.get_top_cards(1))
|
|
team_1_stiche.move_cards(player_2_pile.get_top_cards(1))
|
|
team_1_stiche.move_cards(player_3_pile.get_top_cards(1))
|
|
team_1_stiche.move_cards(player_4_pile.get_top_cards(1))
|
|
else:
|
|
team_2_stiche.move_cards(player_1_pile.get_top_cards(1))
|
|
team_2_stiche.move_cards(player_2_pile.get_top_cards(1))
|
|
team_2_stiche.move_cards(player_3_pile.get_top_cards(1))
|
|
team_2_stiche.move_cards(player_4_pile.get_top_cards(1))
|
|
turn(first_player)
|
|
|
|
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])
|