
Lv.1
下次一定不改鸣!!!!!
签名:乱打游戏; 98华语歌坛染色体重复客观性备份
在 为什么点击没有反应? 中回复
我给大家重新发一下(这个问题应经解决了)
实现效果:点击种田,农业增加并且有云存档
现在效果:增加问题倒是解决了,但没有存档
2021-08-21T21:27:00 点赞:0
在 如何在社区证明自己是大佬? 中回复
import sys, pickle,datetime
from PyQt5 import QtCore, QtGui, QtWidgets, uic
formclass = uic.loadUiType("virtualpet.ui")[0]
class VirtualPetWindow(QtWidgets.QMainWindow, formclass):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.doctor = False
# Initializes values
self.walking = False
self.sleeping = False
self.playing = False
self.eating = False
self.time_cycle = 0
self.hunger = 0
self.happiness = 8
self.health = 8
self.forceAwake = False
# Lists images for ani喵s
self.sleepImages = ["sleep1.gif","sleep2.gif","sleep3.gif",
"sleep4.gif"]
self.eatImages = ["eat1.gif", "eat2.gif"]
self.walkImages = ["walk1.gif", "walk2.gif", "walk3.gif",
"walk4.gif"]
self.playImages = ["play1.gif", "play2.gif"]
self.doctorImages = ["doc1.gif", "doc2.gif"]
self.nothingImages = ["pet1.gif", "pet2.gif", "pet3.gif"]
self.imageList = self.nothingImages
self.imageIndex = 0
# Connects event handlers for toolbar buttons
self.actionStop.triggered.connect(self.stop_Click)
self.actionFeed.triggered.connect(self.feed_Click)
self.actionWalk.triggered.connect(self.walk_Click)
self.actionPlay.triggered.connect(self.play_Click)
self.actionDoctor.triggered.connect(self.doctor_Click)
# Sets up timers
self.myTimer1 = QtCore.QTimer(self)
self.myTimer1.start(500)
self.myTimer1.timeout.connect(self.ani喵_timer)
self.myTimer2 = QtCore.QTimer(self)
self.myTimer2.start(5000)
self.myTimer2.timeout.connect(self.tick_timer)
filehandle = True
# Tries to open pickle file
try:
file = open("savedata_vp.pkl", "rb")
except:
filehandle = False
if filehandle:
save_list = pickle.load(file) # Reads from pickle file if open
file.close()
else:
save_list = [8, 8, 0, datetime.datetime.now(), 0] # Uses default values if pickle file not open
# Pulls individual values out of list
self.happiness = save_list[0]
self.health = save_list[1]
self.hunger = save_list[2]
timestamp_then = save_list[3]
self.time_cycle = save_list[4]
# Checks how long since last run
difference = datetime.datetime.now() - timestamp_then
ticks = int(difference.seconds / 50)
for i in range(0, ticks):
# Simulates all ticks that happened during down time
self.time_cycle += 1
if self.time_cycle == 60:
self.time_cycle = 0
if self.time_cycle <= 48: # Awake
self.sleeping = False
if self.hunger < 8:
self.hunger += 1
else: # Sleeping
self.sleeping = True
if self.hunger < 8 and self.time_cycle % 3 == 0:
self.hunger += 1
if self.hunger == 7 and (self.time_cycle % 2 ==0) \
and self.health > 0:
self.health -= 1
if self.hunger == 8 and self.health > 0:
self.health -=1
# Uses correct ani喵—awake or sleeping
if self.sleeping:
self.imageList = self.sleepImages
else:
self.imageList = self.nothingImages
def sleep_test(self):
# Checks if pet is sleeping before doing an action
if self.sleeping:
result = (QtWidgets.QMessageBox.warning(self, 'WARNING', # Type of dialog
"Are you sure you want to wake your pet up? He'll be unhappy about it!",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, # Buttons to show
QtWidgets.QMessageBox.No)) # Default button
if result == QtWidgets.QMessageBox.Yes:
self.sleeping = False
self.happiness -= 4
self.forceAwake = True
return True
else:
return False
else:
return True
# The doctor button event handler
def doctor_Click(self):
if self.sleep_test():
self.imageList = self.doctorImages
self.doctor = True
self.walking = False
self.eating = False
self.playing = False
# The feed button event handler
def feed_Click(self):
if self.sleep_test():
self.imageList = self.eatImages
self.eating = True
self.walking = False
self.playing = False
self.doctor = False
# The play button event handler
def play_Click(self):
if self.sleep_test():
self.imageList = self.playImages
self.playing = True
self.walking = False
self.eating = False
self.doctor = False
# The walk button event handler
def walk_Click(self):
if self.sleep_test():
self.imageList = self.walkImages
self.walking = True
self.eating = False
self.playing = False
self.doctor = False
# The stop button event handler
def stop_Click(self):
if not self.sleeping:
self.imageList = self.nothingImages
self.walking = False
self.eating = False
self.playing = False
self.doctor = False
def animation_timer(self):
# The animation timer (every 0.5 sec) event handler
if self.sleeping and not self.forceAwake:
self.imageList = self.sleepImages
self.imageIndex += 1
if self.imageIndex >= len(self.imageList):
self.imageIndex = 0
icon = QtGui.QIcon()
# Updates pet’s image (animation)
current_image = self.imageList[self.imageIndex]
icon.addPixmap(QtGui.QPixmap(current_image),
QtGui.QIcon.Disabled, QtGui.QIcon.Off)
self.petPic.setIcon(icon)
self.progressBar_1.setProperty("value", (8-self.hunger)*(100/8.0))
self.progressBar_2.setProperty("value", self.happiness*(100/8.0))
self.progressBar_3.setProperty("value", self.health*(100/8.0))
def tick_timer(self): # Start of main 5 sec timer event handler
# Checks if sleeping or awake
self.time_cycle += 1
if self.time_cycle == 60:
self.time_cycle = 0
if self.time_cycle <= 48 or self.forceAwake:
self.sleeping = False
else:
self.sleeping = True
if self.time_cycle == 0:
self.forceAwake = False
if self.doctor:
# Adds or subtracts units depending on activity
self.health += 1
self.hunger += 1
elif self.walking and (self.time_cycle % 2 == 0):
self.happiness += 1
self.health += 1
self.hunger += 1
elif self.playing:
self.happiness += 1
self.hunger += 1
elif self.eating:
self.hunger -= 2
elif self.sleeping:
if self.time_cycle % 3 == 0:
self.hunger += 1
else:
self.hunger += 1
if self.time_cycle % 2 == 0:
self.happiness -= 1
# Makes sure values are not out of range
if self.hunger > 8: self.hunger = 8
if self.hunger < 0: self.hunger = 0
if self.hunger == 7 and (self.time_cycle % 2 ==0) :
self.health -= 1
if self.hunger == 8:
self.health -=1
if self.health > 8: self.health = 8
if self.health < 0: self.health = 0
if self.happiness > 8: self.happiness = 8
if self.happiness < 0: self.happiness = 0
# Updates progress bars
self.progressBar_1.setProperty("value", (8-self.hunger)*(100/8.0))
self.progressBar_2.setProperty("value", self.happiness*(100/8.0))
self.progressBar_3.setProperty("value", self.health*(100/8.0))
def closeEvent(self, event):
# Saves status and timestamp to pickle file
file = open("savedata_vp.pkl", "wb") # Line-continuation character
save_list = [self.happiness, self.health, self.hunger, \
datetime.datetime.now(), self.time_cycle]
pickle.dump(save_list, file)
event.accept()
def menuExit_selected(self):
self.close()
app = QtWidgets.QApplication(sys.argv)
myapp = VirtualPetWindow()
myapp.show()
app.exec_()
2021-09-05T08:51:37 点赞:0
在 零的二阶名字的奥秘 中回复
空集是指不含任何元素的集合。空集是任何集合的子集,是任何非空集合的真子集。空集不是无;它是内部没有元素的集合。
对任意集合 A,空集是 A 的 子集:∀A:Ø ⊆ A; 对任意集合 A,空集和 A 的 并集为 A:∀A:A ∪ Ø = A; 对任意非空集合 A,空集是 A的 真子集:∀A,,,若A≠Ø,则Ø 真包含于 A。 对任意集合 A,空集和 A 的 交集为空集:∀A,A ∩ Ø = Ø; 对任意集合 A,空集和 A 的笛卡尔积为空集:∀A,A × Ø = Ø; 空集的唯一子集是空集本身:∀A,若 A ⊆ Ø ⊆ A,则 A= Ø;∀A,若A= Ø,则A ⊆ Ø ⊆ A。 空集的元素个数(即它的势)为零; 特别的,空集是有限的:| Ø | = 0; 对于全集,空集的 补集为全集:C UØ=U。 集合论中,若两个集合有相同的元素,则它们相等。那么,所有的空集都是相等的,即空集是唯一的。 考虑到空集是实数线(或任意 拓扑空间)的子集,空集既是 开集、又是 闭集。空集的 边界点集合是空集,是它的子集,因此空集是闭集。空集的内点集合也是空集,是它的子集,因此空集是开集。另外,因为所有的 有限集合是紧致的,所以空集是紧致集合,。 空集的 闭包是空集。
2021-10-01T05:59:33 点赞:4
在 你们现在留了多少个坑? 中回复
没填作:《三国志》《资治通鉴》《战争世界》《捡金币kitten4版》《pianoos》
代耕作:《宇宙上最坑的game》《我不要被叫家长》《sikeralpha0,3》
2021-11-26T19:18:29 点赞:0
在 你们现在留了多少个坑? 中回复
3333333333333333333 imgsrc="http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/b6/sb_thumb.gif"alt="emotion_生病"
2021-11-26T19:19:11 点赞:0
在 故事接龙~ 中回复
男孩回答:“A boy can do evrything for girl”(一个男孩可以为女孩做一切)
女孩听了特别感动
但是……她却忘记了英文接下来是HIJK
He is just kidding (他只是在开玩笑)
女孩笑了笑说:就算他喵我也没关系……后面还有LMNOP
Love Must Need Our Patience
(爱情需要付出耐心)
2021-11-26T20:47:41 点赞:0
在 (已发灌水)把你们上次复制(最后一次复制)的内容发出来 中回复
武松早把土色布衫脱下,上半截揣在腰里,便把那桶酒只一泼在地上,抢入
柜身子里,却好接着那妇人。武松手硬,那里挣紥得。被武松一手接住腰跨,一
只手把冠儿捏做粉碎,揪住云髻,隔柜身子提将出来,望浑酒缸里只一丢,听得
扑同的一声响,可怜这妇人正被直丢在大酒缸里。武松托地从柜身前踏将出来。
有几个当撑的酒保,手脚活些个的,都抢来奔武松。武松手到,轻轻地只一提,
颠入怀里来。两手揪住,也望大酒缸里只一丢,桩在里面。又一个酒保奔来,提
着头只一掠,也丢在酒缸里。再有两个来的酒保,一拳一脚,都被武松打倒了。
先头三个人,在三只酒缸里,那里挣紥得起。后面两个人,在地下扒不动。这几
个火家捣子,打得屁滚尿流。乖的走了一个。武松道:“那厮必然去报蒋门神来。
我就接将去,大路上打倒他好看,教众人笑一笑。”武松大踏步赶将出来。
那个捣子迳奔去报了蒋门神。蒋门神见说,吃了一惊。踢翻了交椅,丢去蝇
拂子,便钻将来。武松恰好迎着。正在大阔路上撞见。蒋门神虽然长大,近因酒
色所迷,淘虚了身子,先自吃了那一惊,奔将来,那步不曾停住,怎地及得武松
虎一般似健的人,又有心来算他。蒋门神见了武松,心里先欺他醉,只顾赶将入
来。说时迟,那时快。武松先把两个拳头去蒋门神脸上虚影一影,忽地转身便走。
蒋门神大怒,抢将来。被武松一飞脚踢起,踢中蒋门神小腹上。双手按了,便蹲
下去。武松一踅,踅将过来,那只右脚早踢起,直飞在蒋门神额角上,踢着正中。
望后便倒。武松追入一步,踏住胸脯,提起这醋钵儿大小拳头,望蒋门神脸上便
打。原来说过的打蒋门神扑手:先把拳头虚影一影,便转身,却先飞起左脚,踢
中了,便转过身来,再飞起右脚。这一扑,有名唤做“玉环步,鸳鸯脚”。这是
武松平生的真才实学,非同小可。打的蒋门神在地下叫饶。武松喝道:“若要我
饶你性命,只要依我三件事。”蒋门神在地下叫道:“好汉饶我!休说三件,便
是三伯件,我也依得。”
2022-09-12T14:36:20 点赞:2