简体   繁体   English

vb.net代码读取标签错误

[英]vb.net code reads lables wrong

Okay, so I am making a game, like cookie clicker, or in my case - http://www.silvergames.com/poop-clicker (don't ask...), so that when you click on the icon in the center, it changes the total value by adding 1. On the side, you have a picture which you click to increase the amount it generates automatically every second. 好吧,所以我正在制作一个游戏,例如Cookie Clicker,或者就我而言-http: //www.silvergames.com/poop-clicker (不要问...),这样,当您单击在中心,它通过加1来更改总值。在侧面,您单击图片以增加每秒自动生成的数量。
At the moment I have it like this: 此刻我有这样的:

The timer tics every second. 计时器每秒抽动一次。 If the total amount > the cost of upgrade then it shows the picture of the thing you click to upgrade. 如果总金额>升级成本,则会显示您单击升级的事物的图片。

When you click that picture - The cost is taken away from the total amount. 当您单击该图片时-费用将从总金额中扣除。 It changes the amount of times you have used that upgrade by +1. 它将您升级使用的次数更改为+1。
The automatic upgrades per second is changed by +1. 每秒自动升级的数量为+1。
The Cost is increased by 10. 成本增加10。

What is happening is that I click the icon in the middle say 5 times (very quickly) and it only comes up with a total of 3. That in itself is a problem, but the even worse problem is that it shows the picture to click, when i told it to only show when the total value was > 10 (the cost of the upgrade). 发生的是,我单击中间的图标说5次(非常快),总共只显示了3次。这本身就是一个问题,但更糟糕的问题是它显示了要单击的图片,当我告诉它仅显示总值> 10(升级成本)时。

I am really confused, and any help will be much appreciated. 我真的很困惑,任何帮助将不胜感激。

Thanks SkySpear 谢谢SkySpear

PS. PS。 Here's the Code - 这是代码-

Public Class Form1

Private Sub picPoop_Click(sender As Object, e As EventArgs) Handles picPoop.Click
    lblPoops.Text = lblPoops.Text + 1
End Sub

Private Sub picCursor_Click(sender As Object, e As EventArgs) Handles picCursor.Click
    lblPoops.Text = lblPoops.Text - lblCursorCost.Text
    lblCursorAmmount.Text = lblCursorAmmount.Text + 1
    lblPoopsPerSec.Text = lblPoopsPerSec.Text + 1
    lblCursorCost.Text = lblCursorCost.Text + 10
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    lblCursorAmmount.Text = 0
    lblCursorCost.Text = 10
    lblBabyAmmount.Text = 0
    lblBabyCost.Text = 100
    lblBowlAmmount.Text = 0

    picCursor.Hide()
    tmrSec.Start()
End Sub

Private Sub tmrSec_Tick(sender As Object, e As EventArgs) Handles tmrSec.Tick
    If lblPoops.Text > lblCursorCost.Text Then picCursor.Show()
End Sub
End Class

Again, don't ask where this ridiculous idea came from, I can assure you it wasn't mine. 同样,不要问这个荒谬的想法是从哪里来的,我可以向您保证,它不是我的。

Your main problem with this is that in your Timer sub, you are comparing text to text. 您的主要问题是,在Timer子程序中,您正在比较文本。 In this case, a value of "3" > "21", since text comparisons work on a char by char basis. 在这种情况下,值“ 3”>“ 21”,因为文本比较是逐字符进行的。 When this happens, your pictureBox is being shown. 发生这种情况时,将显示您的pictureBox。 As others suggested, you can use any of the string to numeric conversion functions in your timer event to make this work better. 就像其他人建议的那样,您可以在计时器事件中使用任何字符串到数字的转换函数,以使此工作更好。

A slightly better approach would be to declare some class level numeric variables that hold each individual value and displays them when needed. 更好的方法是声明一些类级别的数字变量,这些变量保存每个单独的值并在需要时显示它们。 As an example 举个例子

numPoops += 1
lblPoops.Text = numPoops

This will make sure that all math will work correctly. 这样可以确保所有数学运算都能正确运行。

You are dealing with the Value of the textboxes, not the Text in it. 您正在处理文本框的值,而不是其中的文本。
You should enclose each textbox with VAL() to get its exact value as a number. 您应该使用VAL()围住每个文本框,以获取其确切值作为数字。

Private Sub picPoop_Click(sender As Object, e As EventArgs) Handles picPoop.Click
    lblPoops.Text = VAL(lblPoops.Text) + 1
End Sub

Private Sub picCursor_Click(sender As Object, e As EventArgs) Handles picCursor.Click
    lblPoops.Text = VAL(lblPoops.Text) - VAL(lblCursorCost.Text)
    lblCursorAmmount.Text = VAL(lblCursorAmmount.Text) + 1
    lblPoopsPerSec.Text = VAL(lblPoopsPerSec.Text) + 1
    lblCursorCost.Text = VAL(lblCursorCost.Text) + 10
End Sub

Private Sub tmrSec_Tick(sender As Object, e As EventArgs) Handles tmrSec.Tick
    If VAL(lblPoops.Text) > VAL(lblCursorCost.Text) Then picCursor.Show()
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM