Ejemplo n.º 1
0
 void IGameObservable.notifyObservers(Messages.GameMessages msg, DataPlayer player, List <object> data)
 {
     foreach (IGameObserver obs in observers)
     {
         obs.update(player, msg, data);
     }
 }
Ejemplo n.º 2
0
 public void playerUpdated(DataPlayer player)
 {
     if (player2.Equals(player) || player1.Equals(player))
     {
         setUpMatchStartingValue();
     }
 }
Ejemplo n.º 3
0
 bool checkTurn(DataPlayer player)
 {
     if (Turn == 0)
     {
         return(player.Equals(Player1));
     }
     else
     {
         return(player.Equals(Player2));
     }
 }
Ejemplo n.º 4
0
        void ISoMSelector.acquireSoM(SOM allowed, Result result)
        {
            DataPlayer active = Turn == 0?Player1:Player2;

            (this as IGameObservable).notifyObservers(Messages.GameMessages.GetSOM, active,
                                                      new List <object>()
            {
                new SoMRequest()
                {
                    Allowed = allowed, Result = result
                }
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Game decision point. This method gets messages from connection and decides what arguments to call, as well
        /// as taking care of runtime handlers for SoM requests
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="player"></param>
        /// <param name="data"></param>
        public void getMessageFromConnection(Messages.GameMessages msg, DataPlayer player, List <object> data)
        {
            if (!checkTurn(player))//Not right turn?
            {
                (this as IGameObservable).notifyObservers(Messages.GameMessages.NotPlayerTurn, player, null);
                Match.updateTranscript("Not your turn");
                return;
            }
            CharacterData    attacker = Turn == 0?Player1.Character:Player2.Character, defender = Turn == 0?Player2.Character:Player1.Character;
            ArgNames         actionName  = 0;
            ArgumentFeedback argFeedback = null;

            if (waiting && msg != Messages.GameMessages.somChosen)
            {
                Match.updateTranscript("Waiting for SOM");
                return;
            }

            switch (msg)
            {
            ///This case handles the response from a request to get SoM from the user
            ///We need to translate the response (SoMName,value) into values the Handler needs (JoySorrowValue,AngerFearValue)
            case Messages.GameMessages.somChosen:
                SOM name = (SOM)data[0];
                switch (name)
                {
                case SOM.Joy:
                    argFeedback = SoMHandler(1, 0);
                    break;

                case SOM.Sorrow:
                    argFeedback = SoMHandler(-1, 0);
                    break;

                case SOM.Anger:
                    argFeedback = SoMHandler(0, 1);
                    break;

                case SOM.Fear:
                    argFeedback = SoMHandler(0, -1);
                    break;
                }
                waiting = false;    //Just in case
                break;

            case Messages.GameMessages.Trick:
                actionName  = ArgNames.Trick;
                argFeedback = arguments[actionName].doArgument(attacker, defender, World);
                if ((arguments[actionName] as Trick).repeatTurn())
                {
                    Turn--;    //We turn it back then the regular turn counter turns it back to my turn
                }
                break;

            case Messages.GameMessages.Manipulate:
                actionName = ArgNames.Manipulate;
                goto case Messages.GameMessages.SoMDependentArgument;

            case Messages.GameMessages.Taunt:
                actionName = ArgNames.Taunt;
                goto case Messages.GameMessages.SoMDependentArgument;

            case Messages.GameMessages.Focus:
                actionName = ArgNames.Focus;
                goto case Messages.GameMessages.SoMDependentArgument;

            case Messages.GameMessages.Empathy:
                actionName  = ArgNames.Empathy;
                argFeedback = (arguments[actionName] as Empathy).doArgument(attacker, defender, World);
                if (argFeedback != null && argFeedback.result == Result.None)
                {
                    Match.updateTranscript("Empathy cannot be used\n");
                }
                break;

            case Messages.GameMessages.Bluff:
                actionName = ArgNames.Bluff;
                goto case Messages.GameMessages.GenericArgument;

            case Messages.GameMessages.Charm:
                actionName = ArgNames.Charm;
                goto case Messages.GameMessages.GenericArgument;

            case Messages.GameMessages.Coerce:
                actionName = ArgNames.Coerce;
                goto case Messages.GameMessages.GenericArgument;

            case Messages.GameMessages.Convince:
                actionName = ArgNames.Convince;
                goto case Messages.GameMessages.GenericArgument;

            case Messages.GameMessages.Scare:
                actionName = ArgNames.Scare;
                goto case Messages.GameMessages.GenericArgument;

            case Messages.GameMessages.GenericArgument:
                argFeedback = arguments[actionName].doArgument(attacker, defender, World);
                break;

            case Messages.GameMessages.SoMDependentArgument:
                (arguments[actionName] as SoMDependentArgument).Selector = this;

                argFeedback = (arguments[actionName] as SoMDependentArgument).doArgument(attacker, defender, World);
                //If true then it succeeded so it needs to get SoM
                if (argFeedback == null)
                {
                    waiting = true;
                }
                break;
            }//End Switch

            //Update transcript if there is feedback
            if (argFeedback != null)
            {
                argFeedback.playerName = player.PlayerName;
                Match.updateTranscript(argFeedback);
            }

            if (!waiting)
            {
                //Check Game over
                if (Match.Goal.isGoalReached(defender))
                {
                    (this as IGameObservable).notifyObservers(Messages.GameMessages.GameOver, Match.Player1, null);
                    (this as IGameObservable).notifyObservers(Messages.GameMessages.GameOver, Match.Player2, null);
                }
                else//Not over
                {
                    //Tell players to update and go to next turn
                    (this as IGameObservable).notifyObservers(Messages.GameMessages.ArgumentDone, player, null);
                    Turn = (Turn + 1) % 2;
                }
            }
        }
Ejemplo n.º 6
0
 void ISoMSelector.acquireSoM(List <string> allowed, Result result)
 {
     DataPlayer active = Turn == 0?Player1:Player2;
 }