Пример #1
0
 private static bool IsPassable(Ball ball)
 {
     if (ball.BallWidth >= 0 && ball.BallHeight >= 0 &&
         ball.BallDepth >= 0 && ball.BallWidth < width &&
         ball.BallHeight < height && ball.BallDepth < depth)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #2
0
        private static void ReadInput()
        {
            string[] rawNumbers = Console.ReadLine().Split(' ');
            width = int.Parse(rawNumbers[0]);
            height = int.Parse(rawNumbers[1]);
            depth = int.Parse(rawNumbers[2]);
            cube = new string[width, height, depth];
            //fill in cube
            for (int h = 0; h < height; h++)
            {
                string[] lineFragment = Console.ReadLine().Split(new string[] { " | " }, StringSplitOptions.RemoveEmptyEntries);//reading every line
                for (int d = 0; d < depth; d++)
                {
                    string[] cubeContent = lineFragment[d].Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int w = 0; w < width; w++)
                    {
                        cube[w, h, d] = cubeContent[w];
                    }
                }
            }
               //initial coordinate of the ball
            string[] rawBallCoords = Console.ReadLine().Split();

            int ballWidth = int.Parse(rawBallCoords[0]);
            int ballDepth = int.Parse(rawBallCoords[1]);

            cubeBall = new Ball(ballWidth, 0, ballDepth);
        }
Пример #3
0
        private static void ProcessBallSlides(string command)
        {
            Ball newCubeBall = new Ball(cubeBall);//make a new ball at position

            switch (command)
            {
                case "R":
                    newCubeBall.BallHeight++;
                    newCubeBall.BallWidth++;
                    break;
                case "L":
                    newCubeBall.BallWidth--;
                    newCubeBall.BallHeight++;
                    break;
                case "F":
                    newCubeBall.BallDepth--;
                    newCubeBall.BallHeight++;
                    break;
                case "B":
                    newCubeBall.BallDepth++;
                    newCubeBall.BallHeight++;
                    break;
                case "FL":
                    newCubeBall.BallDepth--;
                    newCubeBall.BallWidth--;
                    newCubeBall.BallHeight++;
                    break;
                case "FR":
                    newCubeBall.BallDepth--;
                    newCubeBall.BallWidth++;
                    newCubeBall.BallHeight++;
                    break;
                case "BL":
                    newCubeBall.BallDepth++;
                    newCubeBall.BallWidth--;
                    newCubeBall.BallHeight++;
                    break;
                case "BR":
                    newCubeBall.BallDepth++;
                    newCubeBall.BallWidth++;
                    newCubeBall.BallHeight++;
                    break;
                default:
                    throw new ArgumentException("Ivalid slide command");
            }

            if (IsPassable(newCubeBall))
            {
                cubeBall = new Ball(newCubeBall);
            }
            else
            {

                PrintMessage();
                Environment.Exit(0);//stop all program
            }
        }
Пример #4
0
 public Ball(Ball ball)
 {
     this.BallWidth = ball.BallWidth;
     this.BallHeight = ball.BallHeight;
     this.BallDepth = ball.BallDepth;
 }
Пример #5
0
        private static void ProccessBallSlides(string command)
        {
            Ball ghostBall = new Ball(cubeBall);

            switch (command)
            {
                case "R": ghostBall.BallHeight++;
                    ghostBall.BallWidth++;
                    break;
                case "L": ghostBall.BallHeight++;
                    ghostBall.BallWidth--;
                    break;
                case "F": ghostBall.BallHeight++;
                    ghostBall.BallDepth--;
                    break;
                case "B": ghostBall.BallHeight++;
                    ghostBall.BallDepth++;
                    break;
                case "FL": ghostBall.BallHeight++;
                    ghostBall.BallDepth--;
                    ghostBall.BallWidth--;
                    break;
                case "FR": ghostBall.BallHeight++;
                    ghostBall.BallDepth--;
                    ghostBall.BallWidth++;
                    break;
                case "BL": ghostBall.BallHeight++;
                    ghostBall.BallDepth++;
                    ghostBall.BallWidth--;
                    break;
                case "BR": ghostBall.BallHeight++;
                    ghostBall.BallDepth++;
                    ghostBall.BallWidth++;
                    break;
                default: throw new ArgumentException("Wrong slide command");
            }

            if (IsPassable(ghostBall))
            {
                cubeBall = new Ball(ghostBall);
            }
            else
            {
                PrintMessage();
                Environment.Exit(0);
            }
        }