我正在编写一个程序,在一段时间(比如半小时)网络流量低于某个阈值时关闭计算机.
这是我工作的伪代码将给出正确的逻辑:
BEGIN SUBPROGRAM
loopFlag = True
Wait 5 minutes # Allows time for boot and for the machine to settle
traffic = 0
WHILE loopFlag = True DO
FOR sec = 0 to 3600
traffic += *network.traffic()*
wait 1 second
ENDFOR
IF traffic < trafficThreshold THEN
loopFlag = False
ENDIF
ENDWHILE
os.ShutDown()
END SUBPROGRAM
Run Code Online (Sandbox Code Playgroud)
我正在寻找的是允许我测量它的Python模块或库.
虽然我已经对此进行了 各种 研究,但这些似乎并不是我所追求的那种功能,无论他们的语言如何.
有关如何实现这一点的任何想法?
我正在制作一个游戏,其中球在一个更大的圆圈内部反弹.较大的圆圈不会移动.
这是我目前用于这些冲突的代码:
def collideCircle(circle, ball):
"""Check for collision between a ball and a circle"""
dx = circle.x - ball.x
dy = circle.y - ball.y
distance = math.hypot(dx, dy)
if distance >= circle.size + ball.size:
# We don't need to change anything about the circle, just the ball
tangent = math.atan2(dy, dx)
ball.angle = 2 * tangent - ball.angle
ball.speed *= elasticity + 0.251
angle = 0.5 * math.pi + tangent
ball.x -= math.sin(angle)
ball.y += math.cos(angle) …Run Code Online (Sandbox Code Playgroud) 我正在使用Python和PyGame编写游戏.(这是在作业中进行的,因此建议另一个具有内置级别解析的游戏开发库是没有用的)
我现在处于游戏物理等完成的阶段,但我还没有找到一种方法来保存和加载游戏中的关卡.以下是我到目前为止所考虑的内容:
所有我正在寻找的是实现这一目标的最佳方法的建议.
TL; DR - 将文件中的游戏关卡解析为Python/PyGame的最佳方法.