コード例 #1
0
        /// <summary>
        /// Generate Random Part
        /// </summary>
        public Part(bool[,] field)
        {
            bool[,] element1 = new bool[2, 3] { {true,false,false},
                                                {true,true,true}};

            bool[,] element2 = new bool[2, 3] { {false,true,false},
                                                {true,true,true}};
            bool[,] element3 = new bool[2, 3] { {false,false,false},
                                                {true,true,true}};
            bool[,] element4 = new bool[2, 3] { {true,true,false},
                                                {false,true,true}};
            bool[,] element5 = new bool[2, 3] { {false,true,true},
                                               {false,true,false}};

            List<bool[,]> availableElements = new List<bool[,]>()
            {
                element1,
                element2,
                element3,
                element4,
                element5
            };
            Random rng = new Random();

            this.elements = element2;
            this.position = new Position(0, 0);
            this.field = field;
        }
コード例 #2
0
 public Part(Position position, bool[,] elements, bool[,] field)
 {
     this.position = position;
     this.elements = elements;
     this.field = field;
 }
コード例 #3
0
 private bool CanMoveTo(Position newPosition)
 {
     try
     {
         Console.SetCursorPosition(newPosition.x, newPosition.y);
         switch (direction)
         {
             case Direction.Left:
                 for (int i = 0; i < elements.GetLength(1); i++)
                 {
                     for (int j = 0; j < elements.GetLength(0); j++)
                     {
                         if (elements[j, i] && field[newPosition.x + elements.GetLength(0) - 1 - j, Console.CursorTop])
                         {
                             return false;
                         }
                     }
                     Console.CursorTop++;
                     Console.CursorLeft = newPosition.x;
                 }
                 break;
             case Direction.Right:
                 for (int i = elements.GetLength(1) - 1; i >= 0; i--)
                 {
                     for (int j = 0; j < elements.GetLength(0); j++)
                     {
                         if (elements[j, i] && field[newPosition.x + j, Console.CursorTop])
                         {
                             return false;
                         }
                     }
                     Console.CursorTop++;
                     Console.CursorLeft = newPosition.x;
                 }
                 break;
             case Direction.Up:
                 for (int i = elements.GetLength(0) - 1; i >= 0; i--)
                 {
                     for (int j = elements.GetLength(1) - 1; j >= 0; j--)
                     {
                         if (elements[i, j] && field[newPosition.x + j, Console.CursorTop])
                         {
                             return false;
                         }
                     }
                     Console.CursorTop++;
                     Console.CursorLeft = newPosition.x;
                 }
                 break;
             case Direction.Down:
                 for (int i = 0; i < elements.GetLength(0); i++)
                 {
                     for (int j = 0; j < elements.GetLength(1); j++)
                     {
                         if (elements[i, j] && field[newPosition.x + j, Console.CursorTop])
                         {
                             return false;
                         }
                     }
                     Console.CursorTop++;
                     Console.CursorLeft = newPosition.x;
                 }
                 break;
             default:
                 break;
         }
         return true;
     }
     catch
     {
         return false;
     }
 }