- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
错误:
File "D:/Users/44749/PycharmProjects/untitled/venv/Game.py", line 271, in draw_messages
text_height = helper_text_height(Constants.FONT_MESSAGE_TEXT) TypeError: helper_text_height() takes 0 positional arguments but 1 was given
我正在尝试在屏幕上显示一些文本但是我一直收到这个错误而且我似乎无法解决它有人知道我可以做些什么来解决这个问题吗?
import pygame
#game files
import Constants
# _____ _____ _______ _____ _ _ _____ _______
# / ____|/ ____|__ __| __ \| | | |/ ____|__ __|
#| (___ | | | | | |__) | | | | | | |
# \___ \| | | | | _ /| | | | | | |
# ____) | |____ | | | | \ \| |__| | |____ | |
#|_____/ \_____| |_| |_| \_\\____/ \_____| |_|
class struc_Tile:
def __init__(self, block_path):
self.block_path = block_path #Creates a place where the player cant walk to
self.explored = False
# ____ ____ _ ______ _____ _______ _____
# / __ \| _ \ | | ____/ ____|__ __/ ____|
#| | | | |_) | | | |__ | | | | | (___
#| | | | _ < _ | | __|| | | | \___ \
#| |__| | |_) | |__| | |___| |____ | | ____) |
# \____/|____/ \____/|______\_____| |_| |_____/
class obj_Actor:
def __init__(self, x, y, name_object, sprite, creature = None, ai = None):
self.x = x #Map address
self.y = y #Map address
self.sprite = sprite
self.creature = creature
if creature:
creature.owner = self
self.ai = ai
if ai:
ai.owner = self
def draw(self):
is_visible = libtcodpy.map_is_in_fov(FOV_MAP, self.x, self.y)
if is_visible:
SURFACE_MAIN.blit(self.sprite, (self.x*Constants.CELL_WIDTH, self.y*Constants.CELL_HEIGHT))
# ____ ___ __ __ ____ ___ _ _ _____ _ _ _____ _____ ____
# / ___/ _ \| \/ | _ \ / _ \| \ | | ____| \ | | ____|_ _/ ___|
#| | | | | | |\/| | |_) | | | | \| | _| | \| | _| | | \___ \
#| |__| |_| | | | | __/| |_| | |\ | |___| |\ | |___ | | ___) |
# \____\___/|_| |_|_| \___/|_| \_|_____|_| \_|_____| |_| |____/
class com_Creature:
#Creatures have health, and can damage other objects by attacking them. can also die
def __init__(self, name_instance, hp = 10, death_function = None):
self.name_instance = name_instance
self.maxhp = hp
self.hp = hp
self.death_function = death_function
#self.x + dx]
#Where you are + Where you want to go
#Are you able to move to the palce you want to go
def move(self, dx, dy):
title_is_wall = (GAME_MAP[self.owner.x + dx][self.owner.y + dy].block_path == True)
target = map_check_for_creatures(self.owner.x + dx, self.owner.y + dy, self)
for object in GAME_OBJECTS:
if (object is not self.owner and
object.x == self.owner.x + dx and
object.y == self.owner.y + dy and
object.creature):
target = object
break
if target:
print (self.name_instance + " Attacks " + target.creature.name_instance + " for 5 damage!")
target.creature.take_damage(5)
if not title_is_wall and target is None:
self.owner.x += dx
self.owner.y += dy
def take_damage(self, damage):
self.hp -= damage
print (self.name_instance + "'s health is " + str(self.hp) + "/" + str(self.maxhp))
if self.hp <= 0:
if self.death_function is not None:
self.death_function(self.owner)
#TODO class com_Item:
#TODO lass com_Container:
# _ ___
# / \ |_ _|
# / _ \ | |
# / ___ \ | |
#/_/ \_\___|
class ai_test:
#Once per turn, execute
def take_turn(self):
self.owner.creature.move(libtcodpy.random_get_int(0, -1, 1),libtcodpy.random_get_int(0, -1, 1))
def death_monster(monster):
print (monster.creature.name_instance + " is dead ")
monster.creature = None
monster.ai = None
# __ __ _____
#| \/ | /\ | __ \
#| \ / | / \ | |__) |
#| |\/| | / /\ \ | ___/
#| | | |/ ____ \| |
#|_| |_/_/ \_\_|
def map_create():
new_map = [[ struc_Tile(False) for y in range (0, Constants.MAP_HEIGHT)] for x in range(0, Constants.MAP_WIDTH) ]
#Creates the actual path block so if its set to tru you cant walk there if its set to false you can walk there
#Also this is where you create new walls floors etc etc
new_map[10][10].block_path = True
new_map[10][15].block_path = True
for x in range(Constants.MAP_WIDTH):
new_map[x][0].block_path = True
new_map[x][Constants.MAP_HEIGHT-1].block_path = True
for y in range(Constants.MAP_HEIGHT):
new_map[0][y].block_path = True
new_map[Constants.MAP_WIDTH-1][y].block_path = True
map_make_fov(new_map)
return new_map
def map_check_for_creatures(x, y, exclude_object = None):
target = None
if exclude_object:
for object in GAME_OBJECTS:
if (object is not exclude_object and
object.x == x and
object.y == y and
object.creature):
target = object
break
if target:
return target
else:
for object in GAME_OBJECTS:
if (object is not exclude_object and
object.x == x and
object.y == y and
object.creature):
target = object
break
if target:
return target
def map_make_fov(incoming_map):
global FOV_MAP
FOV_MAP = libtcodpy.map_new(Constants.MAP_WIDTH, Constants.MAP_HEIGHT)
for y in range(Constants.MAP_HEIGHT):
for x in range(Constants.MAP_WIDTH):
libtcodpy.map_set_properties(FOV_MAP,x ,y,
not incoming_map[x][y].block_path, not incoming_map[x][y].block_path)
def map_calculate_fov():
global FOV_CALCULATE
if FOV_CALCULATE:
FOV_CALCULATE = False
libtcodpy.map_compute_fov(FOV_MAP, PLAYER.x, PLAYER.y, Constants.TORCH_RADIUS, Constants.FOV_LIGHT_WALLS,
Constants.FOV_ALGO)
# ____ ____ ___ _____ _ _ ____
#| _ \| _ \ / \ \ / /_ _| \ | |/ ___|
#| | | | |_) | / _ \ \ /\ / / | || \| | | _
#| |_| | _ < / ___ \ V V / | || |\ | |_| |
#|____/|_| \_\/_/ \_\_/\_/ |___|_| \_|\____|
def draw_game():
global SURFACE_MAIN
#Clear the surface -- if you dont clear it, it will just draw over the last surface
SURFACE_MAIN.fill(Constants.COLOR_DEFAULT_BG)
#Draw the map
draw_map(GAME_MAP)
#Draw all Objects
for obj in GAME_OBJECTS:
obj.draw()
draw_debug()
draw_messages()
#Update the display
pygame.display.flip()
def draw_map(map_to_draw):
for x in range(0, Constants.MAP_WIDTH):
for y in range(0, Constants.MAP_HEIGHT):
is_visible = libtcodpy.map_is_in_fov(FOV_MAP, x, y)
if is_visible:
map_to_draw[x][y].explored = True
if map_to_draw[x][y].block_path == True:
#draw wall
SURFACE_MAIN.blit(Constants.S_WALL, ( x*Constants.CELL_WIDTH, y*Constants.CELL_HEIGHT))
else:
#draw floor
SURFACE_MAIN.blit(Constants.S_FLOOR, (x * Constants.CELL_WIDTH, y*Constants.CELL_HEIGHT))
elif map_to_draw[x][y].explored:
if map_to_draw[x][y].block_path == True:
# draw wall
SURFACE_MAIN.blit(Constants.S_WALLEXPLORED, (x * Constants.CELL_WIDTH, y * Constants.CELL_HEIGHT))
else:
# draw floor
SURFACE_MAIN.blit(Constants.S_FLOOREXPLORED, (x * Constants.CELL_WIDTH, y * Constants.CELL_HEIGHT))
def draw_debug():
draw_text(SURFACE_MAIN, "fps:" + str(int(CLOCK.get_fps())) , (0,0), Constants.COLOR_WHITE, Constants.COLOR_BLACK)
def draw_messages():
to_draw = GAME_MESSAGES
text_height = helper_text_height(Constants.FONT_MESSAGE_TEXT)
start_y = Constants.MAP_HEIGHT*Constants.CELL_HEIGHT - (Constants.NUM_MESSAGES * text_height)
i = 0
for message, color in to_draw:
draw_text(SURFACE_MAIN, message, (0, start_y + (i * text_height), 0), color, Constants.COLOR_BLACK)
i += 1
def draw_text(display_surface, text_to_display, T_coords, text_color, back_color = None):
### this function takes in some text, and displays it on the referenced surface.
text_surface, text_rect = helper_text_objects(text_to_display, text_color, back_color)
text_rect.topleft = T_coords
display_surface.blit(text_surface, text_rect)
# _ _ _
# | | | | | |
# | |__| | ___| |_ __ ___ _ __
# | __ |/ _ \ | '_ \ / _ \ '__|
# | | | | __/ | |_) | __/ |
# |_| |_|\___|_| .__/ \___|_|
# | |
# |_|
def helper_text_objects(incoming_text, incoming_color, incoming_bg):
if incoming_bg:
Text_surface = Constants.FONT_DEBUG_MESSAGE.render(incoming_text, False, incoming_color, incoming_bg)
else:
Text_surface = Constants.FONT_DEBUG_MESSAGE.render(incoming_text, False, incoming_color)
return Text_surface, Text_surface.get_rect()
def helper_text_height():
font_object = font.render("a", False, (0, 0, 0))
font_rect = font_object.get_rect()
return font_rect.height
# _____ __ __ ______
# / ____| /\ | \/ | ____|
#| | __ / \ | \ / | |__
#| | |_ | / /\ \ | |\/| | __|
#| |__| |/ ____ \| | | | |____
# \_____/_/ \_\_| |_|______|
def game_main_loop():
game_quit = False
while not game_quit:
#player action definition
player_action = "no-action"
#handle player input
player_action = game_handle_keys()
map_calculate_fov()
if player_action == "QUIT":
game_quit = True
elif player_action != "no-action":
for obj in GAME_OBJECTS:
if obj.ai:
obj.ai.take_turn()
#Draw game
draw_game()
CLOCK.tick(Constants.GAME_FPS)
#Quit game
pygame.quit()
exit()
def game_initialize():
global SURFACE_MAIN, GAME_MAP, PLAYER, ENEMY, GAME_OBJECTS, FOV_CALCULATE, CLOCK, GAME_MESSAGES
pygame.init()
CLOCK = pygame.time.Clock()
SURFACE_MAIN = pygame.display.set_mode( (Constants.MAP_WIDTH*Constants.CELL_WIDTH,
Constants.MAP_HEIGHT*Constants.CELL_HEIGHT ) )
GAME_MAP = map_create()
GAME_MESSAGES = []
game_message("test message", Constants.COLOR_WHITE)
FOV_CALCULATE = True
creature_com1 = com_Creature("Human")
PLAYER = obj_Actor(1, 1, "Human", Constants.S_PLAYER, creature = creature_com1,)
creature_com2 = com_Creature("Thief", death_function = death_monster)
ai_com = ai_test()
ENEMY = obj_Actor(15, 15, "Bandit", Constants.S_ENEMY,
creature = creature_com2, ai = ai_com)
#Where the enemy is placed
GAME_OBJECTS = [PLAYER, ENEMY]
def game_handle_keys():
global FOV_CALCULATE
#Get player input
events_list = pygame.event.get()
# Process input
for event in events_list:
if event.type == pygame.QUIT:
return "QUIT"
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
PLAYER.creature.move(0, -1)
FOV_CALCULATE = True
return "player-moved"
if event.key == pygame.K_DOWN:
PLAYER.creature.move(0, 1)
FOV_CALCULATE = True
return "player-moved"
if event.key == pygame.K_RIGHT:
PLAYER.creature.move(1, 0)
FOV_CALCULATE = True
return "player-moved"
if event.key == pygame.K_LEFT:
PLAYER.creature.move(-1, 0)
FOV_CALCULATE = True
return "player-moved"
return "no-action"
def game_message(game_msg, msg_color):
GAME_MESSAGES.append((game_msg, msg_color))
#EXECUTION CODE
if __name__ == "__main__":
game_initialize()
game_main_loop()
最佳答案
错误说明了,函数 helper_text_height
不接受任何参数:
def helper_text_height():
...
但是你用
draw_messages
中的参数调用了它功能:
text_height = helper_text_height(Constants.FONT_MESSAGE_TEXT)
也许你想做的是在函数的定义中:
def helper_text_height():
font_object = font.render("a", False, (0, 0, 0))
font_rect = font_object.get_rect()
return font_rect.height
您想添加一个参数
font
像这样:
def helper_text_height(font):
font_object = font.render("a", False, (0, 0, 0))
font_rect = font_object.get_rect()
return font_rect.height
关于python - 我的代码中不断出现错误,无法弄清楚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62505163/
我已经使用 vue-cli 两个星期了,直到今天一切正常。我在本地建立这个项目。 https://drive.google.com/open?id=0BwGw1zyyKjW7S3RYWXRaX24tQ
您好,我正在尝试使用 python 库 pytesseract 从图像中提取文本。请找到代码: from PIL import Image from pytesseract import image_
我的错误 /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference
我已经训练了一个模型,我正在尝试使用 predict函数但它返回以下错误。 Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
根据Microsoft DataConnectors的信息我想通过 this ODBC driver 创建一个从 PowerBi 到 PostgreSQL 的连接器使用直接查询。我重用了 Micros
我已经为 SoundManagement 创建了一个包,其中有一个扩展 MediaPlayer 的类。我希望全局控制这个变量。这是我的代码: package soundmanagement; impo
我在Heroku上部署了一个应用程序。我正在使用免费服务。 我经常收到以下错误消息。 PG::Error: ERROR: out of memory 如果刷新浏览器,就可以了。但是随后,它又随机发生
我正在运行 LAMP 服务器,这个 .htaccess 给我一个 500 错误。其作用是过滤关键字并重定向到相应的域名。 Options +FollowSymLinks RewriteEngine
我有两个驱动器 A 和 B。使用 python 脚本,我在“A”驱动器中创建一些文件,并运行 powerscript,该脚本以 1 秒的间隔将驱动器 A 中的所有文件复制到驱动器 B。 我在 powe
下面的函数一直返回这个错误信息。我认为可能是 double_precision 字段类型导致了这种情况,我尝试使用 CAST,但要么不是这样,要么我没有做对...帮助? 这是错误: ERROR: i
这个问题已经有答案了: Syntax error due to using a reserved word as a table or column name in MySQL (1 个回答) 已关闭
我的数据库有这个小问题。 我创建了一个表“articoli”,其中包含商品的品牌、型号和价格。 每篇文章都由一个 id (ID_ARTICOLO)` 定义,它是一个自动递增字段。 好吧,现在当我尝试插
我是新来的。我目前正在 DeVry 在线学习中级 C++ 编程。我们正在使用 C++ Primer Plus 这本书,到目前为止我一直做得很好。我的老师最近向我们扔了一个曲线球。我目前的任务是这样的:
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的网站中有一段代码有问题;此错误仅发生在 Internet Explorer 7 中。 我没有在这里发布我所有的 HTML/CSS 标记,而是发布了网站的一个版本 here . 如您所见,我在列中有
如果尝试在 USB 设备上构建 node.js 应用程序时在我的树莓派上使用 npm 时遇到一些问题。 package.json 看起来像这样: { "name" : "node-todo",
在 Python 中,您有 None单例,在某些情况下表现得很奇怪: >>> a = None >>> type(a) >>> isinstance(a,None) Traceback (most
这是我的 build.gradle (Module:app) 文件: apply plugin: 'com.android.application' android { compileSdkV
我是 android 的新手,我的项目刚才编译和运行正常,但在我尝试实现抽屉导航后,它给了我这个错误 FAILURE: Build failed with an exception. What wen
谁能解释一下?我想我正在做一些非常愚蠢的事情,并且急切地等待着启蒙。 我得到这个输出: phpversion() == 7.2.25-1+0~20191128.32+debian8~1.gbp108
我是一名优秀的程序员,十分优秀!