Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
    Inherits Form

    ' Game data
    Private songs As New List(Of Song)
    Private currentSongIndex As Integer = 0
    Private score As Integer = 0
    Private timeLeft As Integer = 60
    Private timer As Timer

    ' Runtime controls
    Private lblTitle As Label
    Private lblGargledLyrics As Label
    Private txtGuess As TextBox
    Private btnSubmit As Button
    Private btnSkip As Button
    Private lblScore As Label
    Private lblTime As Label
    Private lblResult As Label
    Private lblCorrectAnswer As Label
    Private pnlGame As Panel
    Private pnlResult As Panel

    ' Song class
    Private Class Song
        Public Property Title As String
        Public Property Artist As String
        Public Property Lyrics As String
        Public Property GargledLyrics As String

        Public Sub New(title As String, artist As String, lyrics As String)
            Me.Title = title
            Me.Artist = artist
            Me.Lyrics = lyrics
            Me.GargledLyrics = GargleLyrics(lyrics)
        End Sub

        Private Function GargleLyrics(lyrics As String) As String
            ' Simple gargling algorithm: keep first and last letter of each word,
            ' scramble middle letters, and replace some vowels
            Dim words = lyrics.Split(" "c)
            Dim result As New List(Of String)
            Dim random As New Random()

            For Each word In words
                If word.Length <= 3 Then
                    result.Add(word)
                Else
                    ' Keep first and last letter
                    Dim firstLetter = word(0)
                    Dim lastLetter = word(word.Length - 1)
                    Dim middle = word.Substring(1, word.Length - 2)

                    ' Scramble middle letters
                    Dim chars = middle.ToCharArray()
                    For i = 0 To chars.Length - 1
                        If random.NextDouble() > 0.5 Then
                            chars(i) = ChrW(AscW(chars(i)) + random.Next(-2, 3))
                        End If
                    Next

                    Dim newWord = firstLetter & New String(chars) & lastLetter
                    result.Add(newWord)
                End If
            Next

            Return String.Join(" ", result)
        End Function
    End Class

    Public Sub New()
        ' Initialize form
        Me.Text = "Gargling Songs Game"
        Me.Size = New Size(800, 650)
        Me.StartPosition = FormStartPosition.CenterScreen

        InitializeSongs()
        InitializeGame()
    End Sub

    Private Sub InitializeSongs()
        ' Add some sample songs
        songs.Add(New Song("Bohemian Rhapsody", "Queen",
            "Is this the real life? Is this just fantasy?"))
        songs.Add(New Song("Imagine", "John Lennon",
            "Imagine all the people living life in peace"))
        songs.Add(New Song("Billie Jean", "Michael Jackson",
            "Billie Jean is not my lover she's just a girl"))
        songs.Add(New Song("Like a Rolling Stone", "Bob Dylan",
            "How does it feel to be on your own with no direction home"))
        songs.Add(New Song("Smells Like Teen Spirit", "Nirvana",
            "Here we are now entertain us I feel stupid and contagious"))
        songs.Add(New Song("Yesterday", "The Beatles",
            "Yesterday all my troubles seemed so far away"))
    End Sub

    Private Sub InitializeGame()
        ' Create main container panel
        pnlGame = New Panel()
        pnlGame.Dock = DockStyle.Fill
        pnlGame.BackColor = Color.LightBlue
        Me.Controls.Add(pnlGame)

        ' Create title label
        lblTitle = New Label()
        lblTitle.Text = "GARGLING SONGS GAME"
        lblTitle.Font = New Font("Arial", 24, FontStyle.Bold)
        lblTitle.ForeColor = Color.DarkBlue
        lblTitle.Size = New Size(600, 40)
        lblTitle.Location = New Point(100, 20)
        lblTitle.TextAlign = ContentAlignment.MiddleCenter
        pnlGame.Controls.Add(lblTitle)

        ' Create score label
        lblScore = New Label()
        lblScore.Text = $"Score: {score}"
        lblScore.Font = New Font("Arial", 14, FontStyle.Bold)
        lblScore.ForeColor = Color.Green
        lblScore.Size = New Size(150, 30)
        lblScore.Location = New Point(20, 80)
        pnlGame.Controls.Add(lblScore)

        ' Create timer label
        lblTime = New Label()
        lblTime.Text = $"Time: {timeLeft}s"
        lblTime.Font = New Font("Arial", 14, FontStyle.Bold)
        lblTime.ForeColor = Color.Red
        lblTime.Size = New Size(150, 30)
        lblTime.Location = New Point(650, 80)
        pnlGame.Controls.Add(lblTime)

        ' Create gargled lyrics label
        lblGargledLyrics = New Label()
        lblGargledLyrics.Font = New Font("Arial", 16, FontStyle.Italic)
        lblGargledLyrics.ForeColor = Color.DarkRed
        lblGargledLyrics.Size = New Size(700, 100)
        lblGargledLyrics.Location = New Point(50, 150)
        lblGargledLyrics.TextAlign = ContentAlignment.MiddleCenter
        lblGargledLyrics.BorderStyle = BorderStyle.FixedSingle
        lblGargledLyrics.BackColor = Color.LightYellow
        pnlGame.Controls.Add(lblGargledLyrics)

        ' Create guess textbox
        txtGuess = New TextBox()
        txtGuess.Font = New Font("Arial", 10)
        txtGuess.Size = New Size(400, 30)
        txtGuess.Location = New Point(200, 300)
        txtGuess.Text = "Enter your guess (Song Title or Artist)..."
        pnlGame.Controls.Add(txtGuess)

        ' Create submit button
        btnSubmit = New Button()
        btnSubmit.Text = "Submit Guess"
        btnSubmit.Font = New Font("Arial", 10, FontStyle.Bold)
        btnSubmit.Size = New Size(150, 40)
        btnSubmit.Location = New Point(300, 350)
        btnSubmit.BackColor = Color.LightGreen
        AddHandler btnSubmit.Click, AddressOf SubmitGuess
        pnlGame.Controls.Add(btnSubmit)

        ' Create skip button
        btnSkip = New Button()
        btnSkip.Text = "Skip Song"
        btnSkip.Font = New Font("Arial", 10)
        btnSkip.Size = New Size(150, 40)
        btnSkip.Location = New Point(300, 400)
        btnSkip.BackColor = Color.LightCoral
        AddHandler btnSkip.Click, AddressOf SkipSong
        pnlGame.Controls.Add(btnSkip)

        ' Create result panel (initially hidden)
        pnlResult = New Panel()
        pnlResult.Size = New Size(600, 200)
        pnlResult.Location = New Point(100, 450)
        pnlResult.BackColor = Color.LightGray
        pnlResult.Visible = False
        pnlGame.Controls.Add(pnlResult)

        ' Create result label
        lblResult = New Label()
        lblResult.Font = New Font("Arial", 16, FontStyle.Bold)
        lblResult.Size = New Size(580, 50)
        lblResult.Location = New Point(10, 20)
        lblResult.TextAlign = ContentAlignment.MiddleCenter
        pnlResult.Controls.Add(lblResult)

        ' Create correct answer label
        lblCorrectAnswer = New Label()
        lblCorrectAnswer.Font = New Font("Arial", 10)
        lblCorrectAnswer.Size = New Size(580, 50)
        lblCorrectAnswer.Location = New Point(10, 80)
        lblCorrectAnswer.TextAlign = ContentAlignment.MiddleCenter
        pnlResult.Controls.Add(lblCorrectAnswer)

        ' Initialize timer
        timer = New Timer()
        timer.Interval = 1000 ' 1 second
        AddHandler timer.Tick, AddressOf TimerTick

        ' Start first song
        LoadNextSong()
        timer.Start()
    End Sub

    Private Sub LoadNextSong()
        If currentSongIndex < songs.Count Then
            Dim song = songs(currentSongIndex)
            lblGargledLyrics.Text = $"GARGLED LYRICS: {song.GargledLyrics}"
            txtGuess.Text = ""
            txtGuess.Focus()
            pnlResult.Visible = False
        Else
            EndGame()
        End If
    End Sub

    Private Sub SubmitGuess(sender As Object, e As EventArgs)
        If currentSongIndex >= songs.Count Then Return

        Dim guess = txtGuess.Text.Trim().ToLower()
        Dim song = songs(currentSongIndex)
        Dim correctTitle = song.Title.ToLower()
        Dim correctArtist = song.Artist.ToLower()

        pnlResult.Visible = True

        If guess.Contains(correctTitle) OrElse guess.Contains(correctArtist) Then
            ' Correct guess
            score += 10
            lblScore.Text = $"Score: {score}"
            lblResult.Text = "CORRECT! +10 points"
            lblResult.ForeColor = Color.Green
        Else
            ' Wrong guess
            lblResult.Text = "INCORRECT!"
            lblResult.ForeColor = Color.Red
        End If

        lblCorrectAnswer.Text = $"Correct answer: {song.Title} by {song.Artist}"

        ' Move to next song after delay
        timer.Stop()
        Dim nextTimer As New Timer()
        nextTimer.Interval = 2000 ' 2 seconds
        AddHandler nextTimer.Tick, Sub(s, ev)
                                       nextTimer.Stop()
                                       nextTimer.Dispose()
                                       currentSongIndex += 1
                                       LoadNextSong()
                                       timer.Start()
                                   End Sub
        nextTimer.Start()
    End Sub

    Private Sub SkipSong(sender As Object, e As EventArgs)
        Dim song = songs(currentSongIndex)

        pnlResult.Visible = True
        lblResult.Text = "SONG SKIPPED"
        lblResult.ForeColor = Color.Orange
        lblCorrectAnswer.Text = $"Correct answer: {song.Title} by {song.Artist}"

        ' Move to next song after delay
        timer.Stop()
        Dim nextTimer As New Timer()
        nextTimer.Interval = 1500 ' 1.5 seconds
        AddHandler nextTimer.Tick, Sub(s, ev)
                                       nextTimer.Stop()
                                       nextTimer.Dispose()
                                       currentSongIndex += 1
                                       LoadNextSong()
                                       timer.Start()
                                   End Sub
        nextTimer.Start()
    End Sub

    Private Sub TimerTick(sender As Object, e As EventArgs)
        timeLeft -= 1
        lblTime.Text = $"Time: {timeLeft}s"

        If timeLeft <= 0 Then
            timer.Stop()
            EndGame()
        End If
    End Sub

    Private Sub EndGame()
        timer.Stop()

        ' Clear game panel
        pnlGame.Controls.Clear()

        ' Create game over screen
        Dim lblGameOver As New Label()
        lblGameOver.Text = "GAME OVER!"
        lblGameOver.Font = New Font("Arial", 32, FontStyle.Bold)
        lblGameOver.ForeColor = Color.Red
        lblGameOver.Size = New Size(600, 50)
        lblGameOver.Location = New Point(100, 100)
        lblGameOver.TextAlign = ContentAlignment.MiddleCenter
        pnlGame.Controls.Add(lblGameOver)

        Dim lblFinalScore As New Label()
        lblFinalScore.Text = $"Final Score: {score}"
        lblFinalScore.Font = New Font("Arial", 24, FontStyle.Bold)
        lblFinalScore.ForeColor = Color.Blue
        lblFinalScore.Size = New Size(600, 40)
        lblFinalScore.Location = New Point(100, 180)
        lblFinalScore.TextAlign = ContentAlignment.MiddleCenter
        pnlGame.Controls.Add(lblFinalScore)

        Dim lblSongsGuessed As New Label()
        lblSongsGuessed.Text = $"Songs Guessed: {currentSongIndex} of {songs.Count}"
        lblSongsGuessed.Font = New Font("Arial", 18)
        lblSongsGuessed.Size = New Size(600, 30)
        lblSongsGuessed.Location = New Point(100, 250)
        lblSongsGuessed.TextAlign = ContentAlignment.MiddleCenter
        pnlGame.Controls.Add(lblSongsGuessed)

        Dim btnPlayAgain As New Button()
        btnPlayAgain.Text = "Play Again"
        btnPlayAgain.Font = New Font("Arial", 10, FontStyle.Bold)
        btnPlayAgain.Size = New Size(150, 50)
        btnPlayAgain.Location = New Point(325, 320)
        btnPlayAgain.BackColor = Color.LightGreen
        AddHandler btnPlayAgain.Click, AddressOf PlayAgain
        pnlGame.Controls.Add(btnPlayAgain)
    End Sub

    Private Sub PlayAgain(sender As Object, e As EventArgs)
        ' Reset game state
        score = 0
        currentSongIndex = 0
        timeLeft = 60

        ' Reinitialize game
        pnlGame.Controls.Clear()
        InitializeGame()
    End Sub

    <STAThread>
    Public Shared Sub Main()
        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)
        Application.Run(New Form1())
    End Sub
End Class
