Exemplo n.º 1
0
        private void clickOnSecondPlayerCanvas(object sender, MouseButtonEventArgs e)
        {
            if (_actualGameType == GameType.Pvp)
            {
                if (_actualPlayer == Player.FirstPlayer)
                {
                    int[,] shipLayout = _viewModel._secondPlayerRefShipmatrix;
                    int[] shipCounts = _viewModel.secondPlayerShipsCounts;
                    int   points     = _viewModel.pointSecondPlayer;
                    _viewModel.guessTile(canvasSecondPlayer, ref shipLayout, ref shipCounts, ref _actualPlayer, _viewModel.GetPointOnCanvas(canvasSecondPlayer));
                    _viewModel.increaseRound();
                    textRound.Content                  = _viewModel.rounds;
                    textPointSecondPlayer.Content      = $"Pont: {_viewModel.pointSecondPlayer}";
                    textSecondPlayerShipCounts.Content = _viewModel.shipCountToString(_viewModel.secondPlayerShipsCounts);
                    _viewModel.endGame(_viewModel.secondPlayerShipsCounts, _actualPlayer, this);
                }
            }
            else if (_actualGameType == GameType.PvAi)
            {
                if (_actualPlayer == Player.FirstPlayer)
                {
                    int[,] aiPlayerShipLayout    = _viewModel._secondPlayerRefShipmatrix;
                    int[,] firstPlayerShipLayout = _viewModel._firstPlayerRefShipMatrix;
                    int[] shipCounts   = _viewModel.secondPlayerShipsCounts;
                    int[] aiShipCounts = _viewModel.firstPlayerShipsCounts;
                    int   points       = _viewModel.pointSecondPlayer;
                    _viewModel.guessTile(canvasSecondPlayer, ref aiPlayerShipLayout, ref shipCounts, ref _actualPlayer, _viewModel.GetPointOnCanvas(canvasSecondPlayer));
                    _viewModel.increaseRound();
                    textRound.Content                  = _viewModel.rounds;
                    textPointFirstPlayer.Content       = $"Pont: {_viewModel.pointSecondPlayer}";
                    textSecondPlayerShipCounts.Content = _viewModel.shipCountToString(_viewModel.secondPlayerShipsCounts);
                    _viewModel.endGame(_viewModel.secondPlayerShipsCounts, _actualPlayer, this);
                    //AI turn
                    int   prevAiPoint = _viewModel.pointFirstPlayer;
                    int[] aiArray     = aIPlayer.AIShoots(ref aiPrevHits, ref aiPrevShots);
                    aiPrevShots.Add(aiArray);
                    Vector aiShot = new Vector(aiArray[0], aiArray[1]);
                    _viewModel.guessTile(canvasFirstPlayer, ref firstPlayerShipLayout, ref aiShipCounts, ref _actualPlayer, aiShot);
                    if (_viewModel.pointFirstPlayer > prevAiPoint)
                    {
                        aiPrevHits.Add(aiArray);
                    }
                    textPointSecondPlayer.Content = $"Pont: {_viewModel.pointFirstPlayer}";

                    _viewModel.endGame(_viewModel.firstPlayerShipsCounts, Player.AIPlayer, this);
                    //textRound.Content = _viewModel.rounds;
                }
            }
        }
Exemplo n.º 2
0
        public void AIShootsFromLastHitTestTest(ref List <int[]> lastHit, ref List <int[]> prevShots, int[,] expectedShoot)
        {
            AIPlayer test = new AIPlayer();

            Assert.That(test.AIShoots(ref lastHit, ref prevShots), Is.SubsetOf(expectedShoot));
        }