コード例 #1
0
    private Point GetRandomLocation()
    {
        bool free = false;

        int xOffset = ((gr.CONSOLE_WIDTH - gameSize.Width) / 2) + 2;
        int yOffset = ((gr.CONSOLE_HEIGHT - gameSize.Height) / 2) + 2;

        Point p = new Point(0, 0);

        do
        {
            int x = ConsoleGraphics.rnd.Next(xOffset, xOffset + gameSize.Width - 2);
            int y = ConsoleGraphics.rnd.Next(yOffset, yOffset + gameSize.Height - 2);

            char ch = gr.ReadFromBuffer(x, y).Char.UnicodeChar;

            // Wenn Platz frei
            if (ch == '\0' || ch == ' ')
            {
                free = true;
                p.X  = x;
                p.Y  = y;
            }
        } while (!free);

        return(p);
    }