public void StartGame()
    {
        networkJobHandle.Complete();
        StartGameMessage startMessage = new StartGameMessage
        {
            StartHP = 10
        };

        SendMessageToAll(startMessage);

        //enviroment data is setup
        serverDataHolder.GameSetup();

        //everyone gets a rooms info message.
        for (int i = 0; i < connections.Length; i++)
        {
            RoomInfoMessage startRoomMessage = serverDataHolder.GetRoomMessage(i);
            SendMessage(startRoomMessage, connections[i]);
        }

        //turn event is called
        PlayerTurnMessage turnMessage = new PlayerTurnMessage
        {
            PlayerID = serverDataHolder.turnID
        };

        SendMessageToAll(turnMessage);
    }
    public void StartGame()
    {
        //first player
        StartGameMessage startGameMessage = new StartGameMessage()
        {
            playerData   = NetworkUtilities.GetNetPlayerData(players[0]),
            opponentData = NetworkUtilities.GetNetPlayerData(players[1])
        };

        SendNetMessage(ref m_Driver, players[0].m_connenction, startGameMessage);


        //second player
        startGameMessage = new StartGameMessage()
        {
            playerData   = NetworkUtilities.GetNetPlayerData(players[1]),
            opponentData = NetworkUtilities.GetNetPlayerData(players[0])
        };

        SendNetMessage(ref m_Driver, players[1].m_connenction, startGameMessage);

        currentPlayer = players.IndexOf(players.Find(x => x.guid == 0));

        gameStarted = true;
    }
Esempio n. 3
0
    public void OnStartGameMessage(int deviceId, StartGameMessage startGameMessage)
    {
        var playerIndex = IndexOfPlayerWithDeviceId(deviceId);

        if (playerIndex < 0)
        {
            return;
        }

        if (_currentGameState == GameState.OnLobby)
        {
            for (var i = 0; i < _globalPlayers.Count; i++)
            {
                var globalPlayer = _globalPlayers[i];
                if (!globalPlayer.LobbyPlayerData.IsReady)
                {
                    return;
                }
            }

            StartGameWithCurrentPlayers();
        }
        else if (_currentGameState == GameState.OnWrapUpScreen)
        {
            AirConsoleBridge.Instance.RequestToShowAds(() =>
            {
                AirConsoleBridge.Instance.BroadcastLoadingScreen("LOADING");
                HeadToTheLobby();
            });
        }
    }
        public void UserApp_StartGameConversation_Test()
        {
            //--------------SET UP VARIABLES-------------------//
            RegistryData registryData = new RegistryData();

            RegistryData.GameInfo gameInfo = new RegistryData.GameInfo();

            TestAppWorker testAppWorker = new TestAppWorker(registryData);

            testAppWorker.StartTest();

            var gameManager = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope1
            };

            gameManager.Start();

            IPEndPoint registryEp    = new IPEndPoint(IPAddress.Loopback, testAppWorker.commFacility.udpCommunicator.Port);
            IPEndPoint gameManagerEp = new IPEndPoint(IPAddress.Loopback, gameManager.Port);

            gameInfo.RemoteEndPoint = gameManagerEp;
            gameInfo.GameActive     = false;

            Assert.IsTrue(registryData.AddGame(gameInfo));

            StartGameMessage msg1 = new StartGameMessage(1);
            Envelope         env1 = new Envelope(msg1, registryEp);

            //--------------TEST INITIAL SET UP AND SEND INITIAL MESSAGE-------------------//
            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));
            Assert.IsFalse(gameInfo.GameActive);

            gameManager.Send(env1);

            Thread.Sleep(1000);

            //--------------TEST OUTCOME-------------------//
            Assert.AreNotSame(msg1, _lastIncomingEnvelope1);

            // Make sure received message isn't null
            Assert.IsNotNull(_lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1.message);

            // Make sure received message is AckMessage
            Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId);
            AckMessage msg2 = _lastIncomingEnvelope1.message as AckMessage;

            Assert.IsNotNull(msg2);

            Assert.IsTrue(gameInfo.GameActive);
            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));

            //--------------CLOSE EVERYTHING-------------------//
            testAppWorker.StopTest();
            gameManager.Stop();
        }
Esempio n. 5
0
    /// <summary>
    /// Called when the countdown for starting the game finished.
    /// </summary>
    private void OnCountDownFinished()
    {
        List <Player> players = PlayersDict.Instance.Players;

        for (int i = 0; i < players.Count; i++)
        {
            players[i].StateCommunicator.lobbyReady = false;
        }

        instance = null;
        GlobalsDict.Instance.GameStateManagerObject.AddComponent <GameManager>();

        int seed = selectedGameMode.randomSeed ? Random.Range(int.MinValue, int.MaxValue) : selectedGameMode.seed;

        if (RAGMatchmaker.Instance.IsReady && RAGMatchmaker.Instance.GetCurrentMatch() != null)
        {
            RAGMatchmaker.Instance.DestroyMatch();
        }

        GameManager.OnStartNewGame(selectedGameMode, seed);

        StartGameMessage sgm = new StartGameMessage
        {
            levelSeed = seed,
            gameMode  = selectedGameMode
        };

        NetworkServer.SendToAll(sgm);

        GameManager.OnLoadNewLevel();

        Destroy(this);
    }
Esempio n. 6
0
        private void HandleCharacterSelectionMessage(String address, AbstractMessage message)
        {
            CharacterSelectionMessage characterSelectionMessage = (CharacterSelectionMessage)message;

            Player currentPlayer = controller.GetPlayer(IPAddress.Parse(address));

            currentPlayer.ClearCharacters();
            foreach (String rootName in characterSelectionMessage.SelectedCharacters)
            {
                currentPlayer.AddCharacter(Bundle.Characters[rootName]);
            }

            foreach (Player player in controller.GetPlayers())
            {
                if (player.GetCharacters().Count == 0)
                {
                    controller.Server.SendData(currentPlayer.IPAddress, new WaitingOponentMessage());
                    return;
                }
            }

            BattleEngine.Initialize(controller.GetLocalPlayer(), controller.GetRemotePlayer());
            StartGameMessage startGameMessage = new StartGameMessage();

            serverStatus = ServerStatus.WaitingCharacterPosition;

            controller.Server.SendToAll(startGameMessage);
        }
Esempio n. 7
0
        // remote case
        public override void OnStartRemoteClient(StartGameMessage initialMessages)
        {
            base.OnStartRemoteClient(initialMessages);

            instance = this;

            clientPlayers = new CacheClientPlayers <TBPlayer>();
        }
    private void StartGame(ref DataStreamReader reader)
    {
        var startGameMessage = new StartGameMessage();

        startGameMessage.DeserializeObject(ref reader);
        dataHolder.myData.hp = startGameMessage.StartHP;
        dataHolder.StartGame();
    }
Esempio n. 9
0
    public void StartGame()
    {
        Debug.Log("PlayButton pressed, requesting game start");

        StartGameMessage startGameMessage = new StartGameMessage();

        PubSubServerInstance.Publish(startGameMessage);
    }
        public void HandleStartGame(Message message)
        {
            StartGameMessage startGameMessage = (StartGameMessage)message;

            Debug.Log("Game Started");
            Menu.Singleton.SetMenu(Menu.Menus.clientGame);
            Menu.Singleton.gameWindow.UpdateHP(startGameMessage.startHealth);
            Menu.Singleton.gameWindow.UpdateGold(0);
        }
Esempio n. 11
0
        public void UdpCommunicator_Multicast()
        {
            var commSender = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = NoOp
            };

            commSender.Start();

            var commReciever = new UdpCommunicator()
            {
                MinPort         = 5000,
                MaxPort         = 5000,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope5
            };

            commReciever.Start();

            Random rand   = new Random();
            short  gameId = (short)rand.Next(1, 1000);

            // Note, we can't test multiple receivers on the same host (localhost), because the
            // port number has to be the same for all receivers

            // Have the receivers join a Group Multicast address
            var multiCastAddress = new IPAddress(new byte[] { 224, 1, 1, 2 });

            commReciever.JoinMulticastGroup(multiCastAddress);

            // Send message to Group Multicast address
            var msg            = new StartGameMessage(gameId);
            var targetEndPoint = new IPEndPoint(IPAddress.Loopback, 5000);
            var env            = new Envelope(msg, targetEndPoint);

            commSender.Send(env);

            Thread.Sleep(100);

            Assert.AreNotSame(msg, _lastIncomingEnvelope5);
            Assert.IsNotNull(_lastIncomingEnvelope5);
            Assert.IsNotNull(_lastIncomingEnvelope5.message);
            Assert.AreEqual(msg.msgId, _lastIncomingEnvelope5.message.msgId);
            Assert.AreEqual(msg.convId, _lastIncomingEnvelope5.message.convId);
            StartGameMessage msg2 = _lastIncomingEnvelope5.message as StartGameMessage;

            Assert.IsNotNull(msg2);
            Assert.AreEqual(msg.GameId, msg2.GameId);

            commReciever.DropMulticastGroup(multiCastAddress);
            commReciever.Stop();
            commSender.Stop();
        }
Esempio n. 12
0
        // remote case
        public override void OnStartRemoteClient(StartGameMessage initialMessages)
        {
            base.OnStartRemoteClient(initialMessages);

            instance = this;

            var initialState = initialMessages.ReadInitialMessage <GameState>();

            remoteMatch = new TurtleMatch();
            remoteMatch.CreateFromInitialState(numRoles, onlineTurtlePrefab, initialState);
        }
        public void TestStartGameMessage()
        {
            StartGameMessage origMessage = new StartGameMessage(1);

            byte[]           bytes          = origMessage.Encode();
            StartGameMessage decodedMessage = StartGameMessage.Decode(bytes);

            Assert.AreEqual(origMessage.MessageType, 3, "Incorrect MessageType");
            Assert.AreEqual(origMessage.MessageType, decodedMessage.MessageType, "MessageType did not match");
            Assert.AreEqual(origMessage.GameId, decodedMessage.GameId, "GameId did not match");
        }
Esempio n. 14
0
        private void SendStartGameMessageToAllUsers()
        {
            var avatars = _gameManager.GetAvatarList();

            for (var i = 0; i < _gameManager.Users.Length; i++)
            {
                var user    = _gameManager.Users[i];
                var message = new StartGameMessage(i, avatars);
                user?.ClientSocket.SendMessage(message);
            }
        }
 private Task RevealPlayers(StartGameMessage message)
 {
     MainCharacter.TrySendBounds();
     return(Scene.QueueAction(() =>
     {
         MainCharacter.ResizeTo(1, 1);
         foreach (var opponent in opponents)
         {
             opponent.ResizeTo(1, 1);
         }
     }).AsAwaitable());
 }
Esempio n. 16
0
    public override void OnStartGame(StartGameMessage msg)
    {
        //register for callbacks
        playerData.handZone.OnCardAdded    += OnPlayerCardAdded_Hand;
        playerData.boardZone.OnCardAdded   += OnPlayerCardAdded_Board;
        playerData.boardZone.OnCardRemoved += OnPlayerCardRemoved_Board;

        opponentData.handZone.OnCardAdded  += OnOpponentCardAdded_Hand;
        opponentData.boardZone.OnCardAdded += OnOpponentCardAdded_Board;

        base.OnStartGame(msg);
    }
Esempio n. 17
0
    public void SendStartGame()
    {
        int startHP          = Random.Range(minPlayerHP, maxPlayerHP);
        var startGameMessage = new StartGameMessage {
            StartHP = (ushort)startHP
        };

        foreach (Client c in server.ClientList)
        {
            server.SendMessage(startGameMessage, c.Connection);
            c.StartHP = startHP;
        }
    }
Esempio n. 18
0
    public virtual void OnStartGame(StartGameMessage msg)
    {
        if (Logger.LogPlayerStartGameMessages)
        {
            Debug.Log($"CLIENT:: Got start game message");
        }

        //LOAD THE PLAYER STATS
        //payer
        LoadPlayerState(ref playerData, msg.playerData);
        //opponent
        LoadPlayerState(ref opponentData, msg.opponentData);
    }
Esempio n. 19
0
    private void OnStartGameMessage(MessageBase _msg, NetworkConnection _connection)
    {
        StartGameMessage startGameMessage = _msg as StartGameMessage;

        Player[] localPlayers = GameObject.FindObjectsOfType <Player>();
        for (int i = 0; i < localPlayers.Length; i++)
        {
            if (localPlayers[i].playerData.guid == startGameMessage.playerData.playerGuid)
            {
                localPlayers[i].OnStartGame(startGameMessage);
            }
        }
    }
Esempio n. 20
0
    private void OnStartGameMessage(StartGameMessage startGameMessage)
    {
        LobbyLevel.Instance.Hide();
        MusicManager.Instance.ChangeState(MusicManager.State.None);

        if (!Player.LocalPlayer || Player.LocalPlayer.isServer)
        {
            GameManager.gameMode.Init(startGameMessage.levelSeed);
        }
        else
        {
            startGameMessage.gameMode.Init(startGameMessage.levelSeed);
            GameManager.gameMode = startGameMessage.gameMode;
        }
    }
Esempio n. 21
0
    public INetworkMessage ReadJoingingAreaMessage(DataStreamReader reader, Message message)
    {
        switch (message.messageType)
        {
        // Read a NewPlayer message.
        case MessageType.NewPlayer:
            var newPlayerMessage = new NewPlayerMessage(message.id);
            newPlayerMessage.Deserialize(ref reader);
            return(newPlayerMessage);

        // Set your playedID and playerInfo.
        case MessageType.Welcome:
            var welcomeMessage = new WelcomeMessage(message.id);
            welcomeMessage.Deserialize(ref reader);

            playerID         = welcomeMessage.playerID;
            playerInfo.color = welcomeMessage.color;

            Send(new SetNameMessage(MessageID.nextID, playerInfo.name));

            return(welcomeMessage);

        // Read a PlayerLeft message.
        case MessageType.PlayerLeft:
            var playerLeftMessage = new PlayerMessage(message.id, message.messageType);
            playerLeftMessage.Deserialize(ref reader);
            return(playerLeftMessage);

        // Load Cave Quest and initialize the players stats.
        case MessageType.StartGame:
            var startGameMessage = new StartGameMessage(message.id);
            startGameMessage.Deserialize(ref reader);

            var caveQuestPlayer = gameObject.AddComponent <CaveQuestPlayer>();
            SceneManager.LoadSceneAsync("Cave Quest").completed += (asyncOperation) =>
            {
                caveQuestPlayer.Initialize(startGameMessage.startHP);
            };

            return(startGameMessage);

        default:
            return(null);
        }
    }
    // Server - tell the clients the game has started
    public void StartGame()
    {
        // Turn on level
        this.levelParent.SetActive(true);

        // Spawn flag
        this.SpawnFlag();

        this.canvasManager.CloseMenu();

        this.serverCam.SetActive(true);
        this.menuCameras[0].SetActive(false);
        this.menuCameras[1].SetActive(false);

        StartGameMessage msg = new StartGameMessage();

        NetworkServer.SendToAll(CustomMsgType.StartGame, msg);
    }
Esempio n. 23
0
        private void HandleStartGameMessage(string address, AbstractMessage message)
        {
            StartGameMessage startGameMessage = (StartGameMessage)message;

            MapEngine.Initialize(IO.LoadMap("amude"));
            Camera.Initialize(MapEngine.GetInstance().Map);

            DefaultDirection charactersDirection;
            Point            charactersPosition;
            AnimationType    charactersAnimation;

            if (controller.IsServer)
            {
                Camera.GetInstance().FocusOn(new Point(0, MapEngine.GetInstance().Map.Height / 2));
                charactersDirection = DefaultDirection.Right;
                charactersPosition  = new Point(0, (MapEngine.GetInstance().Map.Height / 2) - 3);
                charactersAnimation = AnimationType.StaticRight;
            }
            else
            {
                Camera.GetInstance().FocusOn(new Point(MapEngine.GetInstance().Map.Width, MapEngine.GetInstance().Map.Height / 2));
                charactersDirection = DefaultDirection.Left;
                charactersPosition  = new Point(MapEngine.GetInstance().Map.Width - 1, (MapEngine.GetInstance().Map.Height / 2) - 3);
                charactersAnimation = AnimationType.StaticLeft;
            }

            controller.SupressUpdate();

            foreach (Character character in controller.GetLocalPlayer().GetCharacters())
            {
                character.ClearAnimatedMovements();
                character.DefaultDirection = charactersDirection;
                character.MapLocation      = charactersPosition;
                character.AddAnimatedMovement(charactersAnimation, charactersPosition);

                MapEngine.GetInstance().SetObject(character);
                charactersPosition.Y += 1;
            }

            ScreenManager.GetInstance().RemoveLastScreen();
            ScreenManager.GetInstance().AddScreen(GameScreen.GetInstance());

            controller.ReleaseUpdate();
        }
Esempio n. 24
0
    public bool TrySendStartMessage()
    {
#if !UNITY_EDITOR
        if (!validConnections)
        {
            return(false);
        }
#endif

        // Send messages to each connection that the game is starting.
        var startGameMessage = new StartGameMessage(MessageID.nextID, CaveQuestPlayer.maxHealth);
        for (int i = 0; i < connections.Length; i++)
        {
            var connection = connections[i];

            Send(connection, startGameMessage);
        }

        return(true);
    }
Esempio n. 25
0
        public StartGameResult StartGame(
            [SignalRTrigger] InvocationContext context,
            [SignalRParameter] StartGameMessage message,
            [CosmosDB("campaigns", "campaigns", ConnectionStringSetting = "CosmosDBConnection", Id = "{message.CampaignId}")] RemoteCampaign campaign,
            ILogger logger)
        {
            if (campaign == null)
            {
                return(StartGameResult.CampaignNotFound);
            }

            logger.LogInformation($"{context.ConnectionId}:{context.UserId} attempting to start game {message.CampaignId}");
            if (message.CampaignSecret != campaign?.Secret.ToString())
            {
                return(StartGameResult.Unauthorized);
            }

            logger.LogInformation($"{context.ConnectionId}:{context.UserId} authorized to start game {message.CampaignId}");
            context.Claims.Add(OwnerClaim, "true");
            return(StartGameResult.Success);
        }
Esempio n. 26
0
    private void JoinReconnect(NetworkConnection connection, Player oldPlayer)
    {
        NetworkServer.AddPlayerForConnection(connection, oldPlayer.gameObject);
        oldPlayer.playerId = connection.connectionId;

        StartGameMessage sgm = new StartGameMessage()
        {
            gameMode  = GameManager.gameMode,
            levelSeed = GameManager.gameMode.seed
        };

        connection.Send(sgm);

        GenerateLevelMessage glm = new GenerateLevelMessage()
        {
            levelNumber  = GameManager.currentLevel,
            reconnecting = true,
            region       = RegionDict.Instance.Region
        };

        connection.Send(glm);
    }
Esempio n. 27
0
    void CheckEveryoneReady()
    {
        foreach (KeyValuePair <int, BasePlayer> entry in players)
        {
            if (entry.Value.ready == false)
            {
                return;
            }
        }

        // if all are ready, including the server (me), start the game.
        if (ready)
        {
            // notify all clients to start game.
            var startGameMessage = new StartGameMessage();
            startGameMessage.level = level;
            NetworkServer.SendToAll(CustomNetMsg.StartGame, startGameMessage);

            GameStateManager.instance.setGlobalStateIndex(GameStateManager.STATE_PLAYING);
            SceneManager.LoadScene(1);
            SceneManager.sceneLoaded += OnSceneLoaded;
        }
    }
Esempio n. 28
0
    public void StartGame()
    {
        networkJobHandle.Complete();
        StartGameMessage startGameMessage = new StartGameMessage()
        {
            StartHP = 10
        };

        GameHasStarted = true;
        GameObject go   = new GameObject();
        Grid       grid = go.AddComponent <Grid>();

        grid.gameObject.name = "Grid";
        grid.GenerateGrid();
        GameManager.Instance.CurrentGrid = grid;

        for (int i = 0; i < connections.Length; i++)
        {
            NetworkManager.SendMessage(networkDriver, startGameMessage, connections[i]);
        }
        PlayerManager.Instance.SortingPlayerList();
        PlayerTurnMessage playerTurnMessage = new PlayerTurnMessage()
        {
            playerID = 0
        };

        for (int i = 0; i < PlayerManager.Instance.Players.Count; i++)
        {
            PlayerManager.Instance.Players[i].Health = 10;
        }

        for (int i = 0; i < connections.Length; i++)
        {
            NetworkManager.SendMessage(networkDriver, playerTurnMessage, connections[i]);
        }
        UIManager.Instance.DeleteLabels();
    }
Esempio n. 29
0
    public void SetBeginHealth(MessageHeader arg0)
    {
        StartGameMessage startGame = arg0 as StartGameMessage;

        CurrentPlayer.Health = 10;
    }
Esempio n. 30
0
 /// <summary>
 /// Called when the game starts.
 /// </summary>
 /// <param name="msg">Start game message.</param>
 public override void OnStartGame(StartGameMessage msg)
 {
     base.OnStartGame(msg);
     humanPlayer = NetworkingUtils.GetHumanLocalPlayer();
 }
Esempio n. 31
0
        private void StartGame(StartGameMessage obj)
        {
            UnitViewModelCollection.Clear();
            UnitIdViewModelDictionary.Clear();

            if (_backgroundWorker.IsBusy)
                throw new NotImplementedException("About to start background worker while it is still running");

            _backgroundWorker.RunWorkerAsync();
        }
Esempio n. 32
0
 public static void HandleStartGame(StartGameMessage message)
 {
     ObserverData.GameActive = true;
 }