Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        cameras = GameObject.FindObjectsOfType <Camera>();
        for (int i = 0; i < cameras.Length; i++)
        {
            if (cameras[i].CompareTag("MainCamera"))
            {
                mainCamera = cameras[i];
            }
            if (cameras[i].CompareTag("highCamera"))
            {
                highCamera = cameras[i];
            }
        }
        is_normal = true;
        //特殊的下一位,吃碰杠时触发,优先级高于默认,正常情况下为-1
        nextPlayer         = -1;
        highCamera.enabled = false;
        players            = new List <Player>();
        tile_manager       = gameObject.GetComponent <TileManager>();
        tile_manager.Initialize();

        //player位置随缘
        players.Add(Instantiate(humanPlayer, transform));
        players.Add(Instantiate(player, transform));
        players.Add(Instantiate(player, transform));
        players.Add(Instantiate(player, transform));
        //players[0] = Instantiate(player, transform);
        //players[1] = Instantiate(player, transform);
        //players[2] = Instantiate(player, transform);
        //players[3] = Instantiate(player, transform);

        //发牌阶段
        int initial_tile = 14;

        current_player = 0;
        for (int i = 0; i < initial_tile + 1; i++)
        {
            GiveOutTile(players[0]);
        }
        for (int i = 0; i < initial_tile; i++)
        {
            GiveOutTile(players[1]);
        }
        for (int i = 0; i < initial_tile; i++)
        {
            GiveOutTile(players[2]);
        }
        for (int i = 0; i < initial_tile; i++)
        {
            GiveOutTile(players[3]);
        }

        tileGenerator = gameObject.GetComponent <TileGenerator>();
        tileGenerator.Initialize();
        tileGenerator.Generate1(players[0]);
        tileGenerator.Generate2(players[1]);
        tileGenerator.Generate3(players[2]);
        tileGenerator.Generate4(players[3]);
        gameover = false;

        wait_count      = 0;
        player_win      = false;
        player_tiles    = new List <int>();
        player_outtiles = new List <int>();
        play_count_down = 144;
        CountDownUpdate(play_count_down);
    }
Example #2
0
    void AskPlayerPlay()
    {
        List <MyTile> answer_tiles = players[current_player].Play();

        if (answer_tiles != null && answer_tiles.Count == 1)
        {
            play_count_down -= 2;
            CountDownUpdate(play_count_down);
            current_tile = answer_tiles[0];

            if (current_tile.tile_id == -1)
            {
                GameOver();
                return;
            }

            //let the tile out
            current_tile.Go_out();
            audio.Play();
            //set the ok of other three people false
            for (int i = 0; i < 4; i++)
            {
                ok[i] = false;
            }
            ok[current_player] = true;
            //redisplay the current player's tiles
            if (current_player == 0)
            {
                tileGenerator.Generate1(players[current_player]);
            }
            else if (current_player == 1)
            {
                tileGenerator.Generate2(players[current_player]);
            }
            else if (current_player == 2)
            {
                tileGenerator.Generate3(players[current_player]);
            }
            else if (current_player == 3)
            {
                tileGenerator.Generate4(players[current_player]);
            }

            CleanPlayer();
            wait = true;
        }
        if (answer_tiles != null && answer_tiles.Count == 4)
        {
            play_count_down -= 2;
            CountDownUpdate(play_count_down);
            //AddToOutTiles(answer_tiles);
            players[current_player].GetShowTile(answer_tiles[0].tile_id);
            players[current_player].GetShowTile(answer_tiles[1].tile_id);
            players[current_player].GetShowTile(answer_tiles[2].tile_id);
            players[current_player].GetShowTile(answer_tiles[3].tile_id);
            CleanTile(answer_tiles[0], false);
            CleanTile(answer_tiles[1], false);
            CleanTile(answer_tiles[2], false);
            CleanTile(answer_tiles[3], false);
            players[current_player].ClearPotential();
            GiveOutTile(players[current_player]);
            if (current_player == 0)
            {
                tileGenerator.Generate1(players[current_player]);
            }
            else if (current_player == 1)
            {
                tileGenerator.Generate2(players[current_player]);
            }
            else if (current_player == 2)
            {
                tileGenerator.Generate3(players[current_player]);
            }
            else if (current_player == 3)
            {
                tileGenerator.Generate4(players[current_player]);
            }
        }
    }