如何从用户进行pygame打印输入:
我试图让用户键入一些东西,pygame将其打印在屏幕上.
这是我目前的计划:
import pygame, pygame.font, pygame.event, pygame.draw, string
from pygame.locals import *
def get_key():
while 1:
event = pygame.event.poll()
if event.type == KEYDOWN:
return event.key
else:
pass
def display_box(screen, message):
"Print a message in a box in the middle of the screen"
fontobject = pygame.font.Font(None,18)
pygame.draw.rect(screen, (0,0,0),
((screen.get_width() / 2) - 100,
(screen.get_height() / 2) - 10,
200,20), 0)
pygame.draw.rect(screen, (255,255,255),
((screen.get_width() / 2) - 102,
(screen.get_height() / 2) - 12,
204,24), 1)
if len(message) != 0:
screen.blit(fontobject.render(message, 1, …Run Code Online (Sandbox Code Playgroud) 我正在学习一个教程,以便在 Angular 中执行异步验证。我想要实现的是我的自定义验证器,它shouldBeUnique应该在 2 秒延迟后调用。我在其中使用setTimeout函数,但它不起作用。甚至错误消息未显示在 div 中。
这是我的自定义验证错误文件。
import { AbstractControl, ValidationErrors } from '@angular/forms';
export class UsernameValidator {
static cannotContainSpace(control: AbstractControl): ValidationErrors | null {
if ((control.value as string).indexOf(' ') >= 0 ) {
return { cannotContainSpace: true };
}
return null;
}
static shouldBeUnique(control: AbstractControl): Promise<ValidationErrors | null> {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (control.value === 'bilal') {
resolve({shouldBeUnique: true});
} else {
resolve(null);
}
}, 2000);
});
} …Run Code Online (Sandbox Code Playgroud) 我有以下表格:
table A:
FOO (PK) | CLIENT (PK)
table B:
BAR (PK) | CLIENT (PK/FK) | FOO (FK)
Run Code Online (Sandbox Code Playgroud)
PK - >主键
FK - >外键
A和B之间存在一对多关系.我不能简单地这样做:
class AMap
{
public AMap()
{
CompositeId().KeyReference(a => a.FOO)
.KeyReference(a => a.CLIENT);
HasMany(a => a.B);
}
}
class BMap
{
public BMap()
{
CompositeId().KeyReference(a => a.BAR)
.KeyReference(a => a.CLIENT);
References(a => a.A);
}
}
Run Code Online (Sandbox Code Playgroud)
它将失败,但有以下异常:
外键(FKE7804EB3DA7EBD4B:B [FOO]))必须与引用的主键具有相同的列数(A [FOO,CLIENT])
是否可以使用流畅的nhibernate正确映射?
将VB.NET列表对象设置为另一个时,我遇到了问题.在下面的例子中,我创建一个实例,ReadLocations然后创建一个对象ReadLocation,然后我循环ReadLocations并设置ReadLocation1等于rl.
会发生什么事情,如果我然后去改变ReadLocation1其他东西(assdfhsd)它也将改变ReadLocations索引.我真的很困惑为什么它会这样做,除非它是"="符号意味着引用而不是实际设置值.请帮忙,因为我是C#开发人员,但我修改的程序是在VB.NET中.
Dim ReadLocations As New List(Of Model.ReadLocation)
Dim rl1 As New Model.ReadLocation
rl1.LL = "a"
Dim rl2 As New Model.ReadLocation
rl2.LL = "b"
ReadLocations.Add(rl1)
ReadLocations.Add(rl2)
Dim ReadLocation11 As New Model.ReadLocation
For Each rl As Model.ReadLocation In ReadLocations
ReadLocation11 = rl
Next
Run Code Online (Sandbox Code Playgroud) 我试图通过一个带有返回值的简单函数简单地从我的类中获取值,我确定它是一个微不足道的错误,但我对python来说很新
我有一个简单的类设置如下:
class score():
#initialize the score info
def __init__(self):
self.score = 0
self.num_enemies = 5
self.num_lives = 3
# Score Info
def setScore(num):
self.score = num
# Enemy Info
def getEnemies():
return self.num_enemies
# Lives Info
def getLives():
return self.getLives
etc.....
Run Code Online (Sandbox Code Playgroud)
比我创建类的实例:
scoreObj = score()
for enemies in range(0, scoreObj.getEnemies):
enemy_sprite.add(enemy())
Run Code Online (Sandbox Code Playgroud)
我得到的错误是预期整数,但它有一个实例方法
获取此信息的正确方法是什么?
谢谢!
在我的测试中,我将数据定义为数据a List<IUser>.
我想设置一个moq方法GetList,这个方法接收一个boolas参数.我想回复IUser列表哪里IsValid是真的.
我试过这个:
Mock<IUsers> mockUserRepository = new Mock<IUsers>();
mockUserRepository.Setup(mr => mr.GetList(It.IsAny<bool>()))
.Returns((bool i) => _users.Select(x => x.IsValid == i));
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误: cannot convert List<bool> to List<IUser>
class User : IUser
{
public bool IsValid { get; set; }
}
interface IUser
{
bool IsValid { get; set; }
}
interface IUsers
{
List<IUser> GetList(bool isActive);
}
Run Code Online (Sandbox Code Playgroud) 在下面的示例代码中,我想要生成一个指示,表明预定义的数字列表是否与我正在循环的迭代匹配或不匹配.这是我的问题的简化示例.
不幸的是,我的代码不符合我的期望,可能我错过了一些简单的东西.在我的实际应用中,这是通过具有不同输出的极大的一维阵列来完成的,但是这以简单的文本方式展示了它,易于重现.
也许我还应该补充说我正在使用Python 2.7.5.
match = [1, 3, 4]
volumes=10
def vector_covariates(match, volumes):
for i in range(volumes):
if i == match:
print "[*]"
else:
print "[ ]"
vector_covariates(match, volumes)
Run Code Online (Sandbox Code Playgroud)
运行时,输出:
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
Run Code Online (Sandbox Code Playgroud)
而"正确"的输出应该是
[*]
[ ]
[*]
[*]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
Run Code Online (Sandbox Code Playgroud) 我正在尝试用Python创建一个比特币地址.我得到了哈希部分,但是我对Base58Check编码有些麻烦.我用这个包:
https://pypi.python.org/pypi/base58
这是一个例子:
import base58
unencoded_string = "00010966776006953D5567439E5E39F86A0D273BEED61967F6"
encoded_string = base58.b58encode(unencoded_string)
print(encoded_string)
Run Code Online (Sandbox Code Playgroud)
输出是:
bSLesHPiFV9jKNeNbUiMyZGJm45zVSB8bSdogLWCmvs88wxHjEQituLz5daEGCrHE7R7
Run Code Online (Sandbox Code Playgroud)
根据创建比特币地址的技术背景,上面的RIPEMD-160哈希值应为"16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM".也就是说,我的输出是错误的,显然太长了.有谁知道我做错了什么?
编辑:
我添加了十六进制解码(.decode("hex")):
import base58
unencoded_string = "00010966776006953D5567439E5E39F86A0D273BEED61967F6"
encoded_string = base58.b58encode(unencoded_string.decode("hex"))
print(encoded_string)
Run Code Online (Sandbox Code Playgroud)
输出现在看起来更好:
1csU3KSAQMEYLPudM8UWJVxFfptcZSDvaYY477
Run Code Online (Sandbox Code Playgroud)
然而,它仍然是错误的.它必须是字节编码吗?你是如何用Python做到的?
EDIT2:
现在修复它(感谢Arpegius).将str(bytearray.fromhex(hexstring))添加到我的代码中(在Python 2.7中):
import base58
hexstring= "00010966776006953D5567439E5E39F86A0D273BEED61967F6"
unencoded_string = str(bytearray.fromhex( hexstring ))
encoded_string= base58.b58encode(unencoded_string)
print(encoded_string)
Run Code Online (Sandbox Code Playgroud)
输出:
16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM
Run Code Online (Sandbox Code Playgroud) 我的地图功能给我输出:
([[:db/retract 1 :a 23] [:db/retract 1 :b 34]] [[:db/retract 2 :v 45] [:db/retract 2 :o 89]] [[:db/retract 4 :l 6]])
Run Code Online (Sandbox Code Playgroud)
但我想要这些像:
([[:db/retract 1 :a 23] [:db/retract 1 :b 34] [:db/retract 2 :v 45] [:db/retract 2 :o 89][:db/retract 4 :l 6]])
Run Code Online (Sandbox Code Playgroud)
我们应该如何将向量合并为单个向量?
Pygame 中是否有一个函数,每当对象与特定颜色碰撞时返回 True?
我很好奇,因为它对于在 Pygame 中制作 Paint 之类的东西非常有用。
python ×5
pygame ×2
.net ×1
angular ×1
angular6 ×1
bitcoin ×1
c# ×1
clojure ×1
iterable ×1
javascript ×1
loops ×1
mocking ×1
moq ×1
python-2.7 ×1
python-3.x ×1
typescript ×1
vb.net ×1