Imports System.ComponentModel

Public Class frm_scorecontrol

    Dim Match As match
    Dim MatchNumber As Integer = 1
    Dim MatchTimer As match_timer

    Dim CHANGE As Boolean = False
    Dim START_BUTTON As Boolean = False

    Private Sub tmr_display_Tick(sender As Object, e As EventArgs) Handles tmr_display.Tick

        If START_BUTTON = True Then

            DisplayData()

        End If

    End Sub

    Private Sub btn_start_Click(sender As Object, e As EventArgs) Handles btn_start.Click

        If btn_start.Text = "START" Then

            If Not IsNothing(Match) Then Match.StartMatch() Else Exit Sub
            START_BUTTON = True
            CHANGE = True
            MatchTimer = New match_timer(1, 30)
            round_countdown.Interval = 1000
            round_countdown.Enabled = True
            btn_start.Text = "PAUSE"

        ElseIf btn_start.Text = "PAUSE" Then

            btn_start.Text = "RESUME"
            round_countdown.Enabled = False

        ElseIf btn_start.Text = "RESUME" Then

            btn_start.Text = "PAUSE"
            round_countdown.Enabled = True

        End If

    End Sub

    Private Sub btn_blue_shkp_Click(sender As Object, e As EventArgs) Handles btn_blue_shkp.Click

        If CHANGE = True Then MATCH.BlueFighter.AdjustScore(4)

    End Sub

    Private Sub btn_blue_dhkp_Click(sender As Object, e As EventArgs) Handles btn_blue_dhkp.Click

        If CHANGE = True Then MATCH.BlueFighter.AdjustScore(3)

    End Sub

    Private Sub btn_blue_sbkp_Click(sender As Object, e As EventArgs) Handles btn_blue_sbkp.Click

        If CHANGE = True Then Match.BlueFighter.AdjustScore(2)

    End Sub

    Private Sub btn_blue_dbkp_Click(sender As Object, e As EventArgs) Handles btn_blue_dbkp.Click

        If CHANGE = True Then MATCH.BlueFighter.AdjustScore(1)

    End Sub

    Private Sub btn_red_dbkp_Click(sender As Object, e As EventArgs) Handles btn_red_dbkp.Click

        If CHANGE = True Then MATCH.RedFighter.AdjustScore(1)

    End Sub

    Private Sub btn_red_sbkp_Click(sender As Object, e As EventArgs) Handles btn_red_sbkp.Click

        If CHANGE = True Then Match.RedFighter.AdjustScore(2)

    End Sub

    Private Sub btn_red_dhkp_Click(sender As Object, e As EventArgs) Handles btn_red_dhkp.Click

        If CHANGE = True Then MATCH.RedFighter.AdjustScore(3)

    End Sub

    Private Sub btn_red_shkp_Click(sender As Object, e As EventArgs) Handles btn_red_shkp.Click

        If CHANGE = True Then MATCH.RedFighter.AdjustScore(4)

    End Sub

    Private Sub timer_countdown_Tick(sender As Object, e As EventArgs) Handles round_countdown.Tick

        MatchTimer.Run()

    End Sub

    Private Sub btn_blue_shkn_Click(sender As Object, e As EventArgs) Handles btn_blue_shkn.Click

        If CHANGE = True Then MATCH.BlueFighter.AdjustScore(-4)

    End Sub

    Private Sub btn_blue_dhkn_Click(sender As Object, e As EventArgs) Handles btn_blue_dhkn.Click

        If CHANGE = True Then MATCH.BlueFighter.AdjustScore(-3)

    End Sub

    Private Sub btn_blue_sbkn_Click(sender As Object, e As EventArgs) Handles btn_blue_sbkn.Click

        If CHANGE = True Then Match.BlueFighter.AdjustScore(-2)

    End Sub

    Private Sub btn_blue_dbkn_Click(sender As Object, e As EventArgs) Handles btn_blue_dbkn.Click

        If CHANGE = True Then MATCH.BlueFighter.AdjustScore(-1)

    End Sub

    Private Sub btn_red_dbkn_Click(sender As Object, e As EventArgs) Handles btn_red_dbkn.Click

        If CHANGE = True Then MATCH.RedFighter.AdjustScore(-1)

    End Sub

    Private Sub btn_red_sbkn_Click(sender As Object, e As EventArgs) Handles btn_red_sbkn.Click

        If CHANGE = True Then Match.RedFighter.AdjustScore(-2)

    End Sub

    Private Sub btn_red_dhkn_Click(sender As Object, e As EventArgs) Handles btn_red_dhkn.Click

        If CHANGE = True Then MATCH.RedFighter.AdjustScore(-3)

    End Sub

    Private Sub btn_red_shkn_Click(sender As Object, e As EventArgs) Handles btn_red_shkn.Click

        If CHANGE = True Then MATCH.RedFighter.AdjustScore(-4)

    End Sub

    Private Sub btn_blue_pgf_Click(sender As Object, e As EventArgs) Handles btn_blue_pgf.Click

        If CHANGE = True Then
            Match.BlueFighter.AdjustGamjum(1)
            'Match.RedFighter.GetTransfered(1)
        End If

    End Sub

    Private Sub btn_blue_ngf_Click(sender As Object, e As EventArgs) Handles btn_blue_ngf.Click

        If CHANGE = True Then MATCH.BlueFighter.AdjustGamjum(-1)

    End Sub

    Private Sub btn_red_pgf_Click(sender As Object, e As EventArgs) Handles btn_red_pgf.Click

        If CHANGE = True Then MATCH.RedFighter.AdjustGamjum(1)

    End Sub

    Private Sub btn_red_ngf_Click(sender As Object, e As EventArgs) Handles btn_red_ngf.Click

        If CHANGE = True Then MATCH.RedFighter.AdjustGamjum(-1)

    End Sub

    Private Sub btn_end_Click(sender As Object, e As EventArgs) Handles btn_end.Click

        CHANGE = False

        If Not IsNothing(Match) Then Match.EndMatch() Else System.GC.Collect()

        btn_start.Text = "START"
        'Match.RoundTime = New match.timer(Match.MaxRoundMin, Match.MaxRoundSec)
        round_countdown.Enabled = False

    End Sub

    Private Sub lbl_match_number_Click(sender As Object, e As EventArgs) Handles lbl_match_number.Click

        If CHANGE = False Then

            MatchNumber = InputBox("Please Type The Match Number", "Match Number", "1")
            Match = New match(1, MatchNumber)
            DisplayData()

        End If

    End Sub

    Private Sub DisplayData()

        ' Board Display

        Try

        Catch ex As Exception

        End Try

        lbl_round.Text = Match.ROUND
        lbl_match_number.Text = "M" & Match.ID
        lbl_court_number.Text = "C" & Match.COURT & "R" & Match.ROUND

        ' Blue Fighter Data Display
        Try
            lbl_blue_score.Text = Match.BlueFighter.Score
            lbl_blue_gamjum.Text = Match.BlueFighter.Gamjum
            lbl_blue_team.Text = Match.BlueFighter.Person.Team.Title
            lbl_blue_fighter_name.Text = Match.BlueFighter.Person.ShortName
            lbl_blue_code_3.Text = Match.BlueFighter.Person.Team.Country.ISO3
            lbl_blue_gender.Text = Match.BlueFighter.Person.Gender
            lbl_blue_weight_class.Text = Match.BlueFighter.Person.Weight.WeightClass
            lbl_blue_weight_category.Text = Match.BlueFighter.Person.Weight.WeightCategory
        Catch ex As Exception
            lbl_blue_score.Text = 0
            lbl_blue_gamjum.Text = 0
            lbl_blue_team.Text = "BLUE TEAM"
            lbl_blue_fighter_name.Text = "BLUE FIGHTER"
            lbl_blue_code_3.Text = "ISO3"
            lbl_blue_gender.Text = "XGNDR"
            lbl_blue_weight_class.Text = "OPEN WT"
            lbl_blue_weight_category.Text = "UNKNOWN"
        End Try

        Try ' Blue Fighter Flag Image Display
            pb_blue_flag.Image = Image.FromStream(Match.BlueFighter.Person.TEAM.Country.Flag)
            'pb_blue_flag.Visible = True
        Catch ex As Exception
            pb_blue_flag.Image = Nothing
            'pb_blue_flag.Visible = False
        End Try

        Try ' Blue Fighter Logo Image Display
            pb_blue_logo.Image = Image.FromStream(Match.BlueFighter.Person.TEAM.Logo)
            'pb_blue_logo.Visible = True
        Catch ex As Exception
            pb_blue_logo.Image = Nothing
            'pb_blue_logo.Visible = False
        End Try

        ' Red Fighter Data Display
        Try
            lbl_red_score.Text = Match.RedFighter.Score
            lbl_red_gamjum.Text = Match.RedFighter.Gamjum
            lbl_red_team.Text = Match.RedFighter.Person.Team.Title
            lbl_red_fighter_name.Text = Match.RedFighter.Person.ShortName
            lbl_red_code_3.Text = Match.RedFighter.Person.Team.Country.ISO3
            lbl_red_gender.Text = Match.RedFighter.Person.Gender
            lbl_red_weight_class.Text = Match.RedFighter.Person.Weight.WeightClass
            lbl_red_weight_category.Text = Match.RedFighter.Person.Weight.WeightCategory
        Catch ex As Exception
            lbl_red_score.Text = 0
            lbl_red_gamjum.Text = 0
            lbl_red_team.Text = "RED TEAM"
            lbl_red_fighter_name.Text = "RED FIGHTER"
            lbl_red_code_3.Text = "ISO3"
            lbl_red_gender.Text = "XGNDR"
            lbl_red_weight_class.Text = "OPEN WT"
            lbl_red_weight_category.Text = "UNKNOWN"
        End Try

        Try ' Red Fighter Flag Image Display
            pb_red_flag.Image = Image.FromStream(Match.RedFighter.Person.TEAM.Country.Flag)
            'pb_red_flag.Visible = True
        Catch ex As Exception
            pb_red_flag.Image = Nothing
            'pb_red_flag.Visible = False
        End Try

        Try ' Red Fighter Logo Image Display
            pb_red_logo.Image = Image.FromStream(Match.RedFighter.Person.TEAM.Logo)
            'pb_red_logo.Visible = True
        Catch ex As Exception
            pb_red_logo.Image = Nothing
            'pb_red_logo.Visible = False
        End Try

    End Sub

    Private Sub btn_inc_match_Click(sender As Object, e As EventArgs) Handles btn_inc_match.Click

        Try
            MatchNumber += 1
            Match = New match(1, MatchNumber)
            DisplayData()
        Catch ex As Exception
            MatchNumber -= 1
            Match = New match(1, MatchNumber)
            DisplayData()
        End Try

    End Sub

    Private Sub btn_dec_match_Click(sender As Object, e As EventArgs) Handles btn_dec_match.Click

        Try
            MatchNumber -= 1
            Match = New match(1, MatchNumber)
            DisplayData()
        Catch ex As Exception
            MatchNumber += 1
            Match = New match(1, MatchNumber)
            DisplayData()
        End Try

    End Sub

    Private Sub frm_scorecontrol_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Try
            Match = New match(1, MatchNumber)
            DisplayData()
        Catch ex As Exception
            Match = New match(1, MatchNumber)
            DisplayData()
        End Try

    End Sub

    Private Sub pb_blue_logo_Click(sender As Object, e As EventArgs) Handles pb_blue_logo.Click

        If IsNothing(pb_blue_logo.Image) Then
            frm_update_logo.Show()
        End If

    End Sub

    Private Sub pb_red_logo_Click(sender As Object, e As EventArgs) Handles pb_red_logo.Click

        If IsNothing(pb_red_logo.Image) Then
            frm_update_logo.Show()
        End If

    End Sub

    Private Sub frm_scorecontrol_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing

        frm_event_control.Show()

    End Sub

    Private Sub pb_blue_flag_Click(sender As Object, e As EventArgs) Handles pb_blue_flag.Click

        If IsNothing(pb_blue_flag.Image) Then
            frm_update_flag.Show()
        End If

    End Sub

    Private Sub pb_red_flag_Click(sender As Object, e As EventArgs) Handles pb_red_flag.Click

        If IsNothing(pb_red_flag.Image) Then
            frm_update_flag.Show()
        End If

    End Sub

End Class
