Пример #1
0
        static void Main(string[] args)
        {
            // Create world

            var ship1 = new Frigate(objectId: 1, objectTypeId: 1, armor: 200, resistance: 40f);
            var ship2 = new Frigate(objectId: 2, objectTypeId: 1, armor: 200, resistance: 40f);
            var ship3 = new Frigate(objectId: 3, objectTypeId: 1, armor: 200, resistance: 40f);
            var ship4 = new Frigate(objectId: 4, objectTypeId: 1, armor: 200, resistance: 40f);
            var ship5 = new Frigate(objectId: 5, objectTypeId: 2, armor: 300, resistance: 50f);
            var ship6 = new Frigate(objectId: 6, objectTypeId: 2, armor: 300, resistance: 50f);
            var ship7 = new Frigate(objectId: 7, objectTypeId: 2, armor: 300, resistance: 50f);
            var ship8 = new Frigate(objectId: 8, objectTypeId: 1, armor: 200, resistance: 40f);
            var fleet1 = new Fleet(objectId: 10, objectTypeId: 5) { Ships = new[] { ship1, ship2, ship3, ship4, ship8 } };
            var fleet2 = new Fleet(objectId: 11, objectTypeId: 5) { Ships = new[] { ship5, ship6, ship7 } };
            var world = new ModelObject[] { ship1, ship2, ship3, ship4, ship5, ship6, ship7, ship8, fleet1, fleet2 };

            // Create rules & strategies

            var rules = new object[0];
            var actors = new List<ModelObject> { ship1, ship2, ship3, ship4, ship5, ship6, ship7, ship8 };
            var activeActor = actors[0];

            long turnCount = 1;
            int millisecondsInTurn = 10;

            // Circle of life

            while (!IsFightComplete(world))
            {
                Console.Clear();

                var turnStartTime = DateTime.Now;
                Console.WriteLine("==> Turn: {0}. Actor ID: {1}.", turnCount, activeActor.ObjectId);

                PerformTurn(activeActor, world, Attack);

                ShowWorld(world);

                activeActor = NextActor(activeActor, actors);
                turnCount++;

                var turnEndTime = DateTime.Now;
                var turnMilliseconds = (turnEndTime - turnStartTime).TotalMilliseconds;
                var millisecondsToWait = Math.Max(0, millisecondsInTurn - turnMilliseconds);
                Console.WriteLine("Turn took {0} ms. Waiting for {1} to complete the turn.", turnMilliseconds, millisecondsToWait);

                Thread.Sleep((int)millisecondsToWait);
            }
        }
Пример #2
0
 public static void ShowFleet(Fleet fleet)
 {
     Console.WriteLine("Fleet ID: {0}, Ship ids: {1}.", fleet.ObjectId, string.Join(",", fleet.Ships.Select(ship => ship.ObjectId)));
 }