为什么分数不是每一轮都在增加?

  • 本文关键字:一轮 增加 python
  • 更新时间 :
  • 英文 :


我正在为大学做一个python项目,我需要一个评分系统,这样我才能确定比赛的获胜者。代码如下:

import time
import random

#def player_details(message):
#name = input(message)
#return name
#global score
#global count
score = 0
count = 0
def length_card1():

card = p1card
length = len(card)
for i in range(length):
if card[i].isnumeric():
global card_number1
card_number1 = card[I:]

break

def length_card2():
card = p2card
length = len(card)
for i in range(length):
if card[i].isnumeric():
global card_number2
card_number2 = card[I:]

break
# ROUND 1 player 1 and 2 card
def card():
global p1card
global p2card
p1card = (random.choice(new_array))
new_array.remove(p1card)
p2card = (random.choice(new_array))
#player_1 = player_details("Player 1: ")
#player_2 = player_details("Player 2: ")

def win(score, count):

length_card1()
length_card2()

#RED DRAW
if p1card[0] == 'r' and p2card[0] == 'r':
print("Cards are the same colour...")
time.sleep(1)
print("The card with the highest number wins... Good Luck!!")
card_numberp1 = card_number1[0: ]
card_numberp2 = card_number2[0: ]
if card_numberp1 > card_numberp2:
print("Player 1 Wins!!")
score = score +2

else:
print("Player 2 Wins!!")
count = count +2

#BLACK DRAW
if p1card[0] == 'b' and p2card[0] == 'b':
print("Cards are the same colour...")
time.sleep(1)
print("The card with the highest number wins... Good Luck!!")
card_numberp1 = card_number1[0: ]
card_numberp2 = card_number2[0: ]
if card_numberp1 > card_numberp2:
print("Player 1 Wins!!")
score = score +2
else:
print("Player 2 Wins!!")
count = count +2

#YELLOW DRAW
if p1card[0] == 'y' and p2card[0] == 'y':
print("Cards are the same colour...")
time.sleep(1)
print("The card with the highest number wins... Good Luck!!")
card_numberp1 = card_number1[0: ]
card_numberp2 = card_number2[0: ]
if card_numberp1 > card_numberp2:
print("Player 1 Wins!!")
score = score +2

else:
print("Player 2 Wins!!")
count = count +2

#RED BEATS BLACK
if p1card[0] == 'r' and p2card[0] == 'b':
print("Red Beats Black so...")
time.sleep(1)
print("Player 1 Wins!!") 
score = score +2

#BLACK LOSES TO RED
if p1card[0] == 'b' and p2card[0] == 'r':
print("Red Beats Black so...")
time.sleep(1)
print("Player 2 Wins!!")
count = count +2


#YELLOW BEATS RED
if p1card[0] == 'y' and p2card[0] == 'r':
print("Yellow Beats Red so...")
time.sleep(1)
print("Player 1 Wins!!")
score = score +2

#RED LOSES TO YELLOW
if p1card[0] == 'r' and p2card[0] == 'y':
print("Yellow Beats Red so...")
time.sleep(1)
print("Player 2 Wins!!")
count = count +2

#BLACK BEATS YELLOW
if p1card[0] == 'b' and p2card[0] == 'y':
print("Black Beats Yellow so...")
time.sleep(1)
print("Player 1 Wins!!")
score = score +2

#YELLOW LOSES TO BLACK
if p1card[0] == 'y' and p2card[0] == 'b':
print("Black Beats Yellow so...")
time.sleep(1)
print("Player 2 Wins!!")
count = count +2


new_array.remove(p2card)
return score, count


#makes deck and shuffles it
colour = ['red', 'yellow', 'black']
array = []
for i in colour:
for j in range(1,11):
temp = i + " " + str(j)
array.append(temp)
new_array = list(array)
random.shuffle(new_array)
#GETS ROUND 1 CARDS AND WINNER
card()
print("Player 1 your first card was", p1card)
time.sleep(1)
print("Player 2 your first card was", p2card)
win(score, count)
nextround = input("Press ENTER to go to the next round: ")

#GETS THE ROUNDS CARDS AND WINNER#
card()
print("Player 1 your next card was", p1card)
time.sleep(1)
print("Player 2 your next card was", p2card)
win(score, count)
nextround = input("Press ENTER to go to the next round: ")
def round():
#GETS THE ROUNDS CARDS AND WINNER
card()
print("Player 1 your next card was", p1card)
time.sleep(1)
print("Player 2 your next card was", p2card)
win(score, count)
nextround = input("Press ENTER to go to the next round: ")

for i in range(12):
round()

#FINAL ROUND CARDS AND WINNER
card()
print("Player 1 Your Final Card was", p1card)
time.sleep(1)
print("Player 2 Your Final Card was", p2card)
win(score, count)
print(score)
print(count)

每次运行WIN子程序后,每个玩家的分数应在玩家获胜的每轮增加2分。相反,分数保持在0。有没有办法让我的分数每轮增加2分?

从win函数中删除参数,并在win函数中声明全局分数和计数

def win():
global score
global count

然后将所有呼叫从CCD_ 1=>至win()

我测试了你的代码几轮,它使玩家每次获胜的分数增加了2分。

最新更新