Questions about Damage and Hit points
Questions about Damage and Hit points
Questions about Damage and Hit points
Questions about Damage and Hit points
Questions about Damage and Hit points
Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points
Questions about Damage and Hit points Questions about Damage and Hit points
Questions about Damage and Hit points
Go Back  Xtreme Visual Basic Talk > > > Questions about Damage and Hit points


Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-2011, 01:10 PM
WhiteOnyx WhiteOnyx is offline
Newcomer
 
Join Date: Jul 2011
Posts: 4
Default Questions about Damage and Hit points


Hi I'm new to programming im currently enrolled in collage for computer programming but sadly i wont see the first class on programming until January.

so in the mean time I've been teaching myself little by little . I've been using Microsoft's tutorials and reading VB 2010 (Step by Step), which have been real helpful.
when I become snow blind from reading I make my own little programs with what I've learned.
atm I'm tinkering with a few different thing and am planing on making making a text based RPG game to start .

I am currently using VB express 2010 which I really like
anyway here is my problem...

I've made a test app. just tiring to figure out how do the damage and hit point calculations so far it has been fairly simple but i've run into a snag ...

i cant quite figure out how to make the damage dealt keep adding to the enemy's hit points. right know all it does is loop and start over just wondering if i cant get some help on what to put that will make the hit points decrease every time the player is hit .
here is my code so far.
Code:
Public Class Form1

    Dim PHP As Integer   ' PHP = Player Hit Points
    Dim PAC As Integer    ' Player armor class
    Dim PatkRoll As Integer  ' Player attack roll
    Dim PdmgRoll As Integer   ' Player damage roll

    Dim EHP As Integer   '  Enemy Hit Points
    Dim EAC As Integer    ' Enemy armor class
    Dim EatkRoll As Integer  ' Enemy attack roll
    Dim EdmgRoll As Integer   ' Enemy damage roll

    Private Sub Player()
        PHP = 50
        PAC = 10
        PatkRoll = Int(Rnd() * 20)
        PdmgRoll = Int(Rnd() * 10 + 1)
    End Sub

    Private Sub Enemy1()
        EHP = 30
        EAC = 8
        EatkRoll = Int(Rnd() * 20)
        EdmgRoll = Int(Rnd() * 6 + 1)
    End Sub

    Private Sub PlayerAtkandDmg(
        If PatkRoll >= EAC Then
            RichTextBox1.Text = "You hit the enemy for " & PdmgRoll & " Enemys hit Points are now " & EHP - PdmgRoll
        ElseIf PatkRoll < EAC Then
            RichTextBox1.Text = " You Missed the enemy"
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Player()
        Enemy1()
        PlayerAtkandDmg()
    End Sub
End Class
right know I'm just using a button to control what I'm doing . Later ill change it .
I'm tiring to keep it simple . this is just a test
I'm open to all suggestions and better ways to write what I've done but I don't want free hand outs ( if you know what I mean) I'm here to learn

Last edited by passel; 07-15-2011 at 09:17 AM. Reason: Added [code]..[/code] tags
Reply With Quote
  #2  
Old 07-15-2011, 02:16 AM
masterpreenx masterpreenx is offline
Newcomer
 
Join Date: Sep 2010
Location: Davao City Philippines
Posts: 24
Default

you better be familiar on using structure. It makes your player and enemy stats a bit simple to handle and declare.

rather than using this.

Dim PHP As Integer ' PHP = Player Hit Points
Dim PAC As Integer ' Player armor class
Dim PatkRoll As Integer ' Player attack roll
Dim PdmgRoll As Integer ' Player damage roll

better if this.
Code:
Public Structure Player()
  Public Hitpoints as integer = 100
  Public armorclass as integer
  public accuracy as integer = 20
  public damage as integer = 10
End Structure

dim yourplayer as new player()
then you can access using yourplayer.hitpoint -= enemy.attackdamage

this is very useful if you have alot of enemies for example if you have hundreds of mobs around you then you will use an array of players() or enemies() instead rather than declaring hundreds of lines of dim's sounds awful dont you think? =D

now i will modify your codes

Code:
Public Class Form1
  Public Structure Player()
    Public Hitpoints As Integer = 100
    Public armorclass As Integer
    Public accuracy As Integer = 20
    Public damage As Integer = 10
    Public damageroll As Integer
    Public attackroll As Integer
  End Structure

  Dim yourplayer As New player()
  Dim enemyplayer As New player()

  Private Sub Attack()
    yourplayer.armorclass = 10
    enemyplayer.armorclass = 8
    yourplayer.attackroll = Int(Rnd() * yourplayer.accuracy)
    If attackroll >= enemyplayer.armorclass Then
      yourplayer.damageroll = Int(Rnd() * yourplayer.damage + 1)
      enemyplayer.hitpoints -= yourplayer.damageroll
      RichTextBox1.Text = "You hit the enemy for " & yourplayer.damageroll & " Enemy's hit Points are now " & enemyplayer.hitpoints
    ElseIf yourplayer.attackroll < enemyplayer.armorclass Then
      RichTextBox1.Text = " You Missed the enemy"
    End If
  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Attack()
  End Sub

End Class
this will do the trick.

Last edited by passel; 07-15-2011 at 09:15 AM. Reason: Added [code] tags, indented code
Reply With Quote
  #3  
Old 07-15-2011, 10:52 AM
WhiteOnyx WhiteOnyx is offline
Newcomer
 
Join Date: Jul 2011
Posts: 4
Default

Bare with please. I'm tiring to understand what you have done so correct me if I'm wrong PLEASE

Quote:
Originally Posted by masterpreenx View Post
better if this.
Code:
Public Structure Player()
  Public Hitpoints as integer = 100
  Public armorclass as integer
  public accuracy as integer = 20
  public damage as integer = 10
End Structure
dim yourplayer as new player()

then you can access using yourplayer.hitpoint -= enemy.attackdamage
you change all the "Dim's" i made and put them into a Structure and then call upon that structure (Player() ) when needed.

Accuracy would have been the same as PatkRoll right?

i understand the yourplayer.hitpoint but "-=" im not sure correct me if im wrong.
( as far as the code you have written enemy.attackdamage hasn't been declared so im using "5" as an example)
x = 5
100 - x = 95
( this would be the new player hitpoints) now it would take "95" as the new player hitpoint value ? example:
95 - x = 90
so the "-=" means that it takes and holds that value as the player hitpoints right?

Moving on . Sorry im breaking down the code you have written to make sure i understand it correctly .
I haven't gotten into arrays yet in my book i believe its in the next chapter so im not quite sure how to use them but i got an idea .


Quote:
Originally Posted by masterpreenx View Post
Code:
Public Class Form1
  Public Structure Player()
    Public Hitpoints As Integer = 100
    Public armorclass As Integer
    Public accuracy As Integer = 20
    Public damage As Integer = 10
    Public damageroll As Integer
    Public attackroll As Integer
  End Structure

  Dim yourplayer As New player()
  Dim enemyplayer As New player()

  Private Sub Attack()
    yourplayer.armorclass = 10
    enemyplayer.armorclass = 8
    yourplayer.attackroll = Int(Rnd() * yourplayer.accuracy)
    If attackroll >= enemyplayer.armorclass Then
      yourplayer.damageroll = Int(Rnd() * yourplayer.damage + 1)
      enemyplayer.hitpoints -= yourplayer.damageroll
      RichTextBox1.Text = "You hit the enemy for " & yourplayer.damageroll & " Enemy's hit Points are now " & enemyplayer.hitpoints
    ElseIf yourplayer.attackroll < enemyplayer.armorclass Then
      RichTextBox1.Text = " You Missed the enemy"
    End If
  End Sub
you defined enemy as new player() this means that player and enemy have the same stats? if so would it be simpler to create a new structure as
enemy() or would it be better to define the enemy in the Private Sub attack() like you did for the armorclass example:

Code:
Public Class Form1
  Public Structure Player()
    Public Hitpoints As Integer 
    Public armorclass As Integer
    Public accuracy As Integer = 20
    Public damage As Integer = 10
    Public damageroll As Integer
    Public attackroll As Integer
  End Structure

  Dim yourplayer As New player()
  Dim enemyplayer As New player()

  Private Sub Attack()
    yourplayer.Hitpoints = 100
    enemyplayer.Hitpoints = 80
    enemyplayer.damage = 8
    yourplayer.armorclass = 10
    enemyplayer.armorclass = 8
    yourplayer.attackroll = Int(Rnd() * yourplayer.accuracy)
    If attackroll >= enemyplayer.armorclass Then
      yourplayer.damageroll = Int(Rnd() * yourplayer.damage + 1)
      enemyplayer.hitpoints -= yourplayer.damageroll
      RichTextBox1.Text = "You hit the enemy for " & yourplayer.damageroll & " Enemy's hit Points are now " & enemyplayer.hitpoints
    ElseIf yourplayer.attackroll < enemyplayer.armorclass Then
      RichTextBox1.Text = " You Missed the enemy"
    End If
  End Sub
With what I've done now the players Hitpoints and the enemy's Hitpoints are different and I've added the enemy's damage to further the code for the enemys attack round. does it sound like im at least half-way understanding what you have done?
I'm gonna try to redo my code .The way you have done it does making it easier to write it out (half the typing in the future) but then again you never know unless you ask .

Thank You so much for the advice masterpreenx
Reply With Quote
  #4  
Old 07-15-2011, 11:24 AM
passel's Avatar
passelQuestions about Damage and Hit points passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,028
Default

The code given above is more suggestion than an example of working code.

There are a number of syntax errors and issues with the example code given.
A structure is not defined with () after the structure name.
You can't define initialiazation values for items in the structure unless the value is shared across all instances of the structure and then it is no longer unique to the instance.

A problem is that you set the player and enemy's values at the beginning of the Attack routine so they will be reset back to those values every type you call the Attack routine.

So, declare the structure properly.
Declare instances of those structures.
Initialize those instances.
Play the game.
Code:
  Public Structure Player_Type
    Public Hitpoints As Integer
    Public armorclass As Integer
    Public accuracy As Integer
    Public damage As Integer
    Public damageroll As Integer
    Public attackroll As Integer
  End Structure


  Dim Player, Enemy As Player_Type


  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Initialize the data once, when the form loads.
    'You should put the code in an initialization routine so it can be called from here,
    'and called elsewhere in your game if you need to re-initialize the values to start over
    'etc...
    Player.Hitpoints = 100
    Player.damage = 10
    Player.armorclass = 10
    Enemy.Hitpoints = 80
    Enemy.damage = 8
    Enemy.armorclass = 8
  End Sub
Now you modify those values as the game progresses.

X -= Y
is just shorthand for
X = X - Y

Same for +=, *=, /= ....


Later, if you want to have multiple players, or enemies, then you can declare an array of the structure.
[code]
'10 enemies, index 0 to 9
Dim enemy(9) as Player_Type

You could initialize each enemy with different Hitpoints, damage etc.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #5  
Old 07-15-2011, 03:00 PM
WhiteOnyx WhiteOnyx is offline
Newcomer
 
Join Date: Jul 2011
Posts: 4
Default thank you

Thank you for clarifying the "-=" and the others (+=,*=,/+) passel. They will come in handy later as i progress.
as for the arrays im gonna start reading the chapter in my book later tonight on them hopefully I'll have a better understanding of them . I am on the understanding that they are widely use. for tile maps and enemy/player basic stats and so on.

question about the Load() function thought...
is the Load function only called at the beginning of the program? if so instead of putting the stats for the characters ( players and enemy's) in the Load() function could you put private subs in its place and make it look a bit better or would that be more work then what is really needed
Example:

Code:
Public Structure Player_Type
    Public Hitpoints As Integer
    Public armorclass As Integer
    Public accuracy As Integer
    Public damage As Integer
    Public damageroll As Integer
    Public attackroll As Integer
  End Structure

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Player()
    Enemy()

End Sub

Private Sub Player()

    Player.Hitpoints = 100
    Player.damage = 10
    Player.armorclass = 10

End Sub

Private Sub Enemy()

    Enemy.Hitpoints = 80
    Enemy.damage = 8
    Enemy.armorclass = 8

  End Sub
under standing very little about arrays atm I kinda see it as a filing cabinet or a piece of graph paper with coords on it ...( rows and colums)
if i understand right you can pull a specific file out of that " cabinet" if you know were it is like you said "Dim enemy(9) as Player_Type" dim (9) would be the 10th slot in a single row array right? I'm tempted to as more on arrays but i better not I don't want to get over whelmed with to much at once.

as for the code masterpreenx gave me. I understand its more of suggestion and I've come to find that there are 100 ways to the other side of the street in programming. Hints why I'm pulling in all the advice like a sponge and tring to find a way that suits best for me . Either way their is a lot I don't know so every bit of help is appreciated. Once i get more coding done on this little project ill post it .

Thanks again for your input!
Reply With Quote
  #6  
Old 07-15-2011, 09:47 PM
passel's Avatar
passelQuestions about Damage and Hit points passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,028
Default

Yes, creating private subroutines and calling them from the Load event would be preferred, and I noted that in the comments of my example.
If the player dies, and you want to re-initialize the values, you can just call the player sub from another part of your code.
Generally, if you're going to need to do something in an event that you will need to do from other events or logic, than that should be in a routine so it can be called from where ever needed. I don't like calling event handlers directly from code, even in the old legacy VB.
Even if the event handler is the only place the code is needed, it can still be clearer to create a well named subroutine and call it, so later if you return to code you haven't touched in a while collapsing the code to an outline and perusing routine names can be more meaningful.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #7  
Old 07-17-2011, 01:48 PM
WhiteOnyx WhiteOnyx is offline
Newcomer
 
Join Date: Jul 2011
Posts: 4
Default Questions...

I'm just wondering why this is happening ....
I have made the player attack and the enemy attack but when i debug it only shows the enemy's attacks not the players attack in the text ... so i added a timer and that made it work properly , but I can't understand why it wouldn't work without the timer. Here are my questions:
1. Why doesn't this work without the timer .
2. Is there a way to make it work without the timer.
3. say i had 2-3 different Enemy's (Enemy1 , Enemy2 , Enemy3 ) how could i call them randomly would i need to make an array to do this?
4. if i were to set up an experience and item/gold drop counters ,It would be best to put those values in the enemy Subs right?
Example:
Private Sub Enemy1()
EXP = 25
Gold = int(rnd * 50)
.... and so on


this is code with timer it works how i want it to (using 3 sec delay)
Code:

Public Class Form1
    Public Structure Player_Type
        Public Hitpoints As Integer
        Public armorclass As Integer
        Public accuracy As Integer
        Public damage As Integer
        Public damageroll As Integer
        Public attackroll As Integer
    End Structure
    Dim player, Enemy As Player_Type
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        player.Hitpoints = 100
        player.damage = 10
        player.armorclass = 10
        player.accuracy = 20

        Enemy.Hitpoints = 80
        Enemy.damage = 8
        Enemy.armorclass = 8
        Enemy.accuracy = 20
    End Sub

    Private Sub PlayerAttack()

        player.attackroll = Int(Rnd() * player.accuracy)

        If player.attackroll >= Enemy.armorclass Then
            player.damageroll = Int(Rnd() * player.damage + 1)
            Enemy.Hitpoints -= player.damageroll
            RichTextBox1.Text = "You hit the enemy for " & player.damageroll & "               Enemy's hit Points are now " & Enemy.Hitpoints
            ElseIf player.attackroll < Enemy.armorclass Then
                RichTextBox1.Text = " You Missed the enemy"
            End If
        If Enemy.Hitpoints <= 0 Then
            RichTextBox1.Text = " Enemy was Defeated! "
        End If

    End Sub

    Private Sub EnemyAttack()
        Timer1.Enabled = False
        Enemy.attackroll = Int(Rnd() * Enemy.accuracy)

        If Enemy.attackroll >= player.armorclass Then
            Enemy.damageroll = Int(Rnd() * Enemy.damage + 1)
            player.Hitpoints -= Enemy.damageroll
            RichTextBox1.Text = "The enemy hit you for " & Enemy.damageroll & "                    Your hit Points are now " & player.Hitpoints
        ElseIf Enemy.attackroll < Enemy.armorclass Then
            RichTextBox1.Text = " The enemy missed you"
        End If
        If player.Hitpoints <= 0 Then
            RichTextBox1.Text = " You were Defeated! "
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PlayerAttack()
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        EnemyAttack()
    End Sub
End Class

This is how i had it without the timer

Code:
    Private Sub PlayerAttack()

        player.attackroll = Int(Rnd() * player.accuracy)

        If player.attackroll >= Enemy.armorclass Then
            player.damageroll = Int(Rnd() * player.damage + 1)
            Enemy.Hitpoints -= player.damageroll
            RichTextBox1.Text = "You hit the enemy for " & player.damageroll & "               Enemy's hit Points are now " & Enemy.Hitpoints
            ElseIf player.attackroll < Enemy.armorclass Then
                RichTextBox1.Text = " You Missed the enemy"
            End If
        If Enemy.Hitpoints <= 0 Then
            RichTextBox1.Text = " Enemy was Defeated! "
        End If

    End Sub

    Private Sub EnemyAttack()
        
        Enemy.attackroll = Int(Rnd() * Enemy.accuracy)

        If Enemy.attackroll >= player.armorclass Then
            Enemy.damageroll = Int(Rnd() * Enemy.damage + 1)
            player.Hitpoints -= Enemy.damageroll
            RichTextBox1.Text = "The enemy hit you for " & Enemy.damageroll & "                    Your hit Points are now " & player.Hitpoints
        ElseIf Enemy.attackroll < Enemy.armorclass Then
            RichTextBox1.Text = " The enemy missed you"
        End If
        If player.Hitpoints <= 0 Then
            RichTextBox1.Text = " You were Defeated! "
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PlayerAttack()
        EnemyAttack()
    End Sub

  
End Class
With it like this stepping through the debugging it shows it all working but only the EnemyAttack() portion shows in the text. why is this?


Sorry for being such a pain.
Thank You for all the help so far !
Reply With Quote
  #8  
Old 08-05-2011, 06:50 PM
Exiled Exiled is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

I prefer actually using classes, and drawing all enemies at once using a For Loop. Similar to what masterpreenx said.
Reply With Quote
  #9  
Old 08-06-2011, 04:39 PM
passel's Avatar
passelQuestions about Damage and Hit points passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,028
Default

I think both cases work, but since you don't add text to your textbox, you replace it, when you press the button, anything put in the textbox by the player, is immediately replace by the text from the enemy, so you don't see it.
With the timer, you have a three second gap between the two, so you have time to read it.
If you want to see both, when you press the button, in the button event, clear the text box, then call the player and enemy routines, but change the code to add text to the textbox, not replace, i.e.
RichTextBox1.AppendText = " Enemy was Defeated! "
RichTextBox1.AppendText = vbCrLf
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Questions about Damage and Hit points
Questions about Damage and Hit points
Questions about Damage and Hit points Questions about Damage and Hit points
Questions about Damage and Hit points
Questions about Damage and Hit points
Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points Questions about Damage and Hit points
Questions about Damage and Hit points
Questions about Damage and Hit points
 
Questions about Damage and Hit points
Questions about Damage and Hit points
 
-->