Buy the code of the previous day!

zhaozj2021-02-16  61

Import Random

Class item: def __init __ (self): self.attribute = {} Def add (self, index, value): self.attribute [index] = value defprintdesc (self): for key in self.attribute: Print Key, Print Self.attribute [key]

Class ItemFactory: Def __init __ (self): self.basic = {} self.advance = {} Def addbasic (self, index, value): self.basic [index] = Value Def AddadVance (Self, INDEX, VALUE, ODDS) : Self.advance [index] = (value, odds) Def makeaItem (Self): Temp = item () for key in self.basic.keys (): value = random.randint (* Self.basic [key]) TEMP .add (key, value) for key in self.advance.keys (): odds = random.randint (1, 100) if odds> self.advance [key] [1]: value = random.randint (* Self. Advance [Key] [0]) Temp.add (key, value) return temp def main (): bladefac = itemfactory () Bladefac.addbasic ('DAMAGE', (10, 20)) Bladefac.addadvance ('HP', (20, 30), 70) Bladefac.addadvance ('mp', (15, 25), 65) Bladefac.addadvance ('str', (10, 15), 60) Bladefac.addadvance ('DEX', (15 , 20), 55) Bladefac.addadvance ('MAG', (5, 10), 50) BladeOffire = Bladefac.makeaItem () BladeOffire.PrintDesc () if __name__ == '__main__': main ()

转载请注明原文地址:https://www.9cbs.com/read-16479.html

New Post(0)