armeisen
This commit is contained in:
@ -85,6 +85,21 @@ public class Armeise
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
public void MoveRandom()
|
||||||
|
{
|
||||||
|
Random rand = new Random();
|
||||||
|
if (rand.Next(0, 5) == 0)
|
||||||
|
{
|
||||||
|
this.TurnLeft();
|
||||||
|
}
|
||||||
|
else if (rand.Next(0, 5) == 1)
|
||||||
|
{
|
||||||
|
this.TurnRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Move(rand.Next(2, 7));
|
||||||
|
}
|
||||||
|
|
||||||
public void Move(int steps)
|
public void Move(int steps)
|
||||||
{
|
{
|
||||||
switch (directionFacing)
|
switch (directionFacing)
|
||||||
|
@ -1,23 +1,24 @@
|
|||||||
public class Map
|
public class Map
|
||||||
{
|
{
|
||||||
public int sizeY = 10;
|
public int sizeY = 100;
|
||||||
public int sizeX = 10;
|
public int sizeX = 100;
|
||||||
|
|
||||||
// Draws map line by line, replacing the V wit A if ant there
|
// Draws map line by line, replacing the V wit A if ant there
|
||||||
public void DrawMap(int armeiseX, int armeiseY)
|
public void DrawMap(Armeise[] armeisen)
|
||||||
{
|
{
|
||||||
for (int i = 0; i <= sizeY; i++)
|
for (int i = 0; i <= sizeY; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j <= sizeX; j++)
|
for (int j = 0; j <= sizeX; j++)
|
||||||
{
|
{
|
||||||
if (i == armeiseY && j == armeiseX)
|
foreach (Armeise armeise in armeisen)
|
||||||
|
{
|
||||||
|
if (i == armeise.posY && j == armeise.posX)
|
||||||
{
|
{
|
||||||
Console.Write('A');
|
Console.Write('A');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.Write('V');
|
|
||||||
}
|
}
|
||||||
|
Console.Write('.');
|
||||||
}
|
}
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace meise
|
namespace meise
|
||||||
{
|
{
|
||||||
@ -12,8 +13,17 @@ namespace meise
|
|||||||
|
|
||||||
List<Armeise> colony = new List<Armeise>();
|
List<Armeise> colony = new List<Armeise>();
|
||||||
colony = Armeise.PrintColonyStateForEachArmeiseInTheColonyExistingIfItHasPositionAndType();
|
colony = Armeise.PrintColonyStateForEachArmeiseInTheColonyExistingIfItHasPositionAndType();
|
||||||
Armeise.ShowStats(colony);
|
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
foreach (Armeise meise in colony)
|
||||||
|
{
|
||||||
|
meise.MoveRandom();
|
||||||
|
}
|
||||||
|
mapInstance.DrawMap(colony.ToArray());
|
||||||
|
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user