From 87aad30006e4d892fd37533284c4dd88edd56def Mon Sep 17 00:00:00 2001 From: potatoxel Date: Fri, 18 Nov 2022 21:30:40 +0300 Subject: [PATCH] controller --- scenes/game/country.gd | 7 +++++++ scenes/game/game.gd | 7 ++++++- scenes/game/game.tscn | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/scenes/game/country.gd b/scenes/game/country.gd index 8431f05..08259cd 100644 --- a/scenes/game/country.gd +++ b/scenes/game/country.gd @@ -7,6 +7,7 @@ var color var money = 8 var stock_price = 1 var total_stocks = 0 +var player_stocks = [0,0,0] var tile_positions var armies = [] var boats = [] @@ -33,3 +34,9 @@ func remove_boat(unit): func compute_balance(): money += len(factory_positions) - len(armies) - len(boats) + +func get_controller_id(): + for i in len(player_stocks): + if player_stocks[i] >= 4: + return i + return -1 diff --git a/scenes/game/game.gd b/scenes/game/game.gd index d12d71c..8c16bcc 100644 --- a/scenes/game/game.gd +++ b/scenes/game/game.gd @@ -116,6 +116,7 @@ func _refresh_stock_ui(): func _on_stock_buy_button_pressed(country): if turn.object.money >= country.stock_price and country.total_stocks < 7: country.total_stocks += 1 + country.player_stocks[turn.object.id] += 1 turn.object.stocks[country.id] += 1 turn.object.money -= country.stock_price country.money += country.stock_price @@ -124,6 +125,7 @@ func _on_stock_buy_button_pressed(country): func _on_stock_sell_button_pressed(country): if country.money >= country.stock_price and turn.object.stocks[country.id] > 0: country.total_stocks -= 1 + country.player_stocks[turn.object.id] -= 1 turn.object.stocks[country.id] -= 1 turn.object.money += country.stock_price country.money -= country.stock_price @@ -137,7 +139,7 @@ func _process(delta): $CanvasLayer/Control/VBoxContainer/BuyFactory.visible = turn.layer == "country" $CanvasLayer/Control/VBoxContainer/BuyArmy.visible = turn.layer == "country" $CanvasLayer/Control/VBoxContainer/BuyBoat.visible = turn.layer == "country" - + $CanvasLayer/Control/VBoxContainer/Stocks.visible = turn.layer == "player" @@ -156,6 +158,9 @@ func _on_EndTurnButton_pressed(): if turn.layer == "player": _refresh_stock_ui() + else: + $CanvasLayer/Control/ControllerLabel.text = "Controller: " + (players[turn.object.get_controller_id()].name if turn.object.get_controller_id() >= 0 else "none") + $CanvasLayer/Control/ControllerLabel.visible = turn.layer == "country" $CanvasLayer/Control/VBoxContainer/TurnLabel.text = turn.object.name + "'s turn." diff --git a/scenes/game/game.tscn b/scenes/game/game.tscn index 88dcd5f..8518b68 100644 --- a/scenes/game/game.tscn +++ b/scenes/game/game.tscn @@ -110,6 +110,14 @@ margin_left = -79.0 margin_top = -40.0 text = "END TURN" +[node name="ControllerLabel" type="Label" parent="CanvasLayer/Control"] +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = -42.0 +margin_right = 42.0 +margin_bottom = 14.0 +text = "CONTROLLER" + [connection signal="tile_pressed" from="Grid" to="." method="_on_Grid_tile_pressed"] [connection signal="pressed" from="CanvasLayer/Control/VBoxContainer/BuyFactory" to="." method="_on_BuyFactory_pressed"] [connection signal="pressed" from="CanvasLayer/Control/VBoxContainer/BuyArmy" to="." method="_on_BuyArmy_pressed"]