2 Replies - 359 Views - Last Post: 07 May 2012 - 11:02 AM Rate Topic: -----

#1 Unknown1992  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-May 12

I am creating a game & struggling with the high score code

Posted 07 May 2012 - 10:53 AM

I am creating a type of pacman game, I have entered the code for everything else, but I am struggling with the code for the high score, any help would be appreciated :)

Here is my code so far

 Public Class Maze

    Private _finishFlag As Boolean

    Private Property FinishFlag(ByVal pictureBox As PictureBox) As Boolean
        Get
            Return _finishFlag
        End Get
        Set(ByVal value As Boolean)
            _finishFlag = value
        End Set
    End Property

    Property Gameover As Boolean

    Private Property _TotalScore As String

    'part of evaluation include the fact that they go through the water and not around it
    Private Sub Waterman_Game_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Dim Locb4Move As Point
        Locb4Move = man.Location
        'move picture left, right, up, down depending on the key press
        Select Case e.KeyCode
            Case Keys.Left
                man.Left -= 10
            Case Keys.Right
                man.Left += 10
            Case Keys.Up
                man.Top -= 10
            Case Keys.Down
                man.Top += 10
        End Select
        'This is so that if the man collides into the wall, it will not go through the wall it will bounce back 
        If Wall_collide(man) Then
            man.Location = Locb4Move
        End If
        'when the player picks up water, they get points
        If Pickupwater(man) Then
            lblscore.Text = lblscore.Text + 10
        End If
        'If the player collides with the enemies, the player will loose a life
        If evilcollide(man) Then
            lbllives.Text = lbllives.Text - 1
        End If
        'When all 3 lives have gone the game ends
        If lbllives.Text > 0 Then
            tmrevilmove.Enabled = True
        Else
            MessageBox.Show("Game Over")
        End If
        If Finish(man) Then
            MessageBox.Show("Well Done!")
        End If

    End Sub
    Public Class PlayerScore
        Dim Scores As New List(Of PlayerScore)
        Score = (From s In Scores OrderBy s.Score Descending).ToList

    End Class
    'This is so that the player cannot collide into the walls
    Private Function Wall_collide(ByVal pic As PictureBox) As Boolean
        Dim ctl As Control
        For Each ctl In Panel1.Controls
            If TypeOf ctl Is Label Then
                If ctl.Bounds.IntersectsWith(pic.Bounds) Then
                    Return True
                End If
            End If
        Next
        Return False
    End Function
    'This is so when the player picks up the water, the picturebox disapears 
    Private Function Pickupwater(ByVal pic As PictureBox) As Boolean
        Dim ctl As Control
        For Each ctl In Panel1.Controls
            If TypeOf ctl Is PictureBox AndAlso ctl.Name.StartsWith("Water") AndAlso ctl.Visible = True Then
                If ctl.Bounds.IntersectsWith(pic.Bounds) Then
                    ctl.Visible = False
                    Return True
                End If
            End If
        Next
        Return False
    End Function
    'This is when the player collides into the enemies they disapear so it can give the player time to move away 
    Private Function evilcollide(ByVal pic As PictureBox) As Boolean
        Dim ctl As Control
        For Each ctl In Panel1.Controls
            If TypeOf ctl Is PictureBox AndAlso ctl.Name.StartsWith("evil") AndAlso ctl.Visible = True Then
                If ctl.Bounds.IntersectsWith(pic.Bounds) Then
                    ctl.Visible = False
                    tmrevilmove.Stop()
                    tmrresprawn.Start()
                    Return True
                End If
            End If
        Next
        Return False
    End Function
    Private Function Finish(ByVal pic As PictureBox) As Boolean
        Dim ctl As Control
        For Each ctl In Panel1.Controls
            If TypeOf ctl Is PictureBox AndAlso ctl.Name.StartsWith("Finish") Then
                If ctl.Bounds.IntersectsWith(pic.Bounds) Then
                    Return True
                End If
            End If
        Next
        Return False
    End Function

    'This allows the enemies to move randomly around the maze
    Private Sub tmrevilmove_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrevilmove.Tick
        Static evilmove As Integer
        evilmove = Int(Rnd() * 4 + 37)

        Dim Locb4Move As Point
        For I As Integer = 0 To 3
            Locb4Move = evil1.Location

            'move picture left, right, up, down depending on the key press

            Select Case evilmove
                Case Keys.Left
                    evil1.Left -= 10
                Case Keys.Right
                    evil1.Left += 10
                Case Keys.Up
                    evil1.Top -= 10
                Case Keys.Down
                    evil1.Top += 10
            End Select
            If Wall_collide(evil1) Then
                evil1.Location = Locb4Move
            End If

        Next I

        For I As Integer = 0 To 3
            Locb4Move = evil2.Location

            'move picture left, right, up, down depending on the key press

            Select Case evilmove
                Case Keys.Left
                    evil2.Left -= 5
                Case Keys.Right
                    evil2.Left += 5
                Case Keys.Up
                    evil2.Top -= 5
                Case Keys.Down
                    evil2.Top += 5
            End Select
            If Wall_collide(evil2) Then
                evil2.Location = Locb4Move
            End If
        Next I

        If evil1.Visible = False Then tmrevilmove.Enabled = False
        If evil2.Visible = False Then tmrevilmove.Enabled = False

    End Sub
    Private Sub tmrresprawn_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrresprawn.Tick
        'Make the enemies respawn after they have hit the player, this allows the player a chance to get away
        Static spawn_delay As Byte
        spawn_delay += 1
        If spawn_delay > 5 Then
            spawn_delay = 0
            evil1.Visible = True
            evil2.Visible = True
            tmrevilmove.Start()
            tmrresprawn.Stop()
        End If
    End Sub

End Class  

This post has been edited by AdamSpeight2008: 07 May 2012 - 11:14 AM


Is This A Good Question/Topic? 0
  • +

Replies To: I am creating a game & struggling with the high score code

#2 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 204
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: I am creating a game & struggling with the high score code

Posted 07 May 2012 - 10:56 AM

What is your problem you're struggling with exactly?

This post has been edited by nK0de: 07 May 2012 - 10:57 AM

Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,661
  • Joined: 02-June 10

Re: I am creating a game & struggling with the high score code

Posted 07 May 2012 - 11:02 AM

First: Fix your fraking code tags. Its not rocket science. The example is in the text box you pasted your code into for pete's sake
:code:

Second: Other than "I'm struggling" would you like to give a hint, a clue, a little riddle to solve, SOMETHING about what the actual problem is? Here's my suggestion based on what you told us:
If the new score is higher than the old high score than this is the new high score. It's pretty straight-forward logic.


What does "I need help" and "I'm having trouble" mean?

You are getting an error? Your code isn't doing what you expect it to?
What does this error mean?
Or you want someone to design your algorithm for you because you can't think of a way it should work?
I don't want you to write my code, just give me ideas on how to solve my problem. - Read this article
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1