0% found this document useful (0 votes)
23 views

Mini Project Report

This document provides an overview of a mini project on game development. It discusses developing the Connect 4 game. It includes a declaration by the students, Dhruv Tiwari, Aryan Saini, and Anurag Gupta, that the project is their original work. It also acknowledges help received from their professor Mr. Eshank Jain and institution. The document outlines chapters that will cover getting started with Java, leveraging basic concepts like data structures, object-oriented programming principles like inheritance, polymorphism, abstraction and encapsulation, and developing the Connect 4 game using Java.

Uploaded by

Anurag Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Mini Project Report

This document provides an overview of a mini project on game development. It discusses developing the Connect 4 game. It includes a declaration by the students, Dhruv Tiwari, Aryan Saini, and Anurag Gupta, that the project is their original work. It also acknowledges help received from their professor Mr. Eshank Jain and institution. The document outlines chapters that will cover getting started with Java, leveraging basic concepts like data structures, object-oriented programming principles like inheritance, polymorphism, abstraction and encapsulation, and developing the Connect 4 game using Java.

Uploaded by

Anurag Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

i

MINI
PROJECT
on
GAME DEVLOPMENT

A Project report submitted in partial fulfillment of requirements for the


award of the Degree of

Degree of Bachelor of Technology in Computer Science & Engineering

Submitted By

Name:- DHRUV TIWARI


ARYAN SAINI
ANURAG GUPTA
Class: CSE-D
University Roll No:- 2101330100098
2101330100073
2101330100060

SUBMITTED TO:- Mr. ESHANK JAIN SIR


ii

DECLARATION

I hereby declare that the mini project Report entitled,


("CONNECT 4 GAME") is an authentic record of our work as requirements
from JANUARY 2023 to MAY 2023 for the award of degree of B.Tech.
(Computer Science & Engineering), NOIDA INSTITUTE OF
ENGINEERING & TECHNOLOGY, under the guidance of
Mr. ESHANK JAIN SIR.

(Dhruv Tiwari, Aryan Saini, Anurag Gupta)


(University Roll No. 2101330100098, 2101330100073, 2101330100060)

Date: 5/5/2023

Certified that the above statement made by the student is correct to the best of our
knowledge and belief.

Examined by:

1. Mr ESHANK JAIN

Head of Department
(Signature and Seal)
iii

ACKNOWLEDGEMENT

The present project work is the several days study of the various aspects of the project
development. During this the effort in the present study, we have received a great amount
of help from our Chairman Mr. Raman Bhatra, NOIDA INSTITUTE OF
ENGINEERING & TECHNOLOGY GR.NOIDA, which we wish to acknowledge and
thank from depth of our hearts.

I am thankful to our Director Dr. Vinod M. Kapse, for permitting and


encouraging me in doing this project.

My sincere thanks to Dr. Kumud Saxena, Head of the Department in CSE


whose motivation and constant encouragement has led to pursue a project in the field of
software development.

I am very much obliged and thankful to our Coordinator for providing this
opportunity and constant encouragement given by him during the course.

My Parents have put myself ahead of themselves. Because of their hard work and
dedication, I have had opportunities beyond my wildest dreams. My heartfelt thanks to
them for giving me all I ever needed to be successful student and individual.

Finally I express my thanks to all my other professors, classmates, friends,


neighbors and my family members who helped me for the completion of my project and
without infinite love and patience this would never have been possible.
iv

Table of content:-

Declaration by student ii
Acknowledgement iii
Certificate by Company/Industry/Institute iv
Learning Objectives/Internship Objectives vi
Chapters 1: Getting Started with Java 1
1.1 What is Java?
1.2 Java Platforms / Editions

Chapter 2: Leveraging Basic concepts 3


2.1 Data Structures
Chapter 3: Object Oriented Programming 4
3.1 Java Inheritance
3.2 Java Polymorphism
3.3 Java Abstraction
3.4 Java Encapsulation
Chapter 4: Java Game Development 6
4.1 Source Code (Main.java)
4.2 Controller.java
4.3 Game.xml
4.4 hello-view.xml
5.Results and Discussions 23

6.Conclusions and Future Scope 24

7.Bibliography 24
v

Learning Objectives

➢ Internships are generally thought of to be reserved for college students


looking to gain experience in a particular field. However, a wide array of
people can benefit from Training Internships in order to receive real world
experience and develop their skills.

➢ An objective for this position should emphasize the skills you already
possess in the area and your interest in learning more.

➢ Internships are utilized in a few different career fields, including


architecture, engineering, healthcare, economics, advertising and many
more.

➢ Some internships are used to allow individuals to perform scientific


research while others are specifically designed to allow people to gain first
hand experience working.

➢ Utilizing internships is a great way to build your resume and develop


skills that can be emphasized in your resume for future jobs. When you are
applying for a Training Internship, make sure to highlight any special skills
or talents that can make you stand apart from the rest of the applicants so
that you have an improved chance of landing the position.
1

Chapter 1: Getting Started with Java

1.1 What is Java?


Java is a programming language and a platform. Java is a high level, robust,
object-oriented and secure programming language.

Java was developed by Sun Microsystems (which is now the subsidiary of


Oracle) in the year 1995. James Gosling is known as the father of Java.
Before Java, its name was Oak. Since Oak was already a registered
company, so James Gosling and his team changed the name from Oak to
Java.

Java Example
Class solution{
Public static void main(String[] args){
System.out.println(“Hello World”)
}
}
2

1.2 Java Platforms / Editions

There are 4 platforms or editions of Java:

1) Java SE (Java Standard Edition)


It is a Java programming platform. It includes Java programming APIs such
as java.lang, java.io, java.net, java.util, java.sql, java.math etc. It includes
core topics like OOPs, String, Regex, Exception, Inner classes,
Multithreading, I/O Stream, Networking, AWT, Swing, Reflection,
Collection, etc.

2) Java EE (Java Enterprise Edition)


It is an enterprise platform that is mainly used to develop web and enterprise
applications. It is built on top of the Java SE platform. It includes topics like
Servlet, JSP, Web Services, EJB, JPA, etc.

3) Java ME (Java Micro Edition)


It is a micro platform that is dedicated to mobile applications.

4) JavaFX
It is used to develop rich internet applications. It uses a lightweight user
interface API.
3

Chapter 2: Leveraging Basic concepts

2.1 Data Structures

Data Types

Fig. Data type Chart

Java Primitive Data Types


There are 8 types of primitive data types:

o boolean data type


o byte data type
o char data type
o short data type
o int data type
o long data type
o float data type
o double data type
4

Chapter 3: Object Oriented Programming

3.1 Java Inheritance

Inheritance in Java is a mechanism in which one object acquires all the


properties and behaviours of a parent object. It is an important part of OOPs
(Object Oriented programming system).

The idea behind inheritance in Java is that you can create new classes that
are built upon existing classes. When you inherit from an existing class, you
can reuse methods and fields of the parent class. Moreover, you can add new
methods and fields in your current class also.

Inheritance represents the IS-A relationship which is also known as a


parentchild relationship.

3.2 Java Polymorphism

3.2.1 Method Overloading in Java


If a class has multiple methods having same name but different in
parameters, it is known as Method Overloading.

If we have to perform only one operation, having same name of the methods
increases the readability of the program.

Suppose you have to perform addition of the given numbers but there can be
any number of arguments, if you write the method such as a (int, int) for two
parameters, and b(int ,int ,int) for three parameters then it may be difficult
for you as well as other programmers to understand the behavior of the
method because its name differs.

So, we perform method overloading to figure out the program quickly.

There are two ways to overload the method in java

1.By changing number of arguments


2.By changing the data type
5

3.3 Java Abstraction

A class which is declared with the abstract keyword is known as an abstract


class in Java. It can have abstract and non-abstract methods (method with the
body).
Abstraction is a process of hiding the implementation details and showing
only functionality to the user.

Another way, it shows only essential things to the user and hides the internal
details, for example, sending SMS where you type the text and send the
message. You don't know the internal processing about the message delivery.

3.4 Java Encapsulation

Encapsulation in Java is a process of wrapping code and data together into a


single unit, for example, a capsule which is mixed of several medicines. We
can create a fully encapsulated class in Java by making all the data
members of the class private. Now we can use setter and getter methods to
set and get the data in it.

The Java Bean class is the example of a fully encapsulated class.


6

Chapter 4: Java Game Development

4.1 Source Code (Main.java)

package com.example.connect4;
import
javafx.application.Application; import
javafx.application.Platform; import
javafx.event.ActionEvent; import
javafx.event.EventHandler; import
javafx.fxml.FXMLLoader; import
javafx.scene.Scene; import
javafx.scene.control.*; import
javafx.scene.layout.GridPane; import
javafx.scene.layout.Pane; import
javafx.stage.Stage;

import java.io.IOException;

public class Main extends Application {

private Controller controller;


@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new
FXMLLoader(Main.class.getResource("game.fxml"));
GridPane rootGridPane = fxmlLoader.load();

controller = fxmlLoader.getController();
controller.createPlayground();

MenuBar menuBar = createMenu();


menuBar.prefWidthProperty().bind(stage.widthProperty());

Pane menuPane = (Pane) rootGridPane.getChildren().get(0);


menuPane.getChildren().add(menuBar);

Scene scene = new Scene(rootGridPane);


stage.setScene(scene);
stage.setResizable(false); stage.show();

} private MenuBar
createMenu(){

//file menu
Menu fileMenu = new Menu("File");

MenuItem newGame = new MenuItem("New Game");


newGame.setOnAction(actionEvent -> controller.resetGame());
7

MenuItem resetGame = new MenuItem("Reset game");


resetGame.setOnAction(actionEvent -> controller.resetGame());

SeparatorMenuItem separatorMenuItem = new SeparatorMenuItem();


MenuItem exitGame = new MenuItem("Exit game");
exitGame.setOnAction(actionEvent -> exitGame());

fileMenu.getItems().addAll(newGame,resetGame,separatorMenuItem,exitGame
);

//help menu

Menu helpMenu = new Menu("Help");

MenuItem aboutGame = new MenuItem("About Game");


aboutGame.setOnAction(actionEvent -> aboutGame());

SeparatorMenuItem separator = new SeparatorMenuItem();


MenuItem aboutMe = new MenuItem("About me");
aboutMe.setOnAction(actionEvent -> aboutMe());

helpMenu.getItems().addAll(aboutGame,separator,aboutMe);

MenuBar menuBar = new MenuBar();

menuBar.getMenus().addAll(fileMenu,helpMenu);

return menuBar;
}
private void aboutMe() {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("About The Developer");
alert.setHeaderText("Rahul Gautam");
alert.setContentText("I love to play around with code and create
games.\n"+
"connect 4 is one of them. in free time \n"+
"I like to spend time with nears and dears.");
alert.show();
}
private void aboutGame() {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("About Connect game"); alert.setHeaderText("How
to play");
alert.setContentText("Connect Four is a two-player connection
game in which the\n " +
"players first choose a color and then take turns
dropping colored discs\n " +
"from the top into a seven-column, six-row vertically
suspended grid.\n "+
"The pieces fall straight down, occupying the next
available space within\n " +
8

"the column. The objective of the game is to be the


first to form a horizontal,\n " +
"vertical, or diagonal line of four of one's own discs.
Connect Four is a\n " +
"solved game. The first player can always win by playing
the right moves.");

alert.show();
} private void
exitGame() {
Platform.exit();
System.exit(0);
}
private void resetGame() {
}
public static void main(String[] args) {
launch();
} }

4.2 Controller.java
package
com.example.connect4;
import
javafx.animation.TranslateTransition; import
javafx.application.Platform; import
javafx.fxml.FXML; import
javafx.fxml.Initializable; import
javafx.geometry.Point2D; import
javafx.scene.control.*; import
javafx.scene.layout.GridPane; import
javafx.scene.layout.Pane; import
javafx.scene.paint.Color; import
javafx.scene.shape.Circle; import
javafx.scene.shape.Rectangle; import
javafx.scene.shape.Shape; import
javafx.util.Duration;
import java.net.URL; import
java.util.ArrayList; import
java.util.List; import
java.util.Optional; import
java.util.ResourceBundle; import
java.util.stream.Collectors; import
java.util.stream.IntStream;

public class Controller implements Initializable {


private static final int COLUMNS =7; private
static final int ROWS = 6; private static final int
CIRCLE_DIAMETER = 80; private static final String
discColor1 = "#24303E"; private static final String
discColor2 = "#4CAA88";
9

private static String PLAYER_ONE = "Player


One"; private static String PLAYER_TWO = "Player
Two";
private boolean isPlayerOneTurn =
true;

private Disc[][] insertedDiscArray = new Disc[ROWS][COLUMNS];

@FXML
public GridPane rootGridPane;

@FXML
public Pane insertedDiscsPane;

@FXML
public Label playerNameLabel;

@FXML
public TextField playerOneTextField, playerTwoTextField;
@FXML
public Button setNamesButton;

private boolean isAllowToInsert = true;

public void createPlayground(){

setNamesButton.setOnAction(event ->
{
PLAYER_ONE = playerOneTextField.getText();
PLAYER_TWO = playerTwoTextField.getText();
});

Shape rectangleWithHoles = createGameStructuralGrid();

rootGridPane.add(rectangleWithHoles,0,1);
List<Rectangle> rectangleList = createClickableColumns();

for (Rectangle rectangle: rectangleList) {

rootGridPane.add(rectangle,0,1);
}

}
private Shape createGameStructuralGrid(){
Shape rectangleWithHoles = new Rectangle((COLUMNS+1) *
CIRCLE_DIAMETER, (ROWS+1)*CIRCLE_DIAMETER);
for (int row = 0; row < ROWS; row++){
for (int col = 0; col <COLUMNS; col++){
Circle circle = new Circle();
circle.setRadius(CIRCLE_DIAMETER/2);
circle.setCenterX(CIRCLE_DIAMETER/2);
10

circle.setCenterY(CIRCLE_DIAMETER/2);
circle.setSmooth(true);

circle.setTranslateX(col * (CIRCLE_DIAMETER+5) +
CIRCLE_DIAMETER/4);
circle.setTranslateY(row * (CIRCLE_DIAMETER+5) +
CIRCLE_DIAMETER/4);

rectangleWithHoles
=Shape.subtract(rectangleWithHoles,circle);
}

}
rectangleWithHoles.setFill(Color.WHITE);

return rectangleWithHoles;
}
private List<Rectangle> createClickableColumns(){

List<Rectangle> rectangleList = new ArrayList<>();


for (int col=0; col<COLUMNS; col++){

Rectangle rectangle = new Rectangle(CIRCLE_DIAMETER,


(ROWS+1)*CIRCLE_DIAMETER);
rectangle.setFill(Color.TRANSPARENT);
rectangle.setTranslateX(col *
(CIRCLE_DIAMETER+5)+CIRCLE_DIAMETER/4);
rectangle.setOnMouseEntered (event -
> rectangle.setFill(Color.valueOf("#eeeeee26")));
rectangle.setOnMouseExited(event ->
rectangle.setFill(Color.TRANSPARENT));

final int column = col;


rectangle.setOnMouseClicked(event -> {
if (isAllowToInsert){
isAllowToInsert = false;
insertDisc(new Disc(isPlayerOneTurn),column);
}

});
rectangleList.add(rectangle);
}
return rectangleList;

}
private void insertDisc(Disc disc, int column){
int row = ROWS-
1; while (row >=
0){
if(getDiscIfPresent(row,column)==null)
break; row--; } if
(row < 0) return;
11

insertedDiscArray[row][column] = disc;
insertedDiscsPane.getChildren().add(disc);
disc.setTranslateX(column*(CIRCLE_DIAMETER + 5) +
CIRCLE_DIAMETER/4); int currentRow = row;
TranslateTransition translateTransition = new
TranslateTransition(Duration.seconds(0.5),disc);
translateTransition.setToY(row* (CIRCLE_DIAMETER + 5) +
CIRCLE_DIAMETER/4);
translateTransition.setOnFinished(actionEvent -> {

isAllowToInsert = true;
if (gameEnded(currentRow,column)){
gameOver(); return;
}

isPlayerOneTurn = !isPlayerOneTurn;
playerNameLabel.setText(isPlayerOneTurn? PLAYER_ONE :
PLAYER_TWO);

});

translateTransition.play();
}
private boolean gameEnded(int row,int column){

List<Point2D> verticalPoints = IntStream.rangeClosed(row-3 ,row


+ 3)
.mapToObj(r -> new Point2D(r,column))
.collect(Collectors.toList());

List<Point2D> horizontalPoints = IntStream.rangeClosed(column-3


,column + 3)
.mapToObj(col -> new Point2D(row,col))
.collect(Collectors.toList());

Point2D startPoint1 = new Point2D(row-3,column+3);


List<Point2D> diagonalPoints = IntStream.rangeClosed(0,6)
.mapToObj(i -> startPoint1.add(i,-i))
.collect(Collectors.toList());

Point2D startPoint2 = new Point2D(row-3,column-3);


List<Point2D> diagonal2Points = IntStream.rangeClosed(0,6)
.mapToObj(i -> startPoint2.add(i,i))
.collect(Collectors.toList());

boolean isEnded = checkCombinations(verticalPoints) ||


checkCombinations(horizontalPoints)
|| checkCombinations(diagonalPoints) ||
checkCombinations(diagonal2Points);

return isEnded;
12

}
private boolean checkCombinations(List<Point2D> points) {
int chain =0;
for (Point2D point: points) {
int rowIndexForArray = (int) point.getX();
int columnIndexForArray = (int) point.getY();
// Disc disc =
insertedDiscArray[rowIndexForArray][columnIndexForArray];
Disc disc = getDiscIfPresent(rowIndexForArray,
columnIndexForArray);
if (disc != null && disc.isPlayerOneMove ==
isPlayerOneTurn){ chain++;
if (chain == 4){ return true;
}
}else {
chain =0;
}
} return
false;
}
private Disc getDiscIfPresent(int row, int column){

if ((row>=ROWS) || row<0 || column>= COLUMNS || column<0)


return null;

return insertedDiscArray[row][column];

}
private void gameOver(){

String winner = isPlayerOneTurn ? PLAYER_ONE : PLAYER_TWO;


System.out.println("Winner is : " + winner);

Alert alert = new Alert(Alert.AlertType.INFORMATION);


alert.setTitle("Connect four"); alert.setHeaderText("Winner
is : "+ winner); alert.setContentText("Want to Play Again ?
");

ButtonType yesBtn = new ButtonType("yes");


ButtonType noBtn = new ButtonType("No , Exit");
alert.getButtonTypes().setAll(yesBtn,noBtn);

Platform.runLater(()->{
Optional<ButtonType> BtnClicked = alert.showAndWait();
if (BtnClicked.isPresent() && BtnClicked.get()==yesBtn){
resetGame(); }else {
Platform.exit();
System.exit(0);
}
13

});
}
public void resetGame() {
insertedDiscsPane.getChildren().clear(); for
(int row =0; row< insertedDiscArray.length; row++){
for (int col =0; col< insertedDiscArray[row].length; col++){
insertedDiscArray[row][col] = null;
}
}
isPlayerOneTurn = true;
playerNameLabel.setText(PLAYER_ONE); createPlayground();

}
private static class Disc extends Circle{
private final boolean isPlayerOneMove; public
Disc(boolean isPlayerOneMove){
this.isPlayerOneMove = isPlayerOneMove;
setRadius(CIRCLE_DIAMETER/2);
setFill(isPlayerOneMove? Color.valueOf(discColor1):
Color.valueOf(discColor2));

setCenterX(CIRCLE_DIAMETER/2);
setCenterY(CIRCLE_DIAMETER/2);

}
}

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {

} }

4.3 Game.xml
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<GridPane fx:id="rootGridPane" style="-fx-background-color: #D9F7F0;"


xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.example.connect4.Controller">
<columnConstraints>
<ColumnConstraints />
<ColumnConstraints maxWidth="253.39999999999998"
minWidth="193.40001525878904" prefWidth="193.40001525878904" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" />
14

<RowConstraints />

</rowConstraints>
<children>
<Pane GridPane.columnSpan="2" />
<Pane fx:id="insertedDiscsPane" prefHeight="400.0"
prefWidth="200.0" GridPane.rowIndex="1" />
<VBox prefHeight="200.0" style="-fx-background-color: #2B3B4C;"
GridPane.columnIndex="1" GridPane.rowIndex="1">
<children>
<Region prefHeight="0.0" prefWidth="194.0"
VBox.vgrow="ALWAYS" />
<TextField fx:id="playerOneTextField" alignment="CENTER"
promptText="Player One Name">
<VBox.margin>
<Insets bottom="1.0" left="15.0" right="15.0"
top="2.0" />
</VBox.margin>
</TextField>
<TextField fx:id="playerTwoTextField" alignment="CENTER"
promptText="Player Two Name">
<VBox.margin>
<Insets bottom="3.0" left="15.0" right="15.0"
/>
</VBox.margin>
</TextField>
<Button fx:id="setNamesButton" mnemonicParsing="false"
prefHeight="26.0" prefWidth="193.0" text="Set Names">
<VBox.margin>
<Insets bottom="20.0" left="15.0" right="15.0"
/>
</VBox.margin>
</Button>
<Label fx:id="playerNameLabel" alignment="CENTER"
prefHeight="43.0" prefWidth="247.0" text="Player One" textFill="WHITE">
<font>
<Font name="System Bold" size="29.0" />
</font>
</Label>
<Label alignment="CENTER" prefHeight="40.0"
prefWidth="258.0" text="Turn" textFill="WHITE">
<font>
<Font size="28.0" />
</font>
</Label>
<Region prefHeight="228.0" prefWidth="194.0"
VBox.vgrow="ALWAYS" />
</children>
</VBox>
</children>
</GridPane>
15

4.4 hello-view.xml
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>

<?import javafx.scene.control.Button?>
<VBox alignment="CENTER" spacing="20.0"
xmlns:fx="http://javafx.com/fxml"
fx:controller="com.example.connect4.Controller">
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
</padding>

<Label fx:id="welcomeText"/>
<Button text="Hello!" onAction="#onHelloButtonClick"/>
</VBox>
16

Results and Discussions:

Output Screen
17

Conclusions and Future Scope

Thinking of the game as a part of a bigger educational process is


really in the core mind-set that this project wants to promote. Games
can do many things very well, but they certainly cannot do
everything at once.

BIBLIOGRAPHY
The following books are referred during the analysis and execution phase of
the project
Java: The Complete Reference 7th edition.
References: JavaTpoint
https://www.javatpoint.com/

You might also like