如何在pygame中清除窗口上的文本

2023-12-07

在我正在制作的游戏中。我正在尝试解决游戏屏幕出现的问题。

问题是当你死时它会说“你死了”然后我输入“再玩一次”或“退出”。如果您按“退出”,显然它会退出游戏,但如果您再次按“播放”,我想要它做的是重新运行程序。

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

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

    if x + w > mouse[0] > x and y + h > mouse[1] > y:
        pygame.draw.rect(screen, ac, (x, y, w, h))
        if click[0] == 1 and action != None:
            action()
    else:
        pygame.draw.rect(screen, ic, (x, y, w, h))
    smallText = pygame.font.SysFont("comicsansms", 20)
    textSurf, textRect = text_objects(msg, smallText)
    textRect.center = ((x + (w / 2)), (y + (h / 2)))
    screen.blit(textSurf, textRect)



def quitgame():
    pygame.quit()
    quit()

def dead():
    global dead
    dead = True
    
    while dead:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        largeText = pygame.font.SysFont("comicsansms", 115)
        TextSurf, TextRect = text_objects("You Died", largeText)
        TextRect.center = ((display_width / 2), (display_height / 2))
        screen.blit(TextSurf, TextRect)

        button("Play Again", 20, 450, 115, 50, green, bright_green, respawn)
        button("Quit", 250, 450, 100, 50, red, bright_red, quitgame)

        pygame.display.update()
        clock.tick(15)

对于我的重生功能。有人告诉我复制并粘贴 while true 循环中的所有内容,并将其全部放入我的重生函数中,我注意到,当您再次按下“播放”时,音乐和音效正在播放,除了游戏结束屏幕之外的所有内容都在播放。还在玩

如果您需要它,这里是重生函数的代码

def respawn():
    global dead
    global run
    global velotimeser 
    global timeForLevel 
    global font 
    global man 
    global zombie 
    global zombie1 

    global randomside 
    global gunCapacity 
    global points
    global powerMeter 
    global bullets 
    global intro 
    dead = False
    velotimeser = 1
    timeForLevel = 0
    font = pygame.font.SysFont('comicsans', 30, True)
    man = Player(300, 508, 64, 64)
    zombie = Enemy(100, 508, 64, 64, 450)
    zombie1 = Enemy1(100, 508, 64, 64, 450)

    randomside = 0
    gunCapacity = 1
    points = 0
    powerMeter = 0
    bullets = []
    intro = False

    pygame.mixer.music.play(-1)

    run = True
    while run and dead == False:

        clock.tick(27)
        #this is the hitbox for when the zombie collides with the player and the player hasnt shot a bullet or has launched a punch that it should deduct a peice of health and 5 points and move the player back depending on where the zombie is facing


        timeForLevel += 0.05
        
        
        


        if man.hitbox[1] < zombie.hitbox[1] + zombie.hitbox[3] and man.hitbox[1] + man.hitbox[3] > zombie.hitbox[1]:
            if man.hitbox[0] + man.hitbox[2] > zombie.hitbox[0] and man.hitbox[0] < zombie.hitbox[0] + zombie.hitbox[2] and man.punchislaunched == False and zombie.visible == True and zombie.velo > 0 and man.x > zombie.x:
                man.x += 15
                pygame.time.delay(10)
                points -= 5
                man.hit()

        if man.hitbox[1] < zombie.hitbox[1] + zombie.hitbox[3] and man.hitbox[1] + man.hitbox[3] > zombie.hitbox[1]:
            if man.hitbox[0] + man.hitbox[2] > zombie.hitbox[0] and man.hitbox[0] < zombie.hitbox[0] + zombie.hitbox[2] and man.punchislaunched == False and zombie.visible == True and zombie.velo > 0 and man.x < zombie.x:
                man.x -= 15
                pygame.time.delay(10)
                points -= 5
                man.hit()

        if man.hitbox[1] < zombie.hitbox[1] + zombie.hitbox[3] and man.hitbox[1] + man.hitbox[3] > zombie.hitbox[1]:
            if man.hitbox[0] + man.hitbox[2] > zombie.hitbox[0] and man.hitbox[0] < zombie.hitbox[0] + zombie.hitbox[2] and man.punchislaunched == False and zombie.visible == True and zombie.velo < 0 and man.x <= zombie.x:
                man.x -= 15
                pygame.time.delay(10)
                points -= 5
                man.hit()

        if man.hitbox[1] < zombie.hitbox[1] + zombie.hitbox[3] and man.hitbox[1] + man.hitbox[3] > zombie.hitbox[1]:
            if man.hitbox[0] + man.hitbox[2] > zombie.hitbox[0] and man.hitbox[0] < zombie.hitbox[0] + zombie.hitbox[2] and man.punchislaunched == False and zombie.visible == True and zombie.velo < 0 and man.x > zombie.x:
                man.x += 15
                pygame.time.delay(10)
                points -= 5
                man.hit()

        

        #this hitbox detects if the player is touching the zombie whilst punching it
        if man.hitbox[1] < zombie.hitbox[1] + zombie.hitbox[3] and man.hitbox[1] + man.hitbox[3] > zombie.hitbox[1]:
            if man.hitbox[0] + man.hitbox[2] > zombie.hitbox[0] and man.hitbox[0] < zombie.hitbox[0] + zombie.hitbox[2] and man.punchislaunched == True and zombie.visible == True:
                if zombie.velo < 0 and zombie.x < man.x:
                    zombie.x = zombie.x - 15
                    zombie.hit()
                    points += 5
                if zombie.velo < 0 and zombie.x > man.x:
                    zombie.x = zombie.x + 15
                    zombie.hit()
                    points += 5
                if zombie.velo > 0 and zombie.x > man.x:
                    zombie.x = zombie.x + 15
                    zombie.hit()
                    points += 5
                if zombie.velo > 0 and zombie.x < man.x:
                    zombie.x = zombie.x - 15
                    zombie.hit()
                    points += 5

        #this is the hitbox for when the zombie collides with the player and the player hasnt shot a bullet or has launched a punch that it should deduct a peice of health and 5 points and move the player back depending on where the zombie is facing
        if man.hitbox[1] < zombie1.hitbox[1] + zombie1.hitbox[3] and man.hitbox[1] + man.hitbox[3] > zombie1.hitbox[1]:
            if man.hitbox[0] + man.hitbox[2] > zombie1.hitbox[0] and man.hitbox[0] < zombie1.hitbox[0] + zombie1.hitbox[2] and man.punchislaunched == False and zombie1.visible == True and zombie.velo > 0 and man.x > zombie1.x:
                man.x += 15
                pygame.time.delay(10)
                points -= 5
                man.hit()

        if man.hitbox[1] < zombie1.hitbox[1] + zombie1.hitbox[3] and man.hitbox[1] + man.hitbox[3] > zombie1.hitbox[1]:
            if man.hitbox[0] + man.hitbox[2] > zombie1.hitbox[0] and man.hitbox[0] < zombie1.hitbox[0] + zombie1.hitbox[2] and man.punchislaunched == False and zombie1.visible == True and zombie.velo > 0 and man.x < zombie1.x:
                man.x += 15
                pygame.time.delay(10)
                points -= 5
                man.hit()
                
        #same thing here expet its for when the zombie is facing left       
        if man.hitbox[1] < zombie1.hitbox[1] + zombie1.hitbox[3] and man.hitbox[1] + man.hitbox[3] > zombie1.hitbox[1]:
            if man.hitbox[0] + man.hitbox[2] > zombie1.hitbox[0] and man.hitbox[0] < zombie1.hitbox[0] + zombie1.hitbox[2] and man.punchislaunched == False and zombie1.visible == True and zombie1.velo < 0 and man.x < zombie1.x:
                man.x -= 15
                pygame.time.delay(10)
                points -= 5
                man.hit()

        if man.hitbox[1] < zombie1.hitbox[1] + zombie1.hitbox[3] and man.hitbox[1] + man.hitbox[3] > zombie1.hitbox[1]:
            if man.hitbox[0] + man.hitbox[2] > zombie1.hitbox[0] and man.hitbox[0] < zombie1.hitbox[0] + zombie1.hitbox[2] and man.punchislaunched == False and zombie1.visible == True and zombie1.velo < 0 and man.x > zombie1.x:
                man.x -= 15
                pygame.time.delay(10)
                points -= 5
                man.hit()

        #this hitbox detects if the player is touching the zombie whilst punching it
        if man.hitbox[1] < zombie1.hitbox[1] + zombie1.hitbox[3] and man.hitbox[1] + man.hitbox[3] > zombie1.hitbox[1]:
            if man.hitbox[0] + man.hitbox[2] > zombie1.hitbox[0] and man.hitbox[0] < zombie1.hitbox[0] + zombie1.hitbox[2] and man.punchislaunched == True and zombie1.visible == True:
                    if zombie1.velo < 0 and zombie1.x < man.x:
                        zombie1.x = zombie1.x - 15
                        zombie1.hit()
                        points += 1
                    if zombie1.velo < 0 and zombie1.x > man.x:
                        zombie1.x = zombie1.x + 15
                        zombie1.hit()
                        points += 1
                    if zombie1.velo > 0 and zombie1.x > man.x:
                        zombie1.x = zombie1.x + 15
                        zombie1.hit()
                        points += 1
                    if zombie1.velo > 0 and zombie1.x < man.x:
                        zombie1.x = zombie1.x - 15
                        zombie1.hit()
                        points += 1
                        

        #this tels it to shoot one bullet at a time instead of sending a group of bullets to the zombie
        if gunCapacity > 0:
            gunCapacity += 1
        if gunCapacity> 10:
            gunCapacity = 0

        #this tels it to close the programe if you press the big red cross at the top right
        for event in pygame.event.get():


            if event.type == pygame.QUIT:
                run = False
           
        #this sets the collision for when the zombie  touches the bullet
        for bullet in bullets:
            if bullet.y - bullet.radius < zombie.hitbox[1] + zombie.hitbox[3] and bullet.y + bullet.radius > zombie.hitbox[1]:
                if bullet.x + bullet.radius > zombie.hitbox[0] and bullet.x - bullet.radius < zombie.hitbox[0] + zombie.hitbox[2] and zombie.visible == True:
                    if zombie.velo < 0 and zombie.x < man.x:
                        zombie.x = zombie.x - 15
                        zombie.hit()
                        points += 1
                        bullets.pop(bullets.index(bullet))
                    if zombie.velo < 0 and zombie.x > man.x:
                        zombie.x = zombie.x + 15
                        zombie.hit()
                        points += 1
                        bullets.pop(bullets.index(bullet))
                    if zombie.velo > 0 and zombie.x > man.x:
                        zombie.x = zombie.x + 15
                        zombie.hit()
                        points += 1
                        bullets.pop(bullets.index(bullet))
                    if zombie.velo > 0 and zombie.x < man.x:
                        zombie.x = zombie.x - 15
                        zombie.hit()
                        points += 1
                        bullets.pop(bullets.index(bullet))

                    
                    
                        

            #this tells the bullet to delete itself if it touches the the end of the screen
            if bullet.x < 600 and bullet.x > 0:
                bullet.x += bullet.velo
            else:
                bullets.pop(bullets.index(bullet))

        
        #this sets the collision for when the zombie  touches the bullet
        for bullet in bullets:
            if bullet.y - bullet.radius < zombie1.hitbox[1] + zombie1.hitbox[3] and bullet.y + bullet.radius > zombie1.hitbox[1]:
                if bullet.x + bullet.radius > zombie1.hitbox[0] and bullet.x - bullet.radius < zombie1.hitbox[0] + zombie1.hitbox[2] and zombie1.visible == True:
                    if zombie1.velo < 0 and zombie1.x < man.x:
                        zombie1.x = zombie1.x - 15
                        zombie1.hit()
                        points += 1
                        bullets.pop(bullets.index(bullet))
                    if zombie1.velo < 0 and zombie1.x > man.x:
                        zombie1.x = zombie1.x + 15
                        zombie1.hit()
                        points += 1
                        bullets.pop(bullets.index(bullet))
                    if zombie1.velo > 0 and zombie1.x > man.x:
                        zombie1.x = zombie1.x + 15
                        zombie1.hit()
                        points += 1
                        bullets.pop(bullets.index(bullet))
                    if zombie1.velo > 0 and zombie1.x < man.x:
                        zombie1.x = zombie1.x - 15
                        zombie1.hit()
                        points += 1
                        bullets.pop(bullets.index(bullet))
            #this tells the bullet to delete itself if it touches the the end of the screen
            if bullet.x < 600 and bullet.x > 0:
                bullet.x += bullet.velo
            else:
                bullets.pop(bullets.index(bullet))

        
        if timeForLevel > 20:
            velotimeser = 1.0002
            zombie.velo = zombie.velo * velotimeser
            zombie1.velo = zombie1.velo * velotimeser


        

        keys = pygame.key.get_pressed()

        #these are the keaboard bings for all the functions
        if keys[pygame.K_LEFT] and man.x > man.velo:
            man.x -= man.velo
            man.right = False
            man.left = True
            man.Idlecount = 0
            man.guncount = 0
            man.gunisfired = False
            man.standing = False
        elif keys[pygame.K_RIGHT] and man.x < 600 - man.width - man.velo:
            man.x += man.velo
            man.right = True
            man.left = False
            man.Idlecount = 0
            man.guncount = 0
            man.gunisfired = False
            man.standing = False
        elif keys[pygame.K_SPACE]:
            man.gunisfired = True
            man.isIdle = False
            man.standing = True
            man.Idlecount = 0
            man.punchislaunched = False
            man.walkcount = 0
        
        elif keys[pygame.K_x]:
            man.gunisfired = False
            man.isIdle = False
            man.standing = True
            man.Idlecount = 0
            man.guncount = 0
            man.punchislaunched = True
        else:
            man.walkcount = 0
            man.isIdle = True
            man.guncount = 0
            man.gunisfired = False
            man.standing = True
            man.punchislaunched = False
            man.punchcount = 0
        if keys[pygame.K_SPACE] and gunCapacity == 0:
            
            if man.left:
                facing = -1
            else:
                facing = 1
            if len(bullets) < 5:
                bullets.append(Projectile(round(man.x + man.width //2), round(man.y + man.height//2), 6, (0,0,0), facing))
                bulletSound.play()
            gunCapacity = 1

        #this tells the zombie to respawn when it is dead
        if zombie.visible == False:
            randomside = random.randint(1,4)
            if randomside == 1:
                zombie.x = 20
            if randomside ==2:
                zombie.x = 580
            if randomside ==3:
                zombie.x = 580
                zombie1.x = 520
                zombie1.visible = True
                zombie1.health = 10
                zombie1.draw(screen)
            if randomside == 4:
                zombie.x = 20
                zombie1.x = 80
                zombie1.visible = True
                zombie1.health = 10
                zombie1.draw(screen)

            zombie.visible = True
            zombie.health = 10
            zombie.draw(screen)
        print(randomside)

 

    
    
       
    redrawGameWindow()
    Timetext = font.render('Time elapsed:' + str(round(timeForLevel,1)), 1, (255,251,0))
    screen.blit(Timetext, (20, 10))
    

    pygame.display.update()

如果这是足够的代码来显示检查我的Git hub

可以得到解释这是如何发生的或者我如何解决它


谢谢你们的提示,正如你们所说,我应该将变量设置为原始条件。像这样

def respawn():
    global dead
    global run
    global velotimeser 
    global timeForLevel 
    global font 
    global man 
    global zombie 
    global zombie1 

    global randomside 
    global gunCapacity 
    global points
    global powerMeter 
    global bullets 
    global intro 
    dead = False
    velotimeser = 1
    timeForLevel = 0
    font = pygame.font.SysFont('comicsans', 30, True)
    man = Player(300, 508, 64, 64)
    zombie = Enemy(100, 508, 64, 64, 450)
    zombie1 = Enemy1(100, 508, 64, 64, 450)

    randomside = 0
    gunCapacity = 1
    points = 0
    powerMeter = 0
    bullets = []
    intro = False

    pygame.mixer.music.play(-1)

    run = True
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在pygame中清除窗口上的文本 的相关文章

  • Django 的内联管理:一个“预填充”字段

    我正在开发我的第一个 Django 项目 我希望用户能够在管理中创建自定义表单 并向其中添加字段当他或她需要它们时 为此 我在我的项目中添加了一个可重用的应用程序 可在 github 上找到 https github com stephen
  • 如何用python脚本控制TP LINK路由器

    我想知道是否有一个工具可以让我连接到路由器并关闭它 然后从 python 脚本重新启动它 我知道如果我写 import os os system ssh l root 192 168 2 1 我可以通过 python 连接到我的路由器 但是
  • 删除flask中的一对一关系

    我目前正在使用 Flask 开发一个应用程序 并且在删除一对一关系中的项目时遇到了一个大问题 我的模型中有以下结构 class User db Model tablename user user id db Column db String
  • 使用 kivy textinput 的 'input_type' 属性的问题

    您好 我在使用 kivy 的文本输入小部件的 input type 属性时遇到问题 问题是我制作了两个自定义文本输入 其中一个称为 StrText 其中设置了 input type text 然后是第二个文本输入 名为 NumText 其
  • Pandas Merge (pd.merge) 如何设置索引和连接

    我有两个 pandas 数据框 dfLeft 和 dfRight 以日期作为索引 dfLeft cusip factorL date 2012 01 03 XXXX 4 5 2012 01 03 YYYY 6 2 2012 01 04 XX
  • 如何在 Python 中解析和比较 ISO 8601 持续时间? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在寻找一个 Python v2 库 它允许我解析和比较 ISO 8601 持续时间may处于不同单
  • 为什么 PyYAML 花费这么多时间来解析 YAML 文件?

    我正在解析一个大约 6500 行的 YAML 文件 格式如下 foo1 bar1 blah name john age 123 metadata whatever1 whatever whatever2 whatever stuff thi
  • Python 2:SMTPServerDisconnected:连接意外关闭

    我在用 Python 发送电子邮件时遇到一个小问题 me my email address you recipient s email address me email protected cdn cgi l email protectio
  • 如何使用python在一个文件中写入多行

    如果我知道要写多少行 我就知道如何将多行写入一个文件 但是 当我想写多行时 问题就出现了 但是 我不知道它们会是多少 我正在开发一个应用程序 它从网站上抓取并将结果的链接存储在文本文件中 但是 我们不知道它会回复多少行 我的代码现在如下 r
  • 在 Sphinx 文档中*仅*显示文档字符串?

    Sphinx有一个功能叫做automethod从方法的文档字符串中提取文档并将其嵌入到文档中 但它不仅嵌入了文档字符串 还嵌入了方法签名 名称 参数 我如何嵌入only文档字符串 不包括方法签名 ref http www sphinx do
  • 如何使用 pybrain 黑盒优化训练神经网络来处理监督数据集?

    我玩了一下 pybrain 了解如何生成具有自定义架构的神经网络 并使用反向传播算法将它们训练为监督数据集 然而 我对优化算法以及任务 学习代理和环境的概念感到困惑 例如 我将如何实现一个神经网络 例如 1 以使用 pybrain 遗传算法
  • pyspark 将 twitter json 流式传输到 DF

    我正在从事集成工作spark streaming with twitter using pythonAPI 我看到的大多数示例或代码片段和博客是他们从Twitter JSON文件进行最终处理 但根据我的用例 我需要所有字段twitter J
  • Cython 和类的构造函数

    我对 Cython 使用默认构造函数有疑问 我的 C 类 Node 如下 Node h class Node public Node std cerr lt lt calling no arg constructor lt lt std e
  • Python3 在 DirectX 游戏中移动鼠标

    我正在尝试构建一个在 DirectX 游戏中执行一些操作的脚本 除了移动鼠标之外 我一切都正常 是否有任何可用的模块可以移动鼠标 适用于 Windows python 3 Thanks I used pynput https pypi or
  • 仅第一个加载的 Django 站点有效

    我最近向 stackoverflow 提交了一个问题 标题为使用mod wsgi在apache上多次请求后Django无限加载 https stackoverflow com questions 71705909 django infini
  • 如何断言 Unittest 上的可迭代对象不为空?

    向服务提交查询后 我会收到一本字典或一个列表 我想确保它不为空 我使用Python 2 7 我很惊讶没有任何assertEmpty方法为unittest TestCase类实例 现有的替代方案看起来并不正确 self assertTrue
  • Python:XML 内所有标签名称中的字符串替换(将连字符替换为下划线)

    我有一个格式不太好的 XML 标签名称内有连字符 我想用下划线替换它 以便能够与 lxml objectify 一起使用 我想替换所有标签名称 包括嵌套的子标签 示例 XML
  • 在本地网络上运行 Bokeh 服务器

    我有一个简单的 Bokeh 应用程序 名为app py如下 contents of app py from bokeh client import push session from bokeh embed import server do
  • 使用for循环时如何获取前一个元素? [复制]

    这个问题在这里已经有答案了 可能的重复 Python 循环内的上一个和下一个值 https stackoverflow com questions 1011938 python previous and next values inside
  • Scipy Sparse:SciPy/NumPy 更新后出现奇异矩阵警告

    我的问题是由大型电阻器系统的节点分析产生的 我基本上是在设置一个大的稀疏矩阵A 我的解向量b 我正在尝试求解线性方程A x b 为了做到这一点 我正在使用scipy sparse linalg spsolve method 直到最近 一切都

随机推荐

  • 将包含列表的 pandas 列“unstack”成多行[重复]

    这个问题在这里已经有答案了 假设我有以下 Pandas 数据框 df pd DataFrame a 1 2 3 b 1 2 2 3 4 5 a b 0 1 1 2 1 2 2 3 4 2 3 5 我如何 取消堆叠 b 列中的列表以便将其转换
  • WCF:使用 WsHttpBinding 是否可以互操作?

    顾名思义 现在我正在使用 BasicHttpBinding 但我想知道是否可以切换到 WSHttpBinding 并且仍然可以与 Java 等设备进行互操作 wsHttpBinding 和较新的 ws2007HttpBinding 都实现
  • r for 回归循环 lm(y~x)

    Example df lt data frame A 1 5 B 2 6 C 3 7 D 4 8 E 5 9 F 6 10 我想使用像 y 一样的列 1 和 2 以及像 x 一样的其余列来制作回归循环 lm y x my idea lmf
  • 将动态生成的列表中的数据从一个页面传递到另一页面

    在我的 jquery 移动应用程序中 我有一个动态生成的列表视图 我想要做的是当用户单击列表项时 我想从列表项中的隐藏字段获取一个值并将该值传递到另一个页面 以便我可以根据该变量值进行查询 这是多页布局 由于我与第一页位于同一 DOM 中
  • 如何在android中制作通话记录应用程序

    我是一名 android 新手程序员 我想制作一个 android 应用程序来记录电话活动 例如来电 去电或未接来电 并将日志记录到文件 txt 我应该怎么办 请帮我 看一眼通话记录 通话 以下是一些有关使用通话记录的好教程 android
  • 当 JSONP 和 CORS 等解决方法存在时,为什么浏览器有同源策略?

    这个问题有点重复 为什么 XMLHttpRequest 的同源策略 然而 这个答案并不令人满意 因为它没有解决存在解决方法的事实 如问题中所述 答案仅解决与 XMLHttpRequest 直接相关的安全问题 但 JSONP 仍然存在这些问题
  • jquery 一对一切换多个div

    我想做的是在不同的 div 之间切换 这有点难以解释 但我会尝试一下 当页面加载时 将有一个可见的 div 和 4 个带有 display none 的 div 会有一个菜单 链接 1 将显示第一个 div 并隐藏所有其他 div 然后 当
  • Swift 中按属性对类或结构数组进行排序的通用函数

    我想创建一个通用函数来根据传递的属性对类数组进行排序 例如 我有这些课程 public class Car var id Int var manufacturer String var variant String init id Int
  • JPA、SQlite没有这样的表:SEQUENCE

    我对 JPA 和 SQlite 有疑问 我已经从表创建了一个实体 我生成的实体如下所示 Entity Table name sqliteTestTable public class Test implements Serializable
  • 相同代码中的行为不一致

    运行物理模拟大约 20 分钟后会出现错误陷阱 意识到这对于调试来说是一件痛苦的事情 我在一个新项目中复制了相关的子例程 并在错误发生时使用原始输入数据的硬编码副本来调用它 但错误陷阱并没有跳出来 经过两天繁琐的工作来隔离子例程的两个实例的行
  • 将文本从 Firefox WebExtension 中的后台脚本复制到剪贴板

    我正在将 Chrome 扩展程序移植到 Firefox 它具有粘贴到剪贴板的功能 但是 我还没有在 Firefox 中做到这一点 这是我在后台脚本中尝试执行的操作 const input document createElement tex
  • 为什么我的序言规则陷入无限递归

    我的代码可以达到其预期目的 但最后总是陷入循环 给出错误消息 超出堆栈限制 我的代码如下 byCar auckland hamilton byCar hamilton raglan byCar valmont saarbruecken by
  • Javascript 脚本在表单输入中查找乱码

    我需要一个脚本或正则表达式 我将使用 Javascript jQuery 来检查网站上的表单输入 来检查是否有人输入了大部分是乱码的单词 正常的单词或句子应该通过测试 This is a normal sentence pass Peter
  • 非详尽的模式匹配只是因为我省略了“否则=”? [复制]

    这个问题在这里已经有答案了 我用 Haskell 写了一个简单的程序来播放 The Rust 编程语言 一书中描述的猜谜游戏 它的工作原理如下 程序将生成一个 1 到 100 之间的随机整数 然后它会提示玩家输入猜测值 输入猜测后 会显示猜
  • 浏览器窗口之间是否可以进行基于事件的通信? [复制]

    这个问题在这里已经有答案了 是否可以有基于事件的浏览器选项卡 窗口之间的通信 我知道 至少理论上 可以使用本地存储 您能否提供执行此操作的代码的小示例 只需在一个选项卡中发送事件 然后在另一个选项卡中接收事件 有没有库 jquery 插件可
  • ActionController::未知格式

    在我的 Rails 应用程序中 我有一个向服务器发出的 ajax 请求 用于存储一些数据 这曾经工作没有任何问题 但现在我收到一个错误 ActionController UnknownFormat ActionController Unkn
  • Android RemoteViews ListView 滚动

    我正在尝试滚动ListView到某个特定位置AppWidget 然而它没有做任何事情 我也尝试过设置位置方法但不起作用 也没有错误或堆栈跟踪 Code if list size 0 loadLayout R layout rooster w
  • 从类unix系统获取唯一的id

    我想从任何类 Unix 系统 如果可能的话 获得一个唯一的 id 每次我的应用程序在同一台机器上运行时该 id 都会保持不变 如果可能的话 我想从Linux或FreeBSD或Solaris等获得相同的id 我不想为每台机器生成一个新的id
  • 使用 RxSwift 实现简单的可观察结构?

    我试图在 Swift 中提出一个简单的可观察对象并考虑使用RxSwift 我找不到一个简单的例子来做这样的事情 protocol PropertyObservable typealias PropertyType var propertyC
  • 如何在pygame中清除窗口上的文本

    在我正在制作的游戏中 我正在尝试解决游戏屏幕出现的问题 问题是当你死时它会说 你死了 然后我输入 再玩一次 或 退出 如果您按 退出 显然它会退出游戏 但如果您再次按 播放 我想要它做的是重新运行程序 def text objects te