Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Общие вопросы по .NET и C# > for and if


Автор: blackwitcher 10.1.2018, 18:01
Всем привет, не получается у меня нарисовать фигуру в цикле
Код

public class Figure
    {
        public List<Coordinate> Coordinates { get; set; }
        public Positions StorePosition { get; set; }
        public Positions CurrentPosition { get; set; }
    }


Код

public class Factory
    {
        public Square CreateSquare()
        {
            var square = new Square();
            square.Coordinates = new List<Coordinate>
            {
                new Coordinate(1, 1),
                new Coordinate(1, 2),
                new Coordinate(2, 1),
                new Coordinate(2, 2)
            };
            return square; 
        }
     }


вот здесь я завис

Код

class ConsoleTetris:Factory
    {
        static void Main(string[] args)
        {
            Factory factory = new Factory();
            var square = factory.CreateSquare();
            int rows = 10;
            int columns = 7;
            int[,] myArray = new int[rows, columns];

            for (int x = 0; x < rows; x++)
            {
                for (int y = 0; y < columns; y++)
                {
                    for (int i = 0; i < square.Coordinates.Count; i++)
                    {
                        
                        if(square.Coordinates[i].X==1)


                        if (square.Coordinates.Count==1)
                            
                            i++;
                        
                            Console.SetCursorPosition(square.Coordinates.Count, i);
                            Console.Write("#");
                        
                        Console.Write("");
}
}
}


Автор: blackwitcher 11.1.2018, 11:20
Код

if (square.Coordinates[i].X == x && square.Coordinates[i].Y == y)
                            //x++;
                        //y++;
                            Console.SetCursorPosition(/*i, square.Coordinates.Count*/x,y);
                        Console.Write("#");

                        Console.Write("");

вроде работает, но не знаю как правильно вывести на SetCursorPosition

Автор: blackwitcher 11.1.2018, 15:52
Код

Factory factory = new Factory();
            var square = factory.CreateSquare();
            int rows = 20;
            int columns = 10;
            int[,] myArray = new int[rows, columns];

            for (int x = 0; x < rows; x++)
            {
                for (int y = 0; y < columns; y++)
                {
                    for (int i = 0; i < square.Coordinates.Count; i++)
                    {
                        if (square.Coordinates[i].X == x && square.Coordinates[i].Y == y)
                        {
                            Console.SetCursorPosition(x, y);
                            Console.Write("#");
                        }
                        else
                        {
                            Console.Write("");
                        }
                    }
                }
            }


как заставить фигуру падать вниз? smile 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)