AceField/Scripts/Logic/Scoreboard.cs

33 lines
707 B
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using Godot;
namespace AceField.Scripts.Logic;
public record PlayerData(string Name, int Score = 0)
{
public string Name { get; set; } = Name;
public int Score { get; set; } = Score;
};
public partial class Scoreboard : Node
{
public Dictionary<int, PlayerData> Players = new();
public void AddPlayer(int networkId, string playerName = null)
{
Players[networkId] = new PlayerData(playerName ?? $"Player#{networkId}");
}
public void RemovePlayer(int networkId)
{
Players.Remove(networkId);
}
public void AddScore(int networkId, int amount = 1)
{
if (Players[networkId]?.Score == null) return;
Players[networkId]!.Score += amount;
}
}