Exemplo n.º 1
0
        private void Controller_MatchStarted(object sender, EventArgs e)
        {
            footballPitch.Dispatcher.Invoke(() =>
            {
                footballPitch.Width  = controller.Pitch.Width;
                footballPitch.Height = controller.Pitch.Height;
            });

            var initialPlayerPositions = new PositionCollection();

            CreateInitialPlayers(initialPlayerPositions);

            controller.HomePositionCollection = initialPlayerPositions;

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    SetHomeTeamPositions();
                    Stream data         = DataSerializer.CreateSerializedData(controller.HomePositionCollection);
                    PacketHeader header = PacketHeaderCreator.Create(CommandType.ContinuousSet, MessageType.PositionCollection, data.Length);

                    communicator.SendDataAsPacket(new Packet(header, data));

                    Stream ballData         = DataSerializer.CreateSerializedData(controller.BallPosition);
                    PacketHeader ballHeader = PacketHeaderCreator.Create(CommandType.ContinuousSet, MessageType.BallPosition, ballData.Length);

                    communicator.SendDataAsPacket(new Packet(ballHeader, ballData));

                    Thread.Sleep(25);
                }
            }, TaskCreationOptions.LongRunning).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        private void SendAwayTeamDataToBothClient()
        {
            Stream homeTeamPacketBody = DataSerializer.CreateSerializedData(homeTeamData.Team);
            Stream awayTeamPacketBody = DataSerializer.CreateSerializedData(awayTeamData.Team);

            PacketHeader homeTeamPacketHeader = PacketHeaderCreator.Create(CommandType.Set, MessageType.Team, homeTeamPacketBody.Length);
            PacketHeader awayTeamPacketHeader = PacketHeaderCreator.Create(CommandType.Set, MessageType.Team, awayTeamPacketBody.Length);

            homeTeamCommunicator.SendDataAsPacket(new Packet(awayTeamPacketHeader, awayTeamPacketBody));
            awayTeamCommunicator.SendDataAsPacket(new Packet(homeTeamPacketHeader, homeTeamPacketBody));
        }
Exemplo n.º 3
0
        private void ProcessPitchMessage(ServerCommunicator communicator, TeamData teamData1)
        {
            Stream       data   = DataSerializer.CreateSerializedData(pitch);
            PacketHeader header = PacketHeaderCreator.Create(CommandType.Set, MessageType.Pitch, data.Length);

            Console.WriteLine("Pitch getter message has been processed.");

            communicator.SendDataAsPacket(new Packet(header, data));

            Console.WriteLine("Pitch setter message has been sent.");
            Console.WriteLine("Team is ready.");
            teamData1.TeamReady = true;
        }
        public void Initialize()
        {
            // Send Team
            Stream       streamData = DataSerializer.CreateSerializedData(HomeTeam);
            PacketHeader header     = PacketHeaderCreator.Create(CommandType.Set, MessageType.Team, streamData.Length);

            communicator.SendDataAsPacket(new Packet(header, streamData));

            // Send Pitch getter
            Stream       pitchStreamData = DataSerializer.CreateSerializedData(HomeTeam);
            PacketHeader pitchHeader     = PacketHeaderCreator.Create(CommandType.Get, MessageType.Pitch, pitchStreamData.Length);

            communicator.SendDataAsPacket(new Packet(pitchHeader, pitchStreamData));
        }
Exemplo n.º 5
0
        private void SendOverallMatchData(ServerCommunicator communicator, CommandType commandType)
        {
            semaphore.Wait();

            Stream data = DataSerializer.CreateSerializedData(OverallMatchStandingCreator.Create(game, matchTimer,
                                                                                                 communicator != homeTeamCommunicator));

            PositionCollection test = DataSerializer.ReadSerializedData <OverallMatchStanding>(data).PositionCollection;

            PacketHeader header = PacketHeaderCreator.Create(commandType, MessageType.OverallMatchData, data.Length);

            communicator.SendDataAsPacket(new Packet(header, data));

            semaphore.Release();
        }
Exemplo n.º 6
0
        private void MatchTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            awayTeamData.DataSendingStopRequest = true;
            homeTeamData.DataSendingStopRequest = true;

            MatchStanding standing         = MatchStandingCreator.Create(game);
            Stream        standingAsStream = DataSerializer.CreateSerializedData(standing);

            PacketHeader header = PacketHeaderCreator.Create(CommandType.Set, MessageType.MatchResult, standingAsStream.Length);

            homeTeamCommunicator.SendDataAsPacket(new Packet(header, standingAsStream));

            PacketHeader awayHeader = PacketHeaderCreator.Create(CommandType.Set, MessageType.MatchResult, standingAsStream.Length);

            awayTeamCommunicator.SendDataAsPacket(new Packet(awayHeader, standingAsStream));
        }