AJP Micro (Main)
AJP Micro (Main)
EDUCATION
VIDYAVARDHINI’S BHAUSAHEB VARTAK
POLYTECHNIC
MICRO PROJECT
Academic year: 2024-2025
This is to certify that Mr./ Ms. Kyle, Manas, Pranjal Roll No. 1831, 1832, 1833 of
Fifth Semester of Diploma in Computer Engineering (CO) of Institute,
VIDYAVARDHINI’S BHAUSAHEB VARTAK POLYTECHNIC (Code: 0093) has
completed the Micro-Project satisfactorily in Subject - Advanced Java
Programming (22517) for the academic year 2024- 2025 as prescribed in the
curriculum.
Seal Of
Institute
Annexure - I
Part A: Micro Project Proposal
1.0 Aim/Benefits of the Micro-Project: The aim of this micro project is to study Advanced Java
Programming in detail.
3 .0 Proposed Methodology:
1. Literature survey.
2. Collect information through different sources about the device.
3. Analysis of data.
4. Compilation of collected data.
5. Preparation of the circuit.
Sr. Name of
Specifications Qty Remarks
No. Resources/Material
Processor: i3-4160
1. Computer 1
Ram: 4.00 GB
1. Acknowledgement 1
2. Introduction 2
5. Output 10
6. Conclusion 11
7. Reference 11
Acknowledgement
We would like to express our heartfelt gratitude to Mr. Rajesh Garudh, our
esteemed professor, for his invaluable guidance, patience, and unwavering
support throughout this microproject. His expert advice, coupled with his
continuous encouragement, played a crucial role in shaping the direction of our
work. We are deeply indebted to him for the constructive feedback and insights
he provided at every stage, helping us navigate challenges and refine our ideas.
Without his mentorship, this project would not have reached the level of success
it has.
We would also like to extend our profound thanks to all the members of
our group, whose dedication, hard work, and teamwork were fundamental to the
successful completion of this microproject. Each member contributed unique
strengths, and it was through our collective efforts that we were able to overcome
obstacles and meet our objectives. The opportunity to collaborate and share
knowledge has enriched our learning experience in countless ways.
Furthermore, we are grateful to all those who offered their support and
encouragement during the course of this project, whether through their words of
motivation or practical assistance. The lessons we learned and the skills we
developed throughout this process will undoubtedly benefit us in future
endeavors. Once again, we thank everyone who contributed to the successful
completion of this microproject.
Page | 1
Introduction:
Java is a high-level, class-based, and object-oriented programming language that
was originally developed by Sun Microsystems (now owned by Oracle
Corporation) and first released in 1995. It is one of the most widely used and
versatile programming languages in the world due to its design philosophy of
simplicity, portability, and security.
Page | 2
Concept Used in Project
This project focuses on building a basic Tic Tac Toe game using Java Servlet
technology. The goal is to create a simple, web-based version of the game where
users can play against a computer or another player. The project will demonstrate
core Java web development concepts while implementing the game’s basic logic
and user interface.
Key Features
1. Simple Game Interface:
o A basic, interactive game board (3x3 grid) where users can click to
place either "X" or "O."
o Two game modes: single-player (against a basic AI) or two-player
(local, taking turns on the same screen).
2. Game Logic:
o The game checks for win conditions (three in a row: horizontal,
vertical, or diagonal).
o The game announces the result (win, lose, or draw) at the end of each
match.
o A "reset" button allows players to start a new game.
3. Java Servlet Integration:
o Java Servlets handle user input, process moves, and control game
flow on the server side.
o The game state is maintained between turns using simple session
tracking.
4. Frontend:
o The game uses basic HTML, CSS, and JavaScript for the interface
and interaction.
o The user interface is clean and responsive for both desktop and
mobile browsers.
Technology Stack
• Frontend: HTML, CSS, JavaScript
• Backend: Java Servlets for handling game logic and move validation
Page | 3
Source Code
HTML File
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-
scale=1.0" />
<title>Tic Tac Toe</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<nav>MyTicTacToe</nav>
<div class="gameContainer">
<div class="container">
<div class="line"></div>
<div class="box bt-0 bl-0"><span class="boxtext"></span></div>
<div class="box bt-0"><span class="boxtext"></span></div>
<div class="box bt-0 br-0"><span class="boxtext"></span></div>
<div class="box bl-0"><span class="boxtext"></span></div>
<div class="box"><span class="boxtext"></span></div>
<div class="box br-0"><span class="boxtext"></span></div>
<div class="box bl-0 bb-0"><span class="boxtext"></span></div>
<div class="box bb-0"><span class="boxtext"></span></div>
<div class="box bb-0 br-0"><span class="boxtext"></span></div>
</div>
<div class="gameInfo">
<h1>Welcome to Tic Tac Toe</h1>
<div>
<span class="info">Turn for X</span>
<button id="reset">Reset</button>
</div>
<div class="imgbox">
<img src="excited.gif" alt="" />
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Page | 4
CSS File
@import
url('https://fonts.googleapis.com/css2?family=Baloo+Bhaina+2&family=R
oboto&display=swap');
* {
margin: 0;
padding: 0;
}
nav {
background-color: rgb(37, 9, 37);
color: white;
height: 65px;
font-size: 27px;
display: flex;
align-items: center;
text-align-last: center;
padding: 0 12px;
font-family: 'Roboto', sans-serif;
}
.gameContainer {
display: flex;
justify-content: center;
margin-top: 50px;
}
.container {
display: grid;
grid-template-rows: repeat(3, 10vw);
grid-template-columns: repeat(3, 10vw);
font-family: 'Roboto', sans-serif;
position: relative;
}
.box {
border: 2px solid black;
font-size: 8vw;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}
.box:hover {
background-color: rgb(242, 234, 250);
}
Page | 5
.info {
font-size: 22px;
}
.gameInfo {
padding: 0 34px;
font-family: 'Baloo Bhaina 2', cursive;
}
.gameInfo h1 {
font-size: 2.5rem;
}
.imgbox img {
width: 0;
transition: width 1s ease-in-out;
}
.br-0 {
border-right: 0;
}
.bl-0 {
border-left: 0;
}
.bt-0 {
border-top: 0;
}
.bb-0 {
border-bottom: 0;
}
#reset {
margin: 0 23px;
padding: 1px 18px;
background: #f3e7f9;
border-radius: 6px;
cursor: pointer;
font-family: 'Baloo Bhaina 2';
font-size: 15px;
font-weight: bolder;
}
.line {
background-color: black;
Page | 6
height: 3px;
width: 0;
position: absolute;
background-color: #911d91;
transition: width 1s ease-in-out;
}
.gameInfo {
margin-top: 34px;
}
.gameInfo h1 {
font-size: 1.5rem;
}
.container {
grid-template-rows: repeat(3, 20vw);
grid-template-columns: repeat(3, 20vw);
}
}
JavaScript File
console.log("Welcome to Tic Tac Toe")
let music = new Audio("music.mp3")
let audioTurn = new Audio("ting.mp3")
let gameover = new Audio("gameover.mp3")
let turn = "X"
let isgameover = false;
Page | 7
[0, 3, 6, -5, 15, 90],
[1, 4, 7, 5, 15, 90],
[2, 5, 8, 15, 15, 90],
[0, 4, 8, 5, 15, 45],
[2, 4, 6, 5, 15, 135],
]
wins.forEach(e => {
if ((boxtext[e[0]].innerText === boxtext[e[1]].innerText) &&
(boxtext[e[2]].innerText === boxtext[e[1]].innerText) &&
(boxtext[e[0]].innerText !== "")) {
document.querySelector('.info').innerText =
boxtext[e[0]].innerText + " Won"
isgameover = true
music.play();
document.querySelector('.imgbox').getElementsByTagName('i
mg')[0].style.width = "200px";
document.querySelector(".line").style.transform =
`translate(${e[3]}vw, ${e[4]}vw) rotate(${e[5]}deg)`
document.querySelector(".line").style.width = "20vw";
gameover.play();
}
})
}
// Function to check if all boxes are filled and no one has won
const checkDraw = () => {
let boxtext = document.getElementsByClassName('boxtext');
let isDraw = true;
Array.from(boxtext).forEach(element => {
if (element.innerText === "") {
isDraw = false;
}
});
if (isDraw && !isgameover) {
document.querySelector('.info').innerText = "It's a draw!
Please restart the game.";
isgameover = true;
gameover.play();
}
}
// Game Logic
let boxes = document.getElementsByClassName("box");
Array.from(boxes).forEach(element => {
let boxtext = element.querySelector('.boxtext');
element.addEventListener('click', () => {
if (boxtext.innerText === '' && !isgameover) {
boxtext.innerText = turn;
Page | 8
turn = changeTurn();
audioTurn.play();
checkWin();
if (!isgameover) {
document.getElementsByClassName("info")[0].innerText
= "Turn for " + turn;
}
checkDraw(); // Check for draw after every move
}
})
})
Servlet Code
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Page | 9
Output
Page | 10
Conclusion:
In conclusion, this Tic Tac Toe project demonstrates the implementation of
a simple yet functional web-based game using Java Servlet technology. Through
this project, key programming concepts such as handling user input, controlling
game flow, and maintaining session state are put into practice. The game provides
an engaging, interactive experience, showcasing the basic mechanics of turn-
based gameplay, along with Java’s capabilities in building web applications.
While the project focuses on a straightforward game, it serves as a
foundation for future enhancements. Features like AI improvement, online
multiplayer, or persistent score tracking can be added to enrich the user
experience. This project highlights the flexibility and power of Java Servlets in
delivering dynamic web content and opens up possibilities for scaling more
complex applications in the future.
Reference:
a) https://docs.oracle.com/javase/tutorial/
b) https://www.tutorialspoint.com/servlets/index.htm
c) https://codereview.stackexchange.com/questions/234043/tic-tac-toe-game-
in-java
d) https://www.journaldev.com/19862/tic-tac-toe-game-java
Page | 11