Beispiel #1
0
        public MainForm()
        {
            SuspendLayout();

            _humanBoard = new Board();
            _computerBoard = new Board(false);

            _humanPlayer = new HumanPlayer("You", _computerBoard);
            _computerPlayer = new ComputerPlayer("Computer");

            _scoreboard = new ScoreBoard(_humanPlayer, _computerPlayer, 10, 100);
            _controller = new GameController(_humanPlayer, _computerPlayer, _humanBoard, _computerBoard, _scoreboard);

            _shuffleButton = CreateButton(ShuffleCharacter.ToString(), ButtonBackColor);
            _newGameButton = CreateButton(NewGameCharacter.ToString(), ButtonBackColor);
            _startGameButton = CreateButton(StartGameCharacter.ToString(), ButtonBackColor);

            SetupWindow();
            LayoutControls();

            _scoreboard.GameEnded += OnGameEnded;

            _shuffleButton.Click += OnShuffleButtonClick;
            _startGameButton.Click += OnStartGameButtonClick;
            _newGameButton.Click += OnNewGameButtonClick;

            ResumeLayout();

            StartNewGame();
        }
Beispiel #2
0
        public ScoreBoard(Player player1, Player player2, int shipsPerGame, int shotsPerGame)
        {
            SuspendLayout();
            _player1 = player1;
            _player2 = player2;
            _shipsPerGame = shipsPerGame;
            _shotsPerGame = shotsPerGame;

            _player1.MyTurn += OnPlayerTurnChanged;
            _player2.MyTurn += OnPlayerTurnChanged;

            _player1.Shot += OnPlayerMadeShot;
            _player2.Shot += OnPlayerMadeShot;

            var firstPlayerNameLabel = CreateLabel(_player1.Name, InactivePlayerColor);
            var secondPlayerNameLabel = CreateLabel(_player2.Name, InactivePlayerColor);
            _playerNames = new Pair<Label, Label>(firstPlayerNameLabel, secondPlayerNameLabel);

            var firstPlayerStatsLabel = CreateLabel(string.Empty, PlayerStatsColor);
            var secondPlayerStatsLabel = CreateLabel(string.Empty, PlayerStatsColor);
            _playerStats = new Pair<Label, Label>(firstPlayerStatsLabel, secondPlayerStatsLabel);

            _scoreLabel = CreateLabel("", ScoreColor);

            RefreshScore();
            InitPlayerStats();

            ResumeLayout();
        }