Beispiel #1
0
    // Send game info to the server
    public void hostGame()
    {
        if (!isHostingGame)
        {
            string gameInfo;
            isHostingGame = true;

            // Initialize the network game for hosting
            myGame = new NetworkGame()
            {
                gameName        = gameName.text,
                numberOfPlayers = "0",
                maxPlayers      = maxPlayers.text,
                password        = gamePassword.text,
                mapName         = mapName.text
            };

            gameInfo = Constants.addGame + Constants.commandDivider + Network.player.ipAddress + Constants.gameDivider + myGame.gameName +
                       Constants.gameDivider + "0" + Constants.gameDivider + myGame.maxPlayers + Constants.gameDivider + myGame.password + Constants.gameDivider + myGame.mapName;
            sendSocketMessage(gameInfo, serverConnectionID);
        }
        else
        {
            messageLog.text = messageLog.text + "\nError: Already hosting a game.";
        }
    }
Beispiel #2
0
    // Add a game to the server list
    public void addGame(string[] gameInfo, int hostNumber)
    {
        // Create a game and set values
        game                 = new NetworkGame();
        game.ipAddress       = gameInfo[0];
        game.gameName        = gameInfo[1];
        game.numberOfPlayers = gameInfo[2];
        game.maxPlayers      = gameInfo[3];
        game.password        = gameInfo[4];
        game.mapName         = gameInfo[5];
        game.hostID          = hostNumber;
        gameList.Add(game);

        // Set the prefab values
        GameObject gamePNL = Instantiate(gamePanel) as GameObject;

        gamePNL.transform.SetParent(gameListPanel.transform, false);
        Text[] nameText = gamePNL.GetComponentsInChildren <Text>();
        nameText[0].text = gameInfo[1];
        nameText[1].text = gameInfo[2];
        nameText[2].text = "\\" + gameInfo[3];
        nameText[3].text = gameInfo[4];
        nameText[4].text = gameInfo[5];
        nameText[5].text = gameInfo[0];

        game.gamePNL = gamePNL;
    }
Beispiel #3
0
        /// <summary>
        /// Removes the player.
        /// </summary>
        /// <param name="connection">Connection.</param>
        public void RemovePlayer(Connection connection)
        {
            var connectInfos = ConnectionManager.Get(connection);
            var cos          = connectInfos.Lobby.Connection.ToArray();

            foreach (var lobbyConnection in cos)
            {
                //var connectInfos = ConnectionManager.Get(connection);
                var lobbyConnectInfos = ConnectionManager.Get(lobbyConnection);
                var pseudo            = lobbyConnectInfos.Pseudo;
                if ((IsStarted == false && connection == lobbyConnection) ||
                    IsStarted)
                {
                    Console.WriteLine("[LobbyRoom - " + _name + "] " + pseudo + " disconnected");
                    _connections.Remove(lobbyConnection);
                    if (_connections.Count == 0)
                    {
                        LobbyManager.DeleteLobby(_name);
                    }
                    lobbyConnectInfos.Lobby = null;
                    LobbyRoom.Unregister(lobbyConnection);
                    NetworkGame.Unregister(lobbyConnection);
                    if (lobbyConnection.ConnectionInfo.ConnectionState == ConnectionState.Established)
                    {
                        Console.WriteLine("Client: " + pseudo + " is still connected, register it on LobbySelector");
                        SelectLobby.Register(lobbyConnection);
                        lobbyConnection.SendObject("LobbySelect");
                    }
                }
            }
        }
 public void RpcHauntEnded()
 {
     foreach (GamePlayer player in NetworkGame.GetPlayers())
     {
         if (player.isLocalPlayer)
         {
             player.DisplayHauntInfo(gameHaunt.GetComponent <Haunt>());
         }
     }
 }
 public void RpcPrepEnd()
 {
     Time.timeScale = 1;
     foreach (GamePlayer player in NetworkGame.GetPlayers())
     {
         if (player.isLocalPlayer)
         {
             player.StopHauntPrep();
         }
     }
 }
 public void RpcHauntStarted(GameObject haunt)
 {
     gameHaunt      = haunt;
     Time.timeScale = 0;
     foreach (GamePlayer player in NetworkGame.GetPlayers())
     {
         if (player.isLocalPlayer)
         {
             player.DisplayHauntInfo(gameHaunt.GetComponent <Haunt>());
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (!isServer)
        {
            gameState = currState;
        }
        else
        {
            currState = gameState;
        }
        ///Check if the haunt has started yet.
        if (isServer && gameState == HauntState.EXPLORE)
        {
            elapsed += Time.deltaTime;
            if (elapsed >= checkInterval)
            {
                //Debug.Log ("Checking Haunts");
                foreach (Haunt haunt in haunts)
                {
                    if (haunt.CanStartHaunt())
                    {
                        //Debug.Log ("Started Haunt");
                        gameHaunt = GameObject.Instantiate(haunt.gameObject);
                        NetworkServer.Spawn(gameHaunt);
                        gameState = HauntState.PREP;

                        RpcHauntStarted(gameHaunt);
                        return;
                    }
                }
                elapsed = 0;
            }
        }
        else if (isServer && gameState == HauntState.PREP)
        {
            if (ready.Count == NetworkGame.GetPlayers().Length)
            {
                gameState = HauntState.HAUNT;
                RpcPrepEnd();
            }
        }
        else if (isServer && gameState == HauntState.END)
        {
            if (prevState != HauntState.END)
            {
                RpcHauntEnded();
            }
        }
        prevState = gameState;
    }
Beispiel #8
0
    // Use this for initialization
    void Start()
    {
        if (isServer)
        {
            //Debug.Log ("Starting haunt");
            GamePlayer[] players = NetworkGame.GetPlayers();
            switch (type)
            {
            case HauntType.Tratior:
                for (int i = 0; i < players.Length; i++)
                {
                    players [i].RpcSetPlayerState(GamePlayer.PlayerType.HERO);
                }
                SelectTratior(players).RpcSetPlayerState(GamePlayer.PlayerType.TRAITOR);
                break;

            case HauntType.Cooperative:
                for (int i = 0; i < players.Length; i++)
                {
                    players [i].RpcSetPlayerState(GamePlayer.PlayerType.HERO);
                }
                break;

            case HauntType.HiddenTratior:
                for (int i = 0; i < players.Length; i++)
                {
                    players [i].RpcSetPlayerState(GamePlayer.PlayerType.HERO);
                }
                SelectTratior(players).RpcSetPlayerState(GamePlayer.PlayerType.TRAITOR);
                break;

            case HauntType.FreeForAll:
                for (int i = 0; i < players.Length; i++)
                {
                    players [i].RpcSetPlayerState(GamePlayer.PlayerType.MADMAN);
                }
                break;

            case HauntType.Mixed:
                for (int i = 0; i < players.Length; i++)
                {
                    players [i].RpcSetPlayerState(GamePlayer.PlayerType.HERO);
                }
                break;
            }
            HauntStarted();
        }
    }
        private void JoinGame(NetworkGame game)
        {
            var session = this.browser?.Join(game);

            if (session != null)
            {
                if (this.ParentViewController is GameStartViewController parent)
                {
                    parent.JoinGame(session);
                }
                else
                {
                    throw new ArgumentException("Unexpected parent", nameof(this.ParentViewController));
                }
            }
        }
Beispiel #10
0
 /// <summary>
 /// Determines whether this instance can start haunt. This is determined by the haunt checking
 /// the house for what has happened. This method is called quite often, 10 times a second, for
 /// every haunt so it should not be too intensive of a process.
 /// </summary>
 /// <returns><c>true</c> if this instance can start haunt; otherwise, <c>false</c>.</returns>
 public override bool CanStartHaunt()
 {
     foreach (GamePlayer player in NetworkGame.GetPlayers())
     {
         foreach (GameObject item in player.GetComponent <Inventory>().items)
         {
             if (item != null && item.GetComponent <Item>().itemName == "Ring")
             {
                 theRing                   = item;
                 chosenOne                 = player;
                 traitorSpawns[player]     = player.gameObject.transform.position;
                 traitorDeadTimes [player] = 0;
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #11
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            _game.Update(gameTime);

            if (IsNetworkGame)
            {
                while (_broadcastClient.MessagesReceived.Any())
                {
                    NetworkGame.Update(_broadcastClient.MessagesReceived.Dequeue());
                }
            }

            base.Update(gameTime);
        }
    //int toolbarint = 0;
    //string[] toolbarstrings = new string[]{"Toolbar 1", "Toolbar 2","Toolbar 3", "Toolbar 4"};
    void Awake()
    {
        networkScript = GameObject.Find("NetworkCode").GetComponent<NetworkGame>();

        playersScores = new List<PlayerScore>();

        //scoreTitle.material.color = Color.yellow;
        if(scoreTitle != null)
        scoreTextStyle.font = scoreTitle;

        scoreTextStyle.alignment = TextAnchor.MiddleCenter;
        scoreTextStyle.normal.textColor = Color.yellow;
        scoreTextStyle.fontSize = 30;

        screenX = Screen.width * 0.5f - scoreMenuHeight * 0.5f;
        screenY = Screen.height * 0.5f - scoreMenuWidth * 0.5f;

        Script = this;
    }
Beispiel #13
0
    /// <summary>
    /// Starts the haunt. This is used in place of Start() which is used by the abstract Haunt to
    /// setup the default state of the game for the given kind of haunt.
    /// </summary>
    public override void HauntStarted()
    {
        // Restore traitor health
        chosenOne.GetComponent <Damageable>().SetHealth(chosenOne.GetComponent <Damageable>().maxHealth);
        chosenOne.GetComponent <Damageable>().SetSanity(chosenOne.GetComponent <Damageable>().maxSanity);

        // Add speical actions to all Players
        foreach (GamePlayer player in NetworkGame.GetPlayers())
        {
            if (player != chosenOne)
            {
                GameObject visionBox = Instantiate(visionActionBox);
                visionBox.transform.parent        = player.transform.parent;
                visionBox.transform.localPosition = Vector3.zero;
                NetworkServer.Spawn(visionBox);
                RpcAddVisionAction(player.gameObject, visionBox);
            }
        }
    }
Beispiel #14
0
    // Called every frame
    void Update()
    {
        int recHostId;
        int recConnectionId;
        int recChannelId;

        byte[]           recBuffer  = new byte[1024];
        int              bufferSize = 1024;
        int              dataSize;
        byte             error;
        NetworkEventType recNetworkEvent = NetworkTransport.Receive(out recHostId, out recConnectionId, out recChannelId, recBuffer, bufferSize, out dataSize, out error);

        switch (recNetworkEvent)
        {
        case NetworkEventType.Nothing:
            break;

        case NetworkEventType.ConnectEvent:
            messagesField.text = messagesField.text + "\n" + "Incoming connection event received";
            Debug.Log(recConnectionId);
            break;

        case NetworkEventType.DataEvent:
            Stream          stream    = new MemoryStream(recBuffer);
            BinaryFormatter formatter = new BinaryFormatter();
            string          message   = formatter.Deserialize(stream) as string;
            messagesField.text = messagesField.text + "\n" + "Incoming data event recieved";
            proccessNetworkMessage(message, recConnectionId);
            break;

        case NetworkEventType.DisconnectEvent:
            NetworkGame game = gameList.FirstOrDefault(o => o.hostID == recConnectionId);
            if (game != null)
            {
                messagesField.text = messagesField.text + "\n" + "Game Found Removing";
                gameList.Remove(game);
                Destroy(game.gamePNL);
            }
            messagesField.text = messagesField.text + "\n" + "Remote client event disconnected";
            break;
        }
    }
Beispiel #15
0
    void Update()
    {
        if (isServer && HauntManager.gameState == HauntManager.HauntState.HAUNT)
        {
            //Check if traitor(s) have won
            bool allHeroesDead = true;
            foreach (GamePlayer player in NetworkGame.GetPlayers())
            {
                if (player.playerState == GamePlayer.PlayerType.HERO && player.gameObject.GetComponent <Damageable> ().IsDead() == false)
                {
                    allHeroesDead = false;
                }
            }

            /*if (allHeroesDead) {
             *      //Traitor wins
             *      HauntManager.EndHaunt();
             *      winner = GamePlayer.PlayerType.TRAITOR;
             * }*/

            //Check if heroes have won
            if (theRing == null)
            {
                HauntManager.EndHaunt();
                winner = GamePlayer.PlayerType.HERO;
            }

            //Update ring and invisibility
            foreach (GamePlayer player in NetworkGame.GetPlayers())
            {
                if (player.playerState == GamePlayer.PlayerType.TRAITOR)
                {
                    bool hasRing = false;
                    foreach (GameObject item in player.GetComponent <Inventory>().items)
                    {
                        if (item != null)
                        {
                            if (item.GetComponent <Item> ().itemName == "Ring")
                            {
                                hasRing = true;
                                item.GetComponent <Item> ().canDrop = false;
                            }
                        }
                    }
                    traitorHasRing = hasRing;
                    if (hasRing)
                    {
                        RpcMakeInvisible(chosenOne.gameObject);
                    }
                    else
                    {
                        RpcMakeVisible(chosenOne.gameObject);
                    }
                }
                if (player.playerState == GamePlayer.PlayerType.HERO)
                {
                    foreach (GameObject item in player.GetComponent <Inventory>().items)
                    {
                        if (item != null && item.GetComponent <Item> ().itemName == "Ring")
                        {
                            item.GetComponent <Item> ().canDrop = true;
                        }
                    }
                }
            }

            //Update traitor death times
            foreach (GamePlayer player in NetworkGame.GetPlayers())
            {
                if (player.playerState == GamePlayer.PlayerType.TRAITOR &&
                    player.GetComponent <Damageable>().IsDead())
                {
                    if (traitorDeadTimes [player] == 0)
                    {
                        //If the traitor just died
                        player.AddTimedMessage("You are dead, but it's only temporary", respawnTime);
                    }
                    traitorDeadTimes [player] = traitorDeadTimes [player] + Time.deltaTime;
                    if (traitorDeadTimes [player] >= respawnTime)
                    {
                        traitorDeadTimes [player] = 0;
                        player.ServerRespawn();
                        player.gameObject.transform.position = traitorSpawns [player];
                        player.AddTimedMessage("You are back in the world of the living, for now...", 2.5f);
                    }
                }
            }
        }
    }
Beispiel #16
0
        static void Main(string[] args)
        {
            // Given arguments saved to private properties
            CommandLine.Parser.Default.ParseArguments <Options>(args)
            .WithParsed(RunOptions)
            .WithNotParsed(HandleParseError);

            if (_stopArgsGiven)
            {
                return;
            }

            Log($"Chess ai vergiBlue [{_currentVersion}]");

            while (true)
            {
                if (_gameMode <= 0)
                {
                    // User did not explicitly set gamemode in command line arguments
                    _gameMode = InputGameMode();
                }

                if (_gameMode < 0)
                {
                    break;
                }

                if (_gameMode == 1)
                {
                    using var connection = new grpcClientConnection(_fullAddress);
                    NetworkGame.Start(connection, _playerName, false);
                    break;
                }
                else if (_gameMode == 2)
                {
                    Log(Environment.NewLine);
                    Log("Give player name: ");
                    Console.Write(" > ");
                    var playerName = Console.ReadLine() ?? _playerName;
                    Log($"Chess ai {playerName} [{_currentVersion}]");
                    using var connection = new grpcClientConnection(_fullAddress);
                    NetworkGame.Start(connection, playerName, false);
                    break;
                }
                else if (_gameMode == 3)
                {
                    LocalGame.Start(_minimumDelayBetweenMoves, null);
                }
                else if (_gameMode == 4)
                {
                    LocalGame.Start(Math.Max(1000, _minimumDelayBetweenMoves), null);
                }
                else if (_gameMode == 5)
                {
                    LocalGame.CustomStart();
                }
                else if (_gameMode == 9)
                {
                    using var connection = new grpcClientConnection(_fullAddress);
                    NetworkGame.Start(connection, "Connection test AI", true);
                    break;
                }
                else
                {
                    break;
                }

                Log(Environment.NewLine);
            }
        }
 public static void Load()
 {
     NetworkGame.getInstance();
     UdpHandler.getInstance().SendPacket(255, new byte[4]);
 }
Beispiel #18
0
 public PongGameScene(NetworkGame game) : base(game)
 {
 }
    /* -------------------------------------------------------------------------------------------------------- */
    /*
     * UNITY STUFF
     */
    /* -------------------------------------------------------------------------------------------------------- */
    // Use this for initialization
    void Awake()
    {
        Script = this;

        // Background stuff
        mainScreenBGPos.x = 0;
        mainScreenBGPos.y = 0;

        mainScreenBGPos.width = Screen.width;
        mainScreenBGPos.height = Screen.height;

        // Menu stuff
        screenX = Screen.width * 0.5f - menuWidth * 0.5f;
        screenY = Screen.height * 0.5f - menuHeight * 0.5f;
        //screenY = Screen.height * 0.5f - menuHeight * 0.5f;
        currentMenu = MainMenu;

        // Host game window stuff
        subMenuWindow.x = Screen.width * 0.5f - hostMenuWidth * 0.5f;
        subMenuWindow.y = (Screen.height * 0.5f - hostMenuHeight * 0.5f) + hostMenuOffsetY;

        subMenuWindow.width = hostMenuWidth;
        subMenuWindow.height = hostMenuHeight;

        // Network stuff
        netScript = GameObject.Find("NetworkCode").GetComponent<NetworkGame>();
        serverName = netScript.GetServerName();

        if(playerName == null || playerName == "") {

            playerName = "RandomName" + Random.Range(1,999);
        }
    }
    /* -------------------------------------------------------------------------------------------------------- */
    /*
     * UNITY STUFF
     */
    /* -------------------------------------------------------------------------------------------------------- */
    void Awake()
    {
        Script = this;

        scoreScript = GameObject.Find("GameCode").GetComponent<ScoreCounter>();

        networkScript = GameObject.Find("NetworkCode").GetComponent<NetworkGame>();

        levelTimer = (2 + networkScript.levelTimeNetworkGame) * 60;
        //levelTimer = 5.0f;

        menuTime = Time.time;
    }
    /* -------------------------------------------------------------------------------------------------------- */
    /*
     * UNITY STUFF
     */
    /* -------------------------------------------------------------------------------------------------------- */
    void Awake()
    {
        Script = this;

        //http://unity3d.com/support/documentation/Components/net-NetworkLevelLoad.html
        DontDestroyOnLoad(this);
        networkView.group = 1;

        /* HACK TO USE LOCAL MASTER SERVER */
        /*
        MasterServer.ipAddress = "127.0.0.1";
        MasterServer.port = 23466;
        Network.natFacilitatorIP = "127.0.0.1";
        Network.natFacilitatorPort = 50005; // your own port number
        */
    }