Now I am torn between the 2 player's turns. Any suggestions on what is the best
way to handle this? I was thinking about having a player1counter and a
player2counter.
Add 1 for each hit. Not sure how i would tell the program whose turn it was at
that point. Easiest way i imagine would have player 1 fire 3 shots, then pl 2
fire 3
Here is my updated code:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents radLevel1 As System.Windows.Forms.RadioButton
Friend WithEvents radLevel2 As System.Windows.Forms.RadioButton
Friend WithEvents radLevel3 As System.Windows.Forms.RadioButton
Friend WithEvents lblTitle As System.Windows.Forms.Label
Friend WithEvents btnSelect As System.Windows.Forms.Button
Friend WithEvents lblNames As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents btnContinue As System.Windows.Forms.Button
Friend WithEvents btnClear As System.Windows.Forms.Button
Friend WithEvents tmrTarget As System.Windows.Forms.Timer
Friend WithEvents txtpl1 As System.Windows.Forms.TextBox
Friend WithEvents txtpl2 As System.Windows.Forms.TextBox
Friend WithEvents picIntro As System.Windows.Forms.PictureBox
Friend WithEvents picTarget As System.Windows.Forms.PictureBox
Friend WithEvents picCannonBall As System.Windows.Forms.PictureBox
Friend WithEvents picBall As System.Windows.Forms.PictureBox
Friend WithEvents tmrShoot As System.Windows.Forms.Timer
Friend WithEvents btnShoot As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(Form1))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.radLevel3 = New System.Windows.Forms.RadioButton
Me.radLevel2 = New System.Windows.Forms.RadioButton
Me.radLevel1 = New System.Windows.Forms.RadioButton
Me.lblTitle = New System.Windows.Forms.Label
Me.btnSelect = New System.Windows.Forms.Button
Me.picIntro = New System.Windows.Forms.PictureBox
Me.lblNames = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.btnContinue = New System.Windows.Forms.Button
Me.btnClear = New System.Windows.Forms.Button
Me.tmrTarget = New System.Windows.Forms.Timer(Me.components)
Me.picTarget = New System.Windows.Forms.PictureBox
Me.txtpl1 = New System.Windows.Forms.TextBox
Me.txtpl2 = New System.Windows.Forms.TextBox
Me.picBall = New System.Windows.Forms.PictureBox
Me.tmrShoot = New System.Windows.Forms.Timer(Me.components)
Me.btnShoot = New System.Windows.Forms.Button
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.radLevel3)
Me.GroupBox1.Controls.Add(Me.radLevel2)
Me.GroupBox1.Controls.Add(Me.radLevel1)
Me.GroupBox1.Location = New System.Drawing.Point(320, 264)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(264, 184)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Select a skill level:"
Me.GroupBox1.Visible = False
'
'radLevel3
'
Me.radLevel3.Location = New System.Drawing.Point(56, 104)
Me.radLevel3.Name = "radLevel3"
Me.radLevel3.TabIndex = 2
Me.radLevel3.Text = "Level # 3"
'
'radLevel2
'
Me.radLevel2.Location = New System.Drawing.Point(56, 72)
Me.radLevel2.Name = "radLevel2"
Me.radLevel2.TabIndex = 1
Me.radLevel2.Text = "Level # 2"
'
'radLevel1
'
Me.radLevel1.Location = New System.Drawing.Point(56, 40)
Me.radLevel1.Name = "radLevel1"
Me.radLevel1.TabIndex = 0
Me.radLevel1.Text = "Level # 1"
'
'lblTitle
'
Me.lblTitle.Font = New System.Drawing.Font("Arial Black", 22.2!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0,
Byte))
Me.lblTitle.Location = New System.Drawing.Point(264, 104)
Me.lblTitle.Name = "lblTitle"
Me.lblTitle.Size = New System.Drawing.Size(392, 64)
Me.lblTitle.TabIndex = 1
Me.lblTitle.Text = "TARGET HUNTER"
'
'btnSelect
'
Me.btnSelect.Location = New System.Drawing.Point(496, 456)
Me.btnSelect.Name = "btnSelect"
Me.btnSelect.Size = New System.Drawing.Size(88, 23)
Me.btnSelect.TabIndex = 2
Me.btnSelect.Text = "Select Level"
Me.btnSelect.Visible = False
'
'picIntro
'
Me.picIntro.Image = CType(resources.GetObject("picIntro.Image"),
System.Drawing.Image)
Me.picIntro.Location = New System.Drawing.Point(400, 160)
Me.picIntro.Name = "picIntro"
Me.picIntro.Size = New System.Drawing.Size(112, 80)
Me.picIntro.TabIndex = 3
Me.picIntro.TabStop = False
Me.picIntro.Visible = False
'
'lblNames
'
Me.lblNames.Font = New System.Drawing.Font("Microsoft Sans Serif",
12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.lblNames.Location = New System.Drawing.Point(328, 168)
Me.lblNames.Name = "lblNames"
Me.lblNames.Size = New System.Drawing.Size(288, 40)
Me.lblNames.TabIndex = 4
Me.lblNames.Text = "Please enter player's names:"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(344, 208)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 16)
Me.Label1.TabIndex = 5
Me.Label1.Text = "Player 1:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(344, 240)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 16)
Me.Label2.TabIndex = 7
Me.Label2.Text = "Player 2:"
'
'btnContinue
'
Me.btnContinue.Location = New System.Drawing.Point(424, 272)
Me.btnContinue.Name = "btnContinue"
Me.btnContinue.Size = New System.Drawing.Size(104, 24)
Me.btnContinue.TabIndex = 8
Me.btnContinue.Text = "Continue"
'
'btnClear
'
Me.btnClear.Location = New System.Drawing.Point(544, 272)
Me.btnClear.Name = "btnClear"
Me.btnClear.TabIndex = 9
Me.btnClear.Text = "Clear"
'
'tmrTarget
'
'
'picTarget
'
Me.picTarget.Image = CType(resources.GetObject("picTarget.Image"),
System.Drawing.Image)
Me.picTarget.Location = New System.Drawing.Point(768, 168)
Me.picTarget.Name = "picTarget"
Me.picTarget.Size = New System.Drawing.Size(104, 96)
Me.picTarget.TabIndex = 10
Me.picTarget.TabStop = False
Me.picTarget.Visible = False
'
'txtpl1
'
Me.txtpl1.Location = New System.Drawing.Point(416, 208)
Me.txtpl1.Name = "txtpl1"
Me.txtpl1.Size = New System.Drawing.Size(128, 22)
Me.txtpl1.TabIndex = 11
Me.txtpl1.Text = ""
'
'txtpl2
'
Me.txtpl2.Location = New System.Drawing.Point(416, 240)
Me.txtpl2.Name = "txtpl2"
Me.txtpl2.Size = New System.Drawing.Size(128, 22)
Me.txtpl2.TabIndex = 12
Me.txtpl2.Text = ""
'
'picBall
'
Me.picBall.Image = CType(resources.GetObject("picBall.Image"),
System.Drawing.Image)
Me.picBall.Location = New System.Drawing.Point(464, 464)
Me.picBall.Name = "picBall"
Me.picBall.Size = New System.Drawing.Size(16, 8)
Me.picBall.TabIndex = 14
Me.picBall.TabStop = False
Me.picBall.Visible = False
'
'tmrShoot
'
Me.tmrShoot.Interval = 25
'
'btnShoot
'
Me.btnShoot.Image = CType(resources.GetObject("btnShoot.Image"),
System.Drawing.Image)
Me.btnShoot.Location = New System.Drawing.Point(440, 480)
Me.btnShoot.Name = "btnShoot"
Me.btnShoot.Size = New System.Drawing.Size(56, 64)
Me.btnShoot.TabIndex = 15
Me.btnShoot.Visible = False
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.ClientSize = New System.Drawing.Size(920, 560)
Me.Controls.Add(Me.btnShoot)
Me.Controls.Add(Me.txtpl2)
Me.Controls.Add(Me.txtpl1)
Me.Controls.Add(Me.picTarget)
Me.Controls.Add(Me.btnClear)
Me.Controls.Add(Me.btnContinue)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.lblNames)
Me.Controls.Add(Me.picIntro)
Me.Controls.Add(Me.btnSelect)
Me.Controls.Add(Me.lblTitle)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.picBall)
Me.Name = "Form1"
Me.Text = "TARGET HUNTER"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private timeStep As Integer 'global var
Private player1 As String, player2 As String
Private player1cnt As Integer, player2cnt As Integer
Private Sub boolReverse2(ByRef a As Boolean, ByRef b As Boolean)
'Reverse the values of the parameters
a = Not a
b = Not b
End Sub
Private Sub visReverse2(ByRef c1 As Control, ByRef c2 As Control)
'Reverse the visibility of the parameters
boolReverse2(c1.Visible, c2.Visible)
End Sub
Private Sub visReverse4(ByRef c1 As Control, ByRef c2 As Control, _
ByRef c3 As Control, ByRef c4 As Control)
visReverse2(c1, c2)
visReverse2(c3, c4)
End Sub
Private Sub visReverse8(ByRef c1 As Control, ByRef c2 As Control, _
ByRef c3 As Control, ByRef c4 As Control, _
ByRef c5 As Control, ByRef c6 As Control, _
ByRef c7 As Control, ByRef c8 As Control)
visReverse4(c1, c2, c3, c4)
visReverse4(c5, c6, c7, c8)
End Sub
Private Sub btnSelect_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSelect.Click
If radLevel1.Checked Then
tmrTarget.Enabled = True
tmrTarget.Interval = 800 ' slow speed for target
visReverse2(picTarget, btnShoot)
btnShoot.Visible = True
Else
If radLevel2.Checked Then
tmrTarget.Enabled = True
tmrTarget.Interval = 400 ' Medium speed for target
visReverse2(picTarget, btnShoot)
btnShoot.Visible = True
Else
If radLevel3.Checked Then
tmrTarget.Enabled = True
tmrTarget.Interval = 200 ' Fast speed for target
visReverse2(picTarget, btnShoot)
btnShoot.Visible = True
Else ' Then none of the radio buttons are checked
MsgBox("Please select a difficulty level!")
visReverse4(GroupBox1, btnSelect, lblTitle, picIntro)
End If
End If
End If
visReverse4(lblTitle, picIntro, GroupBox1, btnSelect)
'picTarget.Visible = True
'tmrTarget.Enabled = True
End Sub
Private Sub btnContinue_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnContinue.Click
'Dim player1 As String, player2 As String
player1 = txtpl1.Text
player2 = txtpl2.Text
visReverse8(lblNames, txtpl1, txtpl2, btnContinue, btnClear, GroupBox1,
_
btnSelect, picIntro)
visReverse2(Label1, Label2)
End Sub
Private Sub tmrTarget_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tmrTarget.Tick
'Move the graphic(target) across the form
Static intX As Integer = picTarget.Left
Static intY As Integer = picTarget.Top
Static intWidth As Integer = picTarget.Width
Static intHeight As Integer = picTarget.Height
'Set new x coordinate
intX -= 10
If intX <= -picTarget.Width Then 'Graphic is off edge of form
intX = Me.Width
End If
'Move image
picTarget.SetBounds(intX, intY, intWidth, intHeight)
End Sub
Private Sub tmrShoot_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrShoot.Tick
Dim jump As Integer = 10
With picBall
.Top = .Top - jump
hitIt()
If .Top < jump Then
.Visible = False
tmrShoot.Enabled = False
End If
End With
End Sub
Private Sub btnShoot_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
With picBall
.Left = 454
.Top = 440
.Visible = True
End With
tmrShoot.Enabled = True
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' btnContinue.PerformClick()
'btnSelect.PerformClick()
End Sub
Private Sub btnShoot_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShoot.Click
With picBall
.Left = 454
.Top = 440
.Visible = True
End With
tmrShoot.Enabled = True
End Sub
Function IntervalMember(ByVal x As Single, ByVal a As Single, ByVal b As
Single) _
As Boolean
'true if and only if x is a member of the interval[a,b]
Return (a <= x) And (x <= b)
End Function
Function intervalOverlap(ByVal a As Single, ByVal b As Single, _
ByVal x As Single, ByVal y As Single) As Boolean
'true if and only if interval[a,b] and [x,y] intersect
Return IntervalMember(a, x, y) Or IntervalMember(b, x, y) Or _
IntervalMember(x, a, b) Or IntervalMember(y, a, b)
End Function
Function controlOverlap(ByVal picBall As Control, ByVal picTarget As
Control) As Boolean
'Parameters are assumed to be controls that occupy rectangles, as
determined by
'.Top, .Left, .Height, and .Width properties. Function is true if and
only if the rectangles
'occupied by the parameters overlap.
Return intervalOverlap(picBall.Top, picBall.Top + picBall.Height, _
picTarget.Top, picTarget.Top + picTarget.Height)
And _
intervalOverlap(picBall.Left, picBall.Left +
picBall.Width, _
picTarget.Left, picTarget.Left +
picTarget.Width)
End Function
Function hitIt()
If controlOverlap(picBall, picTarget) = True Then
tmrShoot.Enabled = False
MsgBox("You hit it!")
picBall.Visible = False
End If
End Function
Function playerTurn()
End Function
End Class