heroku config:add APP_KEY_PEM="...your certificate..."
我有:
private void battleButton_Click(object sender, EventArgs e)
{
if (battleDropBox.SelectedItem.ToString() == "Rat")
{
enemyHP.Text = "Enemy HP: " + rat.HP.ToString();
enemyDPS.Text = "Enemy DPS: " + rat.Damage.ToString();
timer.Tick += new EventHandler(timer1_Tick);
timer.Interval = 1000;
timer.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
dealDamage();
}
public void dealDamage()
{
rat.HP--;
enemyHP.Text = "Enemy HP: " + rat.HP.ToString();
}
但我怎样才能这样做,它会减去变化的数量。
答案 0 :(得分:3)
重载方法:
import sqlite3 as db
from PyQt4 import QtCore, QtGui
import sys
con = db.connect('results.db', isolation_level=None)
cur = con.cursor()
cur.execute("SELECT * FROM Results")
all_data = cur.fetchall()
class UiDialog(object):
def setupUi(self, datadb):
datadb.setObjectName("Dialog")
datadb.resize(404, 304)
datadb.setWindowTitle("Database results")
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(datadb.sizePolicy().hasHeightForWidth())
datadb.setSizePolicy(sizePolicy)
datadb.setMinimumSize(QtCore.QSize(404, 304))
datadb.setMaximumSize(QtCore.QSize(404, 304))
self.table = QtGui.QTableWidget(datadb)
self.table.setGeometry(QtCore.QRect(2, 2, 400, 261))
self.table.setObjectName("table")
self.show = QtGui.QPushButton(datadb)
self.show.setGeometry(QtCore.QRect(2, 270, 400, 31))
self.show.setObjectName("show")
self.show.setText("Show results")
QtCore.QObject.connect(self.show, QtCore.SIGNAL("clicked()"), self.populate)
QtCore.QMetaObject.connectSlotsByName(datadb)
def populate(self):
self.table.setRowCount(len(all_data))
self.table.setColumnCount(4)
self.table.setHorizontalHeaderLabels(['Number', 'Keys', 'Time', 'Tries'])
for i, item in enumerate(all_data):
number = QtGui.QTableWidgetItem(str(item[0]))
keys = QtGui.QTableWidgetItem(item[1])
time = QtGui.QTableWidgetItem(str(item[2]))
tries = QtGui.QTableWidgetItem(str(item[3]))
self.table.setItem(i, 0, number)
self.table.setItem(i, 1, keys)
self.table.setItem(i, 2, time)
self.table.setItem(i, 3, tries)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
main_conf = QtGui.QDialog()
ui = UiDialog()
ui.setupUi(main_conf)
main_conf.show()
ret = app.exec_()
sys.exit(ret)
通过这种方式,您可以调用public void dealDamage(int damage)
{
rat.HP -= damage;
enemyHP.Text = "Enemy HP: " + rat.HP.ToString();
}
(不带参数),只需将dealDamage()
减1,也可以调用HP
将dealDamage(yourValue)
减少一个可变数量(即HP
将dealDamage(15)
递减15)。
要从您的勾选事件中调用此功能,如果您希望两个范围之间的随机损坏量,您可以执行以下操作:
HP
然后在你的tick处理程序中,你可以这样做:
void dealRandomDamage(int bottomLimit, int upperLimit)
{
dealDamage((new Random()).Next(bottomLimit, upperLimit));
}
随机减少1到10之间的任何值。
编辑:亚当提出了一个很好的观点。如果您确实采用了这条路线,那么最好将private void timer1_Tick(object sender, EventArgs e)
{
dealRandomDamage(1, 10);
}
函数定义更改为以下内容:
dealDamage()
这将消除造成损害的代码的冗余和重复(没有双关语意)。这样一来,如果你改变了 如何处理损坏的逻辑,那么它只会是对逻辑的一次改变。