Beispiel #1
0
        static void Main(string[] args)
        {
            #region Failsafes
            //This region makes sure the input values from the user are in the proper format.

            int InputNumber()                                      //This checks for the input of number of columns or number of rows.
            {
                if (Int32.TryParse(Console.ReadLine(), out int a)) //This values should always be integer.
                {
                    if (a > 999 || a < 1)                          //The number of rows and columns should be bigger than 0 and smaller than 1 000.
                    {
                        Console.WriteLine("Should be between 1 and 999! Try again:");
                        return(InputNumber());
                    }
                    else
                    {
                        return(a);
                    }
                }
                else
                {
                    Console.WriteLine("Not a proper value! Try again:");
                    return(InputNumber());
                }
            }

            string InputRow(int limit) //This checks for the input of the values for one row.
            {
                string result = Console.ReadLine();

                if (result.Length == limit) //Each row should be the same length as the other ones.
                {
                    foreach (char c in result)
                    {
                        if (c != '1' && c != '0') //Only ones and zeros are excepted as values for each cell.
                        {
                            Console.WriteLine("Row should contain only ones and zeros! Try again:");
                            return(InputRow(limit));
                        }
                    }
                    return(result);
                }
                else
                {
                    Console.WriteLine("Row does not have the right number of characters! Try again:");
                    return(InputRow(limit));
                }
            }

            int InputCoordinate(int limit) //Checks if requested cell coordinates are in bounds.
            {
                if (Int32.TryParse(Console.ReadLine(), out int a))
                {
                    if (a > limit - 1 || a < 0)
                    {
                        Console.WriteLine("Should be between {0} and {1}! Try again:", 0, limit - 1);
                        return(InputCoordinate(limit));
                    }
                    else
                    {
                        return(a);
                    }
                }
                else
                {
                    Console.WriteLine("Not a proper numeric value! Try again:");
                    return(InputCoordinate(limit));
                }
            }

            int InputGenerations() //Checks if input number of generations is a positive integer value.
            {
                if (Int32.TryParse(Console.ReadLine(), out int a))
                {
                    if (a < 1)
                    {
                        Console.WriteLine("Should be bigger than 0! Try again:");
                        return(InputGenerations());
                    }
                    else
                    {
                        return(a);
                    }
                }
                else
                {
                    Console.WriteLine("Not a proper value! Try again:");
                    return(InputGenerations());
                }
            }

            #endregion

            int x = 0;
            int y = 0;
            Console.WriteLine("Please, input number of columns of the grid:");
            x = InputNumber(); //We store the exact number of columns the grid will have.
            Console.WriteLine("Please, input number of rows of the grid:");
            y = InputNumber(); //We store the exact number of rows the grid will have.
            Console.WriteLine(x + ", " + y);

            //Next, we create a collection of rows based on the user input.
            Row[] row0 = new Row[y];

            for (int i = 0; i < y; i++)
            {
                Console.WriteLine("Please, input row number " + i + " of the grid:");
                Row row = new Row(InputRow(x), i); //User enters the values for each row.
                row0[i] = row;
            }

            Grid grid = new Grid(row0); //The rows are assembled into a grid.

            Console.WriteLine("Grid Zero:");
            grid.DisplayGrid(); //Grid is displayed.

            int x1;
            int y1;
            int N;

            Console.WriteLine("Please, input cell coordinate x:");
            x1 = InputCoordinate(x); //Coordinate x for which sell to watch are taken.
            Console.WriteLine("Please, input cell coordinate y:");
            y1 = InputCoordinate(y); //Coordinate y for which sell to watch are taken.
            Console.WriteLine("Please, input number of generations:");
            N = InputGenerations();  //Number of generations is taken.

            int result = 0;

            if (grid.cells[x1, y1].Colour == 1)
            {
                result++; //We check, if the cell is green in the original grid
            }
            for (int n = 0; n < N; n++)
            {
                TransformGrid updater = new TransformGrid(); //We update the grid.
                grid = updater.Update(grid);

                if (grid.cells[x1, y1].Colour == 1)
                {
                    result++; //We increment the number of times the cell in question has been green for every grid generation.
                }
            }

            Console.WriteLine("Number of generations in which the cell was green:");
            Console.WriteLine(result); //Final result is shown.
        }
    public void InitPlayingField()
    {
        player = GetComponent<Player>();

        modelSpawnGrid = GameObject.Find("_" + (player.IsFirstPlayer() ? "P1" : "P2") + "_FieldGrid").GetComponent<TransformGrid>();

        if (isLocalPlayer)
        {
            friendlyCardSpawnLocation = GameObject.Find("_" + (player.IsFirstPlayer() ? "P1" : "P2") + "_friendlyCardsGrid").GetComponent<TransformGrid>();
        }
        else
        {
            friendlyCardSpawnLocation = GameObject.Find("_" + (player.IsFirstPlayer() ? "P2" : "P1") + "_enemyCardsGrid").GetComponent<TransformGrid>();
        }

        for (int i = 0; i < player.gpManager.nwManager.GetComponent<NetworkMenuRelay>().loadedDeck.Length; i++)
        {
            playerDeck.addCardTop(player.gpManager.nwManager.GetComponent<NetworkMenuRelay>().loadedDeck[i]);
        }
        playerDeck.Shuffle();
    }