-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameTile.cs
144 lines (126 loc) · 4.27 KB
/
GameTile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// <c>Game Tile</c> Class.
/// Contains all info about each individual game tile.
/// </summary>
public class GameTile
{
/// <summary>
/// Read only self implemented property that returns the name of the tile.
/// </summary>
/// <value>Name of the tile (terrain).</value>
public string Name { get; }
/// <summary>
/// Read only self implemented property that returns the base coin value of
/// the tile.
/// </summary>
/// <value>Base Coin of the game tile.</value>
public int BaseCoin { get; }
/// <summary>
/// Read only self implemented property that returns the base food value of
/// the tile.
/// </summary>
/// <value>Base Food of the game tile.</value>
public int BaseFood { get; }
/// <summary>
/// Read only property that returns the total coin value of this game tile,
/// based on it's resources and base value.
/// </summary>
/// <value>Total Coin value of the game tile.</value>
public int Coin
{
get
{
int resourcesCoinSum = 0;
foreach (Resource r in Resources)
resourcesCoinSum += r.Coin;
return BaseCoin + resourcesCoinSum;
}
}
/// <summary>
/// Read only property that returns the total food value of this game tile,
/// based on it's resources and base value.
/// </summary>
/// <value>Total Food of the game tile.</value>
public int Food
{
get
{
int resourcesFoodSum = 0;
foreach (Resource r in Resources)
resourcesFoodSum += r.Food;
return BaseFood + resourcesFoodSum;
}
}
/// <summary>
/// Read only self implemented property that returns the base and hovered
/// of this tile/terrain.
/// </summary>
/// <value>Base and Hovered sprites.</value>
public IReadOnlyList<Sprite> Sprites { get; }
/// <summary>
/// Read only self implemented property that stores all the current resources
/// of this game tile.
/// </summary>
/// <value>Current resources of the game tile.</value>
public IReadOnlyList<Resource> Resources => _resourceList;
/// <summary>
/// Private list of Resources.
/// </summary>
private List<Resource> _resourceList;
/// <summary>
/// Constructor method.
/// Sets properties' values and initializes resources list.
/// </summary>
/// <param name="p_name">Name.</param>
/// <param name="p_coin">Coin Value.</param>
/// <param name="p_food">Food Value.</param>
/// <param name="p_sprites">Base and Hovered sprites.</param>
public GameTile(string p_name, int p_coin, int p_food, IReadOnlyList<Sprite> p_sprites)
{
Name = p_name;
BaseCoin = p_coin;
BaseFood = p_food;
Sprites = p_sprites;
// Initializes list.
_resourceList = new List<Resource>();
}
/// <summary>
/// Adds a resource to the list and sorts it alphabetically.
/// </summary>
/// <param name="resource">Resource to add to tile.</param>
public void AddResource(Resource resource)
{
_resourceList.Add(resource);
_resourceList.Sort();
}
/// <summary>
/// Removes a resource from the list.
/// </summary>
/// <param name="resource">Resource to remove from tile.</param>
public void RemoveResource(Resource resource)
{
_resourceList.Remove(resource);
}
/// <summary>
/// Shows all of the tile's important information.
/// </summary>
/// <remarks>Specially useful for debugging.</remarks>
/// <returns>A string with all of the tile's info</returns>
public override string ToString()
{
// String to return.
string m_info = $"\t || {Name} [BC: {BaseCoin}, BF: {BaseFood}] ||";
// Goes through each resource.
foreach (Resource resource in Resources)
{
// Stores relevant resource information in temporary string.
m_info += $" + {resource.Name} [C: {resource.Coin}, F: {resource.Food}]";
}
// Stores current total Coin and Food values in temporary string.
m_info += $" => [C: {Coin}, F: {Food}]";
// Return said string.
return m_info;
}
}