Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/com/zetcode/Snake.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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) {

Expand Down