这是我的代码:
import pygame
import ball
import paddle
from pygame.locals import*
class Score:
def __init__(self, ball, paddle):
self.numbers = [pygame.image.load('digit_0.bmp'),
pygame.image.load('digit_1.bmp'),
pygame.image.load('digit_2.bmp'),
pygame.image.load('digit_3.bmp'),
pygame.image.load('digit_4.bmp'),
pygame.image.load('digit_5.bmp'),
pygame.image.load('digit_6.bmp'),
pygame.image.load('digit_7.bmp'),
pygame.image.load('digit_8.bmp'),
pygame.image.load('digit_9.bmp'),
]
self.player = 0
self.computer = 0
self.secdig = 0
self.ball = ball
self.paddle = paddle
无法弄清楚为什么当计数器应该继续以1为增量时,点(桨)仅保持为1。
def points(self, paddle):
count = 0
point = 0
if self.ball.x < paddle.getX():
count += 1
print(count)
def paint(self, surface):
surface.blit(self.numbers[self.computer], (200, 30))
surface.blit(self.numbers[self.secdig], (160, 30))
答案 0 :(得分:0)
你必须把计数变成一个类变量。
def __init__(self, ball, paddle):
...
self.count = 0
def points(self, paddle):
point = 0
if self.ball.x < paddle.getX():
self.count += 1
print(count)
如果在count
方法中将points()
设置为0,则每次调用该方法时,count都会再次设置为0.
答案 1 :(得分:0)
添加
self.count = 0
到您的班级,然后在积分功能。
中使用它def points(self, paddle):
point = 0
if self.ball.x < paddle.getX():
self.count += 1