Skip to content

ZviMints/HideAndSeekWithGhosts

Repository files navigation

OOP Ex4 - HideAndSeekWithGhosts

Other OOP Exercises:

Ex 2 - https://github.com/ZviMints/OOP_2

Ex 3 - https://github.com/ZviMints/OOP_3

Created during a computer communication course during the second year at Ariel University in the Department of Computer Science, 2018
Project site: https://zvimints.github.io/Ex4/.
Made by: Zvi Mints and Or Abuhazira

About The Project:

The Purpose of the game:
to accumulate a maximum amount of points during the game.
Accumulation of points is a process of eating Pacmans and Fruits by the player.
each Pacman or Fruit that eaten by the Player increases the number of points by 1, the faster the Player finishing the game, the Player earn more points, however, the player can be eaten by ghosts and can hit the walls, The points can go down.

 

Menu:

 Load - The Load button is responsible to load CSV file that includes location of the pacman, fruit, ghost and boxes.

 Play - Game Mode for the Player, the user selects a start mode for the player and then selects a direction, from where the game begins.

 Algo - By clicking on the Algorithm button, the algorithm of the game starts to work, in order to understand how the algorithm works you can access the WIKI page and understand the process of selecting the steps of the algorithm

 Rating - By clicking on the Statistics  button, we will connect to a database which keeps all the data for our high score, the average of the other participants, and high score of the algorithm, By using this function, we can know the relation between our results and other people's results, note that the server is not stored by us but by  an external server.

Example (Rating Frame):

Project Diagram:

Class Hierarchy:

Packages:

NOTE: Explanations for each class can be found on the Wiki page or later in this document

Package - Algorithm: 

Coordinate - This class is responsible for the representation of a Coordinate in the matrix. Each Coordinate has x and y values (in Pixels). In addition, there is an ancestor, an ancestor marked as PRED and an ancestor defined to be the Coordinate that reveals the current Coordinate, PRED used to Backtracking the path.

FindShortestPathFromMat - The class is responsible to find the Shorest Path From input matrix.

GameToMatrix - This Class is responsible to convert from Game to Matrix used for taking steps in the Algorithm.

Maze - This Class is Responsible to represent a Maze, Maze is a char[][] matrix with Objects such that Pacman that can be noticed by 'P' in the matrix, moreover we can see Objects Such that Fruit == 'F' ,Ghosts and Players.

The Algorithm :

Problem: for input file with number of Pacmans,Ghosts,Fruits find a route for a player to get the maximum score, when player can eat pacmans and fruits, and damaged by ghosts and boxes.

Solution: 

The algorithm "reads" the game by creating a Maze object that represents the current situation as a two-dimensional matrix of the amount of pixels on the amount of pixels of the game and return a PATH that set to be the shortest route to the nearest fruit or pacman for the current point of the player.

Input: State of the game

Output: Shortest Path for Start point to End point

Greedy Algorithm:

0. Make Empty Queue (for the Coordinate) and make Empty ArrayList (for the Path)

1. Convert current game into a Matrix as described before

2. Make BFS SEARCH for finding the shortest path from START Point (Player Point)

    to END Point, used by the Matrix.

3.       IF coordinate is intersects Fruit or Pacman, Make BackTracking and return the path

4.       IF coordinate is near Ghost, CONTINUE ( GO TO NEXT ITERATION )

5.       IF coordinate is intersects Box,or in invalid point, CONTINUE ( GO TO NEXT ITERATION )

6.       ELSE, add to the Queue all the neighbors of the current coordinate

NOTE: BackTracking is adding to the ArrayList each Pred of the current Point, until the Pred is null

Package -Coords:

This Class is responsible for actions between Objects of the kind Point3D. The Class is used to Provide a solution for elementary actions between vectors and points in R^3 Vector space.

Package - File format:

This class is responsible to make Dynamic matrix[][] which is row contain Arraylist that represent line in csv the number of rows is the number of csv file lines.

Package - Game:

This class represent Game which include Fruits List and Pacmans List, this class can init Pacmans and Fruits from Matrix.

Package - GUI:

Menu - This class represent the GUI Menu of the Project.

Score - This class represents the game score and time remaining for the game in real time.

StatisticFrame - This class represent the GUI Statistic of the Project.

Statistic - This class is responsible for connecting to the DB and extracting information regarding statistics.

Package - Map:

This class can convert Pixel point to Geo Point and back.

Each map containst Map Map (Image) that represent the background of the Game.

Package -MyFrame:

AlgoThread - TThis Class is responsible for the "Client" algorithm side, this is thread that make all the choices for each step in the game.

GamePanel - The class is the main Panel of the game.

MyFrame - This Class is responsible for the Main connection between all classes we can run this game and get a Frame. connect GUI,Algorithm,Game,Play and more...

Package - Objects:

Element - This is an interface that each one of Fruit,Ghost,Pacman need to implement.

Box - This Class represent Box. Every Box has BoxData which include relevant information about the Box such that ID and Geoms.

Fruit - This Class represent Fruit. Every Fruit has FruitData which include relevant information about the Fruit such that ID and Geom.

Ghost - This Class represent Ghost . Every Ghost has GhostData which include relevant information about the Ghost such that ID, Speed, Radius and Geom.

Pacman - This Class represent Pacman . Every Pacman has PacmanData which include relevant information about the Pacman such that ID, Speed, Radius and Geom.

Package - Player:

This package is responsible for representing a player, each player has a picture, degrees and ID name, the degrees represent the direction the player is looking at and this is the direction he will move during the game

Package - JUNIT Testing:

Class
 Brief Explanation
BoxTest This class is responsible to test the BOX Object
FruitTest This class is responsible to test the Fruit Object
GhostTest This class is responsible to test the Ghost Object
MapTest This class is responsible to test the Map, check the transfers from pixels to pixels and vice versa
 
MyCoordsTest

A class that checks all the elementary operations performed in the Coords Class

 
PacmanTest This class is responsible to test the Pacman Object
AlgoTest

Performs a test of the algorithm, given a matrix with initial and final state and with "obstacles", checks whether the output of the algorithm is the shortest path

 

 

About

Final project in OOP course

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages