Example #1
0
    void TransmitPlayerIDs()
    {
        CGC_SetPlayerID setPlayer0 = new CGC_SetPlayerID(0);

        m_connection.TransmitStream(setPlayer0.PackCommand(), 0);
        CGC_SetPlayerID setPlayer1 = new CGC_SetPlayerID(1);

        m_connection.TransmitStream(setPlayer1.PackCommand(), 1);
    }
Example #2
0
        static void Main(string[] args)
        {
            int port;

            ParseArgs(out port, args);

            ServerConnectionManager.Instance.InitializeServer(IPAddress.Any, port);

            Debug.Log("Waiting for connection...");
            ServerConnectionManager.Instance.ConnectToClient(0);
            Debug.Log("Waiting for connection...");
            ServerConnectionManager.Instance.ConnectToClient(1);
            Debug.Log("Both players connected! Starting game...");

            CGC_SetPlayerID setPlayer0 = new CGC_SetPlayerID(0);

            ServerConnectionManager.Instance.TransmitStream(setPlayer0.PackCommand(), 0);
            CGC_SetPlayerID setPlayer1 = new CGC_SetPlayerID(1);

            ServerConnectionManager.Instance.TransmitStream(setPlayer1.PackCommand(), 1);

            bool playing = true;

            CardGameManager cgManager = new CardGameManager();

            cgManager.RunGameLogic();

            while (playing)
            {
                SGCommand player1Command = ServerConnectionManager.Instance.ReceiveStream(0);
                if (player1Command != null)
                {
                    player1Command.ExecuteCommand(cgManager);
                }

                SGCommand player2Command = ServerConnectionManager.Instance.ReceiveStream(1);
                if (player2Command != null)
                {
                    player2Command.ExecuteCommand(cgManager);
                }

                bool connected = ServerConnectionManager.Instance.Connected();
                playing = connected;
            }


            /* TO-DO list
             *  1. Replace all "CGVisualManager.instance.AddCommand(command)" calls with transmitting
             *      the appropriate bitstream to each client
             *  2. Replace all the scripts in the unity project with these ones
             *  3. Re-build this project using the scripts in the unity folder so both projects use the same files
             *  4. Write a servercommand system similar to CGCommand for
             *     sending requests back to the server
             *  5. Document how everything works!
             *  6. Add wait in main server loop
             *
             *
             *
             *
             */
        }
Example #3
0
    public static CGCommand CreateCommandFromPacket(BKSystem.IO.BitStream packet)
    {
        if (packet.Length < 0)
        {
            return(null);
        }

        ushort commandID;

        packet.Position = 0;
        packet.Read(out commandID, 0, 16);
        Debug.Log("Read packet with command ID: " + commandID);

        CGCommand command;

        switch (commandID)
        {
        case (ushort)CGCommandID.CAST_SPELL:
            command = new CGC_CastSpell(packet);
            break;

        case (ushort)CGCommandID.CHANNEL_SPELL:
            command = new CGC_ChannelSpell(packet);
            break;

        case (ushort)CGCommandID.MOVE_CARD_TO_GRAVEYARD:
            command = new CGC_MoveCardToGraveyard(packet);
            break;

        case (ushort)CGCommandID.OPPONENT_DRAW_CARD:
            command = new CGC_OpponentDrawCard(packet);
            break;

        case (ushort)CGCommandID.OPPONENT_PLAY_CARD_FROM_HAND:
            command = new CGC_OpponentPlayCardFromHand(packet);
            break;

        case (ushort)CGCommandID.PLAYER_DRAW_CARD:
            command = new CGC_PlayerDrawCard(packet);
            break;

        case (ushort)CGCommandID.PLAYER_PLAY_CARD_FROM_HAND:
            command = new CGC_PlayerPlayCardFromHand(packet);
            break;

        case (ushort)CGCommandID.SET_LIFE:
            command = new CGC_SetLife(packet);
            break;

        case (ushort)CGCommandID.WAIT_FOR_CAST_SELECTION:
            command = new CGC_WaitForCastSelection(packet);
            break;

        case (ushort)CGCommandID.WAIT_FOR_PLAY_FROM_HAND:
            command = new CGC_WaitForPlayFromHand(packet);
            break;

        case (ushort)CGCommandID.SET_PLAYER_ID:
            command = new CGC_SetPlayerID(packet);
            break;

        case (ushort)CGCommandID.PHASE_TRANSITION:
            command = new CGC_PhaseTransition(packet);
            break;

        case (ushort)CGCommandID.REQUEST_DECK:
            command = new CGC_RequestDeck(packet);
            break;

        case (ushort)CGCommandID.REFRESH_TIMEOUT:
            command = new CGC_RefreshTimeout(packet);
            break;

        default:
            command = null;
            break;
        }

        return(command);
    }