This commit is contained in:
2025-06-30 08:48:08 +02:00
parent e0b5a14a55
commit d3ed2d922e
3 changed files with 69 additions and 43 deletions

View File

@ -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)
{
switch (directionFacing)

View File

@ -1,23 +1,24 @@
public class Map
{
public int sizeY = 10;
public int sizeX = 10;
public int sizeY = 100;
public int sizeX = 100;
// 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 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');
break;
}
else
{
Console.Write('V');
}
Console.Write('.');
}
Console.WriteLine();
}

View File

@ -1,4 +1,5 @@
using System;
using System.Threading;
namespace meise
{
@ -12,8 +13,17 @@ namespace meise
List<Armeise> colony = new List<Armeise>();
colony = Armeise.PrintColonyStateForEachArmeiseInTheColonyExistingIfItHasPositionAndType();
Armeise.ShowStats(colony);
while (true)
{
foreach (Armeise meise in colony)
{
meise.MoveRandom();
}
mapInstance.DrawMap(colony.ToArray());
Thread.Sleep(1000);
}
}
}
}