Technical Documentation - slindel/OOSE GitHub Wiki

1. UML Diagram

2. Scripts/classes

All scripts are written in C#:

MazeGeneration.cs, GUI_Stuff.cs, MovementScript.cs, NetworkManager.cs, Buttons.cs

2.1. MazeGeneration

In here a 2D array for the map of the maze is found. The 2D array consists of X's, O's and "."(dots). A double for-loop runs through the array, and stores its coordinates in a Vector3 variable. It checks the variable in each point ("X"/"O"/".") and instantiates the corresponding prefab in the current coordinate position: X will instantiate a wall prefab O will instantiate a bigball prefab (the bonus coins that give extra points) . will instantiate a ball prefab (the regular coins)

Moreover, the function that instantiates the player prefab is found inside this script as well. These functions are called in the NetworkManager script.

2.2. NetworkManager

In this script the network server is initialized on the Unity Master Server. Once it has been so, the current player becomes host, and the other player will be able to connect to the host via the unique name found on the master server. When a host is created, a player prefab (pacman) will be instantiated as its color will be broadcast as well. When a client connects to the server, another player prefab is instantiated (cop). The Buttons script is calling some function from here. The biggest problem we encountered was that even though player 1(host) receives its color over the internet, clients do not see player 1 having the color it should have, and vice-versa.

2.3. Buttons

Buttons.cs uses the NetworkManager and GUI_Stuff components; it creates buttons for the user to connect to netowork; if the "Start server"-button is pressed, the network server will be initialized, thus making the user the host. If the "Load servers"-button is clicked and there is a current host, yet another button will be instantiated with the host's name,and the second player will thereby be able to connect to the host server. Moreover, if the game is over, the Buttons component will determine the winner of the game by comparing the players' total scores. It will instantiate a new button for the host only, with the option to restart the game - however, the game re-load has not been fully implemented(the maze and the score ressets, but the player cannot be instantiated again) The scores during gameplay are printed by the GUI_Stuff script.

2.4. GUI_Stuff

This script prints and updates the players' scores during gamle, and long as there still are coins left in the maze; once all coins have been collected, the above mentioned game-over method will be called.

2.5. MovementScript

The player controls are collision detection is handled in here. Unity's "Character Control" component is added to allow for simple character movement. In Update(), the player's movement and placement in the map is updated; input of arrow keys are registered and used for horizontal and vertical movement on the map.

The collision is detected via the maze's gameobjects' names; should the player collide with any of the specific gameobject names (ball prefab, bonus ball prefab), points will be added to the score, and the gameobject will be destroyed from the scene.