LJ POLYTECHNIC
A MINI PROJECT REPORT
ON
JAVA PROGRAMMING- SNAKE AND DOTS
GAME
(2024 - 2025)
JAVA-PROGRAMMING
Submitted by:
Sr. # Enrollment # Student Name
1 23012250410149 Vidhisha Mistry
2 23012250410147 Priyank Mistry
3 23012250410148 Priyansh Mistry
4 23012250410196 Parshva Kothari
5 23012250410162 Rushank Nanda
6 23012250410153 Shivam Modi
7 23012250410100 Krunal Nimje
AIM : Develop a Java Snake and Dots Game.
DESCRIPTION:
The Custom Clock is a responsive web application designed to display the current time in
both analog and digital formats with live updates every second. It provides users with an
interactive and visually appealing way to track time while offering modern features such as
global time zones and a theme toggle option between light mode and dark mode.
This project aims to deliver a user-friendly, minimal, and elegant clock interface that is
accessible across all devices due to its responsive design.
Requirements
The clock must display the current time and update every second.
A toggle button should allow switching between light and dark themes.
The layout must be responsive, adapting seamlessly to desktop, tablet, and mobile
devices.
Features
1. Digital Clock – Shows the time in numerical format with hours, minutes, and seconds.
2. Analog Clock – Displays a real-time analog clock with smooth hand movement.
3. Global Time Zones – Allows users to view the current time in different
countries/cities.
4. Theme Toggle – Switch easily between light theme for daytime use and dark theme
for nighttime comfort.
5. Responsive Layout – Works across all devices, ensuring proper alignment and
usability.
6. Beautiful Design – A clean, modern, and visually appealing UI with smooth
transitions and animations.
7. Live Updates – Clock updates automatically every second without requiring refresh.
Purpose
The purpose of this project is to provide a functional yet aesthetic clock system that can
be used as a personal timekeeping tool, embedded in websites, or as a learning project to
understand JavaScript, CSS, and responsive design techniques.
SOURCE CODE :
SNAKE GAME
public class SnakeGame {
public static void main(String[] args) {
new GameFrame();
}
}
GAME PANEL
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
public class GamePanel extends JPanel implements ActionListener {
static final int SCREEN_WIDTH = 1300;
static final int SCREEN_HEIGHT = 750;
static final int UNIT_SIZE = 50;
static final int GAME_UNITS =
(SCREEN_WIDTH*SCREEN_HEIGHT)/(UNIT_SIZE*UNIT_SIZE);
static final int DELAY = 175;
final int x[] = new int[GAME_UNITS];
final int y[] = new int[GAME_UNITS];
int bodyParts = 6;
int applesEaten;
int appleX;
int appleY;
char direction = 'R';
boolean running = false;
Timer timer;
Random random;
GamePanel() {
random = new Random();
[Link](new Dimension(SCREEN_WIDTH,
SCREEN_HEIGHT));
[Link]([Link]);
[Link](true);
[Link](new MyKeyAdapter());
startGame();
}
public void startGame() {
newApple();
running = true;
timer = new Timer(DELAY, this);
[Link]();
}
public void paintComponent(Graphics g) {
[Link](g);
draw(g);
}
public void draw(Graphics g) {
if (running) {
[Link]([Link]);
[Link](appleX, appleY, UNIT_SIZE, UNIT_SIZE);
for (int i = 0; i < bodyParts; i++) {
if (i == 0) {
[Link]([Link]);
[Link](x[i], y[i], UNIT_SIZE, UNIT_SIZE);
} else {
[Link](new Color(45, 180, 0));
[Link](x[i], y[i], UNIT_SIZE, UNIT_SIZE);
}
}
[Link]([Link]);
[Link](new Font("Ink Free", [Link], 40));
FontMetrics metrics = getFontMetrics([Link]());
[Link]("Score: " + applesEaten, (SCREEN_WIDTH -
[Link]("Score: " + applesEaten)) / 2, [Link]().getSize());
} else {
gameOver(g);
}
}
public void newApple() {
appleX = [Link]((int) (SCREEN_WIDTH / UNIT_SIZE)) *
UNIT_SIZE;
appleY = [Link]((int) (SCREEN_HEIGHT / UNIT_SIZE)) *
UNIT_SIZE;
}
public void move() {
for (int i = bodyParts; i > 0; i--) {
x[i] = x[i - 1];
y[i] = y[i - 1];
}
switch (direction) {
case 'U':
y[0] = y[0] - UNIT_SIZE;
break;
case 'D':
y[0] = y[0] + UNIT_SIZE;
break;
case 'L':
x[0] = x[0] - UNIT_SIZE;
break;
case 'R':
x[0] = x[0] + UNIT_SIZE;
break;
}
}
public void checkApple() {
if ((x[0] == appleX) && (y[0] == appleY)) {
bodyParts++;
applesEaten++;
newApple();
}
}
public void checkCollisions() {
for (int i = bodyParts; i > 0; i--) {
if ((x[0] == x[i]) && (y[0] == y[i])) {
running = false;
}
}
if (x[0] < 0 || x[0] > SCREEN_WIDTH || y[0] < 0 || y[0] >
SCREEN_HEIGHT) {
running = false;
}
if (!running) {
[Link]();
}
}
public void gameOver(Graphics g) {
[Link]([Link]);
[Link](new Font("Ink Free", [Link], 40));
FontMetrics metrics1 = getFontMetrics([Link]());
[Link]("Score: " + applesEaten, (SCREEN_WIDTH -
[Link]("Score: " + applesEaten)) / 2, [Link]().getSize());
[Link](new Font("Ink Free", [Link], 75));
FontMetrics metrics2 = getFontMetrics([Link]());
[Link]("Game Over", (SCREEN_WIDTH -
[Link]("Game Over")) / 2, SCREEN_HEIGHT / 2);
}
@Override
public void actionPerformed(ActionEvent e) {
if (running) {
move();
checkApple();
checkCollisions();
}
repaint();
}
public class MyKeyAdapter extends KeyAdapter {
@Override
public void keyPressed(KeyEvent e) {
switch ([Link]()) {
case KeyEvent.VK_LEFT:
if (direction != 'R') {
direction = 'L';
}
break;
case KeyEvent.VK_RIGHT:
if (direction != 'L') {
direction = 'R';
}
break;
case KeyEvent.VK_UP:
if (direction != 'D') {
direction = 'U';
}
break;
case KeyEvent.VK_DOWN:
if (direction != 'U') {
direction = 'D';
}
break;
}
}
}
}
GAME FRAME
import [Link];
public class GameFrame extends JFrame {
GameFrame() {
[Link](new GamePanel());
[Link]("Snake");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](false);
[Link]();
[Link](true);
[Link](null);
}
}
OUTPUT :
CONCLUSION