public void UpdateMove()
 {
     x = _scrollTargetRect.anchoredPosition.x;
     y = _scrollTargetRect.anchoredPosition.y;
     if (MoveEventEnabled)
     {
         moved.Invoke(_scrollTargetRect.anchoredPosition.x, _scrollTargetRect.anchoredPosition.y);
     }
 }
Example #2
0
        /// <summary>
        /// OnUpdateSelected event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public virtual void OnUpdateSelected(BaseEventData eventData)
        {
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                var axisEvent = new AxisEventData(EventSystem.current)
                {
                    moveDir = MoveDirection.Left,
                };
                OnMoveEvent.Invoke(axisEvent);
                return;
            }

            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                var axisEvent = new AxisEventData(EventSystem.current)
                {
                    moveDir = MoveDirection.Right,
                };
                OnMoveEvent.Invoke(axisEvent);
                return;
            }

            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                var axisEvent = new AxisEventData(EventSystem.current)
                {
                    moveDir = MoveDirection.Up,
                };
                OnMoveEvent.Invoke(axisEvent);
                return;
            }

            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                var axisEvent = new AxisEventData(EventSystem.current)
                {
                    moveDir = MoveDirection.Down,
                };
                OnMoveEvent.Invoke(axisEvent);
                return;
            }

            if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
            {
                var isEnter = Input.GetKey(KeyCode.Return) || Input.GetKey(KeyCode.KeypadEnter);
                var isShift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
                if (!(isEnter && isShift))
                {
                    OnSubmitEvent.Invoke(eventData, isEnter);
                }

                return;
            }
        }
Example #3
0
        /// <summary>
        /// Performs the specified move, if it's available.
        /// </summary>
        /// <param name="move">The specified move.</param>
        /// <param name="force">Whether to perform the move even if it's unavailable.</param>
        /// <returns>Whether the move was performed.</returns>
        public bool Perform(Move move, bool force, bool mute)
        {
            if (move == null || move.CurrentState == Move.State.Active)
            {
                return(false);
            }

            if (Controller.Interrupted)
            {
                OnInterrupted.Invoke(move);
                return(false);
            }

            if (force)
            {
                if (move.CurrentState == Move.State.Unavailable)
                {
                    if (move.Layer != MoveLayer.None)
                    {
                        End(Layers[move.Layer]);
                        Layers[move.Layer] = move;
                    }

                    var result = move.ChangeState(Move.State.Active, mute);
                    OnPerform.Invoke(move);
                    return(result);
                }

                if (move.CurrentState == Move.State.Available)
                {
                    return(Perform(move, false, mute));
                }

                return(false);
            }
            else
            {
                if (move.CurrentState != Move.State.Available)
                {
                    return(false);
                }

                if (move.Layer != MoveLayer.None)
                {
                    End(Layers[move.Layer]);
                    Layers[move.Layer] = move;
                }

                var result = move.ChangeState(Move.State.Active, mute);
                OnPerform.Invoke(move);
                return(result);
            }
        }
Example #4
0
        /// <summary>
        /// Removes the specified move from the moveset.
        /// </summary>
        /// <param name="move">The specified move.</param>
        public bool Remove(Move move)
        {
            var result = Moves.Remove(move);

            if (!result)
            {
                return(false);
            }

            move.NotifyManagerRemove(this);
            OnRemove.Invoke(move);

            var go = move.gameObject;

            Destroy(move);

            var moves = go.GetComponents <Move>();

            if (moves.Length == 0 || moves.All(move1 => move1.Manager != this))
            {
                Destroy(go);
            }

            return(true);
        }
Example #5
0
 private void InvokeMoveEvent(Transform trans)
 {
     if (moved != null)
     {
         moved.Invoke(trans);
     }
 }
        private void UpdateEvent(DateTime _start)
        {
            Event    item     = DragDropHelper.Item.Event;
            TimeSpan duration = item.End - item.Start;

            item.Start = _start;
            item.End   = _start.Add(duration);
            MoveEvent?.Invoke(item);
        }
 private void HeroMoved(Unit hero, Cell from, Cell to, IntVector2 direction)
 {
     if (!gameObject.activeInHierarchy)
     {
         return;
     }
     run.Invoke(hero, from, to, direction);
     heroRun.Invoke(hero);
 }
Example #8
0
 private void WindowEventCallback(IntPtr hWinEventHook, SWEH_Events eventType, IntPtr hWnd, SWEH_ObjectId idObject, long idChild, uint dwEventThread, uint dwmsEventTime)
 {
     if (hWnd == windowHandle)
     {
         if (eventType == SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE && idObject == (SWEH_ObjectId)SWEH_CHILDID_SELF)
         {
             MoveEvent?.Invoke(this, new MoveEventArgs());
         }
     }
 }
Example #9
0
 private void InvokeMoveEvent(MoveDirection move)
 {
     if (MoveEvent != null)
     {
         MoveEvent.Invoke(new BoardEvent
         {
             BoardEventType = BoardEventType.PlayerMoved,
             Move           = move
         });
     }
 }
Example #10
0
 void Update()
 {
     foreach (var key in _inputs.Keys)
     {
         if (Input.GetKeyDown(key))
         {
             MoveEvent?.Invoke(this, new InfoEventArgs <Direction>(_inputs[key]));
             break;
         }
     }
 }
Example #11
0
        private void MoveAction(int obj)
        {
            List <int> routeList = new List <int>();//记录下经过的路径

            routeList.Add(CurrentPlayer.Location.Index);

            Random ran  = new Random();
            int    step = ran.Next(1, 7);

            //执行Move
            int roadIndex = CurrentPlayer.RoadIndex;
            int direction = CurrentPlayer.Direction;
            var location  = CurrentPlayer.Location;

            for (int i = 0; i < step; i++)
            {
                Location tempLocation  = null;
                int      tempDirection = direction;
                int      tempRoadIndex = roadIndex;

                //同一条线路往前走
                RoadInfo sameRoad = location.RoadInfos.First(p => p.RoadIndex == roadIndex);
                tempLocation = direction == 1 ? sameRoad.ForwardLocation : sameRoad.BackwardLocation;
                //三岔路时,随机走(必须是三岔路,即另一条路的两个方向都必须是有路的)
                if (tempLocation == null)
                {
                    tempDirection = ran.Next(2) == 0 ? -1 : 1;
                    RoadInfo otherRoad = location.RoadInfos.First(p => p.RoadIndex != roadIndex);
                    tempRoadIndex = otherRoad.RoadIndex;
                    tempLocation  = tempDirection == 1 ? otherRoad.ForwardLocation : otherRoad.BackwardLocation;
                    //死胡同时
                    if (tempLocation == null)
                    {
                        tempRoadIndex = roadIndex;
                        tempDirection = -direction;
                        tempLocation  = tempDirection == 1 ? sameRoad.ForwardLocation : sameRoad.BackwardLocation;
                    }
                }

                direction = tempDirection;
                location  = tempLocation;
                roadIndex = tempRoadIndex;

                routeList.Add(location.Index);
            }

            CurrentPlayer.RoadIndex = roadIndex;
            CurrentPlayer.Direction = direction;
            CurrentPlayer.Location  = location;

            //UI动画
            MoveEvent?.Invoke(routeList);
        }
Example #12
0
        public void HandleState(Move move)
        {
            if (!move.enabled || !move.gameObject.activeInHierarchy)
            {
                return;
            }
            if (move.CurrentState == Move.State.Unavailable)
            {
                if (!move.Available)
                {
                    return;
                }

                move.ChangeState(Move.State.Available);
                OnAvailable.Invoke(move);
            }

            if (move.CurrentState == Move.State.Available)
            {
                if (!move.Available)
                {
                    move.ChangeState(Move.State.Unavailable);
                    OnUnavailable.Invoke(move);
                }
                else if (move.AllowShouldPerform && move.ShouldPerform)
                {
                    Perform(move, false, false);
                }
            }
            else if (move.CurrentState == Move.State.Active)
            {
                if (move.AllowShouldEnd && move.ShouldEnd)
                {
                    End(move);
                    OnAvailable.Invoke(move);
                }
            }
        }
Example #13
0
 public virtual void OnUpdateSelected(BaseEventData eventData)
 {
     if (Input.GetKeyDown(KeyCode.LeftArrow))
     {
         var axisEvent = new AxisEventData(EventSystem.current);
         axisEvent.moveDir = MoveDirection.Left;
         OnMoveEvent.Invoke(axisEvent);
         return;
     }
     if (Input.GetKeyDown(KeyCode.RightArrow))
     {
         var axisEvent = new AxisEventData(EventSystem.current);
         axisEvent.moveDir = MoveDirection.Right;
         OnMoveEvent.Invoke(axisEvent);
         return;
     }
     if (Input.GetKeyDown(KeyCode.UpArrow))
     {
         var axisEvent = new AxisEventData(EventSystem.current);
         axisEvent.moveDir = MoveDirection.Up;
         OnMoveEvent.Invoke(axisEvent);
         return;
     }
     if (Input.GetKeyDown(KeyCode.DownArrow))
     {
         var axisEvent = new AxisEventData(EventSystem.current);
         axisEvent.moveDir = MoveDirection.Down;
         OnMoveEvent.Invoke(axisEvent);
         return;
     }
     //if (Input.GetKeyDown(KeyCode.Tab))
     if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
     {
         OnSubmitEvent.Invoke(eventData);
         return;
     }
 }
Example #14
0
        /// <summary>
        /// Ends the specified move if it's active.
        /// </summary>
        /// <param name="move">The specified move.</param>
        /// <returns>Whether the move was ended.</returns>
        public bool End(Move move)
        {
            if (move == null || move.CurrentState != Move.State.Active)
            {
                return(false);
            }

            if (move.Layer != MoveLayer.None)
            {
                Layers[move.Layer] = null;
            }

            move.ChangeState(move.Available ? Move.State.Available : Move.State.Unavailable);
            OnEnd.Invoke(move);

            return(true);
        }
Example #15
0
    public virtual void MoveTo(Directory directory)
    {
        Directory previousDirectory = currentDirectory;

        currentDirectory = directory;
        directoryHistory.Insert(0, previousDirectory);
        transform.parent = currentDirectory.transform;
        onMove.Invoke(currentDirectory, previousDirectory);
        if (previousDirectory != null)
        {
            previousDirectory.EntityExit(currentDirectory, this);
            previousDirectory.onEntityEnter.RemoveListener(OnEntityEnterMyDirectory);
            previousDirectory.onEntityExit.RemoveListener(OnEntityExitMyDirectory);
        }
        currentDirectory.EntityEnter(previousDirectory, this);
        currentDirectory.onEntityEnter.AddListener(OnEntityEnterMyDirectory);
        currentDirectory.onEntityExit.AddListener(OnEntityExitMyDirectory);
    }
Example #16
0
    public void Move(Vector2 moveTo)
    {
        Debug.Log("Move");
        if (moveTo.x > 0)
        {
            SetRotation(1);
            sword.sortingOrder = 0;
        }

        if (moveTo.x < 0)
        {
            SetRotation(0);
            sword.sortingOrder = 4;
        }

        var vec = moveTo * (speed * Time.deltaTime);

        _event.Invoke(vec);
        body.MovePosition(body.position + vec);
    }
Example #17
0
    public void OnButtonPress(string buttonType)
    {
        switch (buttonType)
        {
        case "Jump":
            JumpEvent?.Invoke();
            break;

        case "MoveRight":
            MoveEvent?.Invoke(1);
            break;

        case "MoveLeft":
            MoveEvent?.Invoke(-1);
            break;

        case "Stop":
            MoveEvent?.Invoke(0);
            break;
        }
    }
Example #18
0
        public void MoveBlock(Tower from, Tower to)
        {
            Block block = from.TopBlock;

            if (block == null || !to.AddBlockToTop(block))
            {
                return;
            }
            from.TopBlock = null;
            Tower[] curTowers = new Tower[3];
            for (int i = 0; i < 3; i++)
            {
                curTowers[i] = new Tower(blockCount);
                curTowers[i].SetBlocks(towers[i].GetBlocks());
            }
            MoveInfo moveInfo = new MoveInfo(curTowers);

            moves.Add(moveInfo);
            BlockMoved?.Invoke(moveInfo);
            CheckGame();
        }
        // Update is called once per frame
        void Update()
        {
            //if (Input.GetAxis("Moving") != 0 && MoveEvent != null)
            //    MoveEvent.Invoke(Input.GetAxis("Moving"));

            if (MoveEvent != null)
            {
                MoveEvent.Invoke(Input.GetAxis("Moving"));
            }

            if (Input.GetKeyDown(KeyCode.Space) && CryEvent != null)
            {
                CryEvent.Invoke(Input.GetAxis("Cry"));
            }

            if ((Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftControl)) && BlockEvent != null)
            {
                BlockEvent.Invoke(Input.GetAxis("Block"));
            }

            _ExecutingCommands();
        }
Example #20
0
        public static bool DeviceInput(IDeviceInput input)
        {
            // Mouse move is handled here to reduce performance impact due to its high frequency
            if (input.Key == Key.MouseMove)
            {
                if (input.Injected)
                {
                    return(false);
                }
                MoveEvent?.Invoke();
                LastMouseAction = Time.Now;
                return(IsLocked || IsMouseLocked || IsMouseMoveLocked);
            }

            if (input.Key.IsUnknown())
            {
                return(false);
            }
            var key = !StatelessNumpad || !input.Key.IsNumpad() ? input.Key : MapNumpad(input.Key);

            // Deal with injected input
            if (input.Injected && (!key.IsMedia() || (uint)input.ExtraInfo == pid))
            {
                if (!key.IsStateless())
                {
                    if (input.State)
                    {
                        DownKeysVirtual.Add(key);
                    }
                    else
                    {
                        DownKeysVirtual.Remove(key);
                    }
                }

                return(false);
            }

            // Record key state if it has changed (ignore auto-repeat presses)
            if (input.State != IsDown(key))
            {
                if (!key.IsStateless())
                {
                    SetState(key, input.State);
                }
                History.Push(new KeyState(key, input.State));
                GlobalIDs[key] = ++CurrentGlobalID;
            }

            // Invoke special key event subscriptions
            InputEvent?.Invoke(key, input.State);

            // Check lock state
            bool locked = IsLocked || IsAllKeysLocked || (key.IsMouse() ? IsMouseLocked : IsKeyboardLocked) || IsLockedKey(key);
            bool blocked;

            // Update idle info
            if (key.IsMouse())
            {
                LastMouseAction = Time.Now;
            }
            else
            {
                LastKeyboardAction = Time.Now;
            }

            // If hotkey is running tell it that the key has been released
            if (!input.State && HotkeyManager.CurrentHotkeys.ContainsKey(key))
            {
                blocked = HotkeyManager.KeyUp(key);
            }

            // Block key if locked
            else if (locked)
            {
                return(true);
            }

            // Hotkey for that key is already running
            else if (HotkeyManager.CurrentHotkeys.ContainsKey(key))
            {
                blocked = HotkeyManager.IsBlocked(key);
            }

            // Pass key event to hotkey manager
            else if (input.State)
            {
                blocked = HotkeyManager.KeyDown(key);
            }
            else
            {
                blocked = HotkeyManager.KeyUp(key);
            }

            if (!blocked)
            {
                SetStateVirtual(key, input.State);
            }
            return(blocked);
        }
Example #21
0
 public void OnMove(InputAction.CallbackContext context)
 {
     MoveEvent.Invoke(context.ReadValue <Vector2>());
 }
        private void Update()
        {
            // Determine which keys are currently being pressed.
            bool pressingW = Input.GetKey(KeyCode.W);
            bool pressingS = Input.GetKey(KeyCode.S);
            bool pressingA = Input.GetKey(KeyCode.A);
            bool pressingD = Input.GetKey(KeyCode.D);
            bool pressingQ = Input.GetKey(KeyCode.Q);
            bool pressingE = Input.GetKey(KeyCode.E);
            //bool pressingSpace = Input.GetKey(KeyCode.Space)
            // bool pressingUp = Input.GetKey(KeyCode.UpArrow);
            // bool pressingDown = Input.GetKey(KeyCode.DownArrow);
            // bool pressingLeft = Input.GetKey(KeyCode.LeftArrow);
            // bool pressingRight = Input.GetKey(KeyCode.RightArrow);

            // Convert to simple summaries of whether movement and/or rotation is required this frame.
            // bool isMoving = pressingW || pressingS || pressingA || pressingD || pressingQ || pressingE;
            // bool isRotating = pressingUp || pressingDown || pressingLeft || pressingRight;

            bool isMoving   = pressingW || pressingS || pressingA || pressingD;
            bool isRotating = pressingQ || pressingE;

            // If no change is to be applied this frame, we skip any further processing.
            if (!isMoving && !isRotating)
            {
                return;
            }

            // Convert key presses to directions of movement and rotation.
            // float xInput = pressingD ? 1 : pressingA ? -1 : 0;
            // float yInput = pressingE ? 1 : pressingQ ? -1 : 0;
            // float zInput = pressingW ? 1 : pressingS ? -1 : 0;
            // float rotX = pressingDown ? 1 : pressingUp ? -1 : 0;
            // float rotY = pressingRight ? 1 : pressingLeft ? -1 : 0;

            float xInput = pressingD ? 1 : pressingA ? -1 : 0;
            float zInput = pressingW ? 1 : pressingS ? -1 : 0;
            float rot    = pressingQ ? -1 : pressingE ? 1 : 0;

            // Apply movement. We skip this if there is no movement this frame.
            Vector3 positionBefore = transform.position;

            if (isMoving)
            {
                // Move the camera at a speed that is linearly dependent on the height of the camera above
                // the ground plane to make camera manual camera movement practicable. The movement speed
                // is clamped between 1% and 100% of the configured MovementSpeed.
                float   speed   = Mathf.Clamp(transform.position.y, MovementSpeed * 0.01f, MovementSpeed);
                Vector3 forward = Quaternion.Euler(0, Azimuth, 0) * Vector3.forward;
                Vector3 right   = Quaternion.Euler(0, Azimuth, 0) * Vector3.right;

                Vector3 motion =
                    (right * xInput + forward * zInput /* + yInput * Vector3.up*/) * speed * Time.deltaTime;
                Vector3 position = transform.position + motion;

                // Enforce min/max height.
                position.y         = Mathf.Clamp(position.y, Height, Height);
                transform.position = position;
            }

            // Rotate, adding change in rotation to current rotation (recorded before overriden for
            // movement). We skip this if there is no rotation this frame.
            if (isRotating)
            {
                Azimuth += rot * RotationSpeed * Time.deltaTime;

                // Inclination = Mathf.Clamp(
                //     Inclination + rotX * RotationSpeed * Time.deltaTime, MinXRotation, MaxXRotation);

                // Quaternion.Euler is documented as applying X-rotation before Y-rotation, in world space.
                transform.localRotation = Quaternion.Euler(/*Inclination*/ 10, Azimuth, 0);
            }

            // Invoke any defined Actions to inform other classes of any change in Camera's movement or
            // rotation this frame.
            if (isMoving)
            {
                // Pass in the amount moved this frame (current position minus position last frame).
                OnMove.Invoke(transform.position - positionBefore);
            }

            if (isRotating)
            {
                OnRotate.Invoke();
            }

            OnTransform.Invoke();
        }
Example #23
0
 protected void NotifyAdd(Move move)
 {
     Moves.Add(move);
     move.NotifyManagerAdd(this);
     OnAdd.Invoke(move);
 }
Example #24
0
 public void InvokeMoveEvent(MoveDirection direction) => MoveEvent?.Invoke(direction);
Example #25
0
        public void ProcessMessage(Frame frame)
        {
            switch (frame.MsgType)
            {
            case MessageType.Connect:
                break;

            case MessageType.Exchange:
                Room Room;
                switch (frame.GameMsgType)
                {
                case GameMessageType.CreateGame:

                    if (IsContaninsRoom(frame.RoomId, out Room) == false)
                    {
                        Room = ((CreateRoom)frame.Data).ToRoom(Rooms.Count + 1);
                        Rooms.Add(Room);
                        Cnsl.AppendText("[SYSTEM]: создана комната " + Room.Name + " с идентификатором " + Room.Id + "\n");
                        Cnsl.AppendText("[" + Room.Name + "]: подключился игрок " + Room.ActivePlayer.Name + "\n");
                    }
                    break;

                case GameMessageType.Connect:
                    if (IsContaninsRoom(frame.RoomId, out Room) == true)
                    {
                        if (Room.AddPlayer((string)frame.Data))
                        {
                            Cnsl.AppendText("[" + Room.Name + "]: подключился игрок " + (string)frame.Data + "\n");
                            MoveEvent?.Invoke(Room);
                        }
                    }
                    break;

                case GameMessageType.Send:
                    if (IsContaninsRoom(frame.RoomId, out Room) == true)
                    {
                        int move = new Random(Convert.ToInt32((int)DateTime.Now.Ticks)).Next(1, 7);
                        if (move == 1)
                        {
                            Cnsl.AppendText("[" + Room.Name + "]: игрок " + Room.ActivePlayer.Name + "сделал ход и ему выпало 1. Ход переходит к следующему игроку\n");
                            Room.ActivePlayer.LastRound.Add(move);
                            Room.NextPlayer();
                            Room.ActivePlayer.LastRound.Clear();
                        }
                        else
                        {
                            if (Room.ActivePlayer.Score + Room.ActivePlayer.LastRound.Sum() + move >= 100)
                            {
                                Room.ActivePlayer.LastRound.Add(move);
                                Room.ActivePlayer.Rounds.Add(Room.ActivePlayer.LastRound.Sum());
                                Room.ActivePlayer.LastRound.Clear();
                                Cnsl.AppendText("[" + Room.Name + "]: игрок " + Room.ActivePlayer.Name + "сделал ход " + move + ", и победил в игре со счетом " + Room.ActivePlayer.Score + Room.ActivePlayer.LastRound.Sum() + move + "\n");
                                Room.Status = GameStatus.Over;
                            }
                            else
                            {
                                Cnsl.AppendText("[" + Room.Name + "]: игрок " + Room.ActivePlayer.Name + "сделал ход и ему выпало " + move + "\n");
                                Room.ActivePlayer.LastRound.Add(move);
                            }
                        }
                        MoveEvent?.Invoke(Room);
                    }
                    break;

                case GameMessageType.Wait:
                    if (IsContaninsRoom(frame.RoomId, out Room) == true)
                    {
                        if (Room.ActivePlayer.Name == frame.Data.ToString())
                        {
                            Room.ActivePlayer.Rounds.Add(Room.ActivePlayer.LastRound.Sum());
                            Room.NextPlayer();
                            Room.ActivePlayer.LastRound.Clear();
                            MoveEvent?.Invoke(Room);
                        }
                    }
                    break;
                }
                break;

            case MessageType.Disconnect:
                if (IsContaninsRoom(frame.RoomId, out Room) == true)
                {
                    if (Room.Players.Count < 2)
                    {
                        Cnsl.AppendText("[" + Room.Name + "]: игрок " + (string)frame.Data + " покидает игру\n");
                        Cnsl.AppendText("[SYSTEM]: комната " + Room.Name + " расформирована\n");
                        Rooms.Remove(Room);
                    }
                    else
                    {
                        Cnsl.AppendText("[" + Room.Name + "]: игрок " + (string)frame.Data + " покидает игру\n");
                        Room.RemovePlayer((string)frame.Data);
                        MoveEvent?.Invoke(Room);
                    }
                }
                break;
            }
        }
Example #26
0
 public void GetMove(Position position, string login)
 {
     MoveEvent?.Invoke(position, login);
 }
Example #27
0
 public void Move(int x, int y)
 {
     X += x;
     Y += y;
     MoveEvent?.Invoke($"Смещение на x = {x}, y = {y}");
 }
Example #28
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (playSolo && enemies.Count <= 0)
            {
                Random random = new Random();
                enemies.Add(createNewEnemy(enemyID_Solo++, random.Next(550, 700), random.Next(50, 350), random.Next(1, 5) * 10, random.Next(1, 3), random.Next(1, 3)));
                timer2.Stop();
                timer2.Start();
            }

            if (playSolo)
            {
                time = time.AddMilliseconds(-25);
                if (time.Subtract(time1).TotalMilliseconds >= 0)
                {
                    timerLlabel.Text = time.ToString("mm:ss.fffK");
                }
                else
                {
                    timerLlabel.Text = time1.ToString("mm:ss.fffK");
                    timer1.Stop();
                    timer2.Stop();
                }
            }

            if (!playSolo && !firstConntect && Server.serverStarted)
            {
                firstConntect = true;
                ClientUnit cu = new ClientUnit();
                threadClient = new Thread(cu.Main);
                //thread.Start(textBox1.Text);
                threadClient.Start(textBox2.Text + " " + portTextBox1.Text);
            }
            if (!timerBlock)
            {
                timer2.Start();
                timerBlock = true;
            }
            List <Enemy> en       = new List <Enemy>();
            List <Shell> sh       = new List <Shell>();
            bool         moveDone = false;

            Refresh();
            //Произошла отрисовка столкновения. После чего удаляю пулю и врага

            for (int i = 0; i < shells.Count; i++)
            {
                for (int j = 0; j < enemies.Count; j++)
                {
                    try
                    {
                        if ((shells[i].x + 20 >= enemies[j].x) && (shells[i].x <= enemies[j].x + 20) &&
                            (shells[i].y + 5 >= enemies[j].y) && (shells[i].y <= enemies[j].y + 20))
                        {
                            enemies[j].killedBy = shells[i].whoShoot;

                            Console.WriteLine("killed by " + enemies[j].killedBy + "                                          player ID " + player.ID);

                            if (enemies[j].killedBy == player.ID)
                            {
                                player.score += enemies[j].killBonus;
                            }
                            else
                            {
                                anotherPlayer.score += enemies[j].killBonus;
                            }

                            en.Add(enemies[j]);
                            sh.Add(shells[i]);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("           !!!!!!!!!! Exception in enemies/shells cycle");
                    }
                }
            }
            if (en.Count > 0)
            {
                List <int> killedEnemiesIDs = new List <int>();
                List <int> killedShellsIDs  = new List <int>();

                string package = "";


                foreach (Enemy enemy in en)
                {
                    enemies.Remove(enemy);
                    killedEnemiesIDs.Add(enemy.enemyID);
                    package += " " + enemy.enemyID + " " + enemy.killedBy;
                }
                foreach (Shell shell in sh)
                {
                    shells.Remove(shell);
                    killedShellsIDs.Add(shell.shellID);
                    package += " " + shell.shellID;
                }
                if (!playSolo)
                {
                    ClientUnit.Send(ClientUnit.socket, ClientUnit.PacketInfo.EnemyKilled, package);
                }
            }
            /////
            MoveEvent?.Invoke();

            if (player != null)
            {
                scoreLabel.Text = player.score.ToString();
                if (anotherPlayer != null)
                {
                    anotherPlayerScoreLabel.Text = anotherPlayer.score.ToString();
                }

                if (WPressed)
                {
                    player.y -= 10;
                    moveDone  = true;
                }
                if (APressed)
                {
                    player.x -= 10;
                    moveDone  = true;
                }
                if (SPressed)
                {
                    player.y += 10;
                    moveDone  = true;
                }
                if (DPressed)
                {
                    player.x += 10;
                    moveDone  = true;
                }
                if (!playSolo && moveDone)
                {
                    ClientUnit.Send(ClientUnit.socket, ClientUnit.PacketInfo.Position);
                }
            }
            if (player != null && anotherPlayer != null)
            {
                if (player.score >= 200 && anotherPlayer.score < 200)
                {
                    timer1.Stop();
                    MessageBox.Show("You win! Congratulations!");
                }
                if (anotherPlayer.score >= 200 && player.score < 200)
                {
                    timer1.Stop();
                    MessageBox.Show("You lose =(");
                }
                if (player.score >= 200 && anotherPlayer.score >= 200)
                {
                    timer1.Stop();
                    MessageBox.Show("Draw");
                }
            }
            if (isReloading)
            {
                reloadProgress += 2;
            }
        }
Example #29
0
 public void UIInputMove()
 {
     MoveEvent?.Invoke(2);
 }
Example #30
0
 public static void Update(int ida, int idb, Point point, Point point2)
 {
     Console.WriteLine("FFFFF");
     MoveEvent?.Invoke(ida, idb, point, point2);
 }