Nacken Wordle fertig
Jetzt fehlt nur noch eine Datenbank mit wörtern
This commit is contained in:
parent
d9b40a6dcc
commit
d218b291aa
|
@ -1,41 +1,71 @@
|
|||
@page "/wordle"
|
||||
|
||||
<PageTitle>Nacken Wordle</PageTitle>
|
||||
<MudText Align="Align.Center" Class="mt-2 mb-2"> Rate ein Wort mit 5 Buchstaben:</MudText>
|
||||
|
||||
<MudText Align="Align.Center" Class="mt-2 mb-2"> Willkommen zum Nacken Wordle</MudText>
|
||||
|
||||
<!-- Hidden Alerts -->
|
||||
<div hidden="@hideAlert">
|
||||
<MudContainer MaxWidth="MaxWidth.Small">
|
||||
<MudAlert Severity="Severity.Success">Korrekt!</MudAlert>
|
||||
<MudGrid>
|
||||
<MudItem xs="1"></MudItem>
|
||||
<MudItem xs="8">
|
||||
<MudAlert Severity="Severity.Success">Korrekt!</MudAlert>
|
||||
</MudItem>
|
||||
<MudItem xs="2">
|
||||
<MudIconButton Icon="@Icons.Filled.Replay" Color="Color.Primary" aria-label="nochmal spielen" OnClick="@PlayAgain"></MudIconButton>
|
||||
</MudItem>
|
||||
<MudItem xs="1"></MudItem>
|
||||
</MudGrid>
|
||||
</MudContainer>
|
||||
</div>
|
||||
|
||||
<!-- Matrix mit Buchstabenfeldern -->
|
||||
<div class="d-flex justify-center mt-2 mb-2">
|
||||
<div>
|
||||
@for(int i = 0; i < 6; i++)
|
||||
@foreach(var guess in PreviousGuesses)
|
||||
{
|
||||
<div class="d-flex mb-2">
|
||||
@for(int j = 0; j < 5; j++)
|
||||
|
||||
<!-- WHY FAILURE?????????????????????????? -->
|
||||
@for(int i = 0; i < 5; i++)
|
||||
{
|
||||
|
||||
<MudPaper Class="mr-2" Width="60px" Height="60px" Outlined="true">
|
||||
<MudText Typo="Typo.h3" Align="Align.Center"></MudText>
|
||||
</MudPaper>
|
||||
<!-- Wer hat sich denn sowas ausgedacht? -->
|
||||
var j = i;
|
||||
if(@guess.ToUpper()[j] == secret.ToUpper()[j])
|
||||
{
|
||||
<MudPaper Style="border-color: green; border-width: 4px;" Class="mr-2" Width="60px" Height="60px" Outlined="true">
|
||||
<MudText Typo="Typo.h3" Align="Align.Center">@guess.ToUpper()[j]</MudText>
|
||||
</MudPaper>
|
||||
}else if (secret.ToUpper().Contains(@guess.ToUpper()[j]))
|
||||
{
|
||||
<MudPaper Style="border-color: yellow; border-width: 4px;" Class="mr-2" Width="60px" Height="60px" Outlined="true">
|
||||
<MudText Typo="Typo.h3" Align="Align.Center">@guess.ToUpper()[j]</MudText>
|
||||
</MudPaper>
|
||||
}else
|
||||
{
|
||||
<MudPaper Style="border-width: 4px;" Class="mr-2" Width="60px" Height="60px" Outlined="true">
|
||||
<MudText Typo="Typo.h3" Align="Align.Center">@guess.ToUpper()[j]</MudText>
|
||||
</MudPaper>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="d-flex justify-center">
|
||||
<MudPaper Class="d-flex gap-4" Width="390px">
|
||||
<MudTextField @ref="textField" T="string" FullWidth="true" @bind-Value="Input" Label="Dein Tipp:" Variant="Variant.Outlined" MaxLength="5" Mask="@mask">Hi</MudTextField>
|
||||
|
||||
<MudButton style="height:56px; margin-top:6px;" Class="justify-center" Size="Size.Large" Variant="Variant.Outlined" EndIcon="@Icons.Material.Filled.Send" Color="Color.Primary" OnClick=@ButtonOnClick>OK</MudButton>
|
||||
</MudPaper>
|
||||
</div>
|
||||
|
||||
<!-- Input dialogue feld -->
|
||||
<MudContainer MaxWidth="MaxWidth.Small" @onkeyup="@Check4Enter">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="1"></MudItem>
|
||||
<MudItem xs="8">
|
||||
<MudTextField Class="" @ref="textField" T="string" FullWidth="true" @bind-Value="Input" Label="Dein Tipp:" Variant="Variant.Outlined" MaxLength="5" Mask="@mask">Hi</MudTextField>
|
||||
</MudItem>
|
||||
<MudItem xs="2">
|
||||
<MudButton style="height:56px; margin-top:6px;" Class="justify-center" Size="Size.Large" Variant="Variant.Outlined" EndIcon="@Icons.Material.Filled.Send" Color="Color.Primary" OnClick=@ButtonOnClick>OK</MudButton>
|
||||
</MudItem>
|
||||
<MudItem xs="1"></MudItem>
|
||||
</MudGrid>
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
public string Input { get; set; }
|
||||
|
@ -44,17 +74,40 @@
|
|||
|
||||
public MudTextField<string> textField;
|
||||
|
||||
public List<string> PreviousGuesses = new List<string>();
|
||||
|
||||
//Keine Ahnung wie das funktionert... Danke StackOverflow :)
|
||||
public IMask mask = new RegexMask(@"^[A-Za-z]{0,5}$");
|
||||
|
||||
private string secret = "penis";
|
||||
public string secret = "penis";
|
||||
private bool found = false;
|
||||
|
||||
public void Check4Enter(KeyboardEventArgs e)
|
||||
{
|
||||
Console.Out.WriteLine(e);
|
||||
Console.Out.WriteLine(e.Code);
|
||||
if (e.Code == "Enter" || e.Code == "NumpadEnter")
|
||||
{
|
||||
if(found)
|
||||
{
|
||||
PlayAgain();
|
||||
}
|
||||
else
|
||||
{
|
||||
ButtonOnClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ButtonOnClick()
|
||||
{
|
||||
if(Input != null)
|
||||
if(Input != null && Input.Length == 5 && !found)
|
||||
{
|
||||
Console.Out.WriteLine(Input);
|
||||
PreviousGuesses.Add(Input);
|
||||
if(secret.ToLower() == Input.ToLower())
|
||||
{
|
||||
found = true;
|
||||
textField.Clear();
|
||||
hideAlert = false;
|
||||
}
|
||||
|
@ -63,17 +116,12 @@
|
|||
textField.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Color getColor(char letter, int position, string secret)
|
||||
public void PlayAgain()
|
||||
{
|
||||
if (position > secret.Length) return Color.Primary;
|
||||
|
||||
if(letter == secret[position]) return Color.Success;
|
||||
|
||||
if (secret.Contains(letter)) return Color.Warning;
|
||||
|
||||
return Color.Primary;
|
||||
PreviousGuesses.Clear();
|
||||
hideAlert = true;
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue