예제 #1
0
        public void SetAgentInfo(GameStarted gameInfo)
        {
            var sh       = new StrategyHandler(gameInfo);
            var strategy = sh.GetStrategy(Configuration.Strategy);

            this.AgentInfo = new AgentInfo(strategy, gameInfo);
        }
예제 #2
0
    IEnumerator GameStart()
    {
        yield return(StartCoroutine(LoadLevel()));

        yield return(StartCoroutine(BattlePrepare()));

        yield return(StartCoroutine(FocusTeamMember()));

        gameEnded = false;
        if (GameStarted != null)
        {
            GameStarted.Invoke(this, new EventArgs());
        }
        //角色加入忽略层
        Units.ForEach(u => u.gameObject.layer = 2);
        yield return(new WaitForSeconds(gameStartTime));

        foreach (var unit in Units)
        {
            unit.UnitClicked   += OnUnitClicked;
            unit.UnitDestroyed += OnUnitDestroyed;
            //设置同盟列表。
        }

        Units.ForEach(u => { u.Initialize(); }); //战斗场景角色初始化。

        StartCoroutine(RoundStart());
    }
예제 #3
0
 private void OnGameStarted()
 {
     if (GameStarted != null)
     {
         GameStarted.Raise();
     }
 }
예제 #4
0
        /// <summary>Handles the message.</summary>
        /// <param name="message">The message.</param>
        public void Handle(GameStarted message)
        {
            EnsureInitialized();
            GameMode     = message.GameMode;
            Hero         = Heroes.FirstOrDefault(x => x.Key == message.Hero);
            OpponentHero = Heroes.FirstOrDefault(x => x.Key == message.OpponentHero);
            GoFirst      = message.GoFirst;
            StartTime    = message.StartTime;
            IsRunning    = true;
            Deck         = deckManager.GetOrCreateDeckBySlot(BindableServerCollection.Instance.DefaultName, message.Deck);
            events.PublishOnBackgroundThread(new ToggleFlyoutCommand(Flyouts.CurrentGame)
            {
                Show = true
            });
            events.PublishOnBackgroundThread(new ToggleFlyoutCommand(Flyouts.EditGame)
            {
                Show = false
            });
            var vm = IoC.Get <GameStartedBalloonViewModel>();

            vm.SetGameResult(message);
            events.PublishOnBackgroundThread(new TrayNotification("A new game has started", vm, 10000)
            {
                BalloonType = BalloonTypes.GameStartEnd
            });
            RefreshStats();
        }
예제 #5
0
        private void OnPlayerPressed()
        {
            player.Pressed -= OnPlayerPressed;

            ScoreManager.StartCount();
            GameStarted?.Invoke();
        }
예제 #6
0
 void GameListPanel_Inputed(IFocusable sender, InputEventArgs args)
 {
     if (args.InputInfo.IsPressed(ButtonType.Circle))
     {
         if (GameStarted != null)
         {
             sound.Play(PPDSetting.DefaultSounds[1], -1000);
             GameStarted.Invoke(this, new GameEventArgs(gameList.List[currentIndex]));
         }
     }
     else if (args.InputInfo.IsPressed(ButtonType.Down))
     {
         currentIndex++;
         if (currentIndex >= gameList.List.Length)
         {
             currentIndex = 0;
         }
         sound.Play(PPDSetting.DefaultSounds[0], -1000);
     }
     else if (args.InputInfo.IsPressed(ButtonType.Up))
     {
         currentIndex--;
         if (currentIndex < 0)
         {
             currentIndex = gameList.List.Length - 1;
         }
         sound.Play(PPDSetting.DefaultSounds[0], -1000);
     }
     scrollIndex = currentIndex - scrollIndex >= 5 ? scrollIndex + 1 : scrollIndex;
     scrollIndex = scrollIndex > currentIndex ? currentIndex : scrollIndex;
 }
예제 #7
0
        private List <int> GetSubareasLengths(GameStarted gameInfo)
        {
            int taskAreaSize = gameInfo.BoardSize.Y.Value - gameInfo.GoalAreaSize * 2;
            //fields on the edge of each agents subarea (the edge that's closer to the enemy)
            //will be where agent closer to the enemy will put his collected pieces
            //same for closest to goal area non goalie agent
            //so we have to subtract 1 from task area size as line of fields just next to goal area
            //will belong to goalie and should not be included in dividing among non goalie agents
            int nonGoalieAreaSize = taskAreaSize - 1;
            //task area is divided near equally among agents
            int subareaSize = gameInfo.AlliesIds.Count() == 0 ? 1 : nonGoalieAreaSize / gameInfo.AlliesIds.Count();
            //it usually isn't exactly equally divided
            //certain number (indicated by biggerSubareasCount) of agents in front will have +1 field
            int        biggerSubareasCount  = nonGoalieAreaSize - subareaSize * gameInfo.AlliesIds.Count();
            int        smallerSubareasCount = gameInfo.AlliesIds.Count() - biggerSubareasCount;
            List <int> res = new List <int>
            {
                gameInfo.GoalAreaSize + 1//goalie subarea
            };

            for (int i = 0; i < smallerSubareasCount; i++)
            {
                res.Add(subareaSize);
            }
            for (int i = 0; i < biggerSubareasCount; i++)
            {
                res.Add(subareaSize + 1);
            }
            Console.WriteLine("subareas count" + res.Count);
            return(res);
        }
    private void Start()
    {
        // Score
        ManagerScore.I.Initialize(this);

        // A little of UI
        if (UIGameOver != null)
        {
            UIGameOver.SetActive(false);
        }
        else
        {
            Debug.LogWarning("UIGameOver is missing, please set", this);
        }

        if (TetrominoListForMatch.Count < 1)
        {
            Debug.LogError("TetraminoPrefabs for a match wasn't set", this);
        }

        if (GridData != null)
        {
            GridWidth  = GridData.GridWidth;
            GridHeight = GridData.GridHeight;
        }
        Grid = new Transform[GridWidth, GridHeight];

        if (TetrominoSpawnedTraced.Count == 0)
        {
            GameStarted?.Invoke();
            SpawnTetromino();
        }
    }
예제 #9
0
        /// <summary>
        /// Handles the notification.
        /// </summary>
        /// <param name="n">The n.</param>
        private void HandleNotification(Notification n)
        {
            switch (n.NotificationType)
            {
            case Notification.Type.GameStarted:
                // if game already started
                if (Maze != null)
                {
                    return;
                }
                Maze = Maze.FromJSON(n.Data);
                GameStarted?.Invoke();
                break;

            case Notification.Type.GameOver:
                GameOver?.Invoke(n.Data);
                break;

            case Notification.Type.PlayerMoved:
                MoveUpdate mu = MoveUpdate.FromJSON(n.Data);
                OtherPosition = GetEstimatedPosition(OtherPosition, mu.Direction);
                break;

            default:
                break;
            }
        }
예제 #10
0
        private (int Min, int Max) GetMyBounds(GameStarted gameInfo, List <int> subareasLengths, int myIndex)
        {
            int minBound, maxBound;

            if (_board.Team == Team.Blue)
            {
                minBound = 0;
                int i;
                for (i = 0; i < myIndex; i++)
                {
                    minBound += subareasLengths[i];
                }
                maxBound = minBound + subareasLengths[i] - 1;
            }
            else
            {
                maxBound = gameInfo.BoardSize.Y.Value - 1;
                int i;
                for (i = 0; i < myIndex; i++)
                {
                    maxBound -= subareasLengths[i];
                }
                minBound = maxBound - subareasLengths[i] + 1;
            }
            return(minBound, maxBound);
        }
 public void GameStarted_Invoke(ServerCore server)
 {
     if (GameStarted != null)
     {
         GameStarted.Invoke(server);
     }
 }
예제 #12
0
 protected void OnGameStarted(EventArgs e)
 {
     if (GameStarted != null)
     {
         GameStarted.Invoke(this, e);
     }
 }
예제 #13
0
        private void StartGameProcessMonitoring()
        {
            var dispatcher = Dispatcher.CurrentDispatcher;

            ThreadPool.QueueUserWorkItem(_ =>
            {
                while (gameProcessMonitoring.Wait(1000) == false)
                {
                    bool localIsRunGameLocked = dispatcher.Invoke(() => IsRunGameLocked);

                    var processes = Process.GetProcessesByName(Constants.ProcessName);

                    if (processes.Length > 0 && IsRunGameLocked == false)
                    {
                        dispatcher.Invoke(() =>
                        {
                            IsRunGameLocked = true;
                            Status          = "Dark Souls 3 is running...";
                            GameStarted?.Invoke(this, EventArgs.Empty);
                        });
                    }
                    else if (processes.Length == 0 && IsRunGameLocked)
                    {
                        dispatcher.Invoke(() =>
                        {
                            IsRunGameLocked = false;
                            Status          = "Dark Souls 3 has stopped...";
                            GameStopped?.Invoke(this, EventArgs.Empty);
                        });
                    }
                }

                gameProcessMonitoring.Reset();
            });
        }
예제 #14
0
        public void Start()
        {
            GameStarted.Raise(this, new BigTwoEventArgs());

            DealHands();

            var activePlayerIndex = 0;

            PlayedCards activeCards = null;

            // while all players have at least one card the game continues
            while (players.All(p => p.CardCount > 0))
            {
                IPlayer activePlayer = players[activePlayerIndex];

                PlayerTurnStart.Raise(this, new BigTwoPlayerEventArgs(activePlayer));

                // If the active cards belong to the active player, It means that
                // all other players have passed meaning this player has won the sequence.
                if (activeCards != null && activePlayer == activeCards.Player)
                {
                    // clear the active card to start a new sequence.
                    SequenceCompleted.Raise(this, new BigTwoPlayerEventArgs(activeCards.Player));
                    activeCards = null;
                }

                PlayedCards nextCards = activePlayer.PlayTurn(activeCards);

                PlayerPlayedTurn.Raise(this, new BigTwoPlayerHandEventArgs(activePlayer, nextCards));

                // null is a passed turn
                if (nextCards != null)
                {
                    // Ensure the cards the player is trying to play are valid
                    nextCards.Validate(activeCards);

                    activeCards = nextCards;

                    // Remove the played cards from the players hand
                    activePlayer.RemoveCards(nextCards);
                }


                // Advance to next player
                activePlayerIndex++;

                if (activePlayerIndex >= players.Count)
                {
                    activePlayerIndex = 0;
                }

                PlayerTurnEnd.Raise(this, new BigTwoPlayerEventArgs(activePlayer));
            }

            // Get the winner and notify everyone that the game is over!
            IPlayer winner = players.Single(p => p.CardCount == 0);

            GameCompleted.Raise(this, new BigTwoPlayerEventArgs(winner));
        }
예제 #15
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButtonDown("Jump"))
     {
         GameStarted?.Invoke();
         this.enabled = false;
     }
 }
        public static void HandleMessage(GameStarted request, CommunicationServer server, Socket handler)
        {
            //FIXME HELLO BUG HERE BECAUSE WE USE INT in GetGameByID and not ULONG
            IGame game = server.RegisteredGames.GetGameById((int)request.gameId);

            game.HasStarted = true;
            //server.startedGames.Add(game.Name);
        }
예제 #17
0
        public Event Handle(StartGame startGame)
        {
            var gameStarted = new GameStarted();

            _unstoredEvents.Add(gameStarted);

            return(gameStarted);
        }
예제 #18
0
        /// <summary>
        /// Method is called once, at the beggining of the game.
        /// </summary>
        public void StartGame()
        {
            GameStarted?.Invoke(this);

            Units.FindAll(u => u.PlayerNumber.Equals(CurrentPlayerNumber)).ForEach(u => u.OnTurnStart());
            Players.Find(p => p.PlayerNumber.Equals(CurrentPlayerNumber)).Play(this);
            Debug.Log("Game started");
        }
예제 #19
0
        public void StartGame()
        {
            if (_isPlaying == false)
            {
                _isPlaying = true;
            }

            GameStarted?.Invoke();
        }
예제 #20
0
 public void Start()
 {
     Clear();
     NextPolyomino = new Tetromono();
     Place(currentPolyomino);
     scoreBoard.Reset();
     IsStarted = true;
     GameStarted?.Invoke();
 }
예제 #21
0
        private void Start()
        {
            GameStarted?.Invoke(this, EventArgs.Empty);

            IList <string> letterPairs = _letterPairGenerator.GetLetterPairList(4); // TODO: use numPairs from settings

            LetterPairsGenerated?.Invoke(this, new LetterPairsEventArgs(letterPairs));
            _timer.StartAsync(45 * letterPairs.Count); // TODO: use time from settings
        }
예제 #22
0
 internal void StartGame()
 {
     if (Players.Count >= MinPlayerCount)
     {
         _gameStarted = true;
         InitRoom();
         GameStarted.Invoke(this);
     }
 }
예제 #23
0
        private void StartGame()
        {
            gameStartedTime = Time.time;
            UpdateAsteroidEventTime();
            StartNextWave();

            isGameInProgress = true;
            GameStarted?.Invoke();
        }
예제 #24
0
        public void StartGame(CellState firstPlayerColor)
        {
            this.firstPlayerColor = firstPlayerColor;
            currentPlayerColor    = firstPlayerColor;
            secondPlayerColor     = Field.GetOppositeColor(firstPlayerColor);

            GameStarted?.Invoke(field.Cells);

            GetAvailableCells();
        }
예제 #25
0
 public void StartGame()
 {
     if (GameStarted != null)
     {
         GameStarted.Invoke(this, new EventArgs());
     }
     Units.FindAll(u => u.PlayerNumber.Equals(CurrentPlayerNumber)).ForEach(u => { u.OnTurnStart(); });
     Players.Find(p => p.PlayerNumber.Equals(CurrentPlayerNumber)).Play(this);
     Debug.Log("Game Started");
 }
예제 #26
0
        private void TriggerEvents(bool recursive)
        {
            int originalCount = eventQueue.Count;

            // Do not use foreach as eventQueue might change
            for (int i = 0; i < (recursive ? eventQueue.Count : originalCount); i++)
            {
                // Performance is not a problem since events are rare!
                var arg = eventQueue[i];
                if (arg is GamerJoinedEventArgs)
                {
                    if (GamerJoined != null)
                    {
                        GamerJoined.Invoke(this, arg as GamerJoinedEventArgs);
                    }
                }
                else if (arg is GamerLeftEventArgs)
                {
                    if (GamerLeft != null)
                    {
                        GamerLeft.Invoke(this, arg as GamerLeftEventArgs);
                    }
                }
                else if (arg is GameStartedEventArgs)
                {
                    if (GameStarted != null)
                    {
                        GameStarted.Invoke(this, arg as GameStartedEventArgs);
                    }
                }
                else if (arg is GameEndedEventArgs)
                {
                    if (GameEnded != null)
                    {
                        GameEnded.Invoke(this, arg as GameEndedEventArgs);
                    }
                }
                else if (arg is NetworkSessionEndedEventArgs)
                {
                    if (SessionEnded != null)
                    {
                        SessionEnded.Invoke(this, arg as NetworkSessionEndedEventArgs);
                    }
                }
            }

            if (recursive)
            {
                eventQueue.Clear();
            }
            else
            {
                eventQueue.RemoveRange(0, originalCount);
            }
        }
예제 #27
0
 public StrategyHandler(GameStarted gameInfo)
 {
     handlers = new Dictionary <StrategyType, IStrategy>()
     {
         { StrategyType.SampleStrategy, new SampleStrategy(
               gameInfo.BoardSize.X.Value, gameInfo.BoardSize.Y.Value, gameInfo.TeamId, gameInfo.GoalAreaSize) },
         { StrategyType.LongBoardStrategy, new LongBoard.MasterStrategy(gameInfo) },
         { StrategyType.CommunicateStrategy, new CommunicateStrategy(
               gameInfo.BoardSize.X.Value, gameInfo.BoardSize.Y.Value, gameInfo.TeamId, gameInfo.GoalAreaSize) },
     };
 }
예제 #28
0
        public void SetGameResult(GameStarted gameResult)
        {
            if (gameResult == null)
            {
                throw new ArgumentNullException("gameResult");
            }

            GameMode     = gameResult.GameMode;
            Hero         = heroRepository.Query(q => q.FirstOrDefault(x => x.Key == gameResult.Hero));
            OpponentHero = heroRepository.Query(q => q.FirstOrDefault(x => x.Key == gameResult.OpponentHero));
        }
 private void Update()
 {
     if (!_gameStarted)
     {
         if (Input.GetMouseButtonDown(0))
         {
             GameStarted?.Invoke();
             _gameStarted = true;
         }
     }
 }
예제 #30
0
        private void OnLobbyNetworkReceived(NetPeer peer, NetDataReader dataReader)
        {
            NetMessage instruction = (NetMessage)dataReader.GetInt();

            switch (instruction)
            {
            case NetMessage.ServerClosed:
                OnServerClosed();
                break;

            case NetMessage.ClientsCount:
                int count = dataReader.GetInt();
                OnClientsCount(count);
                break;

            case NetMessage.AddPlayer:
                PlayerAdded?.Invoke(this, new LobbyPlayerEventArgs()
                {
                    PlayerID        = dataReader.GetString(),
                    ControllerIndex = (PlayerControllerIndex)dataReader.GetInt()
                });
                break;

            case NetMessage.RemovePlayer:
                PlayerRemoved?.Invoke(this, new LobbyPlayerEventArgs()
                {
                    PlayerID = dataReader.GetString()
                });
                break;

            case NetMessage.PrepareToStartGame:
                PreparingGameToStart?.Invoke(this, new LobbyOptionsArgs {
                    PlayersCount = dataReader.GetInt(),
                    Map          = dataReader.GetInt(),
                    Biome        = dataReader.GetInt(),
                });
                break;

            case NetMessage.InstantiateCharacter:
                InstantiateCharacter?.Invoke(this, new LobbyPlayerEventArgs {
                    PlayerID        = dataReader.GetString(),
                    ControllerIndex = (PlayerControllerIndex)dataReader.GetInt(),
                    Type            = (Pj.Type)dataReader.GetInt(),
                    X = dataReader.GetFloat(), Y = dataReader.GetFloat()
                });
                break;

            case NetMessage.StartGame:
                this.SetGameplay();
                GameStarted?.Invoke(this, EventArgs.Empty);
                break;
            }
        }
예제 #31
0
 private GameStarted TriggerGameStarted()
 {
     GameStarted action = new GameStarted();
     sut.OnGameStarted(action);
     return action;
 }