Exemple #1
0
        private void ClientResivedMessage(object sender, NetManager.EventClientMsgArgs e)
        {
            int n = BitConverter.ToInt32(e.Msg, 0);

            if (n == 18)
            {
                var command = BitConverter.ToChar(e.Msg, 4);                 //пропускаем 1й символ
                SendCommand(command);
            }
        }
Exemple #2
0
        private void NmClient_OnReseive(object sender, NetManager.EventClientMsgArgs e)
        {
            if (listenServer)
            {
                int command = BitConverter.ToInt32(e.Msg, 0);

                if (command == com_up)
                {
                }
                else if (command == com_down)
                {
                    labelServCmd.Text = "Server last cmd: down";
                    spc.Down();
                }
                else if (command == com_right)
                {
                    labelServCmd.Text = "Server last cmd: right";
                    spc.Right();
                }
                else if (command == com_rMove)
                {
                    labelServCmd.Text = "Server last cmd: right move";
                    spc.RightMove();
                }
                else if (command == com_left)
                {
                    labelServCmd.Text = "Server last cmd: left";
                    spc.Left();
                }
                else if (command == com_lMove)
                {
                    labelServCmd.Text = "Server last cmd: left move";
                    spc.LeftMove();
                }
                else if (command == com_esLeft)
                {
                    labelServCmd.Text = "Server last cmd: esLeft";
                    spc.EaseRight();
                }
                else if (command == com_esRight)
                {
                    labelServCmd.Text = "Server last cmd: esRight";
                    spc.EaseLeft();
                }
                else if (command == com_run)
                {
                    labelServCmd.Text = "Server last cmd: bot run";
                    gameBot.RunAsync();
                }
                else if (command == com_pause)
                {
                    labelServCmd.Text = "Server last cmd: bot pause";
                    gameBot.Stop();
                }
                else if (command == com_fire)
                {
                    labelServCmd.Text = "Server last cmd: fire";
                    spc.Fire();
                }
            }
        }
Exemple #3
0
        private void Client_Reseive(object sender, NetManager.EventClientMsgArgs e)
        {
            int n = BitConverter.ToInt32(e.Msg, 0);

            //int _channelNumber = 23;
            if (n == 6)
            {
                if (!game.IsGameEnded)
                {
                    Frame dataFrame = new Frame(e.Msg);
                    List<int> dataStart = new List<int>();
                    timing += Frame.LengthData;
                    setTime();
                    if (!playersReady)
                    {
                        for (int i = 0; i < _channelCount; i++)
                        {
                            dataStart.Add(_channelNumbers[i] * Frame.LengthData);
                        }

                        for (int j = 0; j < dataStart.Count; j++)
                        {
                            values[j].Add(dataFrame.Data[dataStart[j]]);
                            k[j]++;
                        }

                        if (values[0].Count % 21 == 0)
                        {
                            for (int i = 0; i < _channelCount; i++)
                            {
                                List<double> l = setArr(values[i], values[i].Count - 21, values[i].Count);
                                double s = SquareDiff.GetSquareDiff(l);
                                diffs[i].Add(s);
                                strain[i] = CheckMuscles(s);
                            }
                            if (strain[0] == true && strain[1] == true)
                            {
                                playersReady = true;
                                timingstart = timing;
                            }

                        }
                        if (values[0].Count % 105 == 0)
                        {
                            showAllres();
                        }
                    }
                    else
                    {
                        if (!gameStarted)
                        {
                            label1.Text = "Приготовтесь: первый ход игрока 1";
                            if (timing - timingstart > 10000)
                            {
                                label1.Text = "FIGHT";
                                gameStarted = true;
                                timingstart = timing;
                               // leftTurn = false;
                                ChangeState();
                                values[0].Clear();
                                values[1].Clear();
                                diffs[0].Clear();
                                diffs[1].Clear();
                                foreach (Series s in ChartForDiff.Series)
                                {
                                    s.Points.Clear();
                                }
                            }
                        }
                        else // идет игра
                        {
                            int k = getChannel();
                            if (timing - timingstart > 30000)
                            {
                                values[k].Clear();
                                game.makeTurn((int)findMax(diffs[k]), leftTurn);
                                diffs[k].Clear();
                                ChangeState();
                                SetHP();
                            }
                            else
                            {
                                dataStart.Add(_channelNumbers[k] * Frame.LengthData);
                                for (int i = 0; i < Frame.LengthData; i++)
                                {
                                    values[k].Add(dataFrame.Data[k + i]);
                                }
                                if (values[k].Count % 21 == 0)
                                {
                                    List<double> l = setArr(values[k], values[k].Count - 21, values[k].Count);
                                    double s = SquareDiff.GetSquareDiff(l);
                                    diffs[k].Add(s);
                                }
                                if (values[k].Count % 105 == 0)
                                    showAllres();
                            }

                        }
                    }
                }
                else
                {
                    if (!gameEnded)
                    {
                       
                        PlaceResults();
                        gameEnded = true;
                    }
                                     
                }
            }
        }