Create a Visual Basic program to calculate and display the running score for a b
ID: 3871598 • Letter: C
Question
Create a Visual Basic program to calculate and display the running score for a basketball game. Zip your files. Submit the program before the 5:00 deadline. Name your project using your initials and the number of the program. Write a program to track and display the running score for a basketball game. The user enters the team names. They then track the running score by clicking on the appropriate Buttons. The Clear Button clears the teams, output and scores and starts a new game. Each Button adds the appropriate amount to the teams score and displays the score, the team that scored and the type of score . Use the proper naming conventions for all controls and variables. Include a prologue and comment your code Be sure to: Scoring VB icon included create and code all Buttons working Exit and Clear Buttons accumulators work correctly • put the VB icon on the form - create and code all the Buttons include a working Exit Button - include a working clear Button - use an accumulator for each teams score , add the correct amount for each Button - display the correct output for each Button a comment your code - include a prologue at the top of the code format your output - properly name all controls - properly name all variables . submit the all required files correct output displayed comments and prologue properly named controls properly named variables , Total 15Explanation / Answer
using UnityEngine;
using System.Collections;
public class Basket : MonoBehaviour
{
public GameObject score;
public AudioClip basket;
void OnCollisionEnter()
{
audio.Play();
}
void OnTriggerEnter()
{
int currentScore = int.Parse(score.GetComponent().text) + 1;
score.GetComponent().text = currentScore.ToString();
AudioSource.PlayClipAtPoint(basket, transform.position);
}
}
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour
{
public GameObject ball;
private Vector3 throwSpeed = new Vector3(0, 26, 40);
public Vector3 ballPos;
private bool thrown = false;
private GameObject ballClone;
public GameObject availableShotsGO;
private int availableShots = 5;
public GameObject meter;
public GameObject arrow;
private float arrowSpeed = 0.3f;
private bool right = true;
public GameObject gameOver;
void FixedUpdate()
{
if (arrow.transform.position.x < 4.7f && right)
{
arrow.transform.position += new Vector3(arrowSpeed, 0, 0);
}
if (arrow.transform.position.x >= 4.7f)
{
right = false;
}
if (right == false)
{
arrow.transform.position -= new Vector3(arrowSpeed, 0, 0);
}
if ( arrow.transform.position.x <= -4.7f)
{
right = true;
}
if (Input.GetButton("Fire1") && !thrown && availableShots > 0)
{
thrown = true;
availableShots--;
availableShotsGO.GetComponent().text = availableShots.ToString();
ballClone = Instantiate(ball, ballPos, transform.rotation) as GameObject;
throwSpeed.y = throwSpeed.y + arrow.transform.position.x;
throwSpeed.z = throwSpeed.z + arrow.transform.position.x;
ballClone.rigidbody.AddForce(throwSpeed, ForceMode.Impulse);
audio.Play();
}
if (ballClone != null && ballClone.transform.position.y < -16)
{
Destroy(ballClone);
thrown = false;
throwSpeed = new Vector3(0, 26, 40);
if (availableShots == 0)
{
arrow.renderer.enabled = false;
Instantiate(gameOver, new Vector3(0.31f, 0.2f, 0), transform.rotation);
Invoke("restart", 2);
}
}
}
void restart()
{
Application.LoadLevel(Application.loadedLevel);
}
}
<Serializable()>
Class UsersList
Public Property members As List(Of User)
Sub New()
members = New List(Of User)
End Sub
Public Sub add(user As User)
If IsNothing(members) = False Then
members.Add(user)
End If
End Sub
End Class
Class User
Public scores As List(Of Single)
Public Property name As String
Sub New()
scores = New List(Of Single)
End Sub
Public Sub add(score As Single)
If IsNothing(scores) = False Then
scores.Add(score)
End If
End Sub
End Class
And For user input you can do two ways :
'Displaying warning when it is not valid float number
'works for floating numbers too
Private Sub TextBox_TextChanged(sender As System.Object, e As System.EventArgs) Handles YouTextbox1.TextChanged,YourTextbox2.TextChanged
Dim cheked As TextBox = CType(sender, TextBox)
If IsNothing(cheked) = False Then
Dim f As Single
If Single.TryParse(cheked.Text, f) = False Then
MessageBox.Show("Warning .Please enter valid number")
End If
End If
End Sub
'not allow user enter to type wrong keys
Private Sub TextBox1_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox.KeyPress
'Disallow user type anything besides numbers
If e.KeyChar < CChar("0") Or e.KeyChar > CChar("9") Then
e.Handled = True
End If
End Sub
Public Class Form1
Private Score1 As Integer = 0
Private score2 As Integer = 0
Public Const GWL_STYLE As Integer = (-16)
Public Const ES_NUMBER As Integer = &H2000
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal handle As IntPtr, ByVal nIndex As Integer) As Integer
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal handle As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Public Sub SetNumbersOnlyTextBox(ByVal TB As TextBox)
SetWindowLong(TB.Handle, GWL_STYLE, GetWindowLong(TB.Handle, GWL_STYLE) Or ES_NUMBER)
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
SetNumbersOnlyTextBox(txtScore1)
SetNumbersOnlyTextBox(txtScore1)
DisplayScores()
End Sub
Private Sub btnAddScore1_Click(sender As System.Object, e As System.EventArgs) Handles btnAddScore1.Click
If txtScore1.Text.Trim.Length > 0 Then
Score1 = Score1 + CInt(txtScore1.Text)
DisplayScores()
txtScore1.Clear()
End If
End Sub
Private Sub btnAddScore2_Click(sender As System.Object, e As System.EventArgs) Handles btnAddScore2.Click
If txtScore2.Text.Trim.Length > 0 Then
score2 = score2 + CInt(txtScore2.Text)
DisplayScores()
txtScore2.Clear()
End If
End Sub
Private Sub DisplayScores()
lblScore1.Text = Score1
lblScore2.Text = score2
End Sub
End Class
'Declarations
Private score As Integer = 0
Private userAnswer As Decimal
'...Form Initialization Code...
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If Decimal.TryParse(TextBox1.Text, userAnswer) Then
If answer = userAnswer Then
score += 1
TextBox2.Text = score
MsgBox("Congrats")
Else
MsgBox("Incorrect Answer")
End If
End If
End Sub