Snaparazzi/Assets/Scripts/ScoringPage.cs

68 lines
2.0 KiB
C#
Raw Normal View History

2024-01-29 22:49:48 +00:00
using System.Collections;
using System.Collections.Generic;
2024-02-04 16:57:05 +00:00
using System.Linq;
2024-01-29 22:49:48 +00:00
using UnityEngine;
public class ScoringPage : MonoBehaviour
{
2024-01-31 22:45:05 +00:00
[SerializeField] private List<PlayerSticker> playerStickers;
2024-02-04 16:57:05 +00:00
private Dictionary<string,int> scoreByUser = new Dictionary<string,int>();
private void Awake()
{
if(playerStickers == null || playerStickers.Count == 0)
{
Debug.LogError("You must provide the player stickers to the Scoring Page", this);
}
}
2024-01-31 22:45:05 +00:00
public void Initialize(Room _room)
2024-01-29 22:49:48 +00:00
{
AudioManager.Instance.ChangeMusic(MusicTitle.Ending);
2024-01-31 22:45:58 +00:00
gameObject.SetActive(true);
2024-01-31 22:45:05 +00:00
foreach(PlayerSticker p in playerStickers)
{
p.gameObject.SetActive(false);
}
2024-01-29 22:49:48 +00:00
gameObject.SetActive(true);
2024-01-31 22:45:05 +00:00
Player[] players = _room.GetOrderedPlayerList().ToArray();
2024-02-04 16:57:05 +00:00
foreach (var player in players)
{
scoreByUser[player.id] = 0;
getPlayerScore(_room, player);
}
var sortedList = scoreByUser.ToList();
scoreByUser = scoreByUser.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
List<string> playersId = scoreByUser.Keys.ToList();
2024-02-25 17:30:14 +00:00
int countPlayers = scoreByUser.Keys.ToList().Count;
for (int i = 0; i < countPlayers; i++)
2024-01-31 22:45:05 +00:00
{
2024-02-25 17:30:14 +00:00
Player p = _room.GetPlayerById(scoreByUser.Keys.ToList()[i]);
2024-01-31 22:45:05 +00:00
playerStickers[i].gameObject.SetActive(true);
2024-02-25 17:30:14 +00:00
string nameAndScore = p.name +'\n'+ scoreByUser[p.id] +" pts";
playerStickers[i].Initialize(nameAndScore, i);
2024-01-31 22:45:05 +00:00
}
2024-01-29 22:49:48 +00:00
}
2024-02-04 16:57:05 +00:00
public void getPlayerScore(Room _room, Player _player)
{
List<Proposition> propostitions = _room.GetPropositionsForPlayer(_player);
propostitions.ForEach(p =>
{
if(p.voters != null)
{
scoreByUser[_player.id] += p.voters.Count;
}
});
Debug.Log(_player.name);
Debug.Log(scoreByUser[_player.id]);
}
2024-01-29 22:49:48 +00:00
}