会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133408个问题
JAVA 全系列/第十二阶段:消息中间件(异步消息传递)/ActiveMQ 38236楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 38240楼

 MainGame.window.blit(self.Textsurface('敌方坦克剩余数量%d'%6) ,(10 ,10))

AttributeError: 'NoneType' object has no attribute 'blit'

老师我想显示左上角信息,报了这样一个错,琢磨不明白

# !/user/bin/env python3
# -*- coding: utf-8 -*-

import pygame
TEXTCOLOR=pygame.Color(255,0,0)
BG_COLOR=pygame.Color(255,0,0)
# 创建主类
class MainGame():
    window = None
    def __init__(self):
        pass
    # 开始方法
    def startGame(self):
        # 初始化窗口
        pygame.display.init()
        screen_width = 700
        screen_height = 400
        screen = pygame.display.set_mode([screen_width, screen_height])
        pygame.display.set_caption('坦克大战 1.0')
        while True:
            self.getEvent()
            MainGame.window.blit(self.Textsurface('敌方坦克剩余数量%d'%6),(10,10))
            pygame.display.update()

        # 结束方法
    def endGame(self):
        print('谢谢使用,欢迎下次使用!')
        exit()
    # 左上角文字的绘制
    def Textsurface(self, text):
        pygame.font.init()
        pygame.font.SysFont('kaiti', 18)
        # 绘制文字信息
        textSurface=font.render(text, True, BG_COLOR)
        return textSurface
    # 获取事件
    def getEvent(self):
        eventList = pygame.event.get()
        for event in eventList:
            # 监听事件类型
            if event.type == pygame.QUIT:
                self.endGame()
            # 判断事件类型是否是按下
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_d:
                    print('按下D键,坦克向右移动')
                elif event.key == pygame.K_a:
                    print('按下A键,坦克向左移动')
                elif event.key == pygame.K_w:
                    print('按下W键,坦克向上移动')
                elif event.key == pygame.K_s:
                    print('按下S键,坦克向下移动')
                elif event.key == pygame.K_SPACE:
                    print('坦克发射子弹')





if __name__ == '__main__':
    MainGame().startGame()


Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 38242楼
JAVA 全系列/第十九阶段:亿级高并发电商项目/亿级高并发电商项目(旧) 38244楼

parent.rar


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoServiceImpl': Injection of @Reference dependencies is failed; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.bjsxt.dubbo.service.DemoDubboService. No provider available for the service com.bjsxt.dubbo.service.DemoDubboService from the url zookeeper://192.168.59.128:2181/org.apache.dubbo.registry.RegistryService?application=myConsumer&dubbo=2.0.2&init=false&interface=com.bjsxt.dubbo.service.DemoDubboService&methods=showMsg&pid=13112&register.ip=192.168.59.1&release=2.7.6&revision=1.0-SNAPSHOT&side=consumer&sticky=false&timestamp=1623310222200 to the consumer 192.168.59.1 use dubbo version 2.7.6

image.png

image.png

JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Dubbo 38245楼
JAVA 全系列/第四阶段:数据库与AI协同技术实战/SQL 语言 38247楼

老师好,我在用数组做动态规划算法题时,遇到个问题:


问题是爬楼梯的算法问题:

https://leetcode-cn.com/problems/climbing-stairs/



代码如下:


class Solution {
    public int climbStairs(int n) {
        if(n<=0) return 0;
        if(n==1) return 1;
        if(n==2) return 2;
        int[] dp = new int[n];
        dp[1]=1;
        dp[2]=2;
        for(int i=3;i<=n;i++){
            dp[i]=dp[i-1]+dp[i-2];
        }
        return dp[n];
        
    }
}



我的问题在第六行,在初始化数组时,因为for循环i到n就截止了,因此dp的最后条件是:

dp[n]=dp[n-1]+dp[n-2];


因此第六行创建初始化数组,我认为数组长度为n就够了,但是这里会出现 out of bounds的超出边界问题。


这里应该是初始化一个n+1 长度的数组,但是这里我不懂为什么会超出边界呢?谢谢


JAVA 全系列/第一阶段:AI驱动的JAVA编程/数组和数据存储 38249楼
JAVA 全系列/第六阶段:JavaWeb开发/Servlet技术详解 38250楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637