diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..7d05e99 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# 依赖于环境的 Maven 主目录路径 +/mavenHomeManager.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a9182a4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1be9a07 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java-Snake-Game.iml b/Java-Snake-Game.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Java-Snake-Game.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Java-Snake-Game/com/zetcode/Board$TAdapter.class b/out/production/Java-Snake-Game/com/zetcode/Board$TAdapter.class new file mode 100644 index 0000000..663d767 Binary files /dev/null and b/out/production/Java-Snake-Game/com/zetcode/Board$TAdapter.class differ diff --git a/out/production/Java-Snake-Game/com/zetcode/Board.class b/out/production/Java-Snake-Game/com/zetcode/Board.class new file mode 100644 index 0000000..e65b796 Binary files /dev/null and b/out/production/Java-Snake-Game/com/zetcode/Board.class differ diff --git a/out/production/Java-Snake-Game/com/zetcode/Snake.class b/out/production/Java-Snake-Game/com/zetcode/Snake.class new file mode 100644 index 0000000..d1ab3ad Binary files /dev/null and b/out/production/Java-Snake-Game/com/zetcode/Snake.class differ diff --git a/out/production/Java-Snake-Game/resources/apple.png b/out/production/Java-Snake-Game/resources/apple.png new file mode 100644 index 0000000..90e70c8 Binary files /dev/null and b/out/production/Java-Snake-Game/resources/apple.png differ diff --git a/out/production/Java-Snake-Game/resources/dot.png b/out/production/Java-Snake-Game/resources/dot.png new file mode 100644 index 0000000..312a52b Binary files /dev/null and b/out/production/Java-Snake-Game/resources/dot.png differ diff --git a/out/production/Java-Snake-Game/resources/head.png b/out/production/Java-Snake-Game/resources/head.png new file mode 100644 index 0000000..41886af Binary files /dev/null and b/out/production/Java-Snake-Game/resources/head.png differ diff --git a/src/com/zetcode/Board.java b/src/com/zetcode/Board.java index e81c4e9..030e03e 100644 --- a/src/com/zetcode/Board.java +++ b/src/com/zetcode/Board.java @@ -117,12 +117,14 @@ private void doDrawing(Graphics g) { private void gameOver(Graphics g) { String msg = "Game Over"; + String restartMsg = "Press R to Restart"; Font small = new Font("Helvetica", Font.BOLD, 14); FontMetrics metr = getFontMetrics(small); g.setColor(Color.white); g.setFont(small); g.drawString(msg, (B_WIDTH - metr.stringWidth(msg)) / 2, B_HEIGHT / 2); + g.drawString(restartMsg, (B_WIDTH - metr.stringWidth(restartMsg)) / 2, (B_HEIGHT / 2) + 20); } private void checkApple() { @@ -240,6 +242,13 @@ public void keyPressed(KeyEvent e) { rightDirection = false; leftDirection = false; } + + if (key == KeyEvent.VK_R && !inGame) { + initGame(); + inGame = true; + repaint(); + } } } + }