コード例 #1
0
ファイル: PacketFactory.cs プロジェクト: dorgreen/StrategoLan
        public Packet GetPacketInstance(PacketHeader header)
        {
            Packet packet;

            switch (header)
            {
            case PacketHeader.BoardPacket:
                packet = new BoardPacket();
                break;

            case PacketHeader.PlayerReady:
                packet = new PlayerReadyPacket();
                break;

            case PacketHeader.AttemptMovePacket:
                packet = new AttemptMovePacket();
                break;

            case PacketHeader.ServerToClientGameStatusUpdatePacket:
                packet = new ServerToClientGameStatusUpdatePacket();
                break;

            default:
                throw new NotImplementedException(String.Format("Unhandled PacketHeader @ StaticPacketFactory {0}", header.ToString()));
            }

            return(packet);
        }
コード例 #2
0
ファイル: PacketFactory.cs プロジェクト: dorgreen/StrategoLan
        public Packet GetPacketInstance(PacketHeader header)
        {
            Packet packet = null;

            if (this.flywheel.ContainsKey(header))
            {
                packet = this.flywheel[header];
                packet.Recycle();
                return(packet);
            }
            else
            {
                switch (header)
                {
                case PacketHeader.BoardPacket:
                    packet = new BoardPacket();
                    break;

                case PacketHeader.PlayerReady:
                    packet = new PlayerReadyPacket();
                    break;

                case PacketHeader.AttemptMovePacket:
                    packet = new AttemptMovePacket();
                    break;

                case PacketHeader.ServerToClientGameStatusUpdatePacket:
                    packet = new ServerToClientGameStatusUpdatePacket();
                    break;

                default:
                    throw new NotImplementedException(String.Format("Unhandled PacketHeader @ PacketFactoryFlyWheel {0}", header.ToString()));
                }

                this.flywheel[header] = packet;
                return(packet);
            }
        }