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 Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
Friend WithEvents TextBox7 As System.Windows.Forms.TextBox
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents TextBox8 As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents TextBox9 As System.Windows.Forms.TextBox
Friend WithEvents TextBox10 As System.Windows.Forms.TextBox
Friend WithEvents TextBox11 As System.Windows.Forms.TextBox
Friend WithEvents PictureBox3 As System.Windows.Forms.PictureBox
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents ListBox2 As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.PictureBox2 = New System.Windows.Forms.PictureBox
Me.Label3 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.TextBox6 = New System.Windows.Forms.TextBox
Me.TextBox7 = New System.Windows.Forms.TextBox
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.TextBox8 = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.TextBox9 = New System.Windows.Forms.TextBox
Me.TextBox10 = New System.Windows.Forms.TextBox
Me.TextBox11 = New System.Windows.Forms.TextBox
Me.PictureBox3 = New System.Windows.Forms.PictureBox
Me.Button3 = New System.Windows.Forms.Button
Me.ListBox2 = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button1.Location = New System.Drawing.Point(8, 128)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(104, 48)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Roll Dice"
'
'Button2
'
Me.Button2.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button2.Location = New System.Drawing.Point(136, 128)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(96, 48)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Exit"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(40, 192)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 23)
Me.Label1.TabIndex = 2
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(168, 192)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 23)
Me.Label2.TabIndex = 3
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(24, 232)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(96, 88)
Me.PictureBox1.TabIndex = 4
Me.PictureBox1.TabStop = False
'
'PictureBox2
'
Me.PictureBox2.Location = New System.Drawing.Point(152, 232)
Me.PictureBox2.Name = "PictureBox2"
Me.PictureBox2.Size = New System.Drawing.Size(96, 88)
Me.PictureBox2.TabIndex = 5
Me.PictureBox2.TabStop = False
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(416, 296)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(56, 23)
Me.Label3.TabIndex = 7
'
'TextBox1
'
Me.TextBox1.AutoSize = False
Me.TextBox1.BackColor = System.Drawing.SystemColors.Control
Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.TextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox1.Location = New System.Drawing.Point(496, 32)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(240, 20)
Me.TextBox1.TabIndex = 8
Me.TextBox1.Text = "How to play this game"
'
'TextBox2
'
Me.TextBox2.AutoSize = False
Me.TextBox2.BackColor = System.Drawing.SystemColors.Control
Me.TextBox2.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.TextBox2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox2.Location = New System.Drawing.Point(496, 56)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(240, 20)
Me.TextBox2.TabIndex = 9
Me.TextBox2.Text = "Simply click button ""Roll Dice"""
'
'TextBox3
'
Me.TextBox3.AutoSize = False
Me.TextBox3.BackColor = System.Drawing.SystemColors.Control
Me.TextBox3.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.TextBox3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox3.Location = New System.Drawing.Point(496, 80)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(240, 20)
Me.TextBox3.TabIndex = 10
Me.TextBox3.Text = "If Dice has the same number"
'
'TextBox4
'
Me.TextBox4.AutoSize = False
Me.TextBox4.BackColor = System.Drawing.SystemColors.Control
Me.TextBox4.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.TextBox4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox4.Location = New System.Drawing.Point(496, 104)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(240, 20)
Me.TextBox4.TabIndex = 11
Me.TextBox4.Text = "You Win 5 points"
'
'TextBox5
'
Me.TextBox5.AutoSize = False
Me.TextBox5.BackColor = System.Drawing.SystemColors.Control
Me.TextBox5.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.TextBox5.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox5.Location = New System.Drawing.Point(496, 128)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.Size = New System.Drawing.Size(240, 20)
Me.TextBox5.TabIndex = 12
Me.TextBox5.Text = "If Dice have different numbers"
'
'TextBox6
'
Me.TextBox6.AutoSize = False
Me.TextBox6.BackColor = System.Drawing.SystemColors.Control
Me.TextBox6.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.TextBox6.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox6.Location = New System.Drawing.Point(496, 152)
Me.TextBox6.Name = "TextBox6"
Me.TextBox6.Size = New System.Drawing.Size(240, 20)
Me.TextBox6.TabIndex = 13
Me.TextBox6.Text = "You lose 1 point"
'
'TextBox7
'
Me.TextBox7.AutoSize = False
Me.TextBox7.BackColor = System.Drawing.SystemColors.Control
Me.TextBox7.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.TextBox7.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox7.Location = New System.Drawing.Point(544, 192)
Me.TextBox7.Name = "TextBox7"
Me.TextBox7.Size = New System.Drawing.Size(136, 24)
Me.TextBox7.TabIndex = 14
Me.TextBox7.Text = "Enjoy the game"
Me.TextBox7.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'ListBox1
'
Me.ListBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.ListBox1.Font = New System.Drawing.Font("Courier New", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ListBox1.ItemHeight = 16
Me.ListBox1.Location = New System.Drawing.Point(288, 24)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(200, 242)
Me.ListBox1.TabIndex = 15
'
'TextBox8
'
Me.TextBox8.BackColor = System.Drawing.SystemColors.Control
Me.TextBox8.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.TextBox8.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox8.Location = New System.Drawing.Point(8, 96)
Me.TextBox8.Name = "TextBox8"
Me.TextBox8.Size = New System.Drawing.Size(80, 19)
Me.TextBox8.TabIndex = 16
Me.TextBox8.Text = "Welcome"
'
'Label4
'
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.Location = New System.Drawing.Point(104, 96)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(160, 24)
Me.Label4.TabIndex = 17
'
'TextBox9
'
Me.TextBox9.BackColor = System.Drawing.SystemColors.Control
Me.TextBox9.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.TextBox9.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox9.Location = New System.Drawing.Point(296, 296)
Me.TextBox9.Name = "TextBox9"
Me.TextBox9.Size = New System.Drawing.Size(104, 19)
Me.TextBox9.TabIndex = 19
Me.TextBox9.Text = "Your score"
'
'TextBox10
'
Me.TextBox10.AutoSize = False
Me.TextBox10.BackColor = System.Drawing.SystemColors.Control
Me.TextBox10.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.TextBox10.Font = New System.Drawing.Font("Microsoft Sans Serif", 20.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox10.ForeColor = System.Drawing.SystemColors.HotTrack
Me.TextBox10.Location = New System.Drawing.Point(8, 24)
Me.TextBox10.Name = "TextBox10"
Me.TextBox10.Size = New System.Drawing.Size(264, 40)
Me.TextBox10.TabIndex = 20
Me.TextBox10.Text = "DICE GAME 2008"
'
'TextBox11
'
Me.TextBox11.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.TextBox11.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox11.Location = New System.Drawing.Point(576, 592)
Me.TextBox11.Name = "TextBox11"
Me.TextBox11.Size = New System.Drawing.Size(160, 26)
Me.TextBox11.TabIndex = 21
Me.TextBox11.Text = "By Catherine Dally"
'
'PictureBox3
'
Me.PictureBox3.Location = New System.Drawing.Point(24, 336)
Me.PictureBox3.Name = "PictureBox3"
Me.PictureBox3.Size = New System.Drawing.Size(368, 296)
Me.PictureBox3.TabIndex = 22
Me.PictureBox3.TabStop = False
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(624, 536)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(104, 40)
Me.Button3.TabIndex = 23
Me.Button3.Text = "New Player"
'
'ListBox2
'
Me.ListBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.ListBox2.Font = New System.Drawing.Font("Courier New", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ListBox2.ItemHeight = 16
Me.ListBox2.Location = New System.Drawing.Point(480, 272)
Me.ListBox2.Name = "ListBox2"
Me.ListBox2.Size = New System.Drawing.Size(328, 258)
Me.ListBox2.TabIndex = 24
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(824, 638)
Me.Controls.Add(Me.ListBox2)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.PictureBox3)
Me.Controls.Add(Me.TextBox11)
Me.Controls.Add(Me.TextBox10)
Me.Controls.Add(Me.TextBox9)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.TextBox8)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.TextBox7)
Me.Controls.Add(Me.TextBox6)
Me.Controls.Add(Me.TextBox5)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.PictureBox2)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Cursor = System.Windows.Forms.Cursors.Hand
Me.ForeColor = System.Drawing.SystemColors.ControlText
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Dim score, win, lose As Integer
Dim scorecount As Integer
Dim count As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Dice1 As Integer
Dim Dice2 As Integer
Randomize()
Dice1 = Int(Rnd() * 6) + 1 'Randomising dice 1 between 1 and 6
Dice2 = Int(Rnd() * 6) + 1 'Randomising dice 2 between 1 and 6
Label1.Text = Dice1 'Showing the dice number
Label2.Text = Dice2 'Showing the dice number
PictureBox1.Image = Image.FromFile("Dieside" & CStr(Dice1) & ".gif")
PictureBox2.Image = Image.FromFile("Dieside" & CStr(Dice2) & ".gif")
'Making an If statement that Dice1 and Dice 2 equal then the score is 5 and its a win
If Dice1 = Dice2 Then
score = score + 5
win = win + 1
scorecount = 5 'the score is 5 is won
MsgBox("Luck you 5 points", MsgBoxStyle.Exclamation, "Great")
'Else if Dice1 and Dice2 are different then its a loss and you lose 1 point
Else
score = score - 1
MsgBox("You lost 1 Point", MsgBoxStyle.Critical, "Try Again")
scorecount = -1 'the score is -1 if lost
End If
count = count + 1 'counting how many times the roll dice button is clicked
'Giving instructions for the listbox so that the Dice1 and Dice2 numbers are printed and the
'score also what the score is
ListBox1.Items.Add(Dice1 & " " & Dice2 & " " & scorecount & " " & score)
Label3.Text = score 'shows the score in the label
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("Your total score is " & score & vbCrLf & "You have played " & count & " time(s) and won " & win & " times.", MsgBoxStyle.Information, "Thank You For Playing The Game")
ListBox2.Items.Add(Label4.Text & " " & score)
Me.Close()
'Closes the program when EXIT is pressed also gives a messagebox with the total score, how many times the game was played with amount of wins.
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Label4.Text = InputBox("Enter New Players Name")
ListBox1.Items.Clear()
score = 0
ListBox1.Items.Add("D1 " & "D2 " & "W/L " & "Score")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Add("D1 " & "D2 " & "W/L " & "Score")
Label4.Text = InputBox("Please enter your name")
PictureBox3.Image = Image.FromFile("dice" & ".gif")
'The headers for the list box so that they are always in the listbox.
End Sub
End Class
I have to alter my dice game cansomeone help me.
You are required to modify your initial Dice game from your first assignment to meet the following requirements. Once you have completed your tasks, you must be careful to fully test your project. Make sure the main program cooperate to each sub-program. There must be no bugs inside your project.
Q1. When the program starts, it needs a procedure Sub NewPlayer ( ). The procedure initialises the program and inputs a new player’s name. (10 marks)
Q2. When the player click the “Exit” button to exit the game, the program needs to use the following (Q2.1, Q2.2, Q2.3) procedures and function to 1) save the player’s total score of current game, 2) list the player’s history records and total, 3) show a grade based on player’s average score in the history.
The history average score = (total history scores) / (total times played in history). If the history average score is five or greater than 5, the player is at Master Level; if the history average score is between 0 and 4, the player is at Advanced Level. Otherwise, the player is at Beginner Level.
The sub-program you need to write is as follows:
Q2.1. Write a procedure Sub SaveScore (ByVal name As String, ByVal score As Integer) to save player’s name and score of current game to a text file. (10 marks)
Q2.2. Write a Function Avg(ByVal name As String) As Integer. The function lists only current player’s history scores from the save text file (10 marks). It adds the total score and counts the total times the player plays in the history records (10 marks). Finally, it returns an average score to its main program (5 marks).
Q2.3. Write a procedure Sub Grade (ByVal average As Integer) to show a certain grade the player belongs to (10 marks).
Q3. Add a Button to change player for this program. It needs to save previous player’s score, list records and grade by reusing the sub-program at Q2.1, Q2.2 and Q2.3 before start a new player by reusing procedure at Q1. (20 marks)
Q4. Draw a hierarchy chart depicting all the sub-programs (functions and procedures) under this project. (10 marks)
Q5. Write down steps to inform user how to play your game. It must cover all the features you have provided in your game. (10 marks)
Q6. Provide your ideas to improve this game. (You don’t have to write code.) Give your comments to use Game in programming course. Write your suggestions for the future course. (5 marks)
I dont want it all done for me as I'm slowly working on it but can someone point me in the direction.
I really need help with saving peoples scores in a text file and displaying them when the button is press "save scores"