Exemplo n.º 1
0
        public static GAMEOVERMESSAGE Deserialize(ref BinaryReader reader)
        {
            GAMEOVERMESSAGE output = new GAMEOVERMESSAGE();

            output.playerID = reader.ReadInt32();
            return(output);
        }
Exemplo n.º 2
0
        public void SendMessageToClient(DataMessage msg)
        {
            if (server.ConnectionsCount > 0)
            {
                NetworkMessage sm = new NetworkMessage();


                // Temporary
                switch (msg.type)
                {
                case DataMessage_Type.GAME_STATE:
                    GameStateMessage gameStateMsg = msg as GameStateMessage;
                    sm.Set_Data(gameStateMsg);
                    break;

                case DataMessage_Type.PLAYER_UPDATE:
                    PlayerUpdateMessage playerMsg = msg as PlayerUpdateMessage;
                    sm.Set_Data(playerMsg);
                    break;

                case DataMessage_Type.FENCE_HIT:
                    FenceHitMessage fMsg = msg as FenceHitMessage;
                    sm.Set_Data(fMsg);
                    break;

                case DataMessage_Type.MISSLE_MINE:
                    MissileMineMessage MMMsg = msg as MissileMineMessage;
                    sm.Set_Data(msg);
                    break;

                case DataMessage_Type.ROTATION:
                    RotationMessage rMsg = msg as RotationMessage;
                    sm.Set_Data(msg);
                    break;

                case DataMessage_Type.MISSILEUPDATE:
                    MissileUpdateMessage tmsg = msg as MissileUpdateMessage;
                    sm.Set_Data(msg);
                    break;

                case DataMessage_Type.GAME_OVER:
                    GAMEOVERMESSAGE gomsg = msg as GAMEOVERMESSAGE;
                    sm.Set_Data(msg);
                    break;

                default:
                    break;
                }

                NetOutgoingMessage om = server.CreateMessage();

                om.Write(sm.Serialize());
                server.SendMessage(om, server.Connections, NetDeliveryMethod.ReliableOrdered, 4);

                server.FlushSendQueue();
            }
        }
Exemplo n.º 3
0
        public static void RecieveMessage(DataMessage msg)
        {
            if (instance.state == GAME_STATE.LOBBY)
            {
                switch (msg.type)
                {
                case DataMessage_Type.GAME_STATE:
                    instance.ProcessGameStateMessage(msg as GameStateMessage);
                    break;
                }
            }
            else if (instance.state == GAME_STATE.PLAY)
            {
                switch (msg.type)
                {
                case DataMessage_Type.PLAYER_INPUT:
                    PlayerInputMessage pMsg = msg as PlayerInputMessage;
                    instance.ProcessPlayerInputMessage(pMsg);
                    break;

                case DataMessage_Type.PLAYER_UPDATE:
                    PlayerUpdateMessage updateMsg = msg as PlayerUpdateMessage;
                    instance.ProcessPlayerUpdateMessage(updateMsg);
                    break;

                case DataMessage_Type.FENCE_HIT:
                    FenceHitMessage fenceMsg = msg as FenceHitMessage;
                    instance.ProcessFenceHitMessage(fenceMsg);
                    break;

                case DataMessage_Type.MISSLE_MINE:
                    MissileMineMessage MMMsg = msg as MissileMineMessage;
                    instance.ProcessMissileMineMessage(MMMsg);
                    break;

                case DataMessage_Type.ROTATION:
                    RotationMessage rMsg = msg as RotationMessage;
                    instance.ProcessRotationMessage(rMsg);
                    break;

                case DataMessage_Type.MISSILEUPDATE:
                    MissileUpdateMessage MMsg = msg as MissileUpdateMessage;
                    instance.ProcessMissileUpdateMessage(MMsg);
                    break;

                case DataMessage_Type.GAME_OVER:
                    GAMEOVERMESSAGE gomsg = msg as GAMEOVERMESSAGE;
                    instance.ProcessGameOverMessage(gomsg);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 4
0
 private void AddPointUpdate()
 {
     if (clean == true)
     {
         if (p1Score >= 3 || p2Score >= 3)
         {
             state = GAME_STATE.GAME_OVER;
             GAMEOVERMESSAGE msg = new GAMEOVERMESSAGE(1);
             InputQueue.AddToQueue(msg);
         }
         else
         {
             LoadLevel();
             state = GAME_STATE.PLAY;
         }
     }
 }
Exemplo n.º 5
0
        public static NetworkMessage Deserialize(byte[] bytes)
        {
            BinaryReader   reader = new BinaryReader(new MemoryStream(bytes));
            NetworkMessage output = new NetworkMessage();

            output.data_type = (DataMessage_Type)reader.ReadInt32();

            switch (output.data_type)
            {
            case DataMessage_Type.GAME_STATE:
                output.data = GameStateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.PLAYER_UPDATE:
                output.data = PlayerUpdateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.MISSLE_MINE:
                output.data = MissileMineMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.ROTATION:
                output.data = RotationMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.FENCE_HIT:
                output.data = FenceHitMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.MISSILEUPDATE:
                output.data = MissileUpdateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.GAME_OVER:
                output.data = GAMEOVERMESSAGE.Deserialize(ref reader);
                break;

            default:
                Debug.Assert(false, "INVALID DATA TYPE");
                break;
            }

            return(output);
        }
Exemplo n.º 6
0
 void ProcessGameOverMessage(GAMEOVERMESSAGE msg)
 {
     state = GAME_STATE.GAME_OVER;
     DestroyAll();
 }