예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (_alive)
        {
            Ray        ray = new Ray(transform.position, transform.forward);
            RaycastHit hit;

            //Debug.Log("alive");

            if (Physics.SphereCast(ray, 0.75f, out hit))
            {
                GameObject hitObj = hit.transform.gameObject;

                if (hitObj.GetComponent <PlayerCode>())
                {
                    this.GetComponent <Animator>().SetBool("isWalk", false);
                    if (!isPause)
                    {
                        PlayerCode player = hitObj.GetComponent <PlayerCode>();

                        if (player)
                        {
                            player.Damage();
                            StartCoroutine(Pause());
                        }
                    }
                }
            }
        }
    }
예제 #2
0
        public void PlaceTile_functionality_has_to_work()
        {
            int         nextTurnCount = 0;
            GameManager gameManager   = new GameManager(GameMode.TwoPlayer);

            gameManager.NextTurnEvent += (sender, e) => { nextTurnCount++; };

            List <string> allTiles = new List <string>(gameManager.InitTilePool());

            string tile = new List <string>(gameManager.TilePool).First();

            Assert.ThrowsException <InvalidOperationException>(() => { gameManager.TryPlaceOnGameBoard(tile); }, "Only the active player can place tiles on the gameboard.");

            string tileFromActiveDrawboard = allTiles.Where(t => gameManager.GetActivePlayersDrawBoard().HasTile(t)).ElementAt(0);

            Assert.IsTrue(gameManager.TryPlaceOnGameBoard(tileFromActiveDrawboard));
            Assert.AreEqual(1, gameManager.TurnCount);
            Assert.AreEqual(gameManager.TurnCount, nextTurnCount);
            Assert.IsFalse(gameManager.HasPlaced);

            PlayerCode firstPlayer = (gameManager.ActivePlayer == PlayerCode.Player1) ? PlayerCode.Player2 : PlayerCode.Player1;

            Assert.AreEqual(tileFromActiveDrawboard.GetTriominoTileValue(), gameManager.PlayerPoints[firstPlayer]);
            Assert.IsFalse(gameManager.DrawBoards[firstPlayer].HasTile(tileFromActiveDrawboard));
            Assert.AreEqual(0, gameManager.PlayerPoints[gameManager.ActivePlayer]);
        }
예제 #3
0
        /// <summary>
        /// Adds a tile on the GameBoard, based on the tiles Value, another Tile on the GameBoard besides which the new Tile should be placed
        /// and the faces with which both tiles should be placed towards each other.
        /// </summary>
        /// <param name="player">Der PlayerCode des aktiven Spielers.</param>
        /// <param name="tileName">The new tile.</param>
        /// <param name="hexagons">Die Liste mit Hexagonen, falls vorhanden.</param>
        /// <param name="otherName">The other tile besides which the new tile should be placed.</param>
        /// <param name="tileFace">The new tiles face wich points to the other tile.</param>
        /// <param name="otherFace">The other tiles face which points to the new tile.</param>
        /// <returns>True if tile could be added, false if not</returns>
        public bool TryAddTile(PlayerCode player, string tileName, out List <Hexagon> hexagons, string otherName = null, TileFace?tileFace = null, TileFace?otherFace = null)
        {
            tileName.EnsureTriominoTileName();
            hexagons = new List <Hexagon>();

            if (!this.CanPlaceTileOnGameBoard(tileName, otherName, tileFace, otherFace, out TriominoTile placeableTile))
            {
                return(false);
            }

            this.AddTile(placeableTile);
            this.AddFreeFaces(tileName, otherName, tileFace, otherFace);

            IEnumerable <TriominoTile> directNeighbors = this.GetTileNeighbors(placeableTile);

            this.tileGraph.AddEdgeWithDirectNeighbors(placeableTile.CreateHyperEdgeFromTile(), directNeighbors.Select(n => n.CreateHyperEdgeFromTile()), out HyperEdge addedEdge);
            this.tileGraph.IsPartOfHexagon(addedEdge, out hexagons);

            this.OnTilePlaced(new TriominoTileEventArgs()
            {
                TileName      = tileName,
                OtherTileName = otherName,
                TileFace      = tileFace,
                OtherTileFAce = otherFace,
                Player        = player
            });
            return(true);
        }
예제 #4
0
 /// <summary>
 /// 獲得ポイントの新しいインスタンスを生成します。
 /// </summary>
 /// <param name="tournamentId">大会 ID。</param>
 /// <param name="tennisEventId">種目 ID。</param>
 /// <param name="playerCode">登録番号。</param>
 /// <param name="point">ポイント。</param>
 public EarnedPoints(int tournamentId, string tennisEventId, PlayerCode playerCode, Point point)
 {
     this.TournamentId  = tournamentId;
     this.TennisEventId = tennisEventId;
     this.PlayerCode    = playerCode;
     this.Point         = point;
 }
예제 #5
0
        /// <summary>
        /// Instantiates a new Object of this class.
        /// </summary>
        /// <param name="gameManager">GameManager of the game which this AI-Player is part of.</param>
        /// <param name="player">The AI-Players playerCode.</param>
        public SimpleAIPlayer(GameManager gameManager, PlayerCode player)
        {
            this.GameManager = gameManager;
            this.Player      = player;

            gameManager.NextTurnEvent  += this.PlayersTurn;
            gameManager.GameStartEvent += this.PlayersTurn;
        }
예제 #6
0
    // Mediante esta fúnción, el nombre y el color que el jugaodr escoge en el Lobby será visualizado en la partida.
    public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager, GameObject lobbyPlayer, GameObject gamePlayer)
    {
        LobbyPlayer lobby       = lobbyPlayer.GetComponent <LobbyPlayer>();
        PlayerCode  localPlayer = gamePlayer.GetComponent <PlayerCode>();

        // Se iguala el nombre y el color del Lobby al del avatar concreto. El color y el nombre se almacena en el script Player Code del jugador.
        localPlayer.pName       = lobby.playerName;
        localPlayer.playerColor = lobby.playerColor;
    }
예제 #7
0
        /// <summary>
        /// Determines if  a specific player is played by ai.
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public bool IsAiPlayer(PlayerCode player)
        {
            if (!this.AIPlayers.Any() || !this.AIPlayers.Where(ai => ai.Player.Equals(player)).Any())
            {
                return(false);
            }

            return(true);
        }
예제 #8
0
        /// <summary>
        /// Gets the Drawboard for a specific player.
        /// </summary>
        /// <param name="player">The Player who owns the drawboard.</param>
        /// <returns>The players Drawboard.</returns>
        public DrawBoard GetPlayersDrawBoard(PlayerCode player)
        {
            if (!this.DrawBoards.ContainsKey(player))
            {
                throw new KeyNotFoundException($"Could not found any Drawboard for Player: '{player}'");
            }

            return(this.DrawBoards[player]);
        }
예제 #9
0
        public async Task <Player> UpdatePlayerTelephoneNumber(string playerCode, string telephoneNumber)
        {
            var updatePlayerCode = new PlayerCode(playerCode);
            var player           = await this.playerRepository.FindByPlayerCodeAsync(updatePlayerCode);

            if (player == null)
            {
                throw new NotFoundException(playerCode, typeof(Player));
            }

            player.ChangeTelephoneNumber(telephoneNumber);
            var changed = await this.playerRepository.UpdateAsync(player);

            return(changed);
        }
예제 #10
0
    /// <summary>
    /// Places a tile from a Drawboard.
    /// !!!! This tile was placed within GraphKI.GameManagement.GameBoard before !!!!
    /// </summary>
    /// <param name="player">The Player for whom this tile is placed.</param>
    /// <param name="tileName">The name of the tile to be placed.</param>
    /// <param name="otherTileName">The name of the tile to which the new tile should be placed adjacent to.</param>
    /// <param name="tileFace">The tiles face wich should be adjacent to other tile after placing.</param>
    /// <param name="otherFace">the other tiles face which should be adjacent to tile after placing.</param>
    public void TryPlaceTileFromDrawBoard(PlayerCode player, string tileName, string otherTileName = null, TileFace?tileFace = null, TileFace?otherFace = null)
    {
        GameObject tile = GameObject.Find(tileName);

        if (otherTileName == null || otherTileName == string.Empty || !tileFace.HasValue || !otherFace.HasValue)
        {
            this.PlaceTileInCenter(tile);
            return;
        }

        GameObject otherTile = this.PlacedTiles.transform.Find(otherTileName).gameObject;

        //GameObject otherTile = GameObject.Find(otherTileName);
        this.PlaceTileNextToOther(tile, tileFace.Value, otherTile, otherFace.Value);
        tile.GetComponent <FadeToColor>().StartFadeToOrigin();
    }
예제 #11
0
 /// <summary>
 /// エントリー詳細の新しいインスタンスを生成します。
 /// </summary>
 /// <param name="teamCode">団体登録番号。</param>
 /// <param name="teamName">団体名。</param>
 /// <param name="teamAbbreviatedName">団体名略称。</param>
 /// <param name="playerCode">登録番号。</param>
 /// <param name="playerFamilyName">姓。</param>
 /// <param name="playerFirstName">名。</param>
 /// <param name="point">ポイント。</param>
 public EntryPlayer(
     TeamCode teamCode,
     TeamName teamName,
     TeamAbbreviatedName teamAbbreviatedName,
     PlayerCode playerCode,
     PlayerFamilyName playerFamilyName,
     PlayerFirstName playerFirstName,
     Point point)
 {
     this.TeamCode            = teamCode;
     this.TeamName            = teamName;
     this.TeamAbbreviatedName = teamAbbreviatedName;
     this.PlayerCode          = playerCode;
     this.PlayerFamilyName    = playerFamilyName;
     this.PlayerFirstName     = playerFirstName;
     this.Point = point;
 }
예제 #12
0
        public void DrawTile_functionality_has_to_work()
        {
            int         nextTurnCount = 0;
            GameManager gameManager   = new GameManager(GameMode.ThreePlayer);

            Assert.AreEqual(3, gameManager.DrawBoards.Count());
            gameManager = new GameManager(GameMode.FourPlayer);
            Assert.AreEqual(4, gameManager.DrawBoards.Count());
            gameManager = new GameManager(GameMode.TwoPlayer);
            Assert.AreEqual(2, gameManager.DrawBoards.Count());

            gameManager.NextTurnEvent += (sender, e) =>
            {
                nextTurnCount++;
            };

            Assert.AreEqual(0, gameManager.TurnCount);
            Assert.IsTrue(gameManager.TryDrawTile(out string randomTile));
            Assert.IsTrue(gameManager.GetActivePlayersDrawBoard().HasTile(randomTile));
            Assert.AreEqual(1, gameManager.DrawCount);
            Assert.IsFalse(gameManager.TryNextTurn());

            Assert.IsTrue(gameManager.TryDrawTile(out randomTile));
            Assert.IsTrue(gameManager.GetActivePlayersDrawBoard().HasTile(randomTile));
            Assert.AreEqual(2, gameManager.DrawCount);
            Assert.IsTrue(gameManager.TryDrawTile(out randomTile));
            Assert.IsTrue(gameManager.GetActivePlayersDrawBoard().HasTile(randomTile));
            Assert.AreEqual(3, gameManager.DrawCount);

            Assert.IsFalse(gameManager.TryDrawTile(out randomTile));
            Assert.IsFalse(gameManager.CanDrawTile());

            PlayerCode activePlayer = gameManager.ActivePlayer;

            Assert.IsTrue(gameManager.TryNextTurn());
            Assert.AreEqual(gameManager.TurnCount, nextTurnCount);
            Assert.AreNotEqual(activePlayer, gameManager.ActivePlayer);
            Assert.AreEqual(-25, gameManager.PlayerPoints[activePlayer]);
            Assert.AreEqual(0, gameManager.PlayerPoints[gameManager.ActivePlayer]);

            PlayerCode expectedPlayer = (activePlayer == PlayerCode.Player1) ? PlayerCode.Player2 : PlayerCode.Player1;

            Assert.AreEqual(expectedPlayer, gameManager.ActivePlayer);
        }
예제 #13
0
 /// <summary>
 /// Intantiates a new Object of this class.
 /// </summary>
 /// <param name="player"></param>
 public DrawBoard(PlayerCode player)
 {
     this.Player = player;
     this.Tiles  = new HashSet <string>();
 }
예제 #14
0
 private async void LimitPlayerTurnTime()
 {
     
     while (true)
     {
         
         TurnTimer.Text = (5 - (int)((DateTime.Now - _startTime).TotalSeconds)).ToString();
         if (5 - (int)((DateTime.Now - _startTime).TotalSeconds) == 0)
         {
             _startTime = DateTime.Now;
             _playerNumber = _playerNumber == PlayerCode.PlayerOne ? PlayerCode.PlayerTwo : PlayerCode.PlayerOne;
         }
         LimitPlayerMovement((byte)_playerNumber);
         await Task.Delay(10);
     }
 }
예제 #15
0
    //Function is used to update the UI for players
    private void UpdatePlayerListUI(string players)
    {
        //Start by getting player data
        GameObject[] playerObjects = GameObject.FindGameObjectsWithTag("Player");

        if (HostDecendant)
        {
            OverrideHostDecendantString(players);
        }

        PlayerCode localPlayer = playerObjects[0].GetComponent <PlayerCode>();

        foreach (GameObject playerObj in playerObjects)
        {
            if (playerObj.GetComponent <PlayerCode>().IsLocalPlayer())
            {
                localPlayer = playerObj.GetComponent <PlayerCode>();
                break;
            }
        }

        List <string> rpcPlayers = TurnManager.StringDeseparator(players);

        //Remove all children
        foreach (Transform child in PlayerCircleParentObject.transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        //Get the rankings of players
        List <int> playerRankings = new List <int>();

        for (int i = 1; i <= rpcPlayers.Count; i++)
        {
            int           rank          = i;
            List <string> playerDetails = TurnManager.StringDeseparator(rpcPlayers[i - 1]);
            string        playerScore   = playerDetails[2];
            for (int j = i + 1; j <= rpcPlayers.Count; j++)
            {
                if (TurnManager.StringDeseparator(rpcPlayers[j - 1])[2] == playerScore)
                {
                    rank = j;
                }
                else
                {
                    j = rpcPlayers.Count + 1;
                }
            }
            playerRankings.Add(rank);
        }


        int nonPlayerFound = 0;
        int playerFound    = 0;

        for (int i = rpcPlayers.Count - 1; i >= 0; i--)
        {
            List <string> playerDetails = TurnManager.StringDeseparator(rpcPlayers[i]);
            string        playerUID     = playerDetails[0];
            if (playerUID == localPlayer.PlayerUID || ((playerFound == 0 && i <= 3) || (i <= 2))) //Only show the top 3 players + the local player
            {
                string     playerLetter                = playerDetails[1][0].ToString();
                string     playerScore                 = playerDetails[2];
                int        playerRank                  = playerRankings[i];
                GameObject createdPlayerUI             = (Instantiate(PlayerCirclePrefab, PlayerCirclePrefab.transform.position, Quaternion.Euler(0, 0, 0), PlayerCircleParentObject.transform)) as GameObject;
                LeaderboardCircleUIScript newObjScript = createdPlayerUI.GetComponent <LeaderboardCircleUIScript>();

                Color playerColor;
                if (ColorUtility.TryParseHtmlString("#" + playerDetails[3], out playerColor))
                {
                    newObjScript.SetBackgroundColor(playerColor);
                }

                newObjScript.SetFullName(playerDetails[1]);
                newObjScript.SetUUID(playerUID);


                if (playerUID == localPlayer.PlayerUID)
                {
                    newObjScript.SetOutlineColor(Color.green);
                    playerFound++;
                }
                else
                {
                    nonPlayerFound++;
                }


                newObjScript.TextName.text  = playerLetter;
                newObjScript.TextScore.text = playerScore;
                if (playerRank == 1)
                {
                    newObjScript.TextPosition.text = "1st";
                }
                else if (playerRank == 2)
                {
                    newObjScript.TextPosition.text = "2nd";
                }
                else if (playerRank == 3)
                {
                    newObjScript.TextPosition.text = "3rd";
                }
                else
                {
                    newObjScript.TextPosition.text = playerRank.ToString() + "th";
                }
                newObjScript.ChangeColorAccordingToPosition();
            }
        }
    }
예제 #16
0
    public void RpcTurnEndPlayerListUI(string players)
    {
        if (HostDecendant)
        {
            OverrideHostDecendantString(players);
        }

        List <string> UIplayerUIDs          = new List <string>();
        List <int>    UIplayerScores        = new List <int>();
        List <int>    UIplayerPositionDiffs = new List <int>();

        List <string> CMDplayerUIDs      = new List <string>();
        List <int>    CMDplayerScores    = new List <int>();
        List <string> CMDplayerPositions = new List <string>();
        List <Color>  CmdplayerColors    = new List <Color>();
        List <string> CMDplayerNames     = new List <string>();
        List <string> rpcPlayers         = TurnManager.StringDeseparator(players);
        List <int>    playerRankings     = new List <int>();

        Dictionary <GameObject, int> animationNewPos    = new Dictionary <GameObject, int>();
        Dictionary <string, int>     animationNewScores = new Dictionary <string, int>();

        //Get local player
        GameObject[] playerObjects = GameObject.FindGameObjectsWithTag("Player");
        PlayerCode   localPlayer   = playerObjects[0].GetComponent <PlayerCode>();

        foreach (GameObject playerObj in playerObjects)
        {
            if (playerObj.GetComponent <PlayerCode>().IsLocalPlayer())
            {
                localPlayer = playerObj.GetComponent <PlayerCode>();
                break;
            }
        }

        //Get data from UI icons
        foreach (Transform child in PlayerCircleParentObject.transform)
        {
            UIplayerUIDs.Add(child.GetComponent <LeaderboardCircleUIScript>().GetUUID());
            UIplayerScores.Add(int.Parse(child.GetComponent <LeaderboardCircleUIScript>().TextScore.text));
        }

        //Get data from Cmd function
        for (int i = 1; i <= rpcPlayers.Count; i++)
        {
            int           rank          = i;
            List <string> playerDetails = TurnManager.StringDeseparator(rpcPlayers[i - 1]);
            string        playerScore   = playerDetails[2];
            animationNewScores.Add(playerDetails[0], int.Parse(playerScore));
            for (int j = i + 1; j <= rpcPlayers.Count; j++)
            {
                if (TurnManager.StringDeseparator(rpcPlayers[j - 1])[2] == playerScore)
                {
                    rank = j;
                }
                else
                {
                    j = rpcPlayers.Count + 1;
                }
            }
            playerRankings.Add(rank);
        }
        int nonPlayerFound = 0;
        int playerFound    = 0;

        for (int i = rpcPlayers.Count - 1; i >= 0; i--)
        {
            List <string> playerDetails = TurnManager.StringDeseparator(rpcPlayers[i]);
            string        playerUID     = playerDetails[0];
            if (playerUID == localPlayer.PlayerUID || ((playerFound == 0 && i <= 3) || (i <= 2)))
            {
                string playerLetter = playerDetails[1][0].ToString();
                string playerScore  = playerDetails[2];
                int    playerRank   = playerRankings[i];

                Color playerColor;
                if (ColorUtility.TryParseHtmlString("#" + playerDetails[3], out playerColor))
                {
                    CmdplayerColors.Add(playerColor);
                }

                CMDplayerNames.Add(playerDetails[1]);
                CMDplayerUIDs.Add(playerUID);


                if (playerUID == localPlayer.PlayerUID)
                {
                    playerFound++;
                }
                else
                {
                    nonPlayerFound++;
                }

                CMDplayerScores.Add(int.Parse(playerScore));
                if (playerRank == 1)
                {
                    CMDplayerPositions.Add("1st");
                }
                else if (playerRank == 2)
                {
                    CMDplayerPositions.Add("2nd");
                }
                else if (playerRank == 3)
                {
                    CMDplayerPositions.Add("3rd");
                }
                else
                {
                    CMDplayerPositions.Add(playerRank.ToString() + "th");
                }
            }
        }

        //Check  existing UI positions diffs
        for (int i = 0; i < UIplayerUIDs.Count; i++)
        {
            int diff = -4;
            //Try to see if UI object exists in upcoming leaderboard
            for (int j = 0; j < CMDplayerUIDs.Count; j++)
            {
                if (UIplayerUIDs[i] == CMDplayerUIDs[j])
                {
                    //Player exists in new list, time to register his difference in position
                    diff = -1 * (i - j);//Diff is given minus because object is placed upside down
                    break;
                }
            }
            UIplayerPositionDiffs.Add(diff);
        }

        //Add all UI objects to animator dictionary
        int index = 0;

        foreach (Transform child in PlayerCircleParentObject.transform)
        {
            animationNewPos.Add(child.gameObject, UIplayerPositionDiffs[index]);
            index++;
        }

        //Check if any of the CMD objects didn't appear in the UI list
        for (int i = 0; i < CMDplayerUIDs.Count; i++)
        {
            bool found = false;
            //Try to see if UI object exists in upcoming leaderboard
            for (int j = 0; j < UIplayerUIDs.Count; j++)
            {
                if (UIplayerUIDs[j] == CMDplayerUIDs[i])
                {
                    found = true;
                    break;
                }
            }
            if (!found)//Cmd object doesn't exist in UI, time to make GameObject for it
            {
                GameObject createdPlayerUI = (Instantiate(PlayerCirclePrefab, PlayerCirclePrefab.transform.position, Quaternion.Euler(0, 0, 0), PlayerCircleParentObject.transform)) as GameObject;
                createdPlayerUI.transform.SetSiblingIndex(0);//Set as first child because order is reversed and we want it coming from bottom of leaderboard
                LeaderboardCircleUIScript newObjScript = createdPlayerUI.GetComponent <LeaderboardCircleUIScript>();
                newObjScript.SetBackgroundColor(CmdplayerColors[i]);
                newObjScript.SetFullName(CMDplayerNames[i]);
                newObjScript.SetUUID(CMDplayerUIDs[i]);
                newObjScript.TextName.text     = CMDplayerNames[i][0].ToString();
                newObjScript.TextScore.text    = CMDplayerScores[i].ToString();
                newObjScript.TextPosition.text = CMDplayerPositions[i];
                newObjScript.ChangeColorAccordingToPosition();

                //Add new player to animation dictionary
                animationNewPos.Add(createdPlayerUI, int.Parse(CMDplayerPositions[i].Replace("st", "").Replace("nd", "").Replace("rd", "").Replace("th", "")));
            }
        }

        //Update position text for all UI objects and hide it
        foreach (Transform child in PlayerCircleParentObject.transform)
        {
            LeaderboardCircleUIScript newObjScript = child.GetComponent <LeaderboardCircleUIScript>();
            for (int i = 0; i < CMDplayerUIDs.Count; i++)
            {
                if (newObjScript.GetUUID() == CMDplayerUIDs[i])
                {
                    newObjScript.TextPosition.text = CMDplayerPositions[i];
                    newObjScript.ChangeColorAccordingToPosition();
                }
            }
            newObjScript.SetPositionText(false);
        }

        //Start animation co-routine
        this.GetComponent <TurnManager>().SetupWhoVotedForWhoPanel(players);
        StartCoroutine(AnimateLeaderboardsUI(animationNewPos, animationNewScores, players));
    }