Skip to content
Snippets Groups Projects
Commit 2cf08158 authored by peters's avatar peters
Browse files

Game.swift commentaries

Game.swift has now full commentaries for all attributes and methods.
parent a384521e
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,9 @@
//
import Foundation
/**
Enum holds the different modes in which the game can be. Add more if needed.
*/
enum modes {
case exploration, station, menu, inventory, task, task1
......@@ -27,7 +29,10 @@ enum modes {
}
}
}
/**
Enum holds the different stations. It also holds representations of the stations as strings for printing out or debugging.
Add more station in here and afterwards implement them at the end of the file, see example passwords and socialmedia.
*/
enum gamestations {
case none, passwords, socialmedia, wellbeing
......@@ -44,62 +49,109 @@ enum gamestations {
}
}
}
/**
This class holds all the functionality of the interal representation of the game, and all the functionality to set and get it.
So most of the attributes and methods are static, because there is only one game. Different instances of the game make no sense.
*/
class Game {
/// internal representation of the mode of the game. The game starts in menu, so the variable is initialized with this value.
private static var mode : modes = .menu
/**
Sets the actual mode of the game.
- Parameter mode: New mode in which the game is in. Possible values come from the enum modes.
*/
public static func setMode (mode:modes) {
Game.mode = mode
}
/**
Returns the actual mode of the game.
- Returns: Mode in which the game is. Modes are in the enum modes.
*/
public static func getMode () -> modes {
return Game.mode
}
/**
Returns if the game is in mode menu.
- Returns: True if game mode is menu, otherwise false.
*/
public static func isInMenu () -> Bool {
if Game.mode == .menu {
return true
}
return false
}
/**
Returns if the game is in mode exploration.
- Returns: True if game mode is exploration, otherwise false.
*/
public static func isInExploration () -> Bool {
if Game.mode == .exploration {
return true
}
return false
}
/**
Returns if the game is in mode station.
- Returns: True if game mode is station, otherwise false.
*/
public static func isInStation () -> Bool {
if Game.mode == .station {
return true
}
return false
}
/**
Returns if the game is in mode inventory.
- Returns: True if game mode is inventory, otherwise false.
*/
public static func isInInventory () -> Bool {
if Game.mode == .inventory {
return true
}
return false
}
/**
Returns if the game is in mode task.
- Returns: True if game mode is task, otherwise false.
*/
public static func isInTask () -> Bool {
if Game.mode == .task {
return true
}
return false
}
/**
Returns if the game is in mode task1.
- Returns: True if game mode is task1, otherwise false.
*/
public static func isInTask1 () -> Bool {
if Game.mode == .task1 {
return true
}
return false
}
/// The array of all stations that were set up and added
private static var stations : [Station] = []
/**
Adds the given station to the internal array of stations.
- Parameter station: The station that should be added. The station should be set up correctly before.
*/
private static func addStation (station:Station) {
Game.stations.append(station)
}
/**
Returns a specific station at a position in the internal array of stations.
IMPORTANT: No check is done if the position is out of bounds of the array. Be careful.
- Returns: The station at the position of the internal array
*/
private static func getStation (position:Int) -> Station {
return Game.stations[position]
}
/**
Function returns a station with the given name or nil if no station with the name exists.
- Parameter name: Name of the searched/specific station
- Returns: Station with the given name or nil if no such station exists.
*/
private static func getStation (name:String) -> Station? {
for station in Game.stations {
if station.getName() == name {
......@@ -108,16 +160,25 @@ class Game {
}
return nil
}
/**
Removes all stations from the internal array. Function is needed to do a full reset of the game.
*/
private static func removeStations () {
Game.stations.removeAll()
}
/**
Returns all stations that where set-up in the initialization of the game.
- Returns: All stations as an array of objects of type Station.
*/
public static func getStations () -> [Station] {
return Game.stations
}
/*
/**
Returns all stations that are solved. So the inventory can show the collectables already achieved.
- Returns: Returns all solved stations as an array of objects of type Station.
*/
public static func getSolvedStations () -> [Station] {
var solved : [Station] = []
......@@ -129,17 +190,26 @@ class Game {
return solved
}
/// The actual station where the game is in. Initialized with gamestations.none.
private static var station : gamestations = .none
/**
Sets the actual station.
- Parameter station: The actual station. Must be an entry of enum gamestations.
*/
public static func setActStation (station : gamestations) {
self.station = station
}
/**
Returns the actual station where the game is.
- Returns: The actual station where the game is.
*/
public static func getActStation () -> gamestations {
return self.station
}
/*
/**
Resets all game variables to start again.
Function should be called at the start of the application and when a button for resetting is pressed.
In all other cases the pupils can go resume the game from the main menu with the opened stations.
......@@ -165,12 +235,16 @@ class Game {
print("Game has been resetted.")
}
/*
Ranking Passwords; 3) Nutzungsarten: Gemeinsam genutztes Passwort, persönliches Passwort, Einmal-Passwort; 4) Alternativen: 2-Faktor-Authentifizerung - Legen eines geforderten Musters mit Legesteinen; 5) gute und schlechte Aufbewahrungsmöglichkeiten von Passwörtern - Post-it unter der Tastatur, als Notiz im Handy, als Klartextdatei auf dem Computer, Passwortmanager; 6) Start-Ende
/**
Function sets up the station Passwords with five tasks as we have a cube:
First, the station gets an internal name "Station Passwords", and it is set to be not solved yet.
Second, the tasks are added. Every task gets a name an a description and is set to be not solved yet.
Afterwards every task is added to the station.
- Returns: Function returns the final station as an object of Station.
*/
private static func _prepareStationPasswords () -> Station{
let passwords = Station()
passwords.setName(name: "Station Password")
passwords.setName(name: "Station Passwords")
passwords.setSolved(solved: false)
let task1 = Task()
......@@ -206,10 +280,17 @@ class Game {
return passwords
}
/**
Function sets up the station Social Media with five tasks as we have a cube:
First, the station gets an internal name "Station Social Media", and it is set to be not solved yet.
Second, the tasks are added. Every task gets a name an a description and is set to be not solved yet.
Afterwards every task is added to the station.
IMPORTANT: In the actual state of the game this station is never used. There is no artifact in the real world to be scanned. So this is more of an example how to set up new stations. You should give every task a specific name and description.
- Returns: Function returns the final station as an object of Station.
*/
private static func _prepareStationSocialmedia () -> Station{
let passwords = Station()
passwords.setName(name: "Station Media")
passwords.setName(name: "Station Social Media")
passwords.setSolved(solved: false)
let task1 = Task()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment