How do we add each morg from the list of morgs
into the screen in random position? And then for each morg
we output a success message.
I am using the morg
Class in order to place them in random order.
I am using the petriDish
Class to keep the list of morg
, and add the morg
from the list to the screen.
I am using to Simulation Class to keep track of each morg
and then change their behavior later on.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewMorg
{
class Program
{
static void Main(string[] args)
{
Morg morg = new Morg(0, 0);
DisplayMorg currentDisplay = new DisplayMorg(morg);
currentDisplay.Display();
morg.SetDisplay(currentDisplay);
simulator sim = new simulator();
PetriDish dish = new PetriDish();
dish.AddMorg(morg);
sim.step();
}
}
// simulator used for petriDish
class simulator
{
private PetriDish dish;
public simulator()
{
dish = new PetriDish();
}
public void step()
{
foreach (Morg m in dish.morgs)
{
Console.WriteLine("SUCCESS !!!");
}
}
}
// petrDish
used for the list of morgs
class PetriDish
{
public List<Morg> morgs;
public PetriDish()
{
morgs = new List<Morg>();
}
public void AddMorg(Morg m)
{
morgs.Add(m);
}
}
// class containing morg
attributes
class Morg
{
private DisplayMorg display;
public Morg(int a, int b)
{
x = a;
y = b;
}
protected int x;
protected int y;
public int X { get { return x; } }
public int Y { get { return y; } }
public void SetDisplay(DisplayMorg display)
{ this.display = display; }
public void SetData(int x, int y)
{
this.x = x;
this.y = y;
if (display != null)
{
display.Display();
}
}
public void SetRandom()
{
Random x = new Random();
Random y = new Random();
this.x = x.Next(1, 101);
this.y = y.Next(1, 101);
if (display != null)
{
display.Display();
}
}
}