Professional Documents
Culture Documents
PREPARED BY – Pooja
ROLL NO - 200010140040
2 Acknowledgement
3 Introduction
4 Implementation
5 Result
6 Conclusion
7 References
DECLARATION
I certify that
a. The work in this report is original and has been done by me under
the guidance of my supervisor(s).
b. The work has not been submitted to any other institute for any
degree or diploma.
c. I have followed the guidelines provided by the institute in preparing the
report.
d. I have confirmed to the norms and guidelines given in the Ethical
code of conduct of the institute.
e. Whenever I have used materials (data, theoretical analysis,
figures, and text) from other sources, I have given due credit to
them by citing them in the text of the report and giving their
details in the references. Further, I have taken permission from
the copyright owners of the sources, whenever necessary.
Pooja
ACKNOWLEDGEMENT
In the present world of competition there is a race of existence in
which those are having will to come forward succeed. Project is like a
bridge between theoretical and practical working. With this willing I
joined this particular project. First of all, I would like to thank the
supreme power the Almighty God who is obviously the one has
always guided me to work on the right path of life. Without his grace
this project could not become a reality. Next to him are my parents,
whom I am greatly indebted for me brought up with love and
encouragement to this stage. I am feeling oblige in taking the
opportunity sincerely thanks to Prof. B. R. Kamboj (Vice Chancellor of
GJUS&T, Hisar). Moreover, I am highly obliged in taking the
opportunity to sincerely thanks to all the staff members of computer
department for their generous attitude and friendly behavior. At last,
but not least I am thankful to all my teachers and friends who have
been always helping and encouraging me though out the year. I have
no valuable words to express my thanks, but my heart is still full of
the favors received from every person.
INTRODUCTION
ABOUT PROJECT
Tkinter Components
Tkinter is the most commonly used library for developing GUI (Graphical
User Interface) in Java. It is a standard Java interface to the Tk GUI toolkit
shipped with Java. As Tk and Tkinter are available on most of the Unix
platforms as well as on the Windows system, developing GUI applications
with Tkinter becomes the fastest and easiest.
WIDGETS:
Widgets Description
Label It is used to display text or image on the screen
Button It is used to add buttons to your application
It is used to draw pictures and others layouts like texts,
Canvas graphics etc.
It contains a down arrow to select from list of available
ComboBox options
It displays a number of options to the user as toggle buttons
CheckButton from which user can select any number of options.
Radio It is used to implement one-of-many selection as it allows
Button only one option to be selected
Entry It is used to input single line text entry from user
Frame It is used as container to hold and organize the widgets
It works same as that of label and refers to multi-line and
Message non-editable text
It is used to provide a graphical slider which allows to select
Scale any value from that scale
It is used to scroll down the contents. It provides a slide
Scrollbar controller.
SpinBox It is allows user to select from given set of values
It allows user to edit multiline text and format the way it has
Text to be displayed
Menu It is used to create all kinds of menu used by an application
Implementation
Main.Java
package com.pooja.ConnectFour;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ObservableValue;
import javafx.event.Event;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
@Override
menuPane.getChildren().addAll(menubar);
controller = loader.getController();
controller.createPlayground();
primaryStage.setScene(scene);
primaryStage.setTitle("Connect Four");
primaryStage.setResizable(false);
primaryStage.show();
resetGame.setOnAction(Event ->controller.resetGame());
//help menu
aboutMe.setOnAction(Event ->aboutMe());
menubar.getMenus().addAll(fileMenu, helpMenu);
return menubar;
alert.setHeaderText("Pooja Goyal");
alert.setContentText("I love to play with code and game around ,so i start learn to develop
game." +
alert.show();
alert.setHeaderText("How to play");
"color and then take turns dropping colored discs from the top into a seven-column, " +
"six-row vertically suspended grid. The pieces fall straight down, occupying the next
available" +
" space within the column. The objective of the game is to be the first to form a horizontal,
vertical," +
" or diagonal line of four of one's own discs. Connect Four is a solved game. " +
"The first player can always win by playing the right moves.");
alert.show();
Platform.exit();
System.exit(0);
launch(args);
Controller.java
package com.pooja.ConnectFour;
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 sun.security.provider.SHA;
import java.net.URL;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@FXML
@FXML
@FXML
@FXML
@FXML
Shape rectangleWithHole=createGameStructureGrid();
rootGridPane.add(rectangleWithHole, 0, 1);
List<Rectangle> rectangleList=createClickableColumns();
rootGridPane.add(rectangle,0,1);
setNamebutton.setOnAction(event -> {
Player_One=player_OneTextField.getText();
Player_Two=player_TwoTextField.getText();
playerNameLabel.setText(isPlayerOneTurn?Player_One:Player_Two);
});
circle.setRadius(Circle_Diameter / 2);
circle.setCenterX(Circle_Diameter / 2);
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);
rectangleWithHole.setFill(Color.WHITE);
return rectangleWithHole ;
rectangle.setFill(Color.TRANSPARENT);
rectangle.setTranslateX(col*(Circle_Diameter+5)+Circle_Diameter / 4);
rectangle.setOnMouseEntered(event ->rectangle.setFill(Color.valueOf("#eeeeee26")));
rectangle.setOnMouseClicked(event -> {
if(isAllowedToInsert) {
isAllowedToInsert=false;
});
rectangleList.add(rectangle);
return rectangleList ;
int row=Rows-1;
while (row>=0){
if(getDiscIfPresent(row,column)== null)
break;
row--;
if(row<0)
return;
insertedDiscArray[row][column]=disc;
insertDiscPane.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(event -> {
isAllowedToInsert=true;
if(gameEnded(currentRow,column)){
gameOver();
return;
isPlayerOneTurn =!isPlayerOneTurn;
playerNameLabel.setText(isPlayerOneTurn? Player_One:Player_Two);
});
translateTransition.play();
.collect(Collectors.toList());
.collect(Collectors.toList());
.mapToObj(i ->startPoint1.add(i,-i))
.collect(Collectors.toList());
.mapToObj(i ->startPoint2.add(i,i))
.collect(Collectors.toList());
||checkCombination(diagonal1Point) ||checkCombination(diagonal2Point);
return isEnded;
int chain=0;
chain++;
if (chain == 4) {
return true;
else{
chain=0;
return false;
return null;
return insertedDiscArray[row][column];
System.out.println("Winner is"+winner);
alert.setTitle("Connect Four");
alert.getButtonTypes().setAll(yesBtn,noBtn);
Platform.runLater(() ->{
resetGame();
}else{
Platform.exit();
System.exit(0);
});
insertDiscPane.getChildren().clear();
for(int row=0;row < insertedDiscArray.length;row++){
insertedDiscArray[row][col]=null;
isPlayerOneTurn=true;
playerNameLabel.setText(Player_One);
createPlayground();
this.isPlayerOneMove=isPlayerOneMove;
setRadius(Circle_Diameter/2);
setCenterX(Circle_Diameter/2);
setCenterY(Circle_Diameter/2);
@Override
RESULT
CONCLUSION
This project has been very informative and it helped me to learn about
many interesting concepts of Java.
I learned how to create a Connect four game. And gained a lot of
knowledge about how to handle data and click event in Java. It gave
me motivation to create more such gaming projects.
It was fun to create and play the game and I am looking forward to
add more features to it to make it more interesting.