コード例 #1
0
        public override void Execute(Game game)
        {
            Player sender   = game.GetPlayerByUserId(SenderUserId);
            Player opponent = game.GetOpponentPlayerByUserId(SenderUserId);

            if (sender == null)
            {
                throw new CommandException();
            }
            sender.IsTurn = false;

            if (opponent != null)
            {
                opponent.IsTurn   = false;
                opponent.IsVictor = true;
            }

            var forfeitEvent = new ForfeitEvent(game.GetAllUserIds())
            {
                UserId = sender.User.Id
            };

            Events.Add(forfeitEvent);

            NextState = new GameEndState();
        }
コード例 #2
0
        public void GameEnd()
        {
            var gameEndState = new GameEndState
            {
                CurrentRoundStatus = CurrentRoundStatus
            };

            StateMachine.ChangeState(gameEndState);
        }
コード例 #3
0
ファイル: ClientBehaviour.cs プロジェクト: Pircs/NaoMahjong
        public void RpcGameEnd(EventMessages.GameEndInfo message)
        {
            var endState = new GameEndState
            {
                CurrentRoundStatus = CurrentRoundStatus,
                PlayerNames        = message.PlayerNames,
                Points             = message.Points,
                Places             = message.Places
            };

            StateMachine.ChangeState(endState);
        }
コード例 #4
0
        public void InitializeGameEndState()
        {
            var state = new GameEndState();
            var game  = new Game
            {
                IsActive = true,
                State    = state
            };

            var events = state.Initialize(game).ToList();

            Assert.Empty(events);
            Assert.False(game.IsActive);
        }
コード例 #5
0
 /// <summary>
 /// Cleans up a battleship defense
 /// </summary>
 /// <param name="state">Win/Lose/Draw</param>
 public void Cleanup(GameEndState state)
 {
     // Record defense data
     for (int i = 0; i < AdaptivePlayer.Height; ++i)
     {
         for (int j = 0; j < AdaptivePlayer.Width; ++j)
         {
             // If we were shot at, weigh earlier shots heavier than later shots
             if (_incomingShots[i, j] > 0)
             {
                 AdaptivePlayer.Data.IncomingShots[i][j] += (int)((double)(AdaptivePlayer.Turn - _incomingShots[i, j] + 1) / (double)AdaptivePlayer.Turn * 1000.0d);
             }
         }
     }
 }
コード例 #6
0
    public void GameOver()
    {
        GameplayPanel.SetActive(false);

        currentGameState = GameState.GameOver;

        GameEndState state = succeedBallCount >= 3 ? GameEndState.Success : GameEndState.Fail;

        GameOverPanel.SetActive(true);

        WinStateText.text = "YOU " + (state == GameEndState.Success ? "WIN!" : "LOST!");
        ScoreText.text    = score.ToString();

        LevelManager.Instance.ballRemaining = 5;
        succeedBallCount = 0;
        score            = 0;
        scoreMultipler   = 1;
    }
コード例 #7
0
        public GameState(LevelScript levelScript)
        {
            this.levelScript = levelScript;
            spawnIndices = new List<int>();
            for (int Idx = this.levelScript.spawnPoint.Count; Idx > 0; --Idx)
            {
                spawnIndices.Add(0);
            }

            parentState = null;
            minions = new Dictionary<Point, Minion>();
            ongoingEffects = new Dictionary<Point, Ongoing>();
            resources = new Dictionary<ResourceType, int>();
            turnNumber = 1;
            playableCards = new HashSet<Card>();
            gameEndState = GameEndState.GameRunning;
            cardTextChanges = new Dictionary<Card, TextChanges>();

            levelScript.InitState(this);
        }
コード例 #8
0
        public override void Update(GameTime gameTime)
        {
            if (level != null)
            {
                entityManager?.Update(gameTime);

                GameEndState state = CheckGameState();
                if (state != GameEndState.None)
                {
                    if (gameMode == GameMode.Training)
                    {
                        GameOver?.Invoke(this, new GameOverArgs(state, Convert.ToInt32(Math.Round(GetPlayerHealth()))));
                    }
                    else
                    {
                        GameOver?.Invoke(this, null);
                    }
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Executed by the function "CalculateFitness" from every DNA (individuum)
        /// </summary>
        /// <param name="decisions">decisions of the individuum</param>
        /// <returns>Returns players health</returns>
        public int DoTraining(Genetics.Decision[] decisions)
        {
            Console.WriteLine("Game-Session started!");

            //Setd the "virtual" elapsed time between updates (high values (>16) can break collision detection and pathfinding)
            TimeSpan elapsedTime = new TimeSpan(0, 0, 0, 0, 1);
            GameTime gameTime    = new GameTime(new TimeSpan(0), elapsedTime);

            SetupDecisions(decisions);
            ResetLevel();

            //game session
            GameEndState state = GameEndState.None;

            do
            {
                gameTime.TotalGameTime += elapsedTime;
                Update(gameTime);
                state = CheckGameState();

                //speed up or slow down simulation (can be used to render/spectate in realtime)
                if (gameMode == GameMode.Spectator)
                {
                    Thread.Sleep(4);
                }
            } while (state == GameEndState.None);

            //Set health to 1 if hostage was grabbed
            int health = Convert.ToInt32(Math.Round(GetPlayerHealth()));

            if (health == 0 && player.HostageGrabbed > 0)
            {
                health = 1;
            }

            //Output Trainings results
            DrawTrainingsResault(state, health);
            return(health);
        }
コード例 #10
0
    private void OnGameEnd(string messageType, string messageContent)
    {
        string[] details = decodeMessage(messageContent, '$');

        /* Check if content is empty */
        if (messageContent != "")
        {
            string winningTeam  = details[0];
            string redScoreStr  = details[1];
            string blueScoreStr = details[2];

            /* Check if all details are present */
            if (winningTeam != "" && redScoreStr != "" && blueScoreStr != "")
            {
                int redScore  = 0;
                int blueScore = 0;

                /* Convert the received string to integer (score) */
                int.TryParse(redScoreStr, out redScore);
                int.TryParse(blueScoreStr, out blueScore);

                /* Initialise the game end state and load the scene */
                gameEndState = new GameEndState(winningTeam, redScore, blueScore);
                Debug.Log("END GAME: " + winningTeam + " " + redScore + " " + blueScore);
                Player.removeCurrentIngredient();
                Player.currentStation = "-1";
                SceneManager.LoadScene("PlayerGameOverScreen");
            }
            else
            {
                SendMyMessage(messageType, "Error: one of the details is missing");
            }
        }
        else
        {
            SendMyMessage(messageType, "Error: no details about end game");
        }
    }
コード例 #11
0
    void Start()
    {
        Screen.orientation = ScreenOrientation.Portrait;

        DontDestroyOnLoad(GameObject.Find("Client"));
        client = GameObject.Find("Client").GetComponent <Client>();

        gameEndState = client.gameEndState;

        if (client.getTeam().Equals("red"))
        {
            YourScoreText.text  = "Your Score: " + gameEndState.getRedScore().ToString();
            TheirScoreText.text = "Their Score: " + gameEndState.getBlueScore().ToString();
        }
        else if (client.getTeam().Equals("blue"))
        {
            YourScoreText.text  = "Your Score: " + gameEndState.getBlueScore().ToString();
            TheirScoreText.text = "Their Score: " + gameEndState.getRedScore().ToString();
        }

        UpdateBackground();

        if (client.getTeam().Equals(gameEndState.winningTeamStr()))
        {
            Winner();
        }
        else
        {
            if (gameEndState.getWinningTeam() != GameEndState.EndState.DRAW)
            {
                Loser();
            }
            else
            {
                Draw();
            }
        }
    }
コード例 #12
0
 private void DrawTrainingsResault(GameEndState gameEndState, int health)
 {
     Console.WriteLine("Game-Session ended => State: " + gameEndState.ToString() + ", PlayerHealth(Fitness): " + health.ToString());
 }
コード例 #13
0
 public void LoseGame()
 {
     gameEndState = GameEndState.GameOver;
 }
コード例 #14
0
 /// <summary>
 /// Cleans up an offense
 /// </summary>
 /// <param name="state"></param>
 public void Cleanup(GameEndState state)
 {
 }
コード例 #15
0
        /// <summary>
        /// Cleans up the game
        /// </summary>
        /// <param name="state">win/lose/tie</param>
        public void Cleanup(GameEndState state)
        {
            Offense.Cleanup(state);
            Defense.Cleanup(state);

            Save(state);
        }
コード例 #16
0
ファイル: GameHandler.cs プロジェクト: dirty-casuals/Calamity
 private void Awake( )
 {
     preCalamityState = new GamePreCalamityState( this );
     calamityState = new CalamityState( this );
     nextRoundState = new CalamityRoundState( this );
     gameEndState = new GameEndState( this );
 }
コード例 #17
0
        public GameState(GameState parentState)
        {
            this.gameEndState = parentState.gameEndState;
            this.parentState = parentState;
            this.levelScript = parentState.levelScript;
            turnNumber = parentState.turnNumber;

            spawnIndices = new List<int>();
            foreach (int spawnIndex in parentState.spawnIndices)
            {
                spawnIndices.Add(spawnIndex);
            }

            minions = new Dictionary<Point, Minion>();
            foreach (KeyValuePair<Point, Minion> kv in parentState.minions)
            {
                Minion newP = new Minion(kv.Value);
                minions[newP.position] = newP;

                if (kv.Value == parentState.wizard)
                {
                    wizard = newP;
                }
            }
            UpdateSpellSets();

            ongoingEffects = new Dictionary<Point, Ongoing>();
            foreach (KeyValuePair<Point, Ongoing> kv in parentState.ongoingEffects)
            {
                ongoingEffects.Add(kv.Key, new Ongoing(kv.Value));
            }

            resources = new Dictionary<ResourceType, int>(parentState.resources);
            cardTextChanges = new Dictionary<Card, TextChanges>();
            foreach (KeyValuePair<Card, TextChanges> kv in parentState.cardTextChanges)
            {
                cardTextChanges.Add(kv.Key, kv.Value);
            }
            playableCards = new HashSet<Card>();
        }
コード例 #18
0
        public void TurnEffects(MinionAnimationSequence animation)
        {
            CleanUp(animation);

            List<Minion> savedMinions = new List<Minion>(minions.Values);
            foreach (Minion p in savedMinions)
            {
                p.ResetTemporaryEffects();
            }

            foreach (Minion p in savedMinions)
            {
                p.ApplyOngoingEffects(this, animation);
            }

            foreach(KeyValuePair<Point, Minion> entry in minions )
            {
                if (!entry.Value.TryPayUpkeep(this))
                {
                    Destroyed(entry.Key, entry.Value);
                }
            }

            MinionsAttack(animation);
            CleanUp(animation);

            MoveEnemies(animation);

            var finalMinions = minions.Values.ToList();
            foreach (Minion p in finalMinions)
            {
                p.ApplyOngoingLateEffects(this, animation);
            }

            CleanUp(animation);

            if (gameEndState == GameEndState.GameRunning && WonLevel())
            {
                gameEndState = GameEndState.GameWon;
            }

            turnNumber++;
        }
コード例 #19
0
 /// <summary>
 /// Saves any gathered data about opponents
 /// </summary>
 public abstract void Save(GameEndState state);
コード例 #20
0
        /// <summary>
        /// Saves gathered data
        /// </summary>
        public override void Save(GameEndState state)
        {
            if (state == GameEndState.Win)
                ++Data.Wins;
            else if (state == GameEndState.Loss)
                ++Data.Losses;
            else if (state == GameEndState.Tie)
                ++Data.Ties;

            if (Turn < Data.MinTurns)
                Data.MinTurns = Turn;
            if (Turn > Data.MaxTurns)
                Data.MaxTurns = Turn;

            Data.AverageTurns = (Data.AverageTurns * (float)(Data.Wins + Data.Losses + Data.Ties - 1) + (float)Turn) / (float)(Data.Wins + Data.Losses + Data.Ties);

            using (var stream = File.Create(FileName))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(BattleshipData));
                serializer.Serialize(stream, Data);
            }

            #if DEBUG
            using (var stream = File.Create(FileName + "_Log_" + DateTime.Now.ToString("yyyyMMddhhmmss")))
            {
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    writer.Write(_log.ToString());
                }
            }
            _log.Clear();
            #endif

            //            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null))
            //            {
            //                using (var stream = isoStore.CreateFile(FileName))
            //                {
            //                    XmlSerializer serializer = new XmlSerializer(typeof(BattleshipData));
            //                    serializer.Serialize(stream, Data);
            //                }

            //#if DEBUG
            //                using (var stream = isoStore.CreateFile(FileName + "_Log_" + DateTime.Now.ToString("yyyyMMddhhmmss")))
            //                {
            //                    using (StreamWriter writer = new StreamWriter(stream))
            //                    {
            //                        writer.Write(_log.ToString());
            //                    }
            //                }
            //                _log.Clear();
            //#endif
            //            }
        }