Technical details - ShiraAnaki130/OOP_ex2 GitHub Wiki

API

The API contains the interfaces and classes of the structure of the game.

directed_weighted_graph is an interface that represents directed and weighted graph The class that implements this interface in our project is DWGaph_DS. In this class, we implement all the interfaces that are associated with a graph. The object of DWGaph_DS can add new NodeData to the graph, get NodeData in the graph with a key, get the EdgeData connected between the source and destination keys, connect edges between source and destination keys with a weight, remove nodes and edge.

node_data - Represent the vertex of the graph. The class that implements this interface in our project is NodeData and it's located in WDGraph_DS. The object of NodeData has a unique key, weight, and geo_location.

edge_data - Represent the data of the directed edge between the vertexes. The class that implements this interface in our project is EdgeData and it's located in WDGraph_DS. The object of EdgeData keeps the source and destination node_data and the weight of the edge connected between them.

geo_location - Represent the location of a vertex by 3D point coordinates. The class that implements this interface in our project is GeoLocation and it's located in NodeData. The object of GeoLocation keeps 3 coordination point and has a function to calculate the distance to a given geo_location object.

dw_graph_algorithms - Algorithm class for directed_weighted_graph. The class that implements this interface in our project is DWGaph_Algo. This class needs to init with a directed_weighted_graph before doing any algorithm function. There is an inner class AlgoNodeInfo in this class that keeps the info that necessary for the algorithms include weight and parent.

isconnected: This function checks if the graph is fully connected. The algorithm tries to reach from starting node_data to all node_date on the graph with the BFS algorithm, we use Queue to keep the node that the algorithm will check and set a mark to not add them again to the queue after polling them, it's has a set that keeps all the node_data its poll from the Queue and compares this size with the size of the graph. If it successes the algorithm swaps the directions of the edges and checks them again.

shortestPathDist: This function accepts source and destination keys and checks the shortest distance between them. The algorithm uses a priority queue to keep the nodes that the algorithm will check and set a mark to not add them again to the queue after polling them, the priority of the queue is the AlgoNodeInfo weight distance from the source vertex so far and looking for the destination vertex. if there is no path to the destination vertex the algorithm returns -1.

shortestPath: This function accepts source and destination keys and checks the shortest path between them. the algorithm uses a priority queue to keep the nodes that the algorithm will check and set a mark to not add them again to the queue after polling them, the priority of the queue is the AlgoNodeInfo weight distance from the source vertex so far and looking for the destination vertex. For each vertex in the queue, the algorithm checks his directed edge distance, and the closest to the source set itself as a parent in AlgoNodeInfo, after the algorithm finishes, it sorts the node_data of the parent by weight and returns a List of the path. If there no path the algorithm returns null.

save: This function save the current grapn in JSON format - {"Edges":[{"src":1,"w":2.113816467537033,"dest":2},{"src":1,"w":1.3658974357026388,"dest":3}],"Nodes":[{"pos":"0.0,0.0,0.0","id":1},{"pos":"0.0,0.0,0.0","id":2},{"pos":"0.0,0.0,0.0","id":3}]}

load: This function load a JSON file and create a graph from it. the format- {"Edges":[{"src":1,"w":2.113816467537033,"dest":2},{"src":1,"w":1.3658974357026388,"dest":3}],"Nodes":[{"pos":"0.0,0.0,0.0","id":1},{"pos":"0.0,0.0,0.0","id":2},{"pos":"0.0,0.0,0.0","id":3}]}

game_servise - This interface we didn't need to implement only been used in the gameClient package.

gameClient

The gameClient contains classes of the GUI and information of the game.

unit: Storage class given with the assignment to translate the location of the objects of the game to the window coordination of the game in play. include class Point3D, Rang, Rand2D, Rang2Rang.

CL_Agents- Represent an agent in the game. The object of CL_Agent has a unique ID, value, speed, source key to start with, and destination key, in addition, the object can keep his current edge and pokemon he needs to catch.

CL_Pokemon- Represents a pokemon in the game. The object of CL_Apokemon has a value and a type {-1,1} associated with the direction of the edge it's on, the pokemon keeps the edge it's on.

Arena - Represents the area of the playground and keeps all information. The arena class load JSON files and translate them to lists of CL_Agents, CL_pokemons, and directed_weighted_graph.

myFram - Create the window of the game and initialize myPanel object.

MyPanel - The class that draws the play. myPanel has a function that draws the graph by its vertexes and edges, a function that draws the agent by its id this function has 4 types of Pokeball icons that choose repeatedly, a function that draws the pokemon by its value and it splits into four options, type of the pokemon is 1 and the value is [0,10) will be Psyduck, type of the pokemon is 1 and the value is more than 10 will be Charmander, type of the pokemon is -1 and the value is [0,10) will be Jigglypuff, type of the pokemon is -1 and the value is more than 10 will be Snorlax. In addition, this class has a function that draws the information about the game on the top.

Ex2_client- This class represents the scenario that the player chooses. This class initializes the GUI of the scenario and chooses the first position of the agents. This class runs until the game ends and moves the agents on the board by the shortest path to the biggest closest pokemon not chosen by the other agents on the graph. If there are not any pokemon to go they will wait for the next pokemon to appear.

Ex2 -This class is the GUI of the login in the beginning. this class starts a scenario for an ID and creates a new game for the player to play. if the program starts from the CMD with ID and a scenario the class will avoid the login window and will start the scenario.

Additional files

data - This directory keeps all JSON files for the game to run, and all pictures used with the GUI classes.

test - This directory keeps the tests we do to inform that the function we wrote worked properly.

Ex2.jar - The jar to run the program.