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"
|
@page "/wordle"
|
||||||
|
|
||||||
<PageTitle>Nacken Wordle</PageTitle>
|
<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">
|
<div hidden="@hideAlert">
|
||||||
<MudContainer MaxWidth="MaxWidth.Small">
|
<MudContainer MaxWidth="MaxWidth.Small">
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="1"></MudItem>
|
||||||
|
<MudItem xs="8">
|
||||||
<MudAlert Severity="Severity.Success">Korrekt!</MudAlert>
|
<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>
|
</MudContainer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Matrix mit Buchstabenfeldern -->
|
||||||
<div class="d-flex justify-center mt-2 mb-2">
|
<div class="d-flex justify-center mt-2 mb-2">
|
||||||
<div>
|
<div>
|
||||||
@for(int i = 0; i < 6; i++)
|
@foreach(var guess in PreviousGuesses)
|
||||||
{
|
{
|
||||||
<div class="d-flex mb-2">
|
<div class="d-flex mb-2">
|
||||||
@for(int j = 0; j < 5; j++)
|
|
||||||
|
<!-- WHY FAILURE?????????????????????????? -->
|
||||||
|
@for(int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
|
<!-- Wer hat sich denn sowas ausgedacht? -->
|
||||||
<MudPaper Class="mr-2" Width="60px" Height="60px" Outlined="true">
|
var j = i;
|
||||||
<MudText Typo="Typo.h3" Align="Align.Center"></MudText>
|
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>
|
</MudPaper>
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Input dialogue feld -->
|
||||||
<div class="d-flex justify-center">
|
<MudContainer MaxWidth="MaxWidth.Small" @onkeyup="@Check4Enter">
|
||||||
<MudPaper Class="d-flex gap-4" Width="390px">
|
<MudGrid Spacing="2">
|
||||||
<MudTextField @ref="textField" T="string" FullWidth="true" @bind-Value="Input" Label="Dein Tipp:" Variant="Variant.Outlined" MaxLength="5" Mask="@mask">Hi</MudTextField>
|
<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>
|
<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>
|
</MudItem>
|
||||||
</div>
|
<MudItem xs="1"></MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudContainer>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
public string Input { get; set; }
|
public string Input { get; set; }
|
||||||
|
@ -44,17 +74,40 @@
|
||||||
|
|
||||||
public MudTextField<string> textField;
|
public MudTextField<string> textField;
|
||||||
|
|
||||||
|
public List<string> PreviousGuesses = new List<string>();
|
||||||
|
|
||||||
//Keine Ahnung wie das funktionert... Danke StackOverflow :)
|
//Keine Ahnung wie das funktionert... Danke StackOverflow :)
|
||||||
public IMask mask = new RegexMask(@"^[A-Za-z]{0,5}$");
|
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()
|
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())
|
if(secret.ToLower() == Input.ToLower())
|
||||||
{
|
{
|
||||||
|
found = true;
|
||||||
textField.Clear();
|
textField.Clear();
|
||||||
hideAlert = false;
|
hideAlert = false;
|
||||||
}
|
}
|
||||||
|
@ -63,17 +116,12 @@
|
||||||
textField.Clear();
|
textField.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color getColor(char letter, int position, string secret)
|
public void PlayAgain()
|
||||||
{
|
{
|
||||||
if (position > secret.Length) return Color.Primary;
|
PreviousGuesses.Clear();
|
||||||
|
hideAlert = true;
|
||||||
if(letter == secret[position]) return Color.Success;
|
found = false;
|
||||||
|
|
||||||
if (secret.Contains(letter)) return Color.Warning;
|
|
||||||
|
|
||||||
return Color.Primary;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue