public static void CheckBoundaries(Possition headPossition, Possition movement)
        {
            var newHeadPossition = headPossition.GetNewPossition(movement);

            if (newHeadPossition.Y == -1)
            {
                ConsoleHelper.Clear(headPossition);
                headPossition.Y = Console.WindowHeight - 1;
            }

            if (newHeadPossition.X == -1)
            {
                ConsoleHelper.Clear(headPossition);
                headPossition.X = Console.WindowWidth - 1;
            }

            if (newHeadPossition.X == Console.WindowWidth)
            {
                ConsoleHelper.Clear(headPossition);
                headPossition.X = 0;
            }

            if (newHeadPossition.Y == Console.WindowHeight)
            {
                ConsoleHelper.Clear(headPossition);
                headPossition.Y = 0;
            }
        }
Esempio n. 2
0
 private void Move()
 {
     if (_currentDistance <= 0)
     {
         
         if (transform.position.x > 1f)
         {
             _playerPossition = Possition.right;
             _dirrection = _dirrection == 1 ? 0 : _dirrection;
         }
         else if (transform.position.x < -1f)
         {
             _playerPossition = Possition.left;
             _dirrection = _dirrection == -1 ? 0 : _dirrection;
         }
         else
         {
             _playerPossition = Possition.middle;
             transform.position = new Vector3(0, 0, transform.position.z);
         }
         _playerCondition = PlayerCondition.run;
         return;
     }
     float speed = Distance / AnimationTime;
     float tmpDist = Time.deltaTime * speed;
     _characterController.Move(Vector3.right * _currentDirrection * tmpDist);
     _currentDistance -= tmpDist;
 }
        public static void FindBoxColor(string input)
        {
            Possition actual = new Possition();

            actual.x   = 1;
            actual.y   = 1;
            actual.dir = "xPos";

            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] == 'L')
                {
                    actual = TurnLeft(actual);
                }
                else if (input[i] == 'R')
                {
                    actual = TurnRight(actual);
                }
                else
                {
                    actual = GoAhead(actual);
                }
            }

            Console.WriteLine(CheckColor(actual));
        }
 public static String CheckColor(Possition input)
 {
     if (input.x == 1 && input.y == 1)
     {
         return("GREEN");
     }
     else if ((input.x == 0 && input.y == 0) ||
              (input.x == 2 && input.y == 0) ||
              (input.x == 0 && input.y == 2) ||
              (input.x == 2 && input.y == 2))
     {
         return("RED");
     }
     else
     {
         return("BLUE");
     }
 }
Esempio n. 5
0
        /// <summary>
        /// This method validate the current string in the possitions of strings and validate them agains the others.
        /// If all the others are empty or equal to the one I'm validation then I added as a result.
        /// </summary>
        /// <param name="messages"></param>
        /// <param name="start"></param>
        /// <param name="index"></param>
        /// <param name="possition"></param>
        /// <returns></returns>
        private string MessageToAdd(string[][] messages, int start, int index, Possition possition)
        {
            var retval = string.Empty;

            if (!IsStringEmpty(messages[start][index]))
            {
                switch (possition)
                {
                case Possition.START:
                    if ((messages[start][index] == messages[start + 1][index]) ||
                        (messages[start][index] == messages[start + 2][index]) ||
                        (IsStringEmpty(messages[start + 1][index]) && IsStringEmpty(messages[start + 2][index])))
                    {
                        retval = messages[start][index];
                    }
                    break;

                case Possition.MIDDLE:
                    if ((messages[start][index] == messages[start - 1][index]) ||
                        (messages[start][index] == messages[start + 1][index]) ||
                        (IsStringEmpty(messages[start - 1][index]) && IsStringEmpty(messages[start + 1][index])))
                    {
                        retval = messages[start][index];
                    }
                    break;

                case Possition.END:
                    if ((messages[start][index] == messages[start - 1][index]) ||
                        (messages[start][index] == messages[start - 2][index]) ||
                        (IsStringEmpty(messages[start - 1][index]) && IsStringEmpty(messages[start - 2][index])))
                    {
                        retval = messages[start][index];
                    }
                    break;
                }
            }
            return(retval);
        }
        public static Possition GoAhead(Possition input)
        {
            if (input.dir == "xPos")
            {
                input.x++;
            }
            else if (input.dir == "xNeg")
            {
                input.x--;
            }
            else if (input.dir == "yPos")
            {
                input.y++;
            }
            else
            {
                input.y--;
            }

            if (input.x > 2)
            {
                input.x = 0;
            }
            if (input.x < 0)
            {
                input.x = 2;
            }
            if (input.y > 2)
            {
                input.y = 0;
            }
            if (input.y < 0)
            {
                input.y = 2;
            }

            return(input);
        }
 public static Possition TurnRight(Possition input)
 {
     if (input.dir == "xPos")
     {
         input.dir = "yNeg";
         return(input);
     }
     else if (input.dir == "xNeg")
     {
         input.dir = "yPos";
         return(input);
     }
     else if (input.dir == "yPos")
     {
         input.dir = "xPos";
         return(input);
     }
     else
     {
         input.dir = "xNeg";
         return(input);
     }
 }
 public static void Clear(Possition possition)
 {
     Console.SetCursorPosition(possition.X, possition.Y);
     Console.Write(" ");
 }
 public static void Write(Possition possition, string text)
 {
     Console.SetCursorPosition(possition.X, possition.Y);
     Console.Write(text);
 }