Skip to content

Commit

Permalink
Merge pull request #10 from sleepyspip/rule-variations
Browse files Browse the repository at this point in the history
Rule variations (Sudden Death, Random)
  • Loading branch information
davcri authored Dec 14, 2020
2 parents 7cc5867 + 518042a commit 4d6352c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 10 deletions.
2 changes: 2 additions & 0 deletions GameScenes/Battle/Scripts/Battle.gd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func _on_Field_match_ended():
GlobalState.matches_stats["lost"] += 1
elif match_result == DRAW:
GlobalState.matches_stats["drawn"] += 1
if GlobalState.current_rules["SuddenDeath"]:
return SceneManager.goto_scene("res://GameScenes/Game/Game.tscn", GlobalState.current_rules)
emit_signal("battle_ended", match_result)


Expand Down
35 changes: 31 additions & 4 deletions GameScenes/Battle/Scripts/Player1Cards.gd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ extends VBoxContainer

var selected_card_index


func _ready():
# set an initial selected card
set_current_selected_card(0)
# update the seed
randomize()
# randomize Player cards
randomize_cards()
if GlobalState.current_rules["Random"]:
# update the seed
randomize()
# randomize Player cards
GlobalState.starting_hand = randomize_cards()
else:
GlobalState.starting_hand = set_hand()


func get_card_container_at(index):
Expand All @@ -24,9 +28,11 @@ func get_card_container_at(index):
var card_container = get_child(index)
return card_container


func get_card_count():
return get_child_count() - 1 # 1 node is the Tween node


func set_current_selected_card(index):
assert (index <= get_card_count() - 1)
var selected_card = null
Expand All @@ -39,6 +45,7 @@ func set_current_selected_card(index):
move_right(new_selected_card, 50)
selected_card_index = index


func move_right(card_container, offset):
$Tween.interpolate_property(
card_container,
Expand All @@ -51,6 +58,7 @@ func move_right(card_container, offset):
)
$Tween.start()


func move_left(card_container, offset):
$Tween.interpolate_property(
card_container,
Expand All @@ -63,16 +71,35 @@ func move_left(card_container, offset):
)
$Tween.start()


func randomize_cards():
""" Randomize cards in the Player hand """
var card_ids = []
# for each child
for child in get_children():
# if it is a Container
if "Container" in child.name:
# get the Card node
var card = child.get_child(0)
card.card_id = randi() % 110 # max card id is 109
card_ids.append(card.card_id)
card._ready()
return card_ids

func set_hand(card_ids = [1,2,3,4,5]):
""" Set specific cards in the Player hand """
var id = 0
# for each child
for child in get_children():
# if it is a Container
if "Container" in child.name:
# get the Card node
var card = child.get_child(0)
card.card_id = card_ids[id] # max card id is 109
card._ready()
id += 1
return card_ids


func _on_CardSelected_place_card(card_index, field_position):
var card_container = get_card_container_at(card_index)
Expand Down
2 changes: 1 addition & 1 deletion GameScenes/Battle/Scripts/Results.gd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ func _set_stats():
draw.text = str(matches_stats["drawn"])
lost.text = str(matches_stats["lost"])
total.text = str(matches_stats["won"] + matches_stats["drawn"] + matches_stats["lost"])


Empty file modified GameScenes/Menu/MainMenu/MainMenu.tscn
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion GameScenes/Menu/MainMenu/Scripts/QuickMatch.gd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export(PackedScene) var next_scene


func callback():
SceneManager.goto_scene(next_scene.resource_path)
SceneManager.goto_scene(next_scene.resource_path)
Empty file modified GameScenes/Menu/MainMenu/Scripts/SinglePlayerLabel2.gd
100755 → 100644
Empty file.
7 changes: 3 additions & 4 deletions GameScenes/Menu/SinglePlayerMenu/SinglePlayerMenu.tscn
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ region = Rect2( 256, 894, 249, 82 )
[node name="SinglePlayerMenu" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Background" type="CanvasLayer" parent="."]

Expand Down Expand Up @@ -85,8 +88,6 @@ margin_bottom = 133.0
custom_icons/off = ExtResource( 1 )
custom_icons/on = ExtResource( 2 )
custom_fonts/font = SubResource( 3 )
disabled = true
pressed = true
text = "Random"

[node name="Open" type="CheckButton" parent="UI/MarginContainer/VBoxContainer/MarginContainer/Rules"]
Expand All @@ -105,7 +106,6 @@ margin_bottom = 265.0
custom_icons/off = ExtResource( 1 )
custom_icons/on = ExtResource( 2 )
custom_fonts/font = SubResource( 3 )
disabled = true
text = "Sudden Death"

[node name="Same" type="CheckButton" parent="UI/MarginContainer/VBoxContainer/MarginContainer/Rules"]
Expand Down Expand Up @@ -159,4 +159,3 @@ stretch_mode = 3
script = ExtResource( 5 )

[node name="MenuSelectionPointer" parent="UI/MarginContainer/VBoxContainer/MarginContainer/Rules" instance=ExtResource( 6 )]

1 change: 1 addition & 0 deletions Globals/GlobalState.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var matches_stats = {
} setget set_matches_stats, get_matches_stats

var current_rules = {}
var starting_hand = []

signal matches_stats_changed

Expand Down

0 comments on commit 4d6352c

Please sign in to comment.