Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
    Inherits Form

    ' Game data
    Private characters As New List(Of Character)
    Private currentCharacterIndex As Integer = 0
    Private score As Integer = 0
    Private hintsUsed As Integer = 0

    ' Dynamic controls
    Private hintLabels As New List(Of Label)
    Private WithEvents guessButton As Button
    Private WithEvents nextButton As Button
    Private WithEvents hintButton As Button
    Private WithEvents resetButton As Button
    Private guessTextBox As TextBox
    Private scoreLabel As Label
    Private resultLabel As Label
    Private characterImage As PictureBox

    Public Sub New()
        InitializeGame()
        InitializeForm()
        LoadCharacter(0)
    End Sub

    Private Sub InitializeGame()
        ' Add sample characters with hints
        characters.Add(New Character("Albert Einstein", {
            "I was born in Germany in 1879",
            "I developed the theory of relativity",
            "My most famous equation is E=mc²",
            "I won the Nobel Prize in Physics in 1921",
            "I had wild white hair"
        }, "einstein.jpg"))

        characters.Add(New Character("William Shakespeare", {
            "I was an English playwright born in 1564",
            "I wrote Romeo and Juliet",
            "I'm often called the Bard of Avon",
            "I wrote approximately 39 plays",
            "My theater was called The Globe"
        }, "shakespeare.jpg"))

        characters.Add(New Character("Cleopatra", {
            "I was the last active ruler of the Ptolemaic Kingdom of Egypt",
            "I had relationships with Julius Caesar and Mark Antony",
            "I was known for my intelligence and beauty",
            "I died in 30 BC",
            "I spoke multiple languages"
        }, "cleopatra.jpg"))

        characters.Add(New Character("Leonardo da Vinci", {
            "I was an Italian polymath born in 1452",
            "I painted the Mona Lisa",
            "I was also an inventor and scientist",
            "I kept detailed notebooks",
            "I was fascinated by flight"
        }, "davinci.jpg"))
    End Sub

    Private Sub InitializeForm()
        Me.Text = "Who Am I? Game"
        Me.Size = New Size(800, 600)
        Me.StartPosition = FormStartPosition.CenterScreen

        ' Create title label
        Dim titleLabel As New Label()
        titleLabel.Text = "WHO AM I?"
        titleLabel.Font = New Font("Arial", 24, FontStyle.Bold)
        titleLabel.ForeColor = Color.DarkBlue
        titleLabel.AutoSize = True
        titleLabel.Location = New Point(300, 20)
        Me.Controls.Add(titleLabel)

        ' Create score label
        scoreLabel = New Label()
        scoreLabel.Text = "Score: 0"
        scoreLabel.Font = New Font("Arial", 14)
        scoreLabel.AutoSize = True
        scoreLabel.Location = New Point(650, 20)
        Me.Controls.Add(scoreLabel)

        ' Create picture box for character image
        characterImage = New PictureBox()
        characterImage.Size = New Size(200, 250)
        characterImage.Location = New Point(50, 80)
        characterImage.BorderStyle = BorderStyle.FixedSingle
        characterImage.SizeMode = PictureBoxSizeMode.StretchImage
        Me.Controls.Add(characterImage)

        ' Create hint labels
        Dim hintY As Integer = 80
        For i As Integer = 0 To 4
            Dim hintLabel As New Label()
            hintLabel.Name = "hintLabel" & i
            hintLabel.Text = "Hint " & (i + 1) & ": [Click 'Get Hint' to reveal]"
            hintLabel.Font = New Font("Arial", 10)
            hintLabel.AutoSize = True
            hintLabel.Location = New Point(300, hintY)
            hintLabel.ForeColor = Color.Gray
            hintLabel.Visible = False
            hintLabels.Add(hintLabel)
            Me.Controls.Add(hintLabel)
            hintY += 40
        Next

        ' Create guess textbox
        guessTextBox = New TextBox()
        guessTextBox.Location = New Point(300, 300)
        guessTextBox.Size = New Size(200, 25)
        guessTextBox.Font = New Font("Arial", 12)
        Me.Controls.Add(guessTextBox)

        ' Create guess button
        guessButton = New Button()
        guessButton.Text = "Guess"
        guessButton.Location = New Point(520, 300)
        guessButton.Size = New Size(100, 30)
        guessButton.Font = New Font("Arial", 10, FontStyle.Bold)
        guessButton.BackColor = Color.LightGreen
        AddHandler guessButton.Click, AddressOf GuessButton_Click
        Me.Controls.Add(guessButton)

        ' Create hint button
        hintButton = New Button()
        hintButton.Text = "Get Hint (-5 points)"
        hintButton.Location = New Point(300, 350)
        hintButton.Size = New Size(150, 30)
        hintButton.Font = New Font("Arial", 10)
        hintButton.BackColor = Color.LightBlue
        AddHandler hintButton.Click, AddressOf HintButton_Click
        Me.Controls.Add(hintButton)

        ' Create next button
        nextButton = New Button()
        nextButton.Text = "Next Character"
        nextButton.Location = New Point(470, 350)
        nextButton.Size = New Size(150, 30)
        nextButton.Font = New Font("Arial", 10)
        nextButton.BackColor = Color.LightGoldenrodYellow
        nextButton.Enabled = False
        AddHandler nextButton.Click, AddressOf NextButton_Click
        Me.Controls.Add(nextButton)

        ' Create reset button
        resetButton = New Button()
        resetButton.Text = "Reset Game"
        resetButton.Location = New Point(300, 400)
        resetButton.Size = New Size(320, 30)
        resetButton.Font = New Font("Arial", 10)
        resetButton.BackColor = Color.LightCoral
        AddHandler resetButton.Click, AddressOf ResetButton_Click
        Me.Controls.Add(resetButton)

        ' Create result label
        resultLabel = New Label()
        resultLabel.Text = ""
        resultLabel.Font = New Font("Arial", 12, FontStyle.Bold)
        resultLabel.AutoSize = True
        resultLabel.Location = New Point(300, 450)
        resultLabel.ForeColor = Color.DarkGreen
        Me.Controls.Add(resultLabel)

        ' Add keyboard shortcut for Enter key
        Me.KeyPreview = True
        AddHandler Me.KeyDown, AddressOf Form_KeyDown
        guessButton.TabIndex = 0
    End Sub

    Private Sub LoadCharacter(index As Integer)
        If index >= characters.Count Then
            resultLabel.Text = "Game Over! Final Score: " & score
            nextButton.Enabled = False
            guessButton.Enabled = False
            hintButton.Enabled = False
            Return
        End If

        currentCharacterIndex = index
        hintsUsed = 0

        ' Reset hint labels
        For i As Integer = 0 To hintLabels.Count - 1
            hintLabels(i).Text = "Hint " & (i + 1) & ": [Click 'Get Hint' to reveal]"
            hintLabels(i).ForeColor = Color.Gray
            hintLabels(i).Visible = False
        Next

        ' Clear controls
        guessTextBox.Text = ""
        guessTextBox.Focus()
        resultLabel.Text = ""
        nextButton.Enabled = False

        ' Try to load image
        Try
            Dim imagePath As String = Application.StartupPath & "\" & characters(index).ImageFile
            If System.IO.File.Exists(imagePath) Then
                characterImage.Image = Image.FromFile(imagePath)
            Else
                ' Use placeholder if image doesn't exist
                characterImage.Image = CreatePlaceholderImage()
            End If
        Catch ex As Exception
            characterImage.Image = CreatePlaceholderImage()
        End Try
    End Sub

    Private Function CreatePlaceholderImage() As Image
        Dim bmp As New Bitmap(200, 250)
        Using g As Graphics = Graphics.FromImage(bmp)
            g.Clear(Color.LightGray)
            g.DrawString("Character Image", New Font("Arial", 12), Brushes.Black, 30, 100)
        End Using
        Return bmp
    End Function

    Private Sub GuessButton_Click(sender As Object, e As EventArgs)
        CheckGuess()
    End Sub

    Private Sub HintButton_Click(sender As Object, e As EventArgs)
        If hintsUsed < characters(currentCharacterIndex).Hints.Length Then
            hintLabels(hintsUsed).Text = "Hint " & (hintsUsed + 1) & ": " &
                characters(currentCharacterIndex).Hints(hintsUsed)
            hintLabels(hintsUsed).ForeColor = Color.DarkBlue
            hintLabels(hintsUsed).Visible = True

            ' Deduct points for using hint
            score -= 5
            If score < 0 Then score = 0
            scoreLabel.Text = "Score: " & score

            hintsUsed += 1

            ' Disable hint button if all hints used
            If hintsUsed >= characters(currentCharacterIndex).Hints.Length Then
                hintButton.Enabled = False
            End If
        End If
    End Sub

    Private Sub NextButton_Click(sender As Object, e As EventArgs)
        LoadCharacter(currentCharacterIndex + 1)
        hintButton.Enabled = True
    End Sub

    Private Sub ResetButton_Click(sender As Object, e As EventArgs)
        score = 0
        scoreLabel.Text = "Score: 0"
        LoadCharacter(0)
        hintButton.Enabled = True
        guessButton.Enabled = True
    End Sub

    Private Sub CheckGuess()
        Dim guess As String = guessTextBox.Text.Trim()
        Dim correctAnswer As String = characters(currentCharacterIndex).Name

        If String.Equals(guess, correctAnswer, StringComparison.OrdinalIgnoreCase) Then
            resultLabel.Text = "Correct! It's " & correctAnswer
            resultLabel.ForeColor = Color.Green

            ' Calculate points: 50 base - (10 * hints used)
            Dim points As Integer = 50 - (hintsUsed * 10)
            If points < 10 Then points = 10
            score += points

            scoreLabel.Text = "Score: " & score
            nextButton.Enabled = True
            guessButton.Enabled = False
        Else
            resultLabel.Text = "Incorrect! Try again."
            resultLabel.ForeColor = Color.Red
            guessTextBox.SelectAll()
            guessTextBox.Focus()
        End If
    End Sub

    Private Sub Form_KeyDown(sender As Object, e As KeyEventArgs)
        If e.KeyCode = Keys.Enter AndAlso guessButton.Enabled Then
            CheckGuess()
        End If
    End Sub

    ' Character class to store game data
    Private Class Character
        Public Property Name As String
        Public Property Hints As String()
        Public Property ImageFile As String

        Public Sub New(name As String, hints As String(), imageFile As String)
            Me.Name = name
            Me.Hints = hints
            Me.ImageFile = imageFile
        End Sub
    End Class
End Class

' Program entry point
Module Program
    Sub Main()
        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)
        Application.Run(New Form1())
    End Sub
End Module
