diff --git a/scenes/game/game.gd b/scenes/game/game.gd index dbb1c58..2ae1928 100644 --- a/scenes/game/game.gd +++ b/scenes/game/game.gd @@ -41,7 +41,12 @@ func _setup_players(): player.id = player_id player.name = str(player_id) players.append(player) - + + player.connect("win", self, "_on_player_win", [player]) + +func _on_player_win(player): + $CanvasLayer/Control/Winner.show() + $CanvasLayer/Control/Winner.text = "Player " + player.name + " wins!!!" func _setup_countries(): var id = 0 @@ -58,9 +63,6 @@ func _setup_countries(): $Grid.countries = countries $Grid.setup() - - countries[1].add_unit({}, Vector2(1,1)) - countries[2].add_unit({}, Vector2(1,2)) func _setup_turns(): for player in players: @@ -170,7 +172,7 @@ func _on_stock_sell_button_pressed(country): _refresh_stock_ui() func _on_PayDividends_pressed(): - if turn.object.money > 7: + if turn.object.money >= 7: turn.object.money -= 7 for i in len(turn.object.player_stocks): var stocks = turn.object.player_stocks[i] @@ -250,11 +252,11 @@ func _on_Grid_tile_pressed(v): country.money -= 3 country.add_unit({}, v) "buy_boat": - if country.money >= 3 and $Grid.has_adjacent_factory(v, country) and tile.needs_boat and len(tile.boats) == 0: + if country.money >= 3 and $Grid.has_adjacent_factory(v, country) and tile.needs_boat and not $Grid.tile_have_boat_of_country(tile, country): country.money -= 3 country.add_boat({}, v) null: - if $Grid.selected_thing is Boat and $Grid.selected_thing.get_tile_position() == v or len(tile.boats) == 0: + if is_instance_valid($Grid.selected_thing) and $Grid.selected_thing is Boat and $Grid.selected_thing.get_tile_position() == v or len(tile.boats) == 0: for army in tile.units: if army.country == country: $Grid.selected_thing = army.entity diff --git a/scenes/game/game.tscn b/scenes/game/game.tscn index 4c97084..aaaece9 100644 --- a/scenes/game/game.tscn +++ b/scenes/game/game.tscn @@ -170,6 +170,20 @@ margin_right = 42.0 margin_bottom = 14.0 text = "CONTROLLER" +[node name="Winner" type="Label" parent="CanvasLayer/Control"] +visible = false +modulate = Color( 1, 0.72549, 0, 1 ) +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +margin_left = -192.0 +margin_top = -56.0 +margin_right = -93.0 +margin_bottom = -42.0 +rect_scale = Vector2( 4, 4 ) +text = "Player X Wins!!!" + [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"] diff --git a/scenes/game/player.gd b/scenes/game/player.gd index 18af06a..69a2c75 100644 --- a/scenes/game/player.gd +++ b/scenes/game/player.gd @@ -1,9 +1,11 @@ class_name Player extends Reference +signal win + var id var name -var money = 4 +var money = 4 setget _set_money var stocks = [] #Array of numbers stock[country_id] = stock_amount func _init(): @@ -12,3 +14,8 @@ func _init(): func compute_balance(): pass + +func _set_money(value): + money = value + if value >= 40: + emit_signal("win")