示例#1
0
 public void SendEnableLine(Vector2 pos, LogicLine.Positioning positioning, int nextTurn)
 {
     int[]  netData = { (int)NetworkCode.EnableLine, pos.X, pos.Y, (int)positioning, nextTurn };
     byte[] buffer  = new byte[netData.Length * sizeof(int)];
     Buffer.BlockCopy(netData, 0, buffer, 0, buffer.Length);
     Send(client, buffer);
 }
示例#2
0
        private void SelectOperation(NetworkCode code, byte[] data)
        {
            switch (code)
            {
            case NetworkCode.SendName:
                byte[] stringData = new byte[data.Length - sizeof(int)];
                Array.Copy(data, sizeof(int), stringData, 0, data.Length - sizeof(int));
                string name = Encoding.UTF8.GetString(stringData);
                //MessageBox.Show("ClientName = " + name);
                MultiplayerGameController.Instance.CreatePlayer(1, name, "O", false);
                if (ConnectToServerComplete != null)
                {
                    ConnectToServerComplete(name, ((IPEndPoint)client.RemoteEndPoint).Address.ToString(),
                                            ((IPEndPoint)client.RemoteEndPoint).Port.ToString());
                }
                break;

            case NetworkCode.EnableLine:
                byte[] buffer = new byte[data.Length - sizeof(int)];
                Array.Copy(data, sizeof(int), buffer, 0, data.Length - sizeof(int));
                int[] backData = new int[buffer.Length / sizeof(int)];
                Buffer.BlockCopy(buffer, 0, backData, 0, buffer.Length);
                Vector2 pos = new Vector2(backData[0], backData[1]);
                LogicLine.Positioning positioning = (LogicLine.Positioning)backData[2];
                int nextTurn = backData[3];
                //MessageBox.Show(pos + "\n" + positioning);
                OnLineEnable(pos, positioning, nextTurn);
                break;
            }
        }
示例#3
0
 public LogicLine GetLine(Vector2 pos, LogicLine.Positioning positioning)
 {
     if (positioning == LogicLine.Positioning.Horizontal)
     {
         if (LineTop.Line.Pos == pos)
         {
             return(LineTop.Line);
         }
         if (LineBottom.Line.Pos == pos)
         {
             return(LineBottom.Line);
         }
     }
     if (positioning == LogicLine.Positioning.Vertical)
     {
         if (LineLeft.Line.Pos == pos)
         {
             return(LineLeft.Line);
         }
         if (LineRight.Line.Pos == pos)
         {
             return(LineRight.Line);
         }
     }
     return(null);
 }
        private void LogicLineOnEnabled(Vector2 pos, LogicLine.Positioning positioning)
        {
            NextPlayer();
            OnNextPlayer();
            int nextTurnValue = TurnAgain ? 0 : 1;

            NetworkManager.Instance.NetworkGame.SendEnableLine(pos, positioning, nextTurnValue);
            TurnAgain = false;
        }
        public void EnableLine(Vector2 pos, LogicLine.Positioning positioning, int nextTurn)
        {
            /*int x = pos.X == 0 ? pos.X : pos.X - 1;
             * int y = pos.Y == 0 ? pos.Y : pos.Y - 1;
             * LogicRectangle rect = _gameField[x][y];
             * LogicLine line = rect.GetLine(pos, positioning);*/
            var result = from logicLine in LogicLines
                         where logicLine.Pos == pos && logicLine.LinePositioning == positioning
                         select logicLine;
            LogicLine line = result.First();

            Instance.nextTurn = nextTurn;

            UIController.Instance.NetRequestEnableLine(line);
        }
示例#6
0
 private void LogicLineOnEnabled(Vector2 pos, LogicLine.Positioning positioning)
 {
     NextPlayer();
     OnNextPlayer();
     TurnAgain = false;
 }
示例#7
0
 private void OnLineEnable(Vector2 pos, LogicLine.Positioning positioning, int nextTurn)
 {
     MultiplayerGameController.Instance.EnableLine(pos, positioning, nextTurn);
 }