コード例 #1
0
ファイル: GameSession.cs プロジェクト: psmoq/Battleships
        private void Events_RoundFinished(GamePlayer opponent, GameSessionRoundResult result)
        {
            if (result.ShipsStillFloating)
            {
                return; // game session is only interested in information when to stop
            }
            var winner = opponent;

            _eventBus.OnGameSessionFinished(this, winner);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: psmoq/Battleships
        private static void Events_RoundFinished(GamePlayer player, GameSessionRoundResult result)
        {
            if (result.WasHit && result.WasDestroyed)
            {
                Console.WriteLine($"{player.Name} has destroyed the ship - ship has sunk");
            }

            if (result.WasHit && !result.WasDestroyed)
            {
                Console.WriteLine($"{player.Name} has hit the ship but the ship is still floating");
            }

            if (!result.WasHit && !result.WasDestroyed)
            {
                Console.WriteLine($"{player.Name} has missed the ships");
            }

            if (!result.ShipsStillFloating)
            {
                Console.WriteLine($"{player.Name} has destroyed all ships of his opponent - all ships are sunk");
            }
            else
            {
                if (_humanPlayer != player) // other player finished the round, now it's human turn but first print the state
                {
                    PrintPlayerState(player);
                    GoHumanPlayer();
                }
                else // human player finished the round, now it's other player turn
                {
                    Console.WriteLine();
                    Console.WriteLine($"Waiting for {_session.Player2.Name} shot");
                    Console.WriteLine();
                }
            }
        }
コード例 #3
0
 public void OnShipMissed(GamePlayer opponent)
 {
     RoundFinished?.Invoke(opponent, GameSessionRoundResult.Missed());
 }
コード例 #4
0
 public void OnShipHit(GamePlayer player)
 {
     RoundFinished?.Invoke(player, GameSessionRoundResult.Hit());
 }
コード例 #5
0
 public void OnAllShipsSunk(GamePlayer opponent)
 {
     RoundFinished?.Invoke(opponent, GameSessionRoundResult.AllSunk());
 }
コード例 #6
0
 public void OnRoundSkipped(GamePlayer opponent)
 {
     RoundFinished?.Invoke(opponent, GameSessionRoundResult.Skipped());
 }