I need help on a few things:
1- to fix my encapsulation
I want to write the get/set encapsulation so that the type 'Virus' is defined in the 'Humanity' namespace, but the method 'Mutate' takes an argument of this type and returns a value of this type. Is that correct as it is?
2- Do I need to use lock() when dealing with an enum write/read? In my case the value 'threatLevel'. Same question to the list 'except'. The 'Main_ImmunisationProgramme' method comes from the interface, and should be executed on a separate worker thread, initialized elsewhere in the namespace.
Can anyone help me out on that thought exercise? I'm not familiar with dealing with external DLLs without any documentation, and because this is nothing more than a random Sunday overthinking, I can't compile that to check if it works.
Also, how can I optimise my script so threatLevel value goes below ThreatLevel.Low and Vaccinated list grows bigger? I just wish we could all agree to get vaccinated. No big deal about it...
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Collections.Generic;
namespace Humanity
{
public abstract class GlobalPandemic : ImmunisationProgramme
{
[DllImport("covid.dll", EntryPoint="unknowable")]
public static extern bool Tick();
public static extern Virus Init();
public static extern ThreatLevel Mutate(Virus covid, out ThreatLevel threatLevel, out int seedInfect, out int seedKill);
public static extern Virus Covid
{
get
{
if (covid == null) return covid = Init();
return covid;
}
set
{
covid = value;
}
}
protected Virus covid;
protected List<Vaccine> vaccines;
protected List<People> except;
protected ThreatLevel threatLevel = ThreatLevel.Unknown;
public static void Main()
{
int sleep;
int seedInfect, seedKill;
Random rand;
while (Tick(out sleep) == true)
{
Covid = Mutate(Covid, out threatLevel, out seedInfect, out seedKill);
if (threatLevel > ThreatLevel.Low)
{
Console.WriteLine("Hello, World!");
Pester(WorldPopulation);
}
rand = new Random(seedInfect);
Infect(rand.Next(), except);
rand = new Random(seedKill);
Kill(rand, except);
Thread.Sleep(sleep);
}
}
public void Main_ImmunisationProgramme()
{
int sleep;
vaccines = new List<Vaccine>();
except = new List<People>();
while (Tick_Humanity(out sleep) == true)
{
ResearchAndDevelop<typeof(Covid)>(ref vaccines);
RaiseAwareness(WorldPopulation);
List<People> immunised = Vaccinate(WorldPopulation.Where(x => x.Brain != null), vaccines);
except.Add(immunised);
Thread.Sleep(sleep);
}
}
}
public enum ThreatLevel
{
None = -1,
Minimal = 0,
Low = 1,
Moderate = 2,
High = 3,
AbsoluteChaos = 4,
Unknown = 42
}
}
Aucun commentaire:
Enregistrer un commentaire