UI/GameMenu/WordSelection/WordSelection.razor
@using Sandbox;
@using Sandbox.UI;
@using System;
@using System.Collections.Generic;
@attribute [StyleSheet]
@namespace GuessIt
<root>
<div class="content">
<p class="header">Choose a word!</p>
<div class="words">
<div class="word easy" onclick=@ChooseEasy>
<label>@EasyWord</label>
<label class="mult">0.9x</label>
</div>
<div class="word medium" onclick=@ChooseMedium>
<label>@MediumWord</label>
<label class="mult">1.0x</label>
</div>
<div class="word hard" onclick=@ChooseHard>
<label>@HardWord</label>
<label class="mult">1.1x</label>
</div>
</div>
<div class="timer">
<div class="timer-bar">
<div class="timer-bar-fill"></div>
</div>
</div>
</div>
</root>
@code
{
private string EasyWord { get; set; } = "";
private string MediumWord { get; set; } = "";
private string HardWord { get; set; } = "";
private RealTimeSince Timer = 0f;
protected override void OnAfterTreeRender(bool firstRender)
{
base.OnAfterTreeRender(firstRender);
if (firstRender)
{
Timer = 0f;
// Choose a random word from each list
EasyWord = Utils.GetRandomWord(WORD_DIFFICULTY.EASY);
MediumWord = Utils.GetRandomWord(WORD_DIFFICULTY.MEDIUM);
HardWord = Utils.GetRandomWord(WORD_DIFFICULTY.HARD);
}
}
public override void Tick()
{
base.Tick();
if (Timer > 15f)
{
ChooseRandom();
}
}
void ChooseEasy() { Choose(EasyWord, 0); }
void ChooseMedium() { Choose(MediumWord, 1); }
void ChooseHard() { Choose(HardWord, 2); }
void Choose(string word, int difficulty)
{
if (string.IsNullOrEmpty(word)) return;
GameMenu.Instance.ChooseWord(word, difficulty);
this.Delete();
}
void ChooseRandom()
{
var random = new Random();
var words = new List<string> { EasyWord, MediumWord, HardWord };
var index = random.Next(words.Count);
var word = words[index];
Choose(word, index);
}
protected override int BuildHash()
{
return HashCode.Combine(EasyWord, MediumWord, HardWord);
}
}