# HG changeset patch # User Alys Brooks # Date 2022-01-22 23:47:09 # Node ID 07e6179554d085cbc5db22c4ea81ecd0ccc035fa # Parent b5bd408780c7c7f9ac968869b73d623c5b9089dd Update Cell to follow C# convention while I'm here. diff --git a/isometric-park-fna/CellMap.cs b/isometric-park-fna/CellMap.cs --- a/isometric-park-fna/CellMap.cs +++ b/isometric-park-fna/CellMap.cs @@ -75,7 +75,7 @@ { foreach (Cell cell in row) { - if (cell.hasTree) + if (cell.HasTree) { yield return cell; } @@ -89,7 +89,7 @@ { foreach (Cell cell in row) { - if (cell.hasTree) + if (cell.HasTree) { yield return cell; } @@ -155,7 +155,7 @@ int count = 0; foreach (Cell neighbor in this.iterate_neighbors(x, y)) { - if (neighbor.hasTree) { + if (neighbor.HasTree) { count++; } } @@ -193,15 +193,14 @@ public class Cell { - // public Boolean _hasTree = false; - public CellStatus status { + public CellStatus Status { get; private set; } public String StatusAdjective { get { - return this.status.ToString().Replace("Tree", ""); + return this.Status.ToString().Replace("Tree", ""); } } @@ -216,28 +215,28 @@ } } - public Boolean hasTree { + public Boolean HasTree { get { - return this.status == CellStatus.LivingTree; + return this.Status == CellStatus.LivingTree; } } - public DateTime planted; + public DateTime Planted; - public void addTree(DateTime datetime, TreeType type) { - this.status = CellStatus.LivingTree; + public void AddTree(DateTime datetime, TreeType type) { + this.Status = CellStatus.LivingTree; - this.planted = datetime; + this.Planted = datetime; this.Type = type; } - public void removeTree() { - this.status = CellStatus.Clear; + public void RemoveTree() { + this.Status = CellStatus.Clear; } - public void markTreeDead() { - this.status = CellStatus.DeadTree; + public void MarkTreeDead() { + this.Status = CellStatus.DeadTree; } } } diff --git a/isometric-park-fna/Engines/SimulationBridgeEngine.cs b/isometric-park-fna/Engines/SimulationBridgeEngine.cs --- a/isometric-park-fna/Engines/SimulationBridgeEngine.cs +++ b/isometric-park-fna/Engines/SimulationBridgeEngine.cs @@ -151,7 +151,7 @@ var squares = HasComponent(entity) ? GetComponent(entity).squares : this.all_squares; var removed = 0; var added = 0; - var tree_squares = squares.Where((square) => simulation.map.cells[(int)square.X][(int)square.Y].hasTree); + var tree_squares = squares.Where((square) => simulation.map.cells[(int)square.X][(int)square.Y].HasTree); var to_remove = Math.Abs(delta.deltaTrees.Value); //calculate the probability in order to get the expected number of removed trees @@ -162,18 +162,18 @@ foreach (var square in tree_squares) { var cell = simulation.map.cells[(int)square.X][(int)square.Y]; - if (cell.hasTree + if (cell.HasTree && random_generator.NextDouble() < probability) { if (delta.deltaTrees.Value < 0) { - cell.removeTree(); + cell.RemoveTree(); removed++; } else if (delta.deltaTrees.Value > 0) { var random_type = random_generator.Next(0, 1); - cell.addTree(this.simulation.DateTime, (CellMap.TreeType)random_type); + cell.AddTree(this.simulation.DateTime, (CellMap.TreeType)random_type); added++; } } diff --git a/isometric-park-fna/Engines/Spawners/GameSpawner.cs b/isometric-park-fna/Engines/Spawners/GameSpawner.cs --- a/isometric-park-fna/Engines/Spawners/GameSpawner.cs +++ b/isometric-park-fna/Engines/Spawners/GameSpawner.cs @@ -55,7 +55,7 @@ int random_type = random_generator.Next(0, 2); - cell.addTree(random_date, (TreeType)random_type); + cell.AddTree(random_date, (TreeType)random_type); } } } diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs --- a/isometric-park-fna/FNAGame.cs +++ b/isometric-park-fna/FNAGame.cs @@ -728,7 +728,7 @@ { for (int j = 0; j < this.simulation.map.MapWidth; j += 1) { - if (this.simulation.map.cells[i][j].hasTree) + if (this.simulation.map.cells[i][j].HasTree) { //until we actually simulate: if (this.simulation.map.cells[i][j].Type == TreeType.GenericDeciduous) { drawTileAt(i, j, 142, 2); @@ -745,7 +745,7 @@ // drawTileAt(i, j, 142, 2); // } } - else if (this.simulation.map.cells[i][j].status == CellStatus.DeadTree) { + else if (this.simulation.map.cells[i][j].Status == CellStatus.DeadTree) { drawTileAt(i, j, 141, 2); // System.Console.WriteLine(String.Format("Drew Dead Tree at {0},{1}", i, j)); } @@ -777,14 +777,14 @@ if (MathUtils.BetweenExclusive(this.mouseGrid.X, 0, this.squaresAcross) && MathUtils.BetweenExclusive(this.mouseGrid.Y, 0, this.squaresAcross)) { - has_tree = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].hasTree; + has_tree = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].HasTree; } String status_left = ""; if (MathUtils.BetweenExclusive(this.mouseGrid.X, -1, this.simulation.map.MapWidth) && MathUtils.BetweenExclusive(this.mouseGrid.Y, -1, this.simulation.map.MapHeight)) { - var treeStatus = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].status; + var treeStatus = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].Status; var treeStatusAdjective = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].StatusAdjective; var treeType = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].TypeName; if (treeStatus != CellStatus.Clear) diff --git a/isometric-park-fna/Simulation.cs b/isometric-park-fna/Simulation.cs --- a/isometric-park-fna/Simulation.cs +++ b/isometric-park-fna/Simulation.cs @@ -201,7 +201,7 @@ public int crowded_trees { get { - return this.map.iterate_cells_with_neighbors(7).Where(c => c.hasTree).Count(); + return this.map.iterate_cells_with_neighbors(7).Where(c => c.HasTree).Count(); } } @@ -209,14 +209,14 @@ public int dead_trees { get { - return this.map.iterate_cells().Where(c => (c.status == CellStatus.DeadTree)).Count(); + return this.map.iterate_cells().Where(c => (c.Status == CellStatus.DeadTree)).Count(); } } public float healthy_percent { get { - return (float)(this.map.tree_count - this.map.iterate_cells_with_neighbors(7).Where(c => c.hasTree).Count()) / this.map.tree_count * 100; + return (float)(this.map.tree_count - this.map.iterate_cells_with_neighbors(7).Where(c => c.HasTree).Count()) / this.map.tree_count * 100; } } @@ -224,7 +224,7 @@ { get { - return this.map.iterate_cells().Where(c => c.hasTree).Select(c => (this.DateTime - c.planted).Days / 365.0).Average(); + return this.map.iterate_cells().Where(c => c.HasTree).Select(c => (this.DateTime - c.Planted).Days / 365.0).Average(); } } @@ -232,7 +232,7 @@ { get { - return this.map.iterate_cells().Where(c => c.hasTree).Select(c => (this.DateTime - c.planted).Days / 365.0).Max(); + return this.map.iterate_cells().Where(c => c.HasTree).Select(c => (this.DateTime - c.Planted).Days / 365.0).Max(); } } @@ -271,7 +271,7 @@ if (random.NextDouble() > SPONTANEOUS_NEW_TREE_CHANCE) { var random_type = random.Next(0, 2); - cell.addTree(this.DateTime, (TreeType)random_type); + cell.AddTree(this.DateTime, (TreeType)random_type); } } @@ -281,7 +281,7 @@ if (random.NextDouble() > NEIGHBOR_NEW_TREE_CHANCE) { var random_type = random.Next(0, 2); - cell.addTree(this.DateTime, (TreeType)random_type); + cell.AddTree(this.DateTime, (TreeType)random_type); new_planted += 1; } } @@ -291,7 +291,7 @@ { if (random.NextDouble() > NEIGHBOR_CROWDS_TREE_CHANCE) { - cell.markTreeDead(); + cell.MarkTreeDead(); crowded_out += 1; } } @@ -303,19 +303,19 @@ int x = random.Next(0, this.map.MapWidth); Cell chosen_cell = this.map.cells[x][y]; - if (!chosen_cell.hasTree) { + if (!chosen_cell.HasTree) { var random_type = random.Next(0, 2); - chosen_cell.addTree(this.DateTime, (TreeType)random_type); + chosen_cell.AddTree(this.DateTime, (TreeType)random_type); trees_to_plant -= 1; } } int trees_to_clear = this.tree_clearing; - foreach (Cell cell in this.map.iterate_cells_with_neighbors(7).Where(c => c.hasTree)) + foreach (Cell cell in this.map.iterate_cells_with_neighbors(7).Where(c => c.HasTree)) { if (trees_to_clear > 0) { - cell.removeTree(); trees_to_clear -= 1; + cell.RemoveTree(); } }