public void OnClickAI(bool target = false)
 {
     if (target)
     {
         OnAIselection?.Invoke(transform.position);
     }
     if (activeGamestate == GameState.PLAYERX && affiliation == Player.None)
     {
         affiliation = Player.X;
         //button.image.color = ColorPresets.X;
         OnPlayerAction?.Invoke(activeGamestate);
         AfterPlayerAction?.Invoke(activeGamestate);
     }
     else if (activeGamestate == GameState.PLAYERO && affiliation == Player.None)
     {
         affiliation = Player.O;
         //button.image.color = ColorPresets.O;
         OnPlayerAction?.Invoke(activeGamestate);
         AfterPlayerAction?.Invoke(activeGamestate);
     }
     else
     {
         return;
     }
     text.text = affiliation.ToString();
     if (glitchFontOnHover != null)
     {
         StopCoroutine(glitchFontOnHover);
         isTextGlitching = false;
     }
     text.fontSize = 10;
     playAnimation = true;
 }
Пример #2
0
 public bool Check(int playerId)
 {
     if (playerId != currentTurnPlayerId)
     {
         return(false);
     }
     lock (_lockObj)
     {
         Player player = GetPlayer(playerId);
         if (player != null)
         {
             // if there wasn't any bet or raise,
             // the player is eligible to check
             if (player.CallSum == 0)
             {
                 player.Checked = true;
                 NextPlayerTurn();
                 OnPlayerAction?.Invoke(this, new PlayerActionEventArgs {
                     Player = player
                 });
                 return(true);
             }
         }
         return(false);
     }
 }
    public void OnClick()
    {
        if (gameController.PlayerState != activeGamestate)
        {
            return;
        }

        if (activeGamestate == GameState.PLAYERX && affiliation == Player.None)
        {
            affiliation = Player.X;
            //button.image.color = ColorPresets.X;
            OnPlayerAction?.Invoke(activeGamestate);
            AfterPlayerAction?.Invoke(activeGamestate);
        }
        else if (activeGamestate == GameState.PLAYERO && affiliation == Player.None)
        {
            affiliation = Player.O;
            //button.image.color = ColorPresets.O;
            OnPlayerAction?.Invoke(activeGamestate);
            AfterPlayerAction?.Invoke(activeGamestate);
        }
        else
        {
            return;
        }
        text.text = affiliation.ToString();
        if (glitchFontOnHover != null)
        {
            StopCoroutine(glitchFontOnHover);
            isTextGlitching = false;
        }
        text.fontSize = 10;
        playAnimation = true;
    }
Пример #4
0
        /// <summary>
        /// Creates a new player for a specific level
        /// </summary>
        /// <param name="level">The Level that the player should play in</param>
        /// <param name="location">The starting location of the player</param>
        /// <param name="score">The initial score of the player. Default is 0.</param>
        public PlayerGameObject(Level level, Point location, int score = 0) : base(level.Tiles, level.TimeBetweenActions, "player@4x4", 0, "")
        {
            player = new DummyPlayer(level.Tiles, location, score);
            Level  = level;
            Teleport(location);
            TileField.RevealArea(location);
            soundFootsteps = GameEnvironment.AssetManager.Content.Load <SoundEffect>("footsteps").CreateInstance();

            player.OnPlayerAction += delegate(DummyPlayer player) { OnPlayerAction?.Invoke(this); };
            player.OnPlayerWin    += delegate(DummyPlayer player) { OnPlayerWin?.Invoke(this); };
            player.OnPlayerLose   += delegate(DummyPlayer player)
            {
                OnPlayerLose?.Invoke(this);
                GameEnvironment.AssetManager.PlaySound("scream");
            };
            player.OnMoveSmoothly += delegate(DummyPlayer player, Direction direction)
            {
                MoveSmoothly(direction);
                soundFootsteps.Play();
            };
            player.OnTeleport += delegate(DummyPlayer player)
            {
                Teleport(player.Location);
                GameEnvironment.AssetManager.PlaySound("climbing_sound");
            };
            StoppedMoving += delegate(GameObject obj)
            {
                player.EndMoveSmoothly();
                soundFootsteps.Stop();
            };
        }
Пример #5
0
 public bool Call(int playerId)
 {
     if (playerId != currentTurnPlayerId)
     {
         return(false);
     }
     lock (_lockObj)
     {
         Player player = GetPlayer(playerId);
         if (player != null && player.CallSum > 0)
         {
             if (player.Chips < player.CallSum)
             {
                 player.CallSum   -= player.Chips;
                 player.CalledSum += player.Chips;
                 // Forced to going All-In
                 table.Contribute(player, player.Chips);
             }
             else
             {
                 player.CalledSum += player.CallSum;
                 player.CallSum    = 0;
                 table.Contribute(player, player.CalledSum);
             }
             player.Checked = true;
             NextPlayerTurn();
             OnPlayerAction?.Invoke(this, new PlayerActionEventArgs {
                 Player = player
             });
             return(true);
         }
         return(false);
     }
 }
Пример #6
0
        /// <summary>
        /// Performs the specified action
        /// </summary>
        /// <param name="action">The PlayerAction to perform</param>
        public void PerformAction(PlayerAction action)
        {
            if (!CanPerformAction(action))
            {
                throw new PlayerActionNotAllowedException();
            }

            CurrentTile.PerformAction(this, action);

            OnPlayerAction?.Invoke(this);
        }
Пример #7
0
        public bool Bet(int playerId, int betSum)
        {
            if (playerId != currentTurnPlayerId)
            {
                return(false);
            }
            lock (_lockObj)
            {
                // Can't bet if there is already a bet.
                // Player should raise instead.
                if (currentBet > table.Stake)
                {
                    return(false);
                }
                // The minimum bet sum is current bet sum.
                if (betSum < currentBet)
                {
                    return(false);
                }
                Player player = GetPlayer(playerId);
                if (player != null && player.Chips >= betSum)
                {
                    currentBet = betSum;
                    table.Contribute(player, betSum);
                    player.CalledSum = betSum;
                    player.CallSum   = player.CallSum - betSum < 0 ? 0 : player.CallSum - betSum;

                    foreach (Player p in Players)
                    {
                        if (p == player || p.Folded)
                        {
                            continue;
                        }
                        p.CallSum = currentBet;
                    }
                    player.Checked = true;

                    //if (player.chips == 0) {
                    //// Forced to going All-In
                    //}

                    NextPlayerTurn();
                    OnPlayerAction?.Invoke(this, new PlayerActionEventArgs {
                        Player = player
                    });
                    return(true);
                }
                return(false);
            }
        }
Пример #8
0
        private async Task CheckPlayersLeft(Game existingGame, Game game)
        {
            for (int i = 0; i < existingGame.Players.Count; i++)
            {
                var player = existingGame.Players[i];
                if (game.Players.Find(p => p.Id == player.Id) == null)
                {
                    var filter = Builders <Game> .Filter.Eq(x => x.Id, existingGame.Id);

                    var update = Builders <Game> .Update.Pull(x => x.Players, player);

                    await _gameCollection.UpdateOneAsync(filter, update);

                    OnPlayerAction?.Invoke(this, new PlayerEventArgs("A player has left the game.", player, game));
                }
            }
        }
Пример #9
0
 public bool Raise(int playerId, decimal raiseSum)
 {
     if (playerId != currentTurnPlayerId)
     {
         return(false);
     }
     lock (_lockObj)
     {
         // The minimum raise sum is current bet sum.
         if (raiseSum < currentBet)
         {
             return(false);
         }
         Player player = GetPlayer(playerId);
         if (player != null && player.Chips >= raiseSum)
         {
             foreach (Player p in Players)
             {
                 if (p == player || p.Folded)
                 {
                     continue;
                 }
                 decimal difference = raiseSum - p.CalledSum;
                 p.CallSum += difference;
             }
             player.CalledSum = raiseSum;
             player.CallSum   = player.CallSum - raiseSum < 0 ? 0 : player.CallSum - raiseSum;
             currentBet       = raiseSum;
             table.Contribute(player, raiseSum);
             player.Checked = true;
             NextPlayerTurn();
             OnPlayerAction?.Invoke(this, new PlayerActionEventArgs {
                 Player = player
             });
             return(true);
         }
         return(false);
     }
 }
Пример #10
0
 public bool Fold(int playerId)
 {
     if (playerId != currentTurnPlayerId)
     {
         return(false);
     }
     lock (_lockObj)
     {
         Player playerFold        = null;
         int    foldedPlayerCount = 0;
         foreach (Player player in Players)
         {
             if (player.PlayerId == playerId)
             {
                 playerFold = player;
             }
             if (player.Folded)
             {
                 foldedPlayerCount++;
             }
         }
         if (Players.Count - foldedPlayerCount == 1)
         {
             // can't fold if there is only one player left
             return(false);
         }
         if (playerFold != null)
         {
             playerFold.Folded = true;
             NextPlayerTurn();
             OnPlayerAction?.Invoke(this, new PlayerActionEventArgs {
                 Player = playerFold
             });
             return(true);
         }
         return(false);
     }
 }
Пример #11
0
 // Action
 public void startAction()
 {
     if (current.GetStaminaFillAmount() >= 1)
     {
         OnPlayerAction.Invoke();
         if (current.CompareNameTo("Kero"))
         {
             OnKeroAttack.Invoke();
         }
         else if (current.CompareNameTo("Kutter"))
         {
             OnKutterAttack.Invoke();
             current.SetBool("Action", true);
         }
         else if (current.CompareNameTo("Trisky"))
         {
             current.SetBool("Action", true);
             StartCoroutine(Heal());
         }
         else if (current.CompareNameTo("Cinamon") && isGrounded)
         {
             current.SetBool("Action", true);
             CinemachineController.instance.Shake(0.9f);
         }
         else if (current.CompareNameTo("Panda") && !current.GetBool("Run"))
         {
             current.SetBool("Action", true);
             isTakingPhoto = true;
             StartCoroutine(NoTakingPhoto());
         }
     }
     else if (!deniedAudio.isPlaying)
     {
         deniedAudio.Play();
     }
 }
Пример #12
0
 // Function to trigger OnPlayerAction event
 protected void PlayerActionEvent()
 {
     OnPlayerAction?.Invoke();
 }