创作灵感:Vipcode学习中心
Bug修复:作者的编程老师
使用软件:Vipcode学习中心、python3.10
import time, random #导入时间和随机模块
#Crops的类
class Crops():
def __init__(self,name,cost,price):#类似attribute,他是定义一个人的性格(动物或其他的性能或性格)
self.name=name#定义名字
self.cost=cost#定义本金
self.price=price#定义价格
print("我是",self.name,"。本金",self.cost,"金币。卖出",self.price,"金币")
def grow(self):
print(self.name,"正在生长……")
time.sleep(3)#等待3秒
print(self.name,"已经成熟,可赚",self.price,"金币。")
#Farmer的类
class Farmer():
def __init__(self,name,money):
self.name=name#定义名称
self.money=money#定义有多少钱
self.crops=None#定义有多少农作物
print("我叫",self.name,",我有