diff --git a/src/com/zetcode/Snake.java b/src/com/zetcode/Snake.java index 52040ff..9d25144 100644 --- a/src/com/zetcode/Snake.java +++ b/src/com/zetcode/Snake.java @@ -13,7 +13,13 @@ public Snake() { private void initUI() { add(new Board()); - + // Create the Help button + JButton helpButton = new JButton("Help"); + helpButton.addActionListener(e -> showHelpDialog()); + + // Add the Help button to the bottom of the frame + add(helpButton, BorderLayout.SOUTH); + setResizable(false); pack(); @@ -22,6 +28,24 @@ private void initUI() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } + private void showHelpDialog() { + String message = """ + Welcome to Snake! + + How to Play: + - Use the arrow keys to move the snake. + - Eat the food to grow your snake and earn points. + - Avoid running into walls or yourself. + + Objective: + - Keep growing and achieve the highest score possible! + + Enjoy the game! + """; + JOptionPane.showMessageDialog(this, message, "How to Play", JOptionPane.INFORMATION_MESSAGE); + } + + public static void main(String[] args) {