Пример #1
0
        public void NewGame()
        {
            board.gameObject.SetActive(true);
            board.Clear();
            board.SetPlayer(Seed.Cross);
            CurrentState = GameState.Playing;

            if (NetworkService.IsConnected)
            {
                if (NetworkService.IsMaster)
                {
                    Player1.Name = NetworkService.PlayerName;
                    Player2.Name = NetworkService.OpponentName;

                    Player1.Type = Seed.Cross;
                    Player2.Type = Seed.Nought;
                    board.SetPlayer(Seed.Cross);

                    NetworkService.SendNewGameStarted();
                }
                else
                {
                    Player1.Name = NetworkService.OpponentName;
                    Player2.Name = NetworkService.PlayerName;

                    Player1.Type = Seed.Nought;
                    Player2.Type = Seed.Cross;
                    board.SetPlayer(Seed.Empty);
                }
            }

            OnGameStartSignal.Dispatch(this);
        }
Пример #2
0
        private void GenerateItems()
        {
            for (int row = 0; row < board.rows; row++)
            {
                for (int col = 0; col < board.columns; col++)
                {
                    if (!board[row, col].IsEmpty)
                    {
                        Destroy(board[row, col].Item.gameObject);
                    }
                }
            }

            board.Clear();

            spawnPoints = new Vector2[board.columns];

            for (int row = 0; row < board.rows; row++)
            {
                for (int col = 0; col < board.columns; col++)
                {
                    Item itemPrefab = GetRandomItemPrefab();

                    //check if two previous horizontal items are of the same type and if so, get another random item
                    while (col >= 2 && board[row, col - 1].Item.IsEqual(itemPrefab) && board[row, col - 2].Item.IsEqual(itemPrefab))
                    {
                        itemPrefab = GetRandomItemPrefab();
                    }

                    //check if two previous vertical items are of the same type and if so, get another random item
                    while (row >= 2 && board[row - 1, col].Item.IsEqual(itemPrefab) && board[row - 2, col].Item.IsEqual(itemPrefab))
                    {
                        itemPrefab = GetRandomItemPrefab();
                    }

                    CreateItem(row, col, itemPrefab);
                }
            }

            InitSpawnPoints();
        }