我正在尝试创建一个简单的浮桥游戏(类似于21点),我已经制作了一个牌组列表。如果我给ACE一个1或14的值,我当前的游戏版本可以运行,但是我需要它同时有两个值,所以如果一手牌超过21,ACE会返回1。你知道吗
deck = [ACE, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ACE, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ACE, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ACE, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
所以选卡的基本过程是这样的:
while True:
hand = []
hand.extend(random.sample(deck, 1))
print(hand)
while True:
hit = input("new card? (k/e)")
if hit == "k":
hand.extend(random.sample(deck, 1))
print("")
print("HAND:")
print(hand)
a = sum(hand)
print("")
print("SUM:")
print(a)
if a > 21:
print("")
print("OVER")
break
elif a == 21:
print("")
print("Pontoon")
break
else:
continue
我试着把ACE作为一个函数,但是随机抽样这不管用
def ACE():
if a > 21:
A = 1
else:
A = 14
return int(A)
那我怎么才能让王牌成为1和14的选手呢?你知道吗
不更改变量的值,而是调整求和函数:
输出:
可以通过将ACE定义为类来实现这一点
然后你可以像这样改变数组元素的值
相关问题 更多 >
编程相关推荐