首页 > 解决方案 > 如果语句在java中不起作用,drawString in

问题描述

这里有一些简单的破砖游戏代码。当玩家失去即时消息时,会出现 2 条消息。在 if 语句中,其余代码按预期工作,但没有出现 2 个字符串。任何帮助将不胜感激。

public void paint(Graphics g) {
        //background
        g.setColor(Color.black);
        g.fillRect(1, 1, 692, 592);
        //drawing map
        map.draw((Graphics2D) g);
        //borders
        g.setColor(Color.yellow);
        g.fillRect(0, 0, 3, 592);
        g.fillRect(0, 0, 692, 3);
        g.fillRect(681, 0, 3, 592);
        //scores
        g.setColor(Color.white);
        g.setFont(new Font("serif", Font.BOLD, 25)); //this shows
        g.drawString(""+score, 500,30);
        //paddle
        g.setColor(Color.green);
        g.fillRect(playerX, 550, 100, 8);
        //ball
        g.setColor(Color.yellow);
        g.fillOval(ballposX, ballposY, 20, 20);
        g.dispose();
        if(ballposY > 550) {
            play = false;
            ballXdir = 0;
            ballYdir = 0;
            g.setColor(Color.RED);
            g.setFont(new Font("serif", Font.BOLD, 30));
            g.drawString("Game Over, your score is: ", 200, 200); // this dosent

            g.setFont(new Font("serif", Font.BOLD, 20));
            g.drawString("Press Enter to Restart", 230, 250); //this dosent

        }

    }

标签: java

解决方案


推荐阅读