public AttackAction(BattleshipTeam attacker, BattleshipBoard board, int x, int y)
 {
     this.attacker = attacker;
     this.board    = board;
     xCoord        = x;
     yCoord        = y;
 }
Esempio n. 2
0
 private static void TurnManager_OnPhaseChanged(ITurnPhase fromPhase, ITurnPhase toPhase, ITurnManager turnManager)
 {
     if (toPhase is EnemyPhase ePhase)
     {
         currentTeam = ePhase.EnemyTeam;
     }
     else if (toPhase is PlayerPhase pPhase)
     {
         currentTeam = pPhase.PlayerTeam;
     }
 }
        public BattleshipBoard(BattleshipTeam team)
        {
            Random r = new Random(0);

            this.team = team;
            // TODO: Randomize placement of ships and their rotation
            foreach (var ship in team.Members)
            {
                // 0: Horizontal
                // 1: Vertical
                int orientation = r.Next() % 2;
                int rootX, rootY;
                (int, int)offset;
                if (orientation == 0)
                {
                    rootX  = r.Next(10 - ship.Segments.Length);
                    rootY  = r.Next(10);
                    offset = (1, 0);
                }
                else if (orientation == 1)
                {
                    rootX  = r.Next(10);
                    rootY  = r.Next(10 - ship.Segments.Length);
                    offset = (0, 1);
                }
                else
                {
                    throw new Exception("Oops");
                }

                foreach (Segment s in ship.Segments)
                {
                    board[rootX, rootY] = s;
                    rootX += offset.Item1;
                    rootY += offset.Item2;
                }
            }
            for (int i = 0; i < BOARD_SIZE; ++i)
            {
                for (int j = 0; j < BOARD_SIZE; ++j)
                {
                    if (board[i, j] == null)
                    {
                        board[i, j] = new Segment(null);
                    }
                }
            }
        }
Esempio n. 4
0
        static Arena BuildArena()
        {
            PlayerBattleshipTeam playerTeam = new TeamBuilder <PlayerBattleshipTeam, Ship>()
                                              .Start()
                                              .SetTeamSize(3)
                                              .AddEntity(new Ship("Carrier", CarrierSize))
                                              .AddEntity(new Ship("Battleship", BattleshipSize))
                                              .AddEntity(new Ship("Patrol Boat", PatrolBoatSize))
                                              .Finish();

            playerTeam.PrepareBoard();
            currentTeam = playerTeam;

            EnemyBattleshipTeam enemyTeam = new TeamBuilder <EnemyBattleshipTeam, Ship>()
                                            .Start()
                                            .SetTeamSize(3)
                                            .AddEntity(new Ship("Carrier", CarrierSize))
                                            .AddEntity(new Ship("Battleship", BattleshipSize))
                                            .AddEntity(new Ship("Patrol Boat", PatrolBoatSize))
                                            .Finish();

            enemyTeam.PrepareBoard();

            // I guess alliance graphs aren't really all that useful for 2-sided games.
            // More for games with multiple sides and complex relationships
            playerTeam.Opponent = enemyTeam;
            enemyTeam.Opponent  = playerTeam;

            BattleshipTurnManager turnManager = new BattleshipTurnManager(playerTeam, enemyTeam);

            turnManager.OnPhaseChanged += TurnManager_OnPhaseChanged;

            return(new ArenaBuilder <BattleshipTeam>()
                   // The battleship turn manager also sets up the phases
                   .SetTurnManager(turnManager)
                   // This will probably be removed in 0.3.0-alpha, replaced with a "SetMaxTeamCount" method
                   .SetTeamCount(2)
                   // Add the teams that are participating in this game
                   .AddTeam(playerTeam)
                   .AddTeam(enemyTeam)
                   // Set up the relationship between the teams. Not crucial in this scenario, but still important.
                   .AddBidirectionalTeamRelationship(playerTeam, enemyTeam, TeamRelationship.Opposing)
                   // Get the actual arena
                   .Finish());
        }
        public string ToString(BattleshipTeam viewpoint)
        {
            StringBuilder sb = new StringBuilder();

            for (int y = 0; y < BOARD_SIZE; ++y)
            {
                for (int x = 0; x < BOARD_SIZE; ++x)
                {
                    // TODO: figure out difference between hits, misses, etc.
                    Segment s = board[x, y];

                    if (s.Owner == null)
                    {
                        if (!s.IsHit)
                        {
                            sb.Append('w');
                        }
                        else
                        {
                            sb.Append('X');
                        }
                    }
                    else
                    {
                        if (s.IsHit)
                        {
                            sb.Append('O');
                        }
                        else if (team == viewpoint)
                        {
                            sb.Append('v');
                        }
                        else
                        {
                            sb.Append('w');
                        }
                    }
                }
                sb.Append('\n');
            }
            return(sb.ToString());
        }
Esempio n. 6
0
 public GuessCommand(BattleshipTeam attackingTeam, BattleshipTeam defendingTeam, int x, int y)
     : base(new AttackAction(attackingTeam, defendingTeam.Board, x, y), attackingTeam)
 {
 }
Esempio n. 7
0
 public EnemyPhase(BattleshipTeam enemyTeam, BattleshipTeam playerTeam)
 {
     EnemyTeam       = enemyTeam;
     this.playerTeam = playerTeam;
 }
Esempio n. 8
0
 public PlayerPhase(BattleshipTeam playerTeam, BattleshipTeam enemyTeam)
 {
     PlayerTeam     = playerTeam;
     this.enemyTeam = enemyTeam;
 }