Gebaeude abstrakt implementiert
This commit is contained in:
183
Assets/Scripts/Buildings/ABuilding.cs
Normal file
183
Assets/Scripts/Buildings/ABuilding.cs
Normal file
@@ -0,0 +1,183 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
public abstract class ABuilding : IBuilding
|
||||
{
|
||||
//----------------------------------------------------------------------------
|
||||
// private object variables
|
||||
|
||||
private int _runningCost = 0;
|
||||
private int _scienceCapacity = 0;
|
||||
private int _foodCapacity = 0;
|
||||
private int _industrialCapacity = 0;
|
||||
private int _moneyCapacity = 0;
|
||||
|
||||
private int _militaryPower = 0;
|
||||
|
||||
private bool _isRunning = true;
|
||||
|
||||
private ABuilding.BuildingID _iD = 0;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
public enum BuildingID
|
||||
{
|
||||
Farm,
|
||||
Smeltery,
|
||||
Armory,
|
||||
Spaceport,
|
||||
Market,
|
||||
University
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Getters
|
||||
|
||||
public int GetRunningCost()
|
||||
{
|
||||
if (_isRunning)
|
||||
{
|
||||
return _runningCost;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetScienceCapacity()
|
||||
{
|
||||
if (_isRunning)
|
||||
{
|
||||
return _scienceCapacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetFoodCapacity()
|
||||
{
|
||||
if (_isRunning)
|
||||
{
|
||||
return _foodCapacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetIndustrialCapacity()
|
||||
{
|
||||
if (_isRunning)
|
||||
{
|
||||
return _industrialCapacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetMoneyCapacity()
|
||||
{
|
||||
if (_isRunning)
|
||||
{
|
||||
return _moneyCapacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetMilitaryPower()
|
||||
{
|
||||
if (_isRunning)
|
||||
{
|
||||
return _militaryPower;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRunning()
|
||||
{
|
||||
return _isRunning;
|
||||
}
|
||||
|
||||
public ABuilding.BuildingID GetId()
|
||||
{
|
||||
return _iD;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Setters
|
||||
|
||||
public void SetRunningCost(int newRunningCost)
|
||||
{
|
||||
if (newRunningCost > 0)
|
||||
{
|
||||
_runningCost = newRunningCost;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetScienceCapacity(int newScienceCapacity)
|
||||
{
|
||||
if (newScienceCapacity >= 0)
|
||||
{
|
||||
_scienceCapacity = newScienceCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFoodCapacity(int newFoodCapacity)
|
||||
{
|
||||
if (newFoodCapacity >= 0)
|
||||
{
|
||||
_foodCapacity = newFoodCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIndustrialCapacity(int newIndustrialCapacity)
|
||||
{
|
||||
_industrialCapacity = newIndustrialCapacity;
|
||||
}
|
||||
|
||||
public void SetMoneyCapacity(int newMoneyCapacity)
|
||||
{
|
||||
if (newMoneyCapacity >= 0)
|
||||
{
|
||||
_moneyCapacity = newMoneyCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMilitaryPower(int newMilitaryPower)
|
||||
{
|
||||
if (newMilitaryPower >= 0)
|
||||
{
|
||||
_militaryPower = newMilitaryPower;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetRunning(bool newRunning)
|
||||
{
|
||||
_isRunning = newRunning;
|
||||
}
|
||||
|
||||
public void SetId(ABuilding.BuildingID newId)
|
||||
{
|
||||
_iD = newId;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
44
Assets/Scripts/Buildings/BuildingBuilder.cs
Normal file
44
Assets/Scripts/Buildings/BuildingBuilder.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
public static class BuildingBuilder
|
||||
{
|
||||
public static ABuilding Build(ABuilding.BuildingID eBuilding)
|
||||
{
|
||||
switch (eBuilding)
|
||||
{
|
||||
case ABuilding.BuildingID.Farm:
|
||||
{
|
||||
return new Farm();
|
||||
}
|
||||
|
||||
case ABuilding.BuildingID.Smeltery:
|
||||
{
|
||||
return new Smeltery();
|
||||
}
|
||||
|
||||
case ABuilding.BuildingID.Armory:
|
||||
{
|
||||
return new Armory();
|
||||
}
|
||||
|
||||
case ABuilding.BuildingID.Spaceport:
|
||||
{
|
||||
return new Spaceport();
|
||||
}
|
||||
|
||||
case ABuilding.BuildingID.Market:
|
||||
{
|
||||
return new Market();
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
169
Assets/Scripts/Buildings/BuildingManager.cs
Normal file
169
Assets/Scripts/Buildings/BuildingManager.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
/// <summary>
|
||||
/// Class <c>BuildingManager</c> contains functions to sum up values from buidlings at star system.
|
||||
/// </summary>
|
||||
public class BuildingManager
|
||||
{
|
||||
Dictionary<int, List<IBuilding>> doPlayerBuildings = new Dictionary<int, List<IBuilding>>();
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetAllValues</c> sums up the running cost of all buildings at star system of player.
|
||||
/// <param><c>iId</c> is the id of a player.</param>
|
||||
/// <returns>Returns <c>all values</c> of all buildings at star system of player.</returns>
|
||||
/// More efficient because it iterates only once through list instead of 6 times.
|
||||
/// </summary>
|
||||
public BuildingValues GetAllValues(int iId)
|
||||
{
|
||||
BuildingValues oValues = new BuildingValues();
|
||||
List<IBuilding> loBuildings = doPlayerBuildings[iId];
|
||||
foreach (var oBuilding in loBuildings)
|
||||
{
|
||||
oValues.RunningCost += oBuilding.GetRunningCost();
|
||||
oValues.ScienceCapacity += oBuilding.GetScienceCapacity();
|
||||
oValues.FoodCapacity += oBuilding.GetFoodCapacity();
|
||||
oValues.IndustrialCapacity += oBuilding.GetIndustrialCapacity();
|
||||
oValues.MoneyCapacity += oBuilding.GetMoneyCapacity();
|
||||
oValues.MilitaryPower += oBuilding.GetMilitaryPower();
|
||||
}
|
||||
return oValues;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetRunningCost</c> sums up the running cost of all buildings at star system of player.
|
||||
/// <param><c>iId</c> is the id of a player.</param>
|
||||
/// <returns>Returns <c>running cost</c> of all buildings at star system of player.</returns>
|
||||
/// </summary>
|
||||
public int GetRunningCost(int iId)
|
||||
{
|
||||
int iRunningCost = 0;
|
||||
List<IBuilding> loBuildings = doPlayerBuildings[iId];
|
||||
foreach (var oBuilding in loBuildings)
|
||||
{
|
||||
iRunningCost += oBuilding.GetRunningCost();
|
||||
}
|
||||
return iRunningCost;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetScienceCapacity</c> sums up the science capacity of all buildings at star system of player.
|
||||
/// <param><c>iId</c> is the id of a player.</param>
|
||||
/// <returns>Returns <c>science capacity</c> of all buildings at star system of player.</returns>
|
||||
/// </summary>
|
||||
public int GetScienceCapacity(int iId)
|
||||
{
|
||||
int iScienceCapacity = 0;
|
||||
List<IBuilding> loBuildings = doPlayerBuildings[iId];
|
||||
foreach (var oBuilding in loBuildings)
|
||||
{
|
||||
iScienceCapacity += oBuilding.GetScienceCapacity();
|
||||
}
|
||||
return iScienceCapacity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetFoodCapacity</c> sums up the food capacity of all buildings at star system of player.
|
||||
/// <param><c>iId</c> is the id of a player.</param>
|
||||
/// <returns>Returns <c>food capacity</c> of all buildings at star system of player.</returns>
|
||||
/// </summary>
|
||||
public int GetFoodCapacity(int iId)
|
||||
{
|
||||
int iFoodCapacity = 0;
|
||||
List<IBuilding> loBuildings = doPlayerBuildings[iId];
|
||||
foreach (var oBuilding in loBuildings)
|
||||
{
|
||||
iFoodCapacity += oBuilding.GetFoodCapacity();
|
||||
}
|
||||
return iFoodCapacity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetIndustrialCapacity</c> sums up the industrial capacity of all buildings at star system of player.
|
||||
/// <param><c>iId</c> is the id of a player.</param>
|
||||
/// <returns>Returns <c>industrial capacity</c> of all buildings at star system of player.</returns>
|
||||
/// </summary>
|
||||
public int GetIndustrialCapacity(int iId)
|
||||
{
|
||||
int iIndustrialCapacity = 0;
|
||||
List<IBuilding> loBuildings = doPlayerBuildings[iId];
|
||||
foreach (var oBuilding in loBuildings)
|
||||
{
|
||||
iIndustrialCapacity += oBuilding.GetIndustrialCapacity();
|
||||
}
|
||||
return iIndustrialCapacity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetMoneyCapacity</c> sums up the money capacity of all buildings at star system of player.
|
||||
/// <param><c>iId</c> is the id of a player.</param>
|
||||
/// <returns>Returns <c>money capacity</c> of all buildings at star system of player.</returns>
|
||||
/// </summary>
|
||||
public int GetMoneyCapacity(int iId)
|
||||
{
|
||||
int iMoneyCapacity = 0;
|
||||
List<IBuilding> loBuildings = doPlayerBuildings[iId];
|
||||
foreach (var oBuilding in loBuildings)
|
||||
{
|
||||
iMoneyCapacity += oBuilding.GetMoneyCapacity();
|
||||
}
|
||||
return iMoneyCapacity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetMilitaryCapacity</c> sums up the military capacity of all buildings at star system of player.
|
||||
/// <param><c>iId</c> is the id of a player.</param>
|
||||
/// <returns>Returns <c>military capacity</c> of all buildings at star system of player.</returns>
|
||||
/// </summary>
|
||||
public int GetMilitaryPower(int iId)
|
||||
{
|
||||
int iMilitaryPower = 0;
|
||||
List<IBuilding> loBuildings = doPlayerBuildings[iId];
|
||||
foreach (var oBuilding in loBuildings)
|
||||
{
|
||||
iMilitaryPower += oBuilding.GetMilitaryPower();
|
||||
}
|
||||
return iMilitaryPower;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>BuildNewBuilding</c> checks if building already exists, if not creates a new building and adds it to list.
|
||||
/// <param><c>iPlayerId</c> is the id of a player.</param>
|
||||
/// <param><c>eBuildingId</c> is the id of a building.</param>
|
||||
/// </summary>
|
||||
public void BuildNewBuilding(int iPlayerId, ABuilding.BuildingID eBuildingId)
|
||||
{
|
||||
List<IBuilding> loBuildings = doPlayerBuildings[iPlayerId];
|
||||
foreach (var oBuilding in loBuildings)
|
||||
{
|
||||
if (oBuilding.GetId() == eBuildingId)
|
||||
{
|
||||
// TODO throw exception
|
||||
}
|
||||
}
|
||||
loBuildings.Add(BuildingBuilder.Build(eBuildingId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>DestroyBuilding</c> checks if building exists, if it exists, deletes it from list, if not, returns value of Remove(null).
|
||||
/// <param><c>iPlayerId</c> is the id of a player.</param>
|
||||
/// <param><c>eBuildingId</c> is the id of a building.</param>
|
||||
/// </summary>
|
||||
public void DestroyBuilding(int iPlayerId, ABuilding.BuildingID eBuildingId)
|
||||
{
|
||||
List<IBuilding> loBuildings = doPlayerBuildings[iPlayerId];
|
||||
IBuilding building = null;
|
||||
foreach (var oBuilding in loBuildings)
|
||||
{
|
||||
if (oBuilding.GetId() == eBuildingId)
|
||||
{
|
||||
building = oBuilding;
|
||||
}
|
||||
}
|
||||
//TODO what does Remove return? handle
|
||||
loBuildings.Remove(building);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Assets/Scripts/Buildings/BuildingValues.cs
Normal file
25
Assets/Scripts/Buildings/BuildingValues.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
/// <summary>
|
||||
/// Class <c>BuildingValues</c> is a container to transport data.
|
||||
/// <value></value>
|
||||
/// <value>RunningCost is the running cost of a building.</value>
|
||||
/// <value>ScienceCapacity is the amount of science produced by the building.</value>
|
||||
/// <value>FoodCapacity is the amount of food produced by the building.</value>
|
||||
/// <value>IndustrialCapacity is the amount of industry produced by the building.</value>
|
||||
/// <value>MoneyCapacity is the amount of money produced by the building.</value>
|
||||
/// <value>MilitaryPower is the amount of military produced by the building.</value>
|
||||
/// </summary>
|
||||
public class BuildingValues
|
||||
{
|
||||
public int RunningCost = 0;
|
||||
public int ScienceCapacity = 0;
|
||||
public int FoodCapacity = 0;
|
||||
public int IndustrialCapacity = 0;
|
||||
public int MoneyCapacity = 0;
|
||||
public int MilitaryPower = 0;
|
||||
}
|
||||
}
|
||||
14
Assets/Scripts/Buildings/Food/Farm.cs
Normal file
14
Assets/Scripts/Buildings/Food/Farm.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
public class Farm : ABuilding
|
||||
{
|
||||
public Farm()
|
||||
{
|
||||
SetFoodCapacity(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
76
Assets/Scripts/Buildings/IBuilding.cs
Normal file
76
Assets/Scripts/Buildings/IBuilding.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface <c>IBuilding</c> defines the functions for the buildings.
|
||||
/// <param><c>iId</c> is the id of a player.</param>
|
||||
/// <returns>Returns <c>all values</c> of all buildings at star system of player.</returns>
|
||||
/// More efficient because it iterates only once through list instead of 6 times.
|
||||
/// </summary>
|
||||
public interface IBuilding
|
||||
{
|
||||
//----------------------------------------------------------------------------
|
||||
// Getters
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetRunningCost</c> returns the running cost if the building is running.
|
||||
/// </summary>
|
||||
public int GetRunningCost();
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetScienceCapacity</c> returns the amount of science the building produces if it is running.
|
||||
/// </summary>
|
||||
public int GetScienceCapacity();
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetFoodCapacity</c> returns the amount of food the building produces if it is running.
|
||||
/// </summary>
|
||||
public int GetFoodCapacity();
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetIndustrialCapacity</c> returns the amount of industrial the building produces if it is running.
|
||||
/// </summary>
|
||||
public int GetIndustrialCapacity();
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetMoneyCapacity</c> returns the amount of money the building produces if it is running.
|
||||
/// </summary>
|
||||
public int GetMoneyCapacity();
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetMilitaryPower</c> returns the amount of power the building produces if it is running.
|
||||
/// </summary>
|
||||
public int GetMilitaryPower();
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>IsRunning</c> returns true if the building is running, false if the building is not running.
|
||||
/// </summary>
|
||||
public bool IsRunning();
|
||||
|
||||
/// <summary>
|
||||
/// Function <c>GetId</c> returns id of building.
|
||||
/// </summary>
|
||||
public ABuilding.BuildingID GetId();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Setters
|
||||
|
||||
public void SetRunningCost(int newRunningCost);
|
||||
public void SetScienceCapacity(int newScienceCapacity);
|
||||
public void SetFoodCapacity(int newFoodCapacity);
|
||||
public void SetIndustrialCapacity(int newIndustrialCapacity);
|
||||
public void SetMoneyCapacity(int newMoneyCapacity);
|
||||
public void SetMilitaryPower(int newMilitaryPower);
|
||||
|
||||
public void SetRunning(bool newRunning);
|
||||
|
||||
public void SetId(ABuilding.BuildingID newId);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
13
Assets/Scripts/Buildings/Industry/Smeltery.cs
Normal file
13
Assets/Scripts/Buildings/Industry/Smeltery.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
public class Smeltery : ABuilding
|
||||
{
|
||||
public Smeltery()
|
||||
{
|
||||
SetIndustrialCapacity(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Assets/Scripts/Buildings/Military/Armory.cs
Normal file
13
Assets/Scripts/Buildings/Military/Armory.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
public class Armory : ABuilding
|
||||
{
|
||||
public Armory()
|
||||
{
|
||||
SetMilitaryPower(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Assets/Scripts/Buildings/Misc/Spaceport.cs
Normal file
10
Assets/Scripts/Buildings/Misc/Spaceport.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
public class Spaceport : ABuilding
|
||||
{
|
||||
public Spaceport() { }
|
||||
}
|
||||
}
|
||||
16
Assets/Scripts/Buildings/Money/Market.cs
Normal file
16
Assets/Scripts/Buildings/Money/Market.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
/// <summary>
|
||||
/// Class <c>Market</c> defines the class for market.
|
||||
/// </summary>
|
||||
public class Market : ABuilding
|
||||
{
|
||||
public Market()
|
||||
{
|
||||
SetMoneyCapacity(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Assets/Scripts/Buildings/Science/University.cs
Normal file
13
Assets/Scripts/Buildings/Science/University.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBuilding
|
||||
{
|
||||
public class University : ABuilding
|
||||
{
|
||||
public University()
|
||||
{
|
||||
SetScienceCapacity(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user