starOfWords/Assets/Scripts/Leaderboard.cs
portakal ecb1c9edea Initial commit: Star of Words Unity project
Snapshot of the existing Unity 6 language-learning word game before any
refactoring. Adds Unity .gitignore and .gitattributes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-05 15:31:20 +03:00

93 lines
No EOL
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Leaderboard : MonoBehaviour
{
[Header("━━━ UI SLOTS (10 satır) ━━━━━━━━━━━━━━━")]
public TMP_Text[] rows;
[Header("━━━ BUTONLAR ━━━━━━━━━━━━━━━━━━━━━━━━━━")]
public Button mainMenuButton;
[Header("━━━ MOD SKOR KEYLERİ ━━━━━━━━━━━━━━━━━━")]
public string[] modScoreKeys; // Inspector'dan 12 key gir
// ─── Sabitler ────────────────────────────────
private readonly string[] botNames =
{
"ShadowWolf", "CrystalMind", "NightHunter",
"BlueVortex", "IronSoul", "PixelGhost",
"SilverClaw", "MegaCore", "NeonBlade", "DarkNova"
};
class LBEntry
{
public string name;
public int score;
public LBEntry(string n, int s) { name = n; score = s; }
}
// ============================================================
void Start()
{
GenerateLeaderboard();
if (mainMenuButton != null)
mainMenuButton.onClick.AddListener(() =>
SceneManager.LoadScene("Anamen"));
}
// ============================================================
void GenerateLeaderboard()
{
List<LBEntry> list = new List<LBEntry>();
// ─── Bot skorları ─────────────────────────
int botLimit = Mathf.Min(rows.Length - 1, botNames.Length);
for (int i = 0; i < botLimit; i++)
list.Add(new LBEntry(botNames[i], Random.Range(3000, 12000)));
// ─── Tüm modların toplamı ─────────────────
int totalScore = 0;
if (modScoreKeys != null)
{
foreach (string key in modScoreKeys)
{
if (!string.IsNullOrEmpty(key))
totalScore += PlayerPrefs.GetInt(key + "_High", 0);
}
}
// ─── Yüksek skor güncelle ─────────────────
int savedTotal = PlayerPrefs.GetInt("TotalHighScore", 0);
if (totalScore > savedTotal)
{
savedTotal = totalScore;
PlayerPrefs.SetInt("TotalHighScore", savedTotal);
PlayerPrefs.Save();
}
list.Add(new LBEntry("YOU", savedTotal));
// ─── Sırala ───────────────────────────────
list.Sort((a, b) => b.score.CompareTo(a.score));
// ─── Ekrana yaz ───────────────────────────
for (int i = 0; i < rows.Length; i++)
{
if (i < list.Count)
{
rows[i].text = list[i].name == "YOU"
? $"<color=#00FF00>{i + 1}. {list[i].name} - {list[i].score}</color>"
: $"{i + 1}. {list[i].name} - {list[i].score}";
}
else
{
rows[i].text = $"{i + 1}. ---";
}
}
}
}