java - 如果语句在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
}
}
解决方案
推荐阅读
- python - 使用python切换win 10上的“夜灯”功能
- flutter - 当我按下下载按钮时如何显示带有 CircularProgressIndicator 和下载状态的弹出窗口
- node.js - 如何在 Node.js 中获取和传递变量
- perl - GD::Graph::pie 的值的铭文
- angular - 检查字符串中是否包含一组字符串
- javascript - 未捕获的 ReferenceError:setValue 未在 HTMLDivElement.onclick 中定义
- module - Coq - 统一来自具有相同参数的模块仿函数的类型?
- autodesk-forge - 优化 Forge Design Automation 调用
- angular - 如何将多个订阅的结果转换为 Map 对象?
- python - Django模型计算字段以获取用系统日期减去给定日期的天数