Option Explicit On Public Class Form1 'VARIABLES: Dim xpos As Integer 'the initial x position of 'pic' Dim ypos As Integer 'the initial y position of 'pic' Dim dx As Integer 'how far 'pic' moves horizontally in a given move Dim dy As Integer 'how far 'pic' moves vertically in a given move Dim defaultMinX As Integer 'the default smallest possible value for dx Dim defaultMaxX As Integer 'the default largest possible value for dx Dim defaultMinY As Integer 'the default smallest possible value for dy Dim defaultMaxY As Integer 'the default largest possible value for dy Dim minX As Integer 'the smallest possible value for dx for a given straight line path Dim maxX As Integer 'the largest possible value for dx for a given straight line path Dim minY As Integer 'the smallest possible value for dy for a given straight line path Dim maxY As Integer 'the largest possible value for dy for a given straight line path Dim tol As Integer 'defines how close 'pic' can get to an edge of the screen Dim result As Integer 'stores the result of the random process of generating dx and dy Dim lineDuration As Integer 'how long 'pic' will move in a given straight line path (in milliseconds) Dim lineTimeElapsed As Integer 'how long 'pic' has been moving in a given straight line path (in ms) Dim overallTimeElapsed As Integer 'how much time has elapsed in a given game (in ms) Dim gameDuration As Integer 'the length of a given game (in ms) Dim duration As Integer 'stores a time Dim score As Double 'the player's score Dim difficulty As String 'stores Easy, Medium or Hard Dim timerInterval As Integer 'sets Timer1.Interval, the amount of time between 'ticks' of the Timer Dim timeRemaining As Integer 'the amount of time remaining in the game Dim gameOver As Boolean 'is true if the game is over Dim minLineDuration As Integer 'the minimum possible time that 'pic' can move along a given line 'lineDurationDiff is the additional time (beyond minLineDuration) that 'pic' can move 'along a given line. The maximum time for 'pic' to move along a given line 'is: minLineDuration + lineDurationDiff. Dim lineDurationDiff As Integer 'getRandomInteger calculates a random integer x, where low <= x <= high Private Function getRandomInteger(low As Integer, high As Integer) 'Declare an integer 'diff' and set it equal to the difference between high and low 'Rnd() generates a random number between 0 and 1 'Multiply diff by Rnd(), use CInt() to convert the result to an integer, add it to low, 'and assign this number to 'result' 'Then, return result End Function 'Form1_Load initializes some variables as the form is loading Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load 'Call the function Randomize(). This will allow the random numbers generated to be truly random 'Set 'xpos' equal to 'Me.Width / 2'. This will position 'pic' in the middle of the screen 'Set 'ypos' equal to 'Me.Height / 2'. This does the same thing 'Set 'tol' equal to 50 'Set 'gameDuration' equal to the desired duration of the game, in milliseconds minLineDuration = 500 lineDurationDiff = 500 End Sub 'resetXY sets minX, maxX, minY and maxY back to their default values. 'This method is complete Private Sub resetXY() minX = defaultMinX minY = defaultMinY maxX = defaultMaxX maxY = defaultMaxY End Sub 'Button1_Click runs when Button1 is clicked Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'Set 'gameOver' to False 'Make visible the controls that you want the user to see while playing the game 'Make invisible the controls that should be invisible 'Set 'pic.Left' equal to 'xpos'. Set 'pic.Top' equal to 'ypos'. This positions 'pic' in the center 'Turn on the Timer by setting its Enabled property to True 'Set 'overallTimeElapsed' equal to 0 'If needed, change the Text property of any Labels 'Set up an If - ElseIf - Else statement that depends on which RadioButton the player checked 'If the player checked 'Easy', set 'difficulty' equal to "easy" 'Give values to defaultMinX, defaultMaxX, defaultMinY and defaultMaxY. 'These variables control how far 'pic' will move 'For example, if defaultMinX is set to -10 and defaultMaxX is 10, 'pic' will move between 10 pixels 'to the left and 10 pixels to the right. defaultMinY and defaultMaxY work similarly. 'You can try a range of -10 to 10 and then modify it 'timerInterval controls the interval (in milliseconds) at which the Timer 'ticks' 'For Easy, try setting it to 150 initially 'If the player clicked Medium, try increasing how far 'pic' would move, for example by making 'defaultMinX more negative and defaultMaxX more positive 'You can also change timerInterval 'Make similar changes if the player clicked Hard. 'Call resetXY() to restore minX, maxX, minY and maxY to their default values 'Call newLine() to set a new course for 'pic' End Sub 'newLine() sets 'pic' on a new path, along a new straight line Private Sub newLine() 'Set 'lineTimeElapsed' equal to 0 'Set 'Timer1.Interval' equal to 'timerInterval' 'Rnd() generates a random number between 0 and 1 'Multiply Rnd() by 'lineDurationDiff' and convert the result to an Integer by using CInt() 'then add this number to 'minLineDuration' and assign the result to 'lineDuration' 'The result of this is that when 'pic' is moving, some straight line paths will 'last longer than others. the minimum duration is minLineDuration and the maximum 'duration is minLineDuration + lineDurationDiff 'Get a random value for 'dx' by calling getRandomInteger(minX, maxX) and assigning the result to dx 'Do the same thing for 'dy' using minY and maxY 'The result of this is that 'pic' will move in different directions and in different-size steps 'Set up an IF statement in which you check if both dx and y are 0 'If that happens, Call newLine() 'Finally (not in the IF statement), Call resetXY() End Sub 'feedback() assigns a message to a Label when the game is done, giving the player feedback on how s/he did Private Sub feedback() Dim msg As String 'set up an If - ElseIf - Else structure 'The If statement should run if 'difficulty' is set to "easy" 'inside the If statement, set up an inner If structure that gives feedback based on 'score' 'for example, if score > 100 you could assign "Awesome job" to 'msg' 'if score is between 60 and 100, you could assign "Good job" to 'msg' etc. 'the ElseIf section of the outer If statement runs if 'difficulty' is set to "Medium" 'set up an inner If structure that gives feedback based on 'score' 'the Else section of the outer If statement runs if 'difficulty' is set to "Hard" 'set up an inner If structure that gives feedback based on 'score' 'When the If statements are done, get 'msg' to display in 'lblFeedback' End Sub 'updateCountDown() displays the countdown clock Private Sub updateCountDown() 'display the difference between 'gameDuration' and 'overallTimeElapsed' in 'lblTime' End Sub 'Timer1_Tick() runs at the interval set in Timer1.Interval 'If Timer1.Interval equals 100, for example, this method will run every 100 ms Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 'update 'overallTimeElapsed' by adding 'timerInterval' to it 'check if 'overallTimeElapsed' exceeds 'gameDuration'. 'if it does, the game is over. When the game is over, you'll want to set the Enabled 'property of 'Timer1' to False. Make whatever other changes are appropriate, and 'call the feedback() method. 'if the game is not yet over, update 'lineTimeElapsed' just as you updated 'overallTimeElapsed' 'if 'lineTimeElapsed' exceeds 'lineDuration', it is time to choose a new direction for 'pic' 'so call newLine() 'if the game is not yet over, call updateCountDown() to update the time 'move 'pic' by adding 'dx' to 'pic.Left' 'similarly, move 'pic' by adding 'dy' to 'pic.Top' 'check if the PictureBox is approaching an edge 'if it is, modify minX, maxX, minY or maxY and call newLine() 'the first branch of this If statement is shown 'it deals with the situation in which 'pic' is getting close to the left border and dx < 0. 'if that happens, 'pic' needs a new direction. 'minX' is set to 1, which guarantees 'that, when 'pic' begins on a new path, 'dx' will be at least 1, meaning that 'pic' 'will be moving away from the left border. If (Math.Abs(Me.Left - pic.Left) < tol And dx < 0) Then minX = 1 Call newLine() 'the ElseIf that deals with the situation in which 'pic' is getting close to the bottom border, 'with dy > 0, is also shown. Note that the y position of the screen's bottom border is Me.Bottom, 'and the y position of the bottom of 'pic' is pic.Bottom. Here maxY is set to -1, 'which guarantees that, when 'pic' begins on a new path, 'dy' will be at most -1, meaning that 'pic' will be moving away from the bottom border. ElseIf (Math.Abs(Me.Bottom - pic.Bottom) < tol And dy > 0) Then maxY = -1 Call newLine() 'you should write the ElseIf statements that deal with the right and top borders 'you can use the .Right and .Top properties of Me and pic End If End Sub 'pic_Click() increments and displays the score, when the player clicks on 'pic' 'I recommend adding 1.5, not 1, to 'score' in this method, which makes up for the fact that 'VB ignores some of the clicks on 'pic'. After updating 'score', display it in 'lblScore' 'you can use CInt() to display 'score' as an integer Private Sub pic_Click(sender As Object, e As EventArgs) Handles pic.Click End Sub 'Button2_Click() runs when Button2 is clicked, which begins a new game 'Make the changes needed to begin a new game Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click End Sub End Class