Skip to content

Commit

Permalink
Base code for the snake game
Browse files Browse the repository at this point in the history
  • Loading branch information
sangaryousmane committed Dec 11, 2023
1 parent 622cc4d commit 0dc8e3b
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/games/ludo/LudoGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package games.ludo;

public class LudoGame {
}
19 changes: 19 additions & 0 deletions src/games/snake/GameFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package games.snake;

import javax.swing.*;
import java.awt.*;

public class GameFrame extends JFrame {

public GameFrame() throws HeadlessException {
this.add(new GamePanel());
this.setTitle("SNAKE");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.pack();
this.setVisible(true);
this.setLocationRelativeTo(null);
}


}
65 changes: 65 additions & 0 deletions src/games/snake/GamePanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package games.snake;

import javax.swing.*;

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class GamePanel extends JPanel implements ActionListener {

private static final int SCREEN_WIDTH = 600;
private static final int SCREEN_HEIGHT = 600;
private static final int UNIT_SIZE = 25;
private static final int GAME_UNITS = (SCREEN_WIDTH * SCREEN_HEIGHT) / UNIT_SIZE;
private static final int DELAY = 75;

public GamePanel() {}

// Starts game
public void startGame(){

}

// paint the component
public void paintComponent(Graphics graphics){

}

// Draw on the screen
public void draw(Graphics graphics){

}

// Move the snake
public void move(){

}
// Eat the apple
public void checkApple(){

}

// Check for collisions
public void checkCollisions(){

}
// Game over
public void gameOver(Graphics graphics){

}
@Override
public void actionPerformed(ActionEvent e) {

}

public class MyKeyAdapter extends KeyAdapter{

@Override
public void keyPressed(KeyEvent e) {
super.keyPressed(e);
}
}
}
9 changes: 9 additions & 0 deletions src/games/snake/SnakeGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package games.snake;

public class SnakeGame {

public static void main(String[] args) {

new GameFrame();
}
}
4 changes: 4 additions & 0 deletions src/games/tictactoe/TicTacToe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package games.tictactoe;

public class TicTacToe {
}

0 comments on commit 0dc8e3b

Please sign in to comment.