关于python 2.7:使用Eclipse的PyGame中出现异常语法错误

Unusual Syntax Error in PyGame using Eclipse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pygame
import time
import random
from __builtin__ import quit

pygame.init()

display_width = 800
display_height = 600

black = (0,0,0)
white = (255,255,255)

red = (200,0,0)
green = (0,200,0)

bright_red = (255,0,0)
bright_green = (0,255,0)

ship_width = 73

gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Galaxia Remastered')
clock = pygame.time.Clock()

background = pygame.image.load('space1.png')
background = pygame.transform.scale(background, (800,600))

shipImg = pygame.image.load('ship1.png')
shipImg = pygame.transform.scale(shipImg, (73,73))

mobImg = pygame.image.load('ufo.png')
mobImg = pygame.transform.scale(mobImg, (100,100))

def mobs_dodged(count):
    font = pygame.font.SysFont(None, 25)
    text = font.render("Dodged:"+str(count), True, white)
    gameDisplay.blit(text,(0,0))

def mobs(mobx, moby, mobw, mobh):
    gameDisplay.blit(mobImg,(mobx,moby))

def ship(x,y):
    gameDisplay.blit(shipImg,(x,y))

def text_objects(text,font):
    textSurface = font.render(text, True, white)
    return textSurface, textSurface.get_rect()

def message_display(text):
    font = pygame.font.Font('freesansbold.ttf',115)
    TextSurf, TextRect = text_objects(text,font)
    TextRect.center = ((display_width/2),(display_height/2))
    gameDisplay.blit(TextSurf,TextRect)

    pygame.display.update()

    time.sleep(2)

    game_loop()

def crash():
    message_display('You Crashed!')

def button(msg,x,y,w,h,ic,ac):
    mouse = pygame.mouse.get_pos()

    if x + w > mouse[0] > x and y+h > mouse[1] > y:
        pygame.draw.rect(gameDisplay, ac, (x,y,w,h))
    else:
        pygame.draw.rect(gameDisplay,ic, (x,y,w,h))
    font = pygame.font.Font('freesansbold.ttf',20)
    textSurf, textRect = text_objects(msg, font)
    textRect.center = ((x+(w/2)),(y+(h/2))
    gameDisplay.blit(textSurf, textRect)

最后一行给我一个无效的语法错误,突出显示" gameDisplay"。环顾四周后,我在项目中有了另一个文件"从...导入gameDisplay"。我认为如果删除该行将得到解决,但是它指出"未解决的导入"。我重新启动了Ecplise并清理了我的项目多次,但仍然无法正常工作。我将该程序发送到另一台计算机,但仍然收到相同的错误。当我删除" gameDisplay"行时,它告诉我" def game_intro():"中存在无效的语法。

所有帮助将不胜感激。


您似乎在第74行有一个不匹配的括号
只需删除该行上的第一个,您的代码就可以再次正常工作。.

1
textRect.center = (x+(w/2)),(y+(h/2))