diff --git a/Assets/Scripts/ScoringPage.cs b/Assets/Scripts/ScoringPage.cs index ca1a5af..f2b722c 100644 --- a/Assets/Scripts/ScoringPage.cs +++ b/Assets/Scripts/ScoringPage.cs @@ -1,11 +1,14 @@ using System.Collections; using System.Collections.Generic; +using System.Linq; using UnityEngine; public class ScoringPage : MonoBehaviour { [SerializeField] private List playerStickers; + private Dictionary scoreByUser = new Dictionary(); + private void Awake() { if(playerStickers == null || playerStickers.Count == 0) @@ -25,10 +28,38 @@ public void Initialize(Room _room) gameObject.SetActive(true); Player[] players = _room.GetOrderedPlayerList().ToArray(); - for (int i = 0; i < players.Length; i++) + + 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 playersId = scoreByUser.Keys.ToList(); + for ( int i = 0; i < playersId.Count; i++) + { + Player p = _room.GetPlayerById(playersId[i]); playerStickers[i].gameObject.SetActive(true); - playerStickers[i].Initialize(players[i].name, i); + playerStickers[i].Initialize( p.name , i); } } + + public void getPlayerScore(Room _room, Player _player) + { + List 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]); + + } }