none
How can I determine the winning player as soon as the headquarters is destroyed?

    Question

  • In the load section of the windows form I have created the sprites and implemented their positions with assigned HP. 

    Private Sub Bridge_Wars_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                DoubleBuffered = True
    
                Sprites.Add(New Sprite)
                Sprites.Add(New Sprite)
                Sprites.Add(New Sprite)
                Sprites.Add(New Sprite)
    
                Sprites(0).Name = "Gold Mine Red"
                Sprites(0).HP = 40
    
                Sprites(1).Name = "Headquarters Red"
                Sprites(1).HP = 150
    
                Sprites(2).Name = "Gold Mine Blue"
                Sprites(2).HP = 40
    
                Sprites(3).Name = "Headquarters Blue"
                Sprites(3).HP = 150
    
    
                Sprites(0).ColRow = New Point(0, 6)
                Sprites(1).ColRow = New Point(0, 8)
                Sprites(2).ColRow = New Point(16, 6)
                Sprites(3).ColRow = New Point(16, 8)
    
                For i = 0 To 3
                    Dim pic = New PictureBox()
                    With pic
                        .Name = "Pic" & i.ToString
                        .Size = GridSize
                        .BackgroundImageLayout = ImageLayout.Stretch
                        Dim ImageFile As String = IO.Path.Combine("C:\Users\BusinessOffice1Room\Documents\Waliur File\A Level\Computer Science\Coursework\Work In progression\Import or Export Images\PngFiles\Game Loadup", Sprites(i).Name & ".png")
                        .BackgroundImage = Image.FromFile(ImageFile)
                        Me.Controls.Add(pic)
                        AddHandler .MouseDown, AddressOf Pics_MouseDown
                        AddHandler .MouseDoubleClick, AddressOf Pics_DoubleClick
                        AddHandler .MouseMove, AddressOf pics_MouseMove
                        AddHandler .MouseUp, AddressOf pics_MouseUp
                    End With
                    Sprites(i).Pic = pic
                Next
                Bridge_Wars_Resize(1, Nothing)
            End Sub

    This is the process which allows a sprite to attack another sprite. 

     Private Sub Pics_DoubleClick(Sender As Object, e As MouseEventArgs)
                'show the menu
                If e.Button = MouseButtons.Left Then
                    If TankSelectStatus = 1 Then
                        TargetSprite = DirectCast(Sender, PictureBox).Name
                        TankSelectStatus = 0
                        'select the action
                        Dim AttackListIndex = GetSpriteIndex(AttackSprite)
                        Dim TargetListIndex = GetSpriteIndex(TargetSprite)
                        Dim hp As Integer = Sprites(TargetListIndex).HP - Sprites(AttackListIndex).AP
                        'popup the menu
                        If hp <= 0 Then
                            MsgBox(Sprites(TargetListIndex).Name & " Murked by " & Sprites(AttackListIndex).Name)
                            Sprites(AttackListIndex).HP += Sprites(TargetListIndex).HP
                            'remove sprite from list
                            Sprites(TargetListIndex).Pic.Dispose()
                            Sprites.Remove(Sprites(TargetListIndex))
                        Else
                            Sprites(TargetListIndex).HP = Sprites(TargetListIndex).HP - Sprites(AttackListIndex).AP
                            MsgBox("Still standing")
                        End If
                    Else
                        'reset the tools
                        AttackSprite = DirectCast(Sender, PictureBox).Name
                        TankToolbar.Location = New Point(Sprites(GetSpriteIndex(AttackSprite)).Pic.Right, Sprites(GetSpriteIndex(AttackSprite)).Pic.Bottom)
                        TankToolbar.Visible = True
                    End If
                End If
            End Sub

    In a nutshell the sprites 1 and 3 which are called headquarters I would like to indicate in the mouse_doubleclick to indicate if the health is 0 then the headquarter is removed indicates msgbox that its destroyed and says who is the winner. 



    WRA

    Saturday, April 15, 2017 1:34 PM

Answers

  • All I need is to solve the part where the program indicates it "headquarters" being destroyed.

    It is difficult to see what the problem is.

    If this code:
                Sprites(1).Name = "Headquarters Red"
    establishes that sprite as the Headquarters for Red, then when this code:
                        Sprites(TargetListIndex).Pic.Dispose()
                        Sprites.Remove(Sprites(TargetListIndex))
    executes, the Red headquarters has been destroyed if TargetListIndex is 1 or if Sprites(TargetListIndex).Name is "Headquarters Red".  You haven't explained the difficulty you have in doing that, but I suspect it involves insufficient supporting functions.

    • Marked as answer by Waliur Rahman Saturday, April 22, 2017 11:55 AM
    Sunday, April 16, 2017 10:04 PM

All replies


  •     Private Sub Pics_DoubleClick(Sender As Object, e As MouseEventArgs)
            If e.Button = MouseButtons.Left Then
                'Fully works determines when a tank Is destroyed
                If TankSelectStatus = 1 Then
                    TargetSprite = DirectCast(Sender, PictureBox).Name
                    TankSelectStatus = 0

                    'Declared variables
                    Dim AttackListIndex = GetSpriteIndex(AttackSprite)
                    Dim TargetListIndex = GetSpriteIndex(TargetSprite)
                    Dim hp As Integer = Sprites(TargetListIndex).HP - Sprites(AttackListIndex).AP

                    'select the action
                    If hp <= 0 Then
                        MsgBox(Sprites(TargetListIndex).Name & " Murked by " & Sprites(AttackListIndex).Name)
                        Sprites(AttackListIndex).HP += Sprites(TargetListIndex).HP
                        'remove sprite from list
                        Sprites(TargetListIndex).Pic.Dispose()
                        Sprites.Remove(Sprites(TargetListIndex))
                    Else
                        Sprites(TargetListIndex).HP = Sprites(TargetListIndex).HP - Sprites(AttackListIndex).AP
                        MsgBox("Still standing")
                    End If

                Else
                        'popup the menu
                        AttackSprite = DirectCast(Sender, PictureBox).Name
                    TankToolbar.Location = New Point(Sprites(GetSpriteIndex(AttackSprite)).Pic.Right, Sprites(GetSpriteIndex(AttackSprite)).Pic.Bottom)
                    TankToolbar.Visible = True
                End If
            End If

    WRA

    Sunday, April 16, 2017 11:58 AM
  •                     MsgBox(PL1 & " Has beaten " & PL2)
                        Me.Hide()
                        Game_Result.Show()

    This is a key characteristic which might help get the intended result All I need is to solve the part where the program indicates it "headquarters" being destroyed.              


    WRA

    Sunday, April 16, 2017 6:41 PM
  • All I need is to solve the part where the program indicates it "headquarters" being destroyed.

    It is difficult to see what the problem is.

    If this code:
                Sprites(1).Name = "Headquarters Red"
    establishes that sprite as the Headquarters for Red, then when this code:
                        Sprites(TargetListIndex).Pic.Dispose()
                        Sprites.Remove(Sprites(TargetListIndex))
    executes, the Red headquarters has been destroyed if TargetListIndex is 1 or if Sprites(TargetListIndex).Name is "Headquarters Red".  You haven't explained the difficulty you have in doing that, but I suspect it involves insufficient supporting functions.

    • Marked as answer by Waliur Rahman Saturday, April 22, 2017 11:55 AM
    Sunday, April 16, 2017 10:04 PM
  • Ahh I see, I will break it down to the functions alone of the sprite attack. This code in a nutshell determines attacking sprite, targets a sprite and see if it is destroyed and if so it is removed. 

    What I want to do though is determine when a certain building has been destroyed such as in this case headquarters.  BTW the sub load might be of some help to you too it is at the top of the thread. 

     Private Sub Pics_DoubleClick(Sender As Object, e As MouseEventArgs)
            If e.Button = MouseButtons.Left Then
                'Fully works determines when a tank Is destroyed
                If TankSelectStatus = 1 Then
                    TargetSprite = DirectCast(Sender, PictureBox).Name
                    TankSelectStatus = 0

                    'Declared variables
                    Dim AttackListIndex = GetSpriteIndex(AttackSprite)
                    Dim TargetListIndex = GetSpriteIndex(TargetSprite)
                    Dim hp As Integer = Sprites(TargetListIndex).HP - Sprites(AttackListIndex).AP

                    'select the action
                    If hp <= 0 Then
                        MsgBox(Sprites(TargetListIndex).Name & " Murked by " & Sprites(AttackListIndex).Name)
                        Sprites(AttackListIndex).HP += Sprites(TargetListIndex).HP
                        'remove sprite from list
                        Sprites(TargetListIndex).Pic.Dispose()
                        Sprites.Remove(Sprites(TargetListIndex))
                    Else
                        Sprites(TargetListIndex).HP = Sprites(TargetListIndex).HP - Sprites(AttackListIndex).AP
                        MsgBox("Still standing")
                    End If

                Else
                        'popup the menu
                        AttackSprite = DirectCast(Sender, PictureBox).Name
                    TankToolbar.Location = New Point(Sprites(GetSpriteIndex(AttackSprite)).Pic.Right, Sprites(GetSpriteIndex(AttackSprite)).Pic.Bottom)
                    TankToolbar.Visible = True
                End If
            End If


    WRA

    Monday, April 17, 2017 11:15 AM
  • What I want to do though is determine when a certain building has been destroyed such as in this case headquarters.

    You still haven't explained the problem.  You know what each sprite is by its name.  So when a target gets destroyed and before you remove it from the list, check the name.  Depending on what that name is, take the required action.

    Monday, April 17, 2017 12:36 PM
  • Ahh I see, I will break it down to the functions alone of the sprite attack. This code in a nutshell determines attacking sprite, targets a sprite and see if it is destroyed and if so it is removed. 

    What I want to do though is determine when a certain building has been destroyed such as in this case headquarters.  BTW the sub load might be of some help to you too it is at the top of the thread. 

     Private Sub Pics_DoubleClick(Sender As Object, e As MouseEventArgs)
            If e.Button = MouseButtons.Left Then
                'Fully works determines when a tank Is destroyed
                If TankSelectStatus = 1 Then
                    TargetSprite = DirectCast(Sender, PictureBox).Name
                    TankSelectStatus = 0

                    'Declared variables
                    Dim AttackListIndex = GetSpriteIndex(AttackSprite)
                    Dim TargetListIndex = GetSpriteIndex(TargetSprite)
                    Dim hp As Integer = Sprites(TargetListIndex).HP - Sprites(AttackListIndex).AP

                    'select the action
                    If hp <= 0 Then
                        MsgBox(Sprites(TargetListIndex).Name & " Murked by " & Sprites(AttackListIndex).Name)
                        Sprites(AttackListIndex).HP += Sprites(TargetListIndex).HP
                        'remove sprite from list
                        Sprites(TargetListIndex).Pic.Dispose()
                        Sprites.Remove(Sprites(TargetListIndex))
                    Else
                        Sprites(TargetListIndex).HP = Sprites(TargetListIndex).HP - Sprites(AttackListIndex).AP
                        MsgBox("Still standing")
                    End If

                Else
                        'popup the menu
                        AttackSprite = DirectCast(Sender, PictureBox).Name
                    TankToolbar.Location = New Point(Sprites(GetSpriteIndex(AttackSprite)).Pic.Right, Sprites(GetSpriteIndex(AttackSprite)).Pic.Bottom)
                    TankToolbar.Visible = True
                End If
            End If


    WRA

    Wali,

    In this code you get the picturebox object:

                        AttackSprite = DirectCast(Sender, PictureBox).Name

    And then you locate the toolbar using


              TankToolbar.Location = New Point(Sprites(GetSpriteIndex(AttackSprite)).Pic.Right,
                                                                 Sprites(GetSpriteIndex(AttackSprite)).Pic.Bottom)


    when all you need is

              TankToolbar.Location = AttackSprite .Location

    this tells me you still dont completely get the difference between a list index and a picturebox control.

         Sprites(GetSpriteIndex(AttackSprite)).Pic.Bottom

    Thats like standing next to Betty but instead of talking directly to her you call her Mom on the phone and her mom calls her on the phone and tells her what you said.

    Monday, April 17, 2017 12:39 PM
  • In other words I am going the long way around it and need to look at what code I have now to see how I could indicate if the target building is headquaters

    WRA

    Monday, April 17, 2017 1:49 PM
  • @Tommy and Acamar 

    Manage to solve this problem I was able to indicate when the headquarters is selected then the game is over.

    It was key to know the order of the code is important, I tried some things and eventually got to the solution. 


    WRA

    Saturday, April 22, 2017 11:57 AM