会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133899个问题
JAVA 全系列/第一阶段:AI驱动的JAVA编程/面向对象详解和JVM底层内存分析 18976楼

老师你帮我看下这个问题出在那

"""新增功能:
   加载我方坦克
"""
#导入prcharm模块
import pygame
SCREEN_WIDTH=700    #设置宽度
SCREEN_HEIGHT=500   #设置高度
BG_COLOR=pygame.Color(0,0,0) #设置窗口颜色,0,0,0代表黑色
TEXT_COLOR=pygame.Color(255,0,0)  #设置字体颜色,255,0,0代表红色

#主类
class MainGame():
    window=None
    my_tank=None
    def __init__(self):
        pass
    #开始游戏
    def startGame(self):
        #加载主窗口
        #初始化窗口
        pygame.display.init()
        #设置窗口的大小及显示
        MainGame.window=pygame.display.set_mode([SCREEN_WIDTH,SCREEN_HEIGHT])
        #初始化我方坦克
        MainGame.my_tank=Tank(350,250)
        #设置窗口标题
        pygame.display.set_caption("坦克大战1.03")
        while True:
            #给窗口设置填充色
            MainGame.window.fill(BG_COLOR)
            #获取事件
            self.getEvent()
            #绘制文字
            MainGame.window.blit(self.getTextSuface("敌方坦克剩余数量%d"%6),(10,10))
            #调用坦克显示的方法
            MainGame.my_tank.displayTank()
            pygame.display.update()

    #结束游戏
    def endGame(self):
        print("谢谢使用,欢迎再次使用")
        exit()
    #左上角文字的绘制
    def getTextSuface(self,text):
        #初始化文字模块
        pygame.font.init()
        #查看所有的字体名称
        #print(pygame.font.get_fonts())
        #获取字体Font对象
        font=pygame.font.SysFont("kaiti",18)
        #绘制文字信息
        textSurface=font.render(text,True,TEXT_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_LEFT:
                    print("按下左键,坦克向左移动")
                elif event.key==pygame.K_RIGHT:
                    print("按下右键,坦克向右移动")
                elif event.key==pygame.K_UP:
                    print("按下上键,坦克向上移动")
                elif event.key == pygame.K_DOWN:
                    print("按下下键,坦克向下移动")

#坦克类
class Tank():
    #添加距离左边left 距离上边top
    def __init__(self,left,top):
        #保存加载的照片
        self.images={
            "u":pygame.image.load("img/p1tanKU.gif"),
            "D":pygame.image.load("img/p1tankD.gif"),
            "L":pygame.image.load("img/p1tankL.gif"),
            "R":pygame.image.load("img/p1tankR.gif"),
        }
        #方向
        self.dirction="U"
        #根据当前图片的方向获取图片 surface
        self.image=self.images[self.dirction]
        #根据图片获取区域
        self.rect=self.image.get_rect()
        #设置区域的left 和top
        self.rect.left=left
        self.rect.top=top



    #移动
    def move(self):
        pass
    #射击
    def shot(self):
        pass
    #展示坦克方法
    def displayTank(self):
        #获取展示的对象
        self.image=self.images[self.dirction]
        #调用blit方法展示
        MainGame.window.blit(self.images,self.rect)
#我方坦克
class MyTank(Tank):
    def __init__(self):
        pass
#敌方坦克
class EnemyTank(Tank):
    def __init__(self):
        pass

#子弹类
class Bullet():
    def __init__(self):
        pass
    #移动
    def move(self):
        pass
    #展示子弹的方法:
    def displayBullet(self):
        pass

class Wall():
    def __init__(self):
        pass
    #展示墙壁的方法
    def displayWall(self):
        pass
class Explode():
    def __init__(self):
        pass
    #展示爆炸效果的方法
    def displayExplode(self):
        pass
class Music():
    def __init__(self):
        pass
    #播放音乐
    def play(self):
        pass

if __name__=="__main__":
    #MainGame().startGame()
    MainGame().getTextSuface()


Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 18977楼

src.zip老师 为什么我的飞机显示不出来

JAVA 全系列/第一阶段:AI驱动的JAVA编程/飞机大战小项目训练 18978楼

tkinter *
tkinter.filedialog *  tkinter.colorchooser * tkinter.filedialog *

Application(Frame):

    (master=):
        ().(master)  .master = master
        .textpad = .pack()
        .createWidget()

    ():
        menubar = Menu(root)

        menuFile = Menu(menubar)
        menuEdit = Menu(menubar)
        menuHelp = Menu(menubar)

        menubar.add_cascade(==menuFile)
        menubar.add_cascade(==menuEdit)
        menubar.add_cascade(==menuHelp)

        menuFile.add_command(===.test)
        menuFile.add_command(===.openfile)
        menuFile.add_command(===.savefile)

        menuFile.add_separator()  menuFile.add_command(===.test)

        root[] = menubar

        .textpad = Text(root==)
        .textpad.pack()

        .contextMenu = Menu(root)
        .contextMenu.add_command(==.openAskColor)

        root.bind(.createContextMenu)

    ():
        (askopenfilename(=)=) f:  .textpad.insert(INSERTf.read())
            .filename = f.name

    ():
        (.filename) f:
            c = .textpad.get(END)
            f.write(c)

    ():
        ():
        s1 = askcolor(==)
        root.config(=s1[])

    (event):
        .contextMenu.post(event.x_rootevent.y_root)


__name__ == :
    root = Tk()
    root.geometry()
    root.title()
    app = Application(=root)
    root.mainloop()

C:\Users\微软\AppData\Local\Programs\Python\Python37\python.exe C:/Users/微软/pycharm_execrise/pythonProject/GUI/note.py

Exception in Tkinter callback

Traceback (most recent call last):

  File "C:\Users\微软\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__

    return self.func(*args)

  File "C:/Users/微软/pycharm_execrise/pythonProject/GUI/note.py", line 61, in openfile

    self.textpad.insert(INSERT, f.read())

  File "C:\Users\微软\AppData\Local\Programs\Python\Python37\lib\codecs.py", line 322, in decode

    (result, consumed) = self._buffer_decode(data, self.errors, final)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 0: invalid start byte


Process finished with exit code 0


Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 18981楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/面向对象详解和JVM底层内存分析 18982楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/飞机大战小项目训练 18986楼

package com.bjsxt;

import java.sql.*;

public class JdbcText {
    //插入数据库信息
    public void insertdepartment(String department_name , int location_id){
        Connection conn=null;
        Statement state=null;
        try {
            conn = JdbcUilt.getConnection();
            String sql ="insert into departments values(default,'"+department_name+"',"+location_id+")";
            state = conn.createStatement();
            System.out.println(state.executeUpdate(sql));
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            JdbcUilt.closeZong(state,conn,null);
        }
    }
    //修改数据库信息
    public void Updatedepartment(String department_name , int location_id , int department_id){
        Connection conn = null;
        Statement state = null;
        try{
            conn = JdbcUilt.getConnection();
            state = conn.createStatement();
            String sql = "update departments d set d.department_name='"+department_name+"',d.location_id="+location_id+" where d.department_id="+department_id+"";
            System.out.println(state.executeUpdate(sql));
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JdbcUilt.closeZong(state , conn,null);
        }
    }
    //创建查询方法
    public void selectdepartment(int department_id){
        Connection conn = null;
        Statement state = null;
        ResultSet rs = null;
        try{
            conn = JdbcUilt.getConnection();
            state = conn.createStatement();
            String sql = "select * from departments where department_id"+department_id;
            rs = state.executeQuery(sql);
            while (rs.next()){
                System.out.println(rs.getInt("department_id")+" "+rs.getString("department_name")+" "+rs.getInt(3));
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JdbcUilt.closeZong(state , conn,rs);
        }
    }
    public static void main(String[] args) {
        JdbcText jb = new JdbcText();
        //jb.Updatedepartment("教育部",6,6);
        jb.selectdepartment(6);
    }
}
Wed Jul 28 18:04:16 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'department_id6' in 'where clause'
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.Util.getInstance(Util.java:408)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2491)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2449)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1381)
	at com.bjsxt.JdbcText.selectdepartment(JdbcText.java:45)
	at com.bjsxt.JdbcText.main(JdbcText.java:59)

请问老师我这个报错怎么解决?

JAVA 全系列/第四阶段:数据库与AI协同技术实战/JDBC技术(旧) 18989楼
JAVA 全系列/第六阶段:项目管理与SSM框架/SpringMVC 18990楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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