made some progress
This commit is contained in:
51
fordulo_3/Program/Virus.cs
Normal file
51
fordulo_3/Program/Virus.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Program
|
||||
{
|
||||
public class Virus
|
||||
{
|
||||
public int Name { get; set; }
|
||||
public Virus Parent { get; set; }
|
||||
public List<Virus> Infected { get; private set; }
|
||||
public int InfectionTurn { get; set; }
|
||||
|
||||
public Virus(int name, int infectionTurn = 0)
|
||||
{
|
||||
Name = name;
|
||||
Infected = new List<Virus>();
|
||||
InfectionTurn = infectionTurn;
|
||||
}
|
||||
|
||||
public Virus(int name, Virus parent, int infectionTurn = 0) : this(name, infectionTurn)
|
||||
{
|
||||
Parent = parent;
|
||||
}
|
||||
|
||||
public void Infect(Virus virus)
|
||||
{
|
||||
virus.Parent = this;
|
||||
Infected.Add(virus);
|
||||
}
|
||||
|
||||
public void PrintInfectionTree(string indent = "")
|
||||
{
|
||||
Console.WriteLine($"{indent}Virus {Name}");
|
||||
foreach (var infected in Infected)
|
||||
{
|
||||
infected.PrintInfectionTree(indent + " ");
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintInfectionTreeWithDepth(int maxDepth, int currentDepth = 0, string indent = "")
|
||||
{
|
||||
if (currentDepth > maxDepth) return;
|
||||
|
||||
Console.WriteLine($"{indent}Virus {Name}");
|
||||
foreach (var infected in Infected)
|
||||
{
|
||||
infected.PrintInfectionTreeWithDepth(maxDepth, currentDepth + 1, indent + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user