Question

In: Computer Science

Windows Forms application using Visual Basic: Create a class called Character that a role-playing game might...

Windows Forms application using Visual Basic:

Create a class called Character that a role-playing game might use to represent a character within the game.

A character should include six stats as instance variables –
strength, dexterity, constitution, intelligence, wisdom and charisma (all types are int).
Your class should have a constructor that initializes these six instance variables. Provide Properties with an appropriate set and get block for each instance variable.
In addition, provide a method named getStatsTotal that calculates the total of these six stats, then returns the amount as an int value.
If the total is not positive, it should be set to 0.

Create a form that can be used to create a character, assign the stats and display the stats total.

Solutions

Expert Solution

Program:

Character.vb

Public Class Character

Public strength, dexterity, constitution, intelligence, wisdom, charisma As Integer
Public totalStats As Integer

Sub New(strength1 As Integer, dexterity1 As Integer, constitution1 As Integer, intelligence1 As Integer, wisdom1 As Integer, charisma1 As Integer)
setStrength(strength1)
setDexterity(dexterity1)
setConstitution(constitution1)
SetIntelligence(intelligence1)
setWisdom(wisdom1)
setCharisma(charisma1)
End Sub

Sub setStrength(strength1 As Integer)
strength = strength1
End Sub

Sub setDexterity(deterity1 As Integer)
dexterity = deterity1
End Sub

Sub setConstitution(constitution1 As Integer)
constitution = constitution1
End Sub

Sub SetIntelligence(intelligence1 As Integer)
intelligence = intelligence1
End Sub

Sub setCharisma(charisma1 As Integer)
charisma = charisma1
End Sub

Sub setWisdom(wisdom1 As Integer)
wisdom = wisdom1
End Sub

Function getStrength()
Return strength
End Function

Function getDexterity()
Return dexterity
End Function

Function getConstitution()
Return constitution
End Function

Function getIntelligence()
Return intelligence
End Function

Function getWisdom()
Return wisdom
End Function

Function getCharisma()
Return charisma
End Function

Function getStatsTotal()
totalStats = getStrength() + getDexterity() + getConstitution() + getIntelligence() + getWisdom() + getCharisma()
If (totalStats < 0) Then
totalStats = 0
End If
Return totalStats
End Function
End Class

Form1.vb

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim s, d, c, i, w, charm As Integer
s = Convert.ToInt32(txtStrength.Text)
d = Convert.ToInt32(txtDeterity.Text)
c = Convert.ToInt32(txtConstitution.Text)
i = Convert.ToInt32(txtIntelligence.Text)
w = Convert.ToInt32(txtWisdom.Text)
charm = Convert.ToInt32(txtCharisma.Text)

Dim ch As New Character(s, d, c, i, w, charm)
txtTotalStats.Text = ch.getStatsTotal()

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtTotalStats.Enabled = False

End Sub
End Class

Screen (form):


Related Solutions

Must be in Visual C# using windows forms : Create an application that opens a specified...
Must be in Visual C# using windows forms : Create an application that opens a specified text file and then displays a list of all the unique words found in the file. Hint: Use a LINQ method to remove all duplicate words.
windows forms Application using Visual Basic use visual basic 2012 Part 1: Programming – Income Tax...
windows forms Application using Visual Basic use visual basic 2012 Part 1: Programming – Income Tax Application 1.1 Problem Statement Due to upcoming end of financial year, you are being called in to write a program which will read in a file and produce reports as outlined. Inputs: The input file called IncomeRecord.txt contains a list of Annual income records of employees in a firm. Each record is on a single line and the fields are separated by spaces. The...
Create code In visual Basic, Windows forms that uses case statements to convert the day of...
Create code In visual Basic, Windows forms that uses case statements to convert the day of the week (entered by the user into an integer. (Sunday = 1, Monday = 2, etc.) For this code, think about error checking. What will your code do if the user enters “dog” for example (which is not a day of the week)? What will your code do if the user enters a number or other incorrect input?
Instructions: In this exercise, you’ll design a role playing character class. The Character class attributes should...
Instructions: In this exercise, you’ll design a role playing character class. The Character class attributes should include the characters’s name, gender, class* and race (can be human, elf or dwarf), and additional integer attributes of Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma. Your class should have a constructor that receives this data. For each attribute, provide setters and getters. The class should include methods that calculate and return the user’s total attributes (sums 6 attributes). Write a Java application that prompts...
Must be in C#: 7. E-MAIL ADDRESS BOOK Create a Windows Forms Application with a class...
Must be in C#: 7. E-MAIL ADDRESS BOOK Create a Windows Forms Application with a class named PersonEntry. The PersonEntry class should have properties for a person’s name, e-mail address, and phone number. Also, create a text file that contains the names, e-mail addresses, and phone numbers for at least five people. When the application starts, it should read the data from the file and create a PersonEntry object for each person’s data. The PersonEntry objects should be added to...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: • Number of days on the trip • Amount of airfare, if any • Amount of car rental fees, if any • Number of miles driven, if a private vehicle was used • Amount of parking fees, if any • Amount of...
----------------------------------------------------------------------------------------------- Create a class called MathOperations that a teacher might use to represent the basic type...
----------------------------------------------------------------------------------------------- Create a class called MathOperations that a teacher might use to represent the basic type of mathematical operations that may be performed. The class should include the following: Three double private variables as instance variables, number1, number2, and result. Your class should have a default constructor that initializes the three instance variables to zero. Your class should also have a constructor that initializes the two instance variables (number1 and number2) to the value entered by the user from keyboard....
Create a windows form application in C# that looks and functions like a basic calculator. It...
Create a windows form application in C# that looks and functions like a basic calculator. It must do the following: Add, subtract, multiply, and divide. Account for division by zero. Show at least two decimal places. Retain the last number on the window so that, when the user opens the calculator the next time, the number that was in the window at the last close appears. Have a memory, so that users can store values and recall them. Operate with...
Program on Visual Basic, VBA Create an application that lets the user enter a number of...
Program on Visual Basic, VBA Create an application that lets the user enter a number of seconds and produces output according to the following criteria: There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
Code, pls. Thank you. Exercise - MPG Calculator Create a Windows Forms application and call it...
Code, pls. Thank you. Exercise - MPG Calculator Create a Windows Forms application and call it MPGCalculator Build a form that looks like the form in the video provided. The form consists of 4 labels, 2 textboxes and 3 buttons Name all controls properly. Certain labels do not have to be named Pay attention to video and set all design time properties accordingly. The "x" should be a hot key for the exit button When Calculate is clicked, you should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT