예제 #1
0
        // This method returns list of all allowed moves for controlled object.
        public static List<string> UnallowedMoves(GameObject controlledObject, List<GameObject> staticObjects)
        {
            List<string> unallowedMoves = new List<string>();
            int contObjRow = controlledObject.Position.Row;
            int contObjCol = controlledObject.Position.Col;

            foreach (var staticObject in staticObjects)
            {
                if (controlledObject.CanCollideWith(staticObject.GetObjectType()))
                {
                    // Check controlled object can move to the down
                    if (InSamePosition(new Position(contObjRow + 1, contObjCol), staticObject.Position))
                    {
                        unallowedMoves.Add("Down");
                    }

                    // Check controlled object can move to the up
                    if (InSamePosition(new Position(contObjRow - 1, contObjCol), staticObject.Position))
                    {
                        unallowedMoves.Add("Up");
                    }

                    // Check controlled object can move to the right
                    if (InSamePosition(new Position(contObjRow, contObjCol + 1), staticObject.Position))
                    {
                        unallowedMoves.Add("Right");
                    }

                    // Check controlled object can move to the left
                    if (InSamePosition(new Position(contObjRow, contObjCol - 1), staticObject.Position))
                    {
                        unallowedMoves.Add("Left");
                    }
                }
            }

            return unallowedMoves;
        }
예제 #2
0
 // Methods
 // Visualize any object type
 public void Visualize(GameObject obj)
 {
     Console.SetCursorPosition(obj.Position.Col, obj.Position.Row);
     Console.ForegroundColor = obj.Color;
     Console.Write(obj.Symbol);
 }