Ejemplo n.º 1
0
 /// <summary>
 /// Добавить контроллер
 /// </summary>
 public void AddController(SessionsController controller)
 {
     if (controller == null)
     {
         throw new ArgumentNullException(nameof(controller));
     }
     if (Controllers.Find(q => q.Obj1 == controller) != null)
     {
         throw new ArgumentException("Already in session");
     }
     if (IsPlay)
     {
         throw new ArgumentException("Can't add controller on play");
     }
     Controllers.Add(new FreePair <IControllerInfo, TurnStatus>(controller.ControllerInfo, TurnStatus.expected));
     try
     { controller.AddSession(this); }
     catch { throw; }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Удаляет игрока и его солдат из игры
        /// </summary>
        public void RemoveController(SessionsController controller)
        {
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }
            var c = Controllers.Find(q => q.Obj1 == controller.ControllerInfo);

            if (c == null)
            {
                throw new ArgumentException("This controller is'nt in this session");
            }
            Controllers.Remove(c);
            var objs = SessionObjects.FindAll(cont => cont.Owner == controller);

            foreach (var f in objs)
            {
                f.SetSession(null);
                SessionObjects.Remove(f);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Воздействует на объекты
 /// </summary>
 protected virtual void Action(SessionsController player)
 {
     foreach (var f in modified)
     {
         if (f.Obj1.Owner == player)
         {
             if (f.Obj2 > 0)
             {
                 f.SetObj2(f.Obj2 - 1);
             }
             if (f.Obj2 == 0)
             {
                 modified.Remove(f);
                 f.Obj1.Modifiers.Remove(this);
             }
             else
             {
                 base.Action(f.Obj1 as Container);
             }
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Сделать ход
        /// </summary>
        public void MakeMove(SessionsController sender, int subjectID, string command, object[] param)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var controller = Controllers.Find(q => q.Obj1 == sender.ControllerInfo);

            if (controller == null)
            {
                throw new ArgumentException("Controller is'nt player of this session");
            }
            if (controller.Obj2 != TurnStatus.expected)
            {
                throw new ArgumentException("Controller already make his move");
            }

            var subject = GetObject(subjectID);

            if (subject == null)
            {
                throw new ArgumentException("No subject with this ID in this session");
            }

            var components = subject.GetComponentsOf <Component>();

            foreach (var component in components)
            {
                List <Type> types = new List <Type>();
                foreach (var f in param)
                {
                    types.Add(f.GetType());
                }

                var method = component.GetType().GetMethod(command, types.ToArray());
                if (method == null)
                {
                    throw new ArgumentException("Wrong method or params");
                }

                var attr = method.GetCustomAttribute(typeof(ControllerCommand), true);
                if (attr == null)
                {
                    throw new ArgumentException("Method is'nt controller command");
                }
                if ((attr as ControllerCommand).OnMyTurn != (HisTurn == sender))
                {
                    throw new ArgumentException("Turn error, not your turn");
                }
                method.Invoke(component, param);
                OnSessionChanged.Invoke(this, new SessionChange(sender.ControllerInfo.Name + " has his turn"));
                Controllers.Find(q => q.Obj1 == sender.ControllerInfo).SetObj2(TurnStatus.completed);
                return;
            }
        }
Ejemplo n.º 5
0
 public virtual void OnTurnEnds(SessionsController controller)
 {
 }
Ejemplo n.º 6
0
 public override void OnTurnEnds(SessionsController controller)
 {
     base.OnTurnEnds(controller);
     Action(controller);
 }