コード例 #1
0
 public void ShowField()
 {
     Console.Clear();
     for (ImmovableObject first = First; first != null; first = first.Down)
     {
         for (ImmovableObject firstToRight = first; firstToRight != null; firstToRight = firstToRight.Right)
         {
             if (firstToRight is StandardTrack)
             {
                 if (firstToRight.InUseBy() is Cart)
                 {
                     Console.Write('C');
                 }
                 else
                 {
                     Console.Write('-');
                 }
             }
             else if (firstToRight is Yard)
             {
                 Console.Write('Y');
             }
             else if (firstToRight is Empty)
             {
                 Console.Write(' ');
             }
             else if (firstToRight is StartingPoint)
             {
                 if (firstToRight.InUseBy() is Cart)
                 {
                     Console.Write('C');
                 }
                 else
                 {
                     Console.Write('S');
                 }
             }
             else if (firstToRight is Dock)
             {
                 Console.Write('D');
             }
             else if (firstToRight is Switch)
             {
                 if (firstToRight.InUseBy() is Cart)
                 {
                     Console.Write('C');
                 }
                 else
                 {
                     Console.Write('#');
                 }
             }
         }
         Console.WriteLine();
     }
 }
コード例 #2
0
        private ImmovableObject GetObject(char type, int row)
        {
            ImmovableObject immovableObject = null;

            switch (type)
            {
            case '-':
                immovableObject = new StandardTrack();
                break;

            case 'S':
                immovableObject = new StartingPoint();
                _startingPoints.Add(immovableObject as StartingPoint);
                break;

            case 'E':
                immovableObject = new DoubleEntranceSwitch();
                _switches.Add(immovableObject as Switch);
                break;

            case 'X':
                immovableObject = new DoubleExitSwitch();
                _switches.Add(immovableObject as Switch);
                break;

            case 'Y':
                immovableObject = new Yard();
                break;

            case 'D':
                immovableObject = new Dock(this);
                _dock           = immovableObject as Dock;
                break;

            case '.':
                immovableObject = new EndPoint();
                break;

            case ' ':
                immovableObject = new Empty();
                break;
            }
            return(immovableObject ?? null);
        }
コード例 #3
0
        public void Update(object sender, NotifyEventArgs args)
        {
            Console.Clear();

            #region Boat drawing
            string BoatLane = GetBoatLaneString();

            Console.WriteLine("┌────────────┐");
            Console.WriteLine("~~~~~~~~~~~~~~");
            Console.WriteLine("~~~~~~~~~~~~~~");
            Console.WriteLine(BoatLane);


            #endregion

            #region Map drawing
            ImmovableObject First = _gameController.GetPathFirst();

            var rowindex  = 0;
            var cellindex = 0;
            for (var row = First; row != null; row = row.Down)
            {
                rowindex++;
                cellindex = 0;

                Console.Write("│");
                for (var cell = row; cell != null; cell = cell.Right)
                {
                    cellindex++;
                    if (cell.InUseBy() != null)
                    {
                        if (cell.InUseBy() is Cart fullCart && fullCart.IsFull)
                        {
                            Console.Write("Ü");
                        }
                        else if (cell.InUseBy() is Cart emptyCart && !emptyCart.IsFull)
                        {
                            Console.Write("U");
                        }
                    }