Exemple #1
0
        /// <summary>
        /// Starts a new Connect Four game by clearing the Connect Four board.
        /// </summary>
        /// <param name="resetScores">States whether the scores should be reset to zero or not.</param>
        public void StartNewGame(bool resetScores)
        {
            OnGameReset?.Invoke(this);

            // Clear the game board
            for (int row = 0; row < gameBoardChips.GetLength(0); row++)
            {
                for (int col = 0; col < gameBoardChips.GetLength(1); col++)
                {
                    gameBoardChips[row, col] = Chip.None;
                }
            }

            // Reset both the red player and the yellow player scores
            if (resetScores)
            {
                Scores[Chip.Red] = Scores[Chip.Yellow] = 0;
            }

            // Make the computer do their move if it's their turn
            if (IsComputerTurn)
            {
                PerformComputeMove();
            }

            OnNewGame?.Invoke(this);
        }
        void NewGameButton_OnNewGame(object sender, EventArgs e)
        {
            OnNewGame?.Invoke(this, true);

            _newGameButton.Enabled = false;
            _timerSlider.Enabled   = false;
            _letterLabel.UserInteractionEnabled = false;

            _secs            = GetTimerValueInSeconds();
            _timerLabel.Text = FormatSeconds(GetTimerValueInSeconds());

            //ChooseNewLetter();

            if (_timer != null)
            {
                _timer.Stop();
                _timer.Elapsed -= _timer_Elapsed;
                _timer          = null;
            }

            _timer          = new Timer(1000);
            _timer.Elapsed += _timer_Elapsed;
            _timer.Enabled  = true;
            _timer.Start();
        }
Exemple #3
0
        public void NewGame()
        {
            playerState.Reset();
            scoreKeeper.ResetScore();
            GameState = GameState.InProgress;

            OnNewGame?.Invoke();
        }
Exemple #4
0
        public void StartNewGame()
        {
            _model.NewGame();
            TimerLabel = "0";

            OnPropertyChanged("PauseResumeLabel");
            OnNewGame?.Invoke(this, EventArgs.Empty);
        }
 private void StartNewGame(OnNewGame eventData)
 {
     gameEnded = false;
     SceneManager.LoadScene(startingScene);
     playerName            = eventData.CharacterName;
     currentWorldLevel     = 1;
     Enemy.numberOfEnemies = 0;
     EventManager.Instance.TriggerEvent(new OnPlayerTeleportation(new Vector3(0, 11, 0)));
     EventManager.Instance.TriggerEvent(new OnNumberOfEnemiesChanged(0));
     EventManager.Instance.TriggerEvent(new OnPauseEnd());
 }
Exemple #6
0
    public void StartNewGame()
    {
        if (OnNewGame != null)
        {
            OnNewGame();
        }

        print(string.Format("GC: OnNewGame triggered {0} event call(s)", OnNewGame.GetInvocationList().Length));

        ResetGame();
    }
Exemple #7
0
    public Promise UpdateMetches(TournamentObject info)
    {
        return(new Promise((action, exeption) => {
            SetCurrentTournament(info.Id);

            TournamentManager.Instance.GetDetailsTournamentObject(info.TournamentDetails.Id)
            .Then(detail => {
                ApiManager.Instance.Database.GetMatches(Array.ConvertAll(detail.Matches, match => match.Id))
                .Then(matches => {
                    var myMatch = Array.Find(matches, match => match.State.Equals(ChainTypes.MatchState.InProgress) && match.Players.Contains(me.Id));
                    ApiManager.Instance.Database.GetGames(Array.ConvertAll(myMatch.Games, game => game.Id))
                    .Then(games => {
                        var existTournament = IsTournamentExist(myMatch.Tournament);
                        var existMatch = existTournament && myTournaments[myMatch.Tournament].StartedMatches.Contains(myMatch.Id);
                        if (!existTournament)
                        {
                            myTournaments[myMatch.Tournament] = new TournamentContainer(match => OnNewMatch.Invoke(match), match => OnMatchComplete.Invoke(match));
                        }
                        myTournaments[myMatch.Tournament].UpdateTournamentInfo(info, detail);
                        var opponent = Array.Find(myMatch.Players, account => !me.Id.Equals(account));
                        Repository.GetInPromise(opponent, () => ApiManager.Instance.Database.GetAccount(opponent.Id))
                        .Then(account => {
                            if (!existMatch)
                            {
                                myTournaments[myMatch.Tournament]
                                .NewMatch(myMatch, me, account,
                                          (match, game) => OnNewGame.Invoke(match, game),
                                          (match, game) => OnGameComplete.Invoke(match, game),
                                          (match, game) => OnGameExpectedMove.Invoke(match, game));
                            }
                            var completedGames = myTournaments[myMatch.Tournament].CurrentMatch.CompletedGames;
                            foreach (var game in games)
                            {
                                if (!completedGames.ContainsKey(game.Id))
                                {
                                    if (game.State.Equals(ChainTypes.GameState.Complete))
                                    {
                                        (completedGames[game.Id] = new GameContainer(completedGames.Count + 1, game, me, account))
                                        .CheckState();
                                    }
                                    else
                                    {
                                        myTournaments[myMatch.Tournament].CurrentMatch.NewGame(game).CheckState();
                                    }
                                }
                            }
                            action();
                        });
                    });
                });
            });
        }));
    }
    public void ReceiveNewGame()
    {
        Debug.Log("Starting New Game");

        NetworkPlayerManager.Instance.SetLocalPlayer();
        roundIndex = 0;
        ScoreManager.Instance.ResetScore();

        if (OnNewGame != null)
        {
            OnNewGame.Invoke();
        }
        ChangePhase(Phases.WeaponSelection);

        SoundManager.Instance.ResetAmbiance();
    }
Exemple #9
0
    public void NewGame()
    {
        if (GameActive)
        {
            Debug.Log("Game already running.");
            return;
        }

        _timeRemaining = time;

        menu.SetActive(false);
        NewRound();
        StartCoroutine(GameTimer());
        OnNewGame?.Invoke();
        _audioSource.Play();
    }
        //extract out to seperate class commands
        // net work is just send receive
        private void Execute_Commands(string data, string pretext)
        {
            string[] command = data.Split('~');
            for (int i = 0; i < command.Length; i++)
            {
                string[] cmd = command[i].Split(paramDelimiter);
                switch (cmd[0])
                {// constatnats any litral the data is in the code
                case "Chat":
                    if (cmd[2].Length > 0)
                    {    // send obj not primatives obj validation or some function
                        if (pretext == "Sent")
                        {
                            pretext = "You";
                        }                                              //Properties.Settings.Default.userName; }
                        else
                        {
                            pretext = cmd[1];
                        }
                        OnChatRecieved?.Invoke(this, pretext + cmd[2]);
                    }
                    break;

                case "Move":
                    OnMoveRecieved?.Invoke(this, new MoveArgs(int.Parse(cmd[2]), int.Parse(cmd[1])));
                    break;

                case "StartGame":
                    OnNewGame?.Invoke(this, GameState.GetGameState(cmd[1]));
                    break;

                case "Close":
                    networkActive    = false;
                    otherSideClosing = true;
                    break;
                }
            }
        }
Exemple #11
0
 public void NewGame() => OnNewGame?.Invoke();
 public void StartNewGame(string VehiclePrefabPath)
 {
     Vehicle        = _vehicleFactory.Create(VehiclePrefabPath);
     Time.timeScale = 1f;
     OnNewGame?.Invoke();
 }
 public void OnNewGameClicked()
 {
     OnNewGame?.Invoke(this, EventArgs.Empty);
 }
 private void GameStarted(OnNewGame date)
 {
     gameRunning = true;
 }
 private void Button_NewGame(object sender, RoutedEventArgs e)
 {
     OnNewGame?.Invoke(this, new EventArgs());
     ClearMinefield();
 }
Exemple #16
0
 private void PlayerNewGame(OnNewGame data)
 {
     SetStartingValues();
     RefreshWholeGUI();
 }
Exemple #17
0
        public void Update(LiveSplitState state)
        {
            currentState = state;
            if (!FindEmulator() || !IsLegendOfZelda())
            {
                savedFrames  += currentFrames;
                currentFrames = 0;

                return;
            }

            Progress.Update(Emulator);
            Module.Update(Emulator);

            // Try to calculate the game time in terms of emulated frames
            if (IPPU_TotalEmulatedFrames != null)
            {
                IPPU_TotalEmulatedFrames.Update(Emulator);
                uint frames = IPPU_TotalEmulatedFrames.Current;

                if (Module.Old < GameModule.MAX && Module.Current >= GameModule.MAX)
                {
                    // just hit reset, so save the current frames
                    savedFrames  += currentFrames;
                    currentFrames = 0;
                }
                else if (Module.Old >= GameModule.MAX && Module.Current < GameModule.MAX)
                {
                    // LTTP is playing again, the first (few?) frames of initialization aren't relevant to the time
                    savedFrames  -= frames;
                    currentFrames = frames;
                }
                else if (Module.Current < GameModule.MAX)
                {
                    currentFrames = frames;
                }
            }


            // (snes9x) Resetting the emulator will fill the complete RAM with 0x55.
            // However, there's no Module with ID 0x55, so we're prior to real initialization.
            if (Module.Current >= GameModule.MAX)
            {
                return;
            }

            if (IsRandomized && Module.Current > GameModule.LoadFile)
            {
                CheckForItems();
            }

            // Only check for progress if it changed by one, which is normal story progression.
            // If you load a new game, your progress is 0 (and thus this isn't executed);
            // if you load an existing game, you'll start in state 2 or 3, which also won't lead to this being executed.
            if (Progress.Changed && (Progress.Old + 1) == Progress.Current)
            {
                CheckForProgress();
            }

            // The currently active screen changed.
            if (Module.Changed)
            {
                if (Module.Old == GameModule.LoadFile && Module.Current == GameModule.Dungeon)
                {
                    // Did we just start a new game?
                    if (Progress.Current == GameState.Start)
                    {
                        donePendants = 0;
                        doneCrystals = 0;

                        // Make sure we're not counting our passed frames so far as elapsed time
                        savedFrames = -currentFrames;

                        OnNewGame?.Invoke(this, new StateEventArgs(state));
                    }
                }
                else if ((Module.Old == GameModule.GanonVictory || Module.Old == GameModule.Victory) && Module.Old != Module.Current)
                {
                    // we probably finished some dungeon
                    CheckForFinishedDungeon();
                }

                else if (Module.Old == GameModule.GanonEmerges && Module.Current != GameModule.GanonEmerges)
                {
                    Split?.Invoke(this, new SplitEventArgs(currentState, "Ganon's Tower"));
                }

                else if (Module.Old != GameModule.TriforceRoom && Module.Current == GameModule.TriforceRoom)
                {
                    // we're done, time to go home
                    Split?.Invoke(this, new SplitEventArgs(currentState, ALTTPComponent.TRIFORCE));
                }
            }
        }
Exemple #18
0
    void Repository_OnObjectUpdate(IdObject idObject)
    {
        if (!idObject.SpaceType.Equals(SpaceType.Match))
        {
            return;
        }
        var updatedMatch = idObject as MatchObject;

        if (!updatedMatch.Players.Contains(me.Id))
        {
            return;
        }
        if (updatedMatch.State.Equals(ChainTypes.MatchState.WaitingOnPreviousMatches))
        {
            return;
        }
        Repository.GetInPromise(updatedMatch.Tournament, () => TournamentManager.Instance.LoadTournament(updatedMatch.Tournament.Id)).Then(tournament => {
            Repository.GetInPromise(tournament.TournamentDetails, () => TournamentManager.Instance.GetDetailsTournamentObject(tournament.TournamentDetails.Id)).Then(tournamentDetails => {
                var existTournament = IsTournamentExist(updatedMatch.Tournament);
                var existMatch      = existTournament && myTournaments[updatedMatch.Tournament].StartedMatches.Contains(updatedMatch.Id);
                if (!existTournament)
                {
                    myTournaments[updatedMatch.Tournament] = new TournamentContainer(match => OnNewMatch.Invoke(match), match => OnMatchComplete.Invoke(match));
                }
                myTournaments[updatedMatch.Tournament].UpdateTournamentInfo(tournament, tournamentDetails);
                if (!existMatch && updatedMatch.State.Equals(ChainTypes.MatchState.InProgress))
                {
                    var opponent = Array.Find(updatedMatch.Players, account => !me.Id.Equals(account));
                    Repository.GetInPromise(opponent, () => ApiManager.Instance.Database.GetAccount(opponent.Id)).Then(account => {
                        myTournaments[updatedMatch.Tournament].NewMatch(updatedMatch, me, account,
                                                                        (match, game) => OnNewGame.Invoke(match, game),
                                                                        (match, game) => OnGameComplete.Invoke(match, game),
                                                                        (match, game) => OnGameExpectedMove.Invoke(match, game));
                    });
                }
            });
        });
    }
Exemple #19
0
        void GameMemoryReadThread()
        {
            Trace.WriteLine("[NoLoads] MemoryReadThread");

            while (!ListenGameCancelSource.IsCancellationRequested)
            {
                try
                {
                    Trace.WriteLine("[NoLoads] Waiting for game.exe...");

                    Process game;
                    while ((game = GetGameProcess()) == null)
                    {
                        Thread.Sleep(250);
                        if (ListenGameCancelSource.IsCancellationRequested)
                        {
                            return;
                        }
                    }

                    Trace.WriteLine("[NoLoads] Got game.exe!");

                    FrameCounter = 0;
                    int    prevBufCursor  = 0;
                    string prevBuf        = String.Empty;
                    string currentMap     = String.Empty;
                    string prevCurrentMap = String.Empty;
                    bool   prevIsLoading  = false;

                    while (!game.HasExited)
                    {
                        LogBufferPtr.DerefString(game, 4096, out string buf);
                        LogBufferCursorPtr.Deref(game, out int bufCursor);
                        IsLoadingPtr.Deref(game, out int ret);
                        IsSavingPtr.Deref(game, out int isSaving);

                        bool isLoading = (ret == 2 || isSaving == 256);

                        string log = String.Empty;

                        if ((!buf.Equals(prevBuf) && !prevBuf.Equals(String.Empty)))
                        {
                            int length = (prevBufCursor > bufCursor) ? 4096 - prevBufCursor : bufCursor - prevBufCursor;
                            log = buf.Substring(prevBufCursor, length);
                            if (prevBufCursor > bufCursor)
                            {
                                log += buf.Substring(0, bufCursor);
                            }

                            string[] logLines = Regex.Split(log, @"(?<=\r\n)");

                            Debug.WriteLine(String.Format("------bufCursor: {0} prevBufCursor: {1}-------", bufCursor, prevBufCursor));
                            Debug.WriteLine("--------------------" + FrameCounter + "---------------------");
                            Debug.Write(log);

                            int  cursor = prevBufCursor;
                            uint i      = 0;
                            foreach (string line in logLines)
                            {
                                Match validLine      = Regex.Match(line, @"^(?:Log:|Init:|ScriptLog:|CutLog:|DevSound:|Localization:|Warning:|ScriptWarning:|Exit:|Uninitialized:).+\r\n");
                                Match loadMapRegex   = Regex.Match(line, @"LoadMap: ([^?]+)\?");
                                Match splitRegex     = Regex.Match(line, @"Bringing Level ([^ ?]+)\.MyLevel up for play");
                                Match loadTimeRegex  = Regex.Match(line, @"Load time (?:.+\\)?([^?]+): (\d+\.\d+) seconds total, (\d+\.\d+) app");
                                Match saveStartRegex = Regex.Match(line, @"Saving game\.\.\. filename: .+\.usa");
                                Match saveEndRegex   = Regex.Match(line, @"Log: Moving '.+\.tmp' to '.+\.usa'");

                                if (line.Equals(""))
                                {
                                    continue;
                                }

                                // If the line is incorrect, read again from there next frame
                                if (!validLine.Success && i > 0)
                                {
                                    Debug.WriteLine("\n[Invalid line] " + line);
                                    bufCursor = cursor;
                                    if (bufCursor >= 4096)
                                    {
                                        bufCursor -= 4096;
                                    }
                                    break;
                                }
                                cursor += line.Length;

                                if (loadMapRegex.Success)
                                {
                                    currentMap = loadMapRegex.Groups[1].Value.ToLower();
                                    if (Shrek2Splits.Splits.Any(p => p.Name == currentMap))
                                    {
                                        Split(Shrek2Splits.Splits.First(p => p.Name == currentMap).ID, FrameCounter);
                                    }
                                }
                                else if (line.Contains(Shrek2Splits.NewGame_MemoryLine))
                                {
                                    ListenGameUIThread.Post(d =>
                                    {
                                        OnNewGame?.Invoke(this, EventArgs.Empty);
                                    }, null);
                                }
                                else
                                {
                                    if (Shrek2Splits.Splits.Any(p => p.CutSceneTriggers.Any(x => line.Contains(x))))
                                    {
                                        var splitValue = Shrek2Splits.Splits.FirstOrDefault(p => p.CutSceneTriggers.Any(x => line.Contains(x)));
                                        Split(splitValue.ID, FrameCounter);
                                    }
                                }

                                i++;
                            }
                        }

                        if (currentMap != prevCurrentMap)
                        {
                            Debug.WriteLine(String.Format("[NoLoads] Detected map change from \"{0}\" to \"{1}\" - {2}", prevCurrentMap, currentMap, FrameCounter));

                            if (currentMap == "book_frontend.unr")
                            {
                                ListenGameUIThread.Post(d =>
                                {
                                    if (this.OnMainMenuLoad != null)
                                    {
                                        this.OnMainMenuLoad(this, EventArgs.Empty);
                                    }
                                }, null);
                            }
                        }

                        if (isLoading != prevIsLoading)
                        {
                            if (isLoading)
                            {
                                Trace.WriteLine("[NoLoads] Loading started - " + FrameCounter);
                                ListenGameUIThread.Post(d =>
                                {
                                    if (this.OnLoadStart != null)
                                    {
                                        this.OnLoadStart(this, EventArgs.Empty);
                                    }
                                }, null);
                            }
                            else
                            {
                                Trace.WriteLine("[NoLoads] Loading ended - " + FrameCounter);
                                ListenGameUIThread.Post(d =>
                                {
                                    if (this.OnLoadEnd != null)
                                    {
                                        this.OnLoadEnd(this, EventArgs.Empty);
                                    }
                                }, null);
                            }
                        }

                        FrameCounter++;
                        prevBuf        = buf;
                        prevBufCursor  = bufCursor;
                        prevCurrentMap = currentMap;
                        prevIsLoading  = isLoading;

                        Thread.Sleep(Shrek2Variables.GameLogic_SleepTime);

                        if (ListenGameCancelSource.IsCancellationRequested)
                        {
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.ToString());
                    Thread.Sleep(1000);
                }
            }
        }
 private void ActivatePlayer(OnNewGame eventData)
 {
     gameObject.SetActive(true);
 }