实现尖峰行

时间:2018-12-14 21:59:28

标签: c# arrays

我正在尝试制作一个游戏,我的角色会避免掉落峰值,但是我有一个成功的下降行,但是当第一个下降行到达底部的一半以上时,我无法实现另一个下降行。我该如何实施?我当时在想,如果我使用if语句来确定当行到达某个位置时,它将在上方产生另一行峰值,但是我不知道该如何执行。感谢您抽时间阅读。使用c#。

class Program
{
    static int maxHeight = 30;
    static int maxWidth = 120;
    const int MAX = 9999999;

    static void Main(string[] args)
    {
        Console.BackgroundColor = ConsoleColor.White;
        //build of variables
        int i, j, m, n;
        bool valid = false;
        float spikeY = 0;
        char spike = 'V', erase = ' ';
        int[] spikeAmountArray = new int[MAX]; 
        int randomSpikeAmount;
        int[] spikeXArray;
        int randomXvaraiable;
        //Filling Array with a random amount of spikes
        for (i = 0; i < MAX; i++)
        {
            Random spikeAmount = new Random();
            randomSpikeAmount = spikeAmount.Next(65, 85);
            spikeAmountArray[i] = randomSpikeAmount;
        }
        //Filling spikes rows with different and random X coordinates and validating that each spike has a unique X cooridnate in each row
        for (i = 0; i < MAX; i++)
        {
            spikeXArray = new int[spikeAmountArray[i]];
            do
            {
                for (j = 0; j < spikeAmountArray[i]; j++)
                {
                    Random xVariable = new Random();
                    randomXvaraiable = xVariable.Next(0, maxWidth);
                    spikeXArray[j] = randomXvaraiable;
                }
                for (j = 0; j < spikeAmountArray[i]; j++)
                {
                    for (m = 0; m < spikeXArray[j]; m++)
                    {
                        if(spikeXArray[m] == spikeXArray[j] && j != m)
                        {
                            valid = false;
                            break;
                        }
                        else
                        {
                            valid = true;
                        }
                    }
                }
            } while (!valid);
            //Function of spikes
            do
            {
                for (i = 0; i < MAX; i++)
                {
                    while (spikeY <= maxHeight)
                    {
                        for (j = 0; j < spikeAmountArray[i]; j++)
                        {
                            Console.SetCursorPosition(spikeXArray[j], (int)spikeY);
                            Console.BackgroundColor = ConsoleColor.Gray;
                            Console.ForegroundColor = ConsoleColor.Black;
                            Console.Write(spike);
                        }
                        for (j = 0; j < spikeAmountArray[i]; j++)
                        {
                            Console.SetCursorPosition(spikeXArray[j], (int)spikeY);
                            Console.Write(erase);
                        }
                        spikeY = spikeY + 0.05f;
                    }
                }
            } while (spikeY <= 5);
        }
    }
}

0 个答案:

没有答案