// <auto-generated/>
#pragma warning disable 1591
#pragma warning disable 0414
#pragma warning disable 0649
#pragma warning disable 0169

namespace BlazorMatchGame.Pages
{
    #line hidden
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Components;
#nullable restore
#line 1 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\_Imports.razor"
using System.Net.Http;

#line default
#line hidden
#nullable disable
#nullable restore
#line 2 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\_Imports.razor"
using System.Net.Http.Json;

#line default
#line hidden
#nullable disable
#nullable restore
#line 3 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\_Imports.razor"
using Microsoft.AspNetCore.Components.Forms;

#line default
#line hidden
#nullable disable
#nullable restore
#line 4 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\_Imports.razor"
using Microsoft.AspNetCore.Components.Routing;

#line default
#line hidden
#nullable disable
#nullable restore
#line 5 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\_Imports.razor"
using Microsoft.AspNetCore.Components.Web;

#line default
#line hidden
#nullable disable
#nullable restore
#line 6 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\_Imports.razor"
using Microsoft.AspNetCore.Components.WebAssembly.Http;

#line default
#line hidden
#nullable disable
#nullable restore
#line 7 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\_Imports.razor"
using Microsoft.JSInterop;

#line default
#line hidden
#nullable disable
#nullable restore
#line 8 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\_Imports.razor"
using BlazorMatchGame;

#line default
#line hidden
#nullable disable
#nullable restore
#line 9 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\_Imports.razor"
using BlazorMatchGame.Shared;

#line default
#line hidden
#nullable disable
#nullable restore
#line 2 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\Pages\Index.razor"
using System.Timers;

#line default
#line hidden
#nullable disable
    [Microsoft.AspNetCore.Components.RouteAttribute("/")]
    public partial class Index : Microsoft.AspNetCore.Components.ComponentBase
    {
        #pragma warning disable 1998
        protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
        {
        }
        #pragma warning restore 1998
#nullable restore
#line 38 "d:\tłumaczenia\HeadFirstC#\fourth-edition-master\Code\Chapter_1\BlazorMatchGame\BlazorMatchGame\Pages\Index.razor"
       
    List<string> animalEmoji = new List<string>()
{
        "🐶","🐶",
        "🐺","🐺",
        "🐮","🐮",
        "🦊","🦊",
        "🐱","🐱",
        "🦁","🦁",
        "🐯","🐯",
        "🐹","🐹",
    };

    List<string> shuffledAnimals = new List<string>();
    int matchesFound = 0;
    Timer timer;
    int tenthsOfSecondsElapsed = 0;
    string timeDisplay;

    protected override void OnInitialized()
    {
        timer = new Timer(100);
        timer.Elapsed += Timer_Tick;

        SetUpGame();
    }

    private void SetUpGame()
    {
        Random random = new Random();
        shuffledAnimals = animalEmoji
            .OrderBy(item => random.Next())
            .ToList();
        matchesFound = 0;
        tenthsOfSecondsElapsed = 0;
    }

    string lastAnimalFound = string.Empty;
    string lastDescription = string.Empty;

    private void ButtonClick(string animal, string animalDescription)
    {
        if (lastAnimalFound == string.Empty)
        {
            // First selection of the pair. Remember it.
            lastAnimalFound = animal;
            lastDescription = animalDescription;

            timer.Start();
        }
        else if ((lastAnimalFound == animal) && (animalDescription != lastDescription))
        {
            // Match found! Reset for next pair.
            lastAnimalFound = string.Empty;

            // Replace found animals with empty string to hide them.
            shuffledAnimals = shuffledAnimals
                .Select(a => a.Replace(animal, string.Empty))
                .ToList();

            matchesFound++;
            if (matchesFound == 8)
            {
                timer.Stop();
                timeDisplay += " - Play Again?";

                SetUpGame();
            }
        }
        else
        {
            // User selected a pair that don't match.
            // Reset selection.
            lastAnimalFound = string.Empty;
        }
    }

    private void Timer_Tick(Object source, ElapsedEventArgs e)
    {
        InvokeAsync(() =>
        {
            tenthsOfSecondsElapsed++;
            timeDisplay = (tenthsOfSecondsElapsed / 10F)
                .ToString("0.0s");
            StateHasChanged();
        });
    }

#line default
#line hidden
#nullable disable
    }
}
#pragma warning restore 1591
