daneroo, on 25 September 2008 - 07:54 AM, said:
Great tutorial, well commented and explained thoroughly, Thank-you
Dan
Dan
Email meHey thats great hey man your good keep it up.can you also post the battleship game tutorial plz




2 Votes
Posted 26 March 2011 - 03:43 PM
RodgerB, on 17 December 2007 - 12:34 AM, said:
' Check for top wall. If gameBall.Location.Y < 0 Then gameBall.Location = New Point(gameBall.Location.X, 0) yVel = -yVel End If
' Check for bottom wall. If gameBall.Location.Y > Me.Height - gameBall.Size.Height - 45 Then gameBall.Location = New Point(gameBall.Location.X, Me.Height - gameBall.Size.Height - 45) yVel = -yVel End If
' Check for player paddle. If gameBall.Bounds.IntersectsWith(paddlePlayer.Bounds) Then gameBall.Location = New Point(paddlePlayer.Location.X - gameBall.Size.Width, _ gameBall.Location.Y) xVel = -xVel End If
' Check for computer paddle. If gameBall.Bounds.IntersectsWith(paddleComputer.Bounds) Then gameBall.Location = New Point(paddleComputer.Location.X + paddleComputer.Size.Width + 1, _ gameBall.Location.Y) xVel = -xVel End If
' The player's scores. Dim compScore As Integer = 0 Dim plrScore As Integer = 0
' Check for left wall. If gameBall.Location.X < 0 Then plrScore += 1 gameBall.Location = New Point(Me.Size.Width / 2, Me.Size.Height / 2) plrScoreDraw.Text = Convert.ToString(plrScore) End If
' Check for right wall. If gameBall.Location.X > Me.Width - gameBall.Size.Width - paddlePlayer.Width Then compScore += 1 gameBall.Location = New Point(Me.Size.Width / 2, Me.Size.Height / 2) compScoreDraw.Text = Convert.ToString(compScore) End If
Public Class Game
Dim speed As Single = 10 'speed of ball'
Dim random As New Random() 'Random instance
Dim xVel As Single = Math.Cos(random.Next(5, 10)) * speed
Dim yVel As Single = Math.Cos(random.Next(5, 10)) * speed
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
Help.Visible = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Set the computer player to move according to the ball's position."
If ball.Location.Y > 5 And ball.Location.Y < Me.Height - 40 _
- Player.Height Then
PC.Location = New Point(PC.Location.X, ball.Location.Y)
End If
'Move the ball'
ball.Location = New Point(ball.Location.X + xVel, ball.Location.Y + yVel)
'Watch out for top wall.'
If ball.Location.Y < 0 Then
ball.Location = New Point(ball.Location.X, 0)
yVel = -yVel
End If
'Watch out for bottom wall.'
If ball.Location.Y < Me.Height - ball.Size.Height - 45 Then
ball.Location = New Point(ball.Location.X, Me.Height - ball.Size.Height - 45)
yVel = -yVel
End If
'Check 4 player
If ball.Bounds.IntersectsWith(Player.Bounds) Then
ball.Location = New Point(Player.Location.X - ball.Size.Width, _
ball.Location.Y)
xVel = -xVel
End If
'Check 4 computer
If ball.Bounds.IntersectsWith(PC.Bounds) Then
ball.Location = New Point(PC.Location.X + PC.Size.Width + 1, _
ball.Location.Y)
xVel = -xVel
End If
End Sub
' Move the paddle according to the mouse position.
Private Sub Player_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Player.MouseMove
If e.Y > 5 And e.Y < Me.Height - 40 - Player.Height Then _
Player.Location = New Point(Player.Location.X, e.Y)
End Sub
Private Sub Game_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Set up the game. (hid cursor)
Windows.Forms.Cursor.Hide()
End Sub
End Class
Posted 26 April 2011 - 02:07 PM
Jacques Malan, on 18 August 2010 - 11:23 AM, said:
If compScoreDraw.Text = 5 Then
MessageBox.Show("You lose, better luck next time")
Me.Close()
End If
This post has been edited by Jordan.M: 26 April 2011 - 02:08 PM
Posted 27 May 2011 - 09:24 AM
Posted 22 July 2011 - 11:22 AM
Posted 23 November 2011 - 05:59 PM
Cookiesliyr, on 09 June 2009 - 04:54 AM, said:
Posted 23 November 2011 - 07:04 PM
CodesALot, on 03 June 2010 - 12:06 PM, said:
Posted 28 January 2012 - 09:28 AM
Public Class pongMain
#Region "Globals"
Dim speed As Single = 10 ' Ball Speed
Dim rndInst As New Random() ' Random instance
Dim xVel As Single = Math.Cos(rndInst.Next(5, 10)) * speed
Dim yVel As Single = Math.Sin(rndInst.Next(5, 10)) * speed
' The player's scores.
Dim compScore As Integer = 0
Dim plrScore As Integer = 0
#End Region
#Region "Keep the paddle and score labels in the correct position when the form is resized."
Private Sub pongMain_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
paddlePlayer.Location = New Point(Me.Width - 44, paddlePlayer.Location.Y)
plrScoreDraw.Location = New Point(Me.Width - 54, plrScoreDraw.Location.Y)
End Sub
#End Region
#Region "Hide Cursor"
' Set up the game.
Private Sub pongMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Windows.Forms.Cursor.Hide()
End Sub
#End Region
#Region "End Game on Escape Press"
' Escape the game when escape has been pressed.
Private Sub pongMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyValue = Keys.Escape Then
Me.Close()
End If
End Sub
#End Region
#Region "Move the paddle according to the mouse"
' Move the paddle according to the mouse position.
Private Sub pongMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If e.Y > 5 And e.Y < Me.Height - 40 - paddlePlayer.Height Then _
paddlePlayer.Location = New Point(paddlePlayer.Location.X, e.Y)
End Sub
#End Region
#Region "Main Timer"
Private Sub gameTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gameTimer.Tick
'Set the computer player to move according to the ball's position."
If gameBall.Location.Y > 5 And gameBall.Location.Y < Me.Height - 40 _
- paddlePlayer.Height Then _
paddleComputer.Location = New Point(paddleComputer.Location.X, gameBall.Location.Y)
' Move the game ball.
gameBall.Location = New Point(gameBall.Location.X + xVel, gameBall.Location.Y + yVel)
' Check for top wall.
If gameBall.Location.Y < 0 Then
gameBall.Location = New Point(gameBall.Location.X, 0)
yVel = -yVel
End If
' Check for bottom wall.
If gameBall.Location.Y > Me.Height - gameBall.Size.Height - 45 Then
gameBall.Location = New Point(gameBall.Location.X, Me.Height - gameBall.Size.Height - 45)
yVel = -yVel
End If
' Check for player paddle.
If gameBall.Bounds.IntersectsWith(paddlePlayer.Bounds) Then
gameBall.Location = New Point(paddlePlayer.Location.X - gameBall.Size.Width, _
gameBall.Location.Y)
xVel = -xVel
End If
' Check for computer paddle.
If gameBall.Bounds.IntersectsWith(paddleComputer.Bounds) Then
gameBall.Location = New Point(paddleComputer.Location.X + paddleComputer.Size.Width + 1, _
gameBall.Location.Y)
xVel = -xVel
' Check for left wall.
If gameBall.Location.X < 0 Then
plrScore += 1
gameBall.Location = New Point(Me.Size.Width / 2, Me.Size.Height / 2)
plrScoreDraw.Text = Convert.ToString(plrScore)
End If
' Check for right wall.
If gameBall.Location.X > Me.Width - gameBall.Size.Width - paddlePlayer.Width Then
compScore += 1
gameBall.Location = New Point(Me.Size.Width / 2, Me.Size.Height / 2)
compScoreDraw.Text = Convert.ToString(compScore)
End If
End If
End Sub
#End Region
End Class
Posted 28 May 2012 - 12:16 PM
Dim compSkill As Random()
...
If compSkill <= 100 Then
paddleComputer.Location = New Point(paddleComputer.Location.X, gameBall.Location.Y)
Else
paddleComputer.Location = New Point("Help me make PC like another human") 'I want to invert my moves or make them random
End If
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
