Mini Project Report
Mini Project Report
MINI
PROJECT
on
GAME DEVLOPMENT
Submitted By
DECLARATION
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 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.
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
7.Bibliography 24
v
Learning Objectives
➢ An objective for this position should emphasize the skills you already
possess in the area and your interest in learning more.
Java Example
Class solution{
Public static void main(String[] args){
System.out.println(“Hello World”)
}
}
2
4) JavaFX
It is used to develop rich internet applications. It uses a lightweight user
interface API.
3
Data Types
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.
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.
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.
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;
controller = fxmlLoader.getController();
controller.createPlayground();
} private MenuBar
createMenu(){
//file menu
Menu fileMenu = new Menu("File");
fileMenu.getItems().addAll(newGame,resetGame,separatorMenuItem,exitGame
);
//help menu
helpMenu.getItems().addAll(aboutGame,separator,aboutMe);
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
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;
@FXML
public GridPane rootGridPane;
@FXML
public Pane insertedDiscsPane;
@FXML
public Label playerNameLabel;
@FXML
public TextField playerOneTextField, playerTwoTextField;
@FXML
public Button setNamesButton;
setNamesButton.setOnAction(event ->
{
PLAYER_ONE = playerOneTextField.getText();
PLAYER_TWO = playerTwoTextField.getText();
});
rootGridPane.add(rectangleWithHoles,0,1);
List<Rectangle> rectangleList = createClickableColumns();
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(){
});
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){
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){
return insertedDiscArray[row][column];
}
private void gameOver(){
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.*?>
<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
Output Screen
17
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/