score.gd 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. extends HBoxContainer
  2. var player_labels := {}
  3. func _process(_delta: float) -> void:
  4. var rocks_left := $"../Rocks".get_child_count()
  5. if rocks_left == 0:
  6. var winner_name := ""
  7. var winner_score := 0
  8. for p: int in player_labels:
  9. if player_labels[p].score > winner_score:
  10. winner_score = player_labels[p].score
  11. winner_name = player_labels[p].name
  12. $"../Winner".set_text("THE WINNER IS:\n" + winner_name)
  13. $"../Winner".show()
  14. func increase_score(for_who: int) -> void:
  15. assert(for_who in player_labels)
  16. var pl: Dictionary = player_labels[for_who]
  17. pl.score += 1
  18. pl.label.set_text(pl.name + "\n" + str(pl.score))
  19. func add_player(id: int, new_player_name: String) -> void:
  20. var label := Label.new()
  21. label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
  22. label.text = new_player_name + "\n" + "0"
  23. label.modulate = gamestate.get_player_color(new_player_name)
  24. label.size_flags_horizontal = SIZE_EXPAND_FILL
  25. label.add_theme_font_override("font", preload("res://montserrat.otf"))
  26. label.add_theme_color_override("font_outline_color", Color.BLACK)
  27. label.add_theme_constant_override("outline_size", 9)
  28. label.add_theme_font_size_override("font_size", 18)
  29. add_child(label)
  30. player_labels[id] = {
  31. name = new_player_name,
  32. label = label,
  33. score = 0,
  34. }
  35. func _ready() -> void:
  36. $"../Winner".hide()
  37. func _on_exit_game_pressed() -> void:
  38. gamestate.end_game()