【发布时间】:2014-03-18 16:34:37
【问题描述】:
我通常不知道如何完成以下要点。帮助将不胜感激!!!我已经把到目前为止我得到的代码放在下面,但就像我说的,不知道如何将它合并到我的代码中。非常感谢。
• 计算两个角色的强度属性之间的差异
• 此差除以 5,然后向下舍入以创建“强度修正”
• 对技能属性重复该过程以创建“技能修饰符”
• 每个玩家投掷一个 6 面骰子。
• 如果两个骰子的分数相同,则不做任何更改
• 如果分数不相同,则得分最高的玩家将增加“力量” 修饰符”为力量值,“技能修饰符”为他们的技能值 人物
• 骰子得分较低的玩家从 他们角色的力量和技能值
• 如果技能值变为负数,则将其存储为零
• 如果力量值变为零或负数,则角色死亡。 程序应该:
• 允许用户输入两个角色的力量和技能。
• 使用上述过程显示遭遇的结果。 设计一个算法来描述这个过程。编写、测试和评估代码。"""
import random
def character_attributes():
initial_value = 10
character1_strength = initial_value + (random.randint(1,12) // random.randint(1,4))
character1_skill = initial_value + (random.randint(1,12) // random.randint(1,4))
character2_strength = initial_value + (random.randint(1,12) // random.randint(1,4))
character2_skill = initial_value + (random.randint(1,12) // random.randint(1,4))
print("Character 1 now has a strength attribute of {0}".format(character1_strength))
print("Character 1 now has a skill attribute of {0}".format(character1_skill))
print("Character 2 now has a strength attribute of {0}".format(character2_strength))
print("Character 2 now has a skill attribute of {0}".format (character2_skill))
myfile = open('character_attribute_data.txt', 'w')
myfile.writelines('Character 1 has a strength attribute of : ')
myfile.writelines(str(character1_strength))
myfile.writelines('\n')
myfile.writelines('Character 1 has a skill attribute of: ')
myfile.writelines(str(character1_skill))
myfile.writelines('\n')
myfile.writelines('Character 2 has a strength attribute of : ')
myfile.writelines(str(character2_strength))
myfile.writelines('\n')
myfile.writelines('Character 2 has a strength attribute of : ')
myfile.writelines(str(character2_skill))
myfile.close()
character_attributes()
def dice_roll(number):
if number == 12:
number = random.randint(1,12)
print(number)
return number
elif number == 6:
number = random.randint(1,6)
print(number)
return number
else:
number == 4
number = random.randint(1,4)
print(number)
return number
print("12 sided")
print("6 sided")
print("4 sided")
rolls = {4: [], 6: [], 12: []} # dictionary to hold rolls
while True:
roll = int(input("Which dice would you like to roll? --> ")) # store die size
rolls[roll].append(dice_roll(roll)) # roll and add to dictionary
doRepeat=input("Go again? --> ")
if doRepeat == "no":
break
print(rolls)
【问题讨论】:
-
我认为这最好通过使用类来解决。有两个函数来承担所有的工作是很难维护的。
-
我对计算机还很陌生,而且我在学校的老师不是很好,所以我有点挣扎,所以我决定来这个网站寻求帮助,而不是 snide cmets :)
-
我不希望人们做所有的代码,而只是想要一些提示或提示或其他东西
-
要阻止它级联成一个论点:请参阅我的第一条评论。
class将帮助您做到这一点。请参阅下面的唯一答案。类基本上是一种框架。把它想象成一个模板。您可以在那里存储默认统计信息、默认名称等。老实说,如果您使用 Python 编写具有与上述一样多的变量的游戏类型程序,那么类是您应该学习的第一件事。此外,如果您需要提示和评论,我们有 CodeReview.SE。 -
谢谢大家,我只是担心因为我必须为 gcse 做这个
标签: python python-3.x