Esempio n. 1
0
        public void TestShotResultGettersAndSetters()
        {
            ShotResult shotResult = new ShotResult();

            shotResult.setState(State.miss);
            Assert.IsTrue(shotResult.getState().Equals(State.miss));
        }
Esempio n. 2
0
    public void OnShotFinished(ShotResult result)
    {
        shotHistory.Add(CurrentShot.Value);
        completedRounds = (completedRounds + 1);

        if ((!GameplayService.networked) &&
            (MissionManager.instance.HasCurrentMission()))
        {
            Mission mission = MissionManager.instance.GetMission();

            mission.NextRound(); // next round


            // has this mission finished ?
            // fin de mision
            if (mission.IsMissionFinished())
            {
                ServiceLocator.Request <IPlayerService>().SetGameOver();

                FieldControl.instance.GameOver();
            }
        }

        if (result.Result == Result.Goal)
        {
            CurrentShot = new ShotInformation()
            {
                Result = true,
                Shot   = CurrentShot.Value.Shot
            };

            ++successes;
            //UnityEngine.Debug.Log( "Successes: " + successes );
        }
    }
Esempio n. 3
0
    private void ComputeStats(ShotResult result)
    {
        switch (result.Result)
        {
        case Result.Saved:
            balonesParados++;
            break;

        case Result.Stopped:
            balonesDespejados++;
            break;

        case Result.Goal:
            golesMarcados++;
            golesEncajados++;
            break;

        case Result.OutOfBounds:
            balonesFallados++;
            break;

        case Result.Target:
            dianasAcertadas++;
            break;
        }
    }
Esempio n. 4
0
    public void OnShotResult(ShotResult result)
    {
        // Perfects
        _missionStats["perfects"].Update(result.Perfect);

        // Lanzador

        // acierto = hemos metido gol o le hemos dado a una diana
        _missionStats["shooterWinsGeneric"].Update((result.Result == Result.Goal || result.Result == Result.Target));
        // acierto diana = le hemos dado a una diana
        _missionStats["shooterWinsTarget"].Update((result.Result == Result.Target && FieldControl.instance.HasBullseye));
        // acierto portero = hemos metido gol habiendo un portero
        _missionStats["shooterWinsGoalkeeper"].Update((result.Result == Result.Goal && FieldControl.instance.goalKeeper));
        // acierto sabana = hemos metido gol habiendo una sabana
        _missionStats["shooterWinsSheet"].Update((result.Result == Result.Target && FieldControl.instance.HasSheet));

        // En result.EffectBonusPoints se guardan los puntos obtenidos por bonus de efecto
        _missionStats["effectBonusGeneric"].Update((result.EffectBonusPoints != (int)ScoreManager.EffectBonus.NONE));
        _missionStats["effectBonusLow"].Update((result.EffectBonusPoints == (int)ScoreManager.EffectBonus.LOW));
        _missionStats["effectBonusMedium"].Update((result.EffectBonusPoints == (int)ScoreManager.EffectBonus.MEDIUM));
        _missionStats["effectBonusHigh"].Update((result.EffectBonusPoints == (int)ScoreManager.EffectBonus.HIGH));

        // Portero

        // acierto = parado, despejado o el lanzador tiro fuera
        _missionStats["goalkeeperWinsGeneric"].Update((result.Result == Result.Saved || result.Result == Result.Stopped || result.Result == Result.OutOfBounds));
        // parado
        _missionStats["goalkeeperCatched"].Update((result.Result == Result.Saved));
        // despejado
        _missionStats["goalkeeperSaved"].Update((result.Result == Result.Stopped));
        // recibido gol
        _missionStats["goalkeeperReceivedGoals"].Update((result.Result == Result.Goal));
    }
Esempio n. 5
0
        private static bool InputIteration(GameBoard gameBoard)
        {
            string command = System.Console.ReadLine();

            if (command.ToUpper() == "EXIT")
            {
                return(false);
            }
            ShipCoordinate coordinate;

            if (CoordinateParser.TryGetCoordinate(command, out coordinate))
            {
                ShotResult shotResult = gameBoard.Shot(coordinate);
                switch (shotResult)
                {
                case ShotResult.Miss:
                    Console.WriteLine("Missed shot.");
                    return(true);

                case ShotResult.Hit:
                    Console.WriteLine("Hit shot.");
                    return(true);

                case ShotResult.GameWin:
                    Console.WriteLine("All battheships destroyed.");
                    return(false);

                default: throw new NotSupportedException();
                }
            }
            else
            {
                return(true);
            }
        }
        public void ShootAtOpponent_RetrievesTheGameFromTheRepositoryAndUsesItToShoot()
        {
            //Arrange
            Guid           userId           = Guid.NewGuid();
            Guid           gameId           = Guid.NewGuid();
            GridCoordinate targetCoordinate = new GridCoordinate(1, 1);

            var   existingGameMock = new Mock <IGame>();
            IGame existingGame     = existingGameMock.Object;

            _gameRepositoryMock.Setup(repo => repo.GetById(It.IsAny <Guid>())).Returns(existingGame);

            ShotResult expectedShotResult = RuntimeHelpers.GetUninitializedObject(typeof(ShotResult)) as ShotResult;

            existingGameMock.Setup(game => game.ShootAtOpponent(It.IsAny <Guid>(), It.IsAny <GridCoordinate>())).Returns(expectedShotResult);

            //Act
            var returnedShotResult = _service.ShootAtOpponent(gameId, userId, targetCoordinate);

            //Assert
            Assert.That(returnedShotResult, Is.SameAs(expectedShotResult),
                        "The ShotResult returned should be an instance created by the ShootAtOpponent method of the Game.");

            _gameRepositoryMock.Verify(repo => repo.GetById(gameId), Times.Once,
                                       "The 'GetById' method of the IGameRepository is not called correctly.");

            existingGameMock.Verify(game => game.ShootAtOpponent(userId, targetCoordinate), Times.Once,
                                    "The 'ShootAtOpponent' method of the game returned by the IGameRepository is not called correctly. " +
                                    "The id of the shooter and the target coordinate should be provided.");
        }
Esempio n. 7
0
 public void ShotResult(ShotResult shotResult)
 {
     if (shotResult.Hit)
     {
         gameState = GameState.Destroy;
         _hits.Add(shotResult.Position);
         if (firstShot == null)
         {
             firstShot = shotResult.Position;
         }
         if (shotResult.ShipSunken)
         {
             _misses.UnionWith(ExludeAdjancentPositionsToSunkenShip(_hits, orientation));
             _misses.UnionWith(_hits);//presune policka s trefenou lodi do misses
             gameState   = GameState.Seek;
             horizontal  = true;
             firstShot   = null; //Za předpokladu že tohle bude fungovat, by to mělo jít
             orientation = Orientation.Right;
             _hits.Clear();      //uvolni hits pro dalsi lod
         }
     }
     else
     {
         _misses.Add(shotResult.Position);
     }
 }
        public void DetermineTargetCoordinate_ShouldShootANeighborOfAHitSquare()
        {
            for (int numberOfChecks = 0; numberOfChecks < 5; numberOfChecks++)
            {
                //Arrange
                GridCoordinate hitCoordinate = new GridCoordinateBuilder(_grid.Size).Build();
                _gridBuilder.WithSquareStatus(hitCoordinate, GridSquareStatus.Hit);
                var ship = new ShipBuilder(ShipKind.Carrier).Build();
                _strategy.RegisterShotResult(hitCoordinate, ShotResult.CreateHit(ship, true));

                IList <GridCoordinate> expectedCoordinates = new List <GridCoordinate>();

                foreach (Direction direction in Direction.BasicDirections)
                {
                    GridCoordinate neighbor = hitCoordinate.GetNeighbor(direction);
                    if (!neighbor.IsOutOfBounds(_grid.Size))
                    {
                        expectedCoordinates.Add(neighbor);
                    }
                }

                //Act
                GridCoordinate result = _strategy.DetermineTargetCoordinate();

                Assert.That(expectedCoordinates.Contains(result), Is.True,
                            $"Bij een leeg grid met een raak shot op {hitCoordinate} " +
                            $"moet er geschoten worden op ייn van de volgende coordinaten: {expectedCoordinates.ToArray().Print()}. " +
                            $"De strategie kiest soms echter {result}");

                Setup();
            }
        }
Esempio n. 9
0
        public void RegisterShotResult(GridCoordinate target, ShotResult shotResult)
        {
            if (shotResult.Hit)
            {
                hitted.Add(target);
                candidates.AddRange(this.GetNeighbours(target, this.possibleDirections, GridSquareStatus.Untouched));
            }
            else
            {
                missed.Add(target);
            }
            untouched.Remove(target);
            candidates.Remove(target);

            if (shotResult.SunkenShip != null)
            {
                foreach (IShip ship in this.ships.ToList())
                {
                    if (ship.Kind == shotResult.SunkenShip.Kind)
                    {
                        this.ships.Remove(ship);
                    }
                }


                foreach (IGridSquare square in shotResult.SunkenShip.Squares)
                {
                    List <GridCoordinate> neighbours = this.GetNeighbours(square.Coordinate, this.possibleDirections, GridSquareStatus.Untouched);
                    foreach (GridCoordinate neighbour in neighbours)
                    {
                        candidates.Remove(neighbour);
                    }
                }
            }
        }
        public void DisplayResult(ShotResult result)
        {
            _outputWriter.SetCursorPosition(0, _cursorHelper.TextResultTop);

            if (result?.Coordinate != null)
            {
                _outputWriter.Write($"> {result.Coordinate} -> {result.Description}");
            }
            else
            {
                _outputWriter.Write($"> {result?.Description}");
            }

            FillLineWithSpaces();

            _outputWriter.SetCursorPosition(0, _cursorHelper.TextResultTop + 1);

            _outputWriter.Write("> ");

            FillLineWithSpaces();

            _outputWriter.SetCursorPosition(2, _cursorHelper.TextResultTop + 1);

            if (result != null && result.Kind == ShotResult.Kinds.GameEnd)
            {
                DisplayEndGameInfo();
            }
        }
        public void ShotResultHitAndSank()
        {
            var sr = new ShotResult(true, true);

            Assert.IsTrue(sr.WasSank);
            Assert.IsTrue(sr.WasHit);
        }
        public void ReallySwapActivePlayers_AfterMiss()
        {
            var target = new CellPosition(5, 6);

            A.CallTo(() => player2.SelfField.Shoot(target)).Returns(ShotResult.Miss(target));
            A.CallTo(() => player2.SelfField.SurvivedShips.Values).Returns(new[] { 1 });
            gameController.Shoot(target);

            var knowledge = new GameFieldKnowledge(gameController.Rules.FieldSize);

            A.CallTo(() => player2.OpponentFieldKnowledge).Returns(knowledge);
            var affectedCells = new[] { new CellPosition(2, 2), new CellPosition(1, 8) };

            A.CallTo(() => player1.SelfField.Shoot(target)).Returns(ShotResult.Hit(target, affectedCells));
            gameController.Shoot(target);

            foreach (var position in knowledge.EnumeratePositions())
            {
                var expected = position.Equals(target)
                    ? true
                    : (affectedCells.Contains(position)
                        ? (bool?)false
                        : null);
                knowledge[position].Should().Be(expected);
            }
        }
        public void DisplayResult_GoodCoordinatesWithSink_CoordinatesAreDisplayed()
        {
            _cursorHelperMock.Setup(x => x.TextResultTop)
            .Returns(22);
            _outputWriterMock.Setup(x => x.SetCursorPosition(0, 22));
            _outputWriterMock.Setup(x => x.SetCursorPosition(0, 23));
            _outputWriterMock.Setup(x => x.SetCursorPosition(2, 23));
            _outputWriterMock.Setup(x => x.Write(It.IsAny <string>()));
            var shotResult = new ShotResult
            {
                Coordinate = new Coordinate(4, 4), Kind = ShotResult.Kinds.Sink,
                SinkShip   = new List <Coordinate> {
                    new Coordinate(3, 4), new Coordinate(4, 4)
                },
                Description = "Shit has been sink."
            };

            _sut.DisplayResult(shotResult);

            _cursorHelperMock.Verify(x => x.GetLeftForCoordinate(It.IsAny <Coordinate>()), Times.Never);
            _cursorHelperMock.Verify(x => x.GetTopForCoordinate(It.IsAny <Coordinate>()), Times.Never);
            _cursorHelperMock.Verify(x => x.TextResultTop, Times.Exactly(3));
            _outputWriterMock.Verify(x => x.SetCursorPosition(It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(3));
            _outputWriterMock.Verify(x => x.SetCursorPosition(0, 22), Times.Once);
            _outputWriterMock.Verify(x => x.SetCursorPosition(0, 23), Times.Once);
            _outputWriterMock.Verify(x => x.SetCursorPosition(2, 23), Times.Once);
            _outputWriterMock.Verify(x => x.Write(It.IsAny <string>()), Times.Exactly(4));
            _outputWriterMock.Verify(x => x.Write(It.Is <string>(y => y.Contains("E5"))), Times.Once);
            _outputWriterMock.Verify(x => x.Write(It.Is <string>(y => y.Contains("->"))), Times.Once);
            _outputWriterMock.Verify(x => x.Write(It.Is <string>(y => y.Contains("Shit has been sink."))), Times.Once);
            _outputWriterMock.Verify(x => x.Write(It.Is <string>(y => y.Contains("End"))), Times.Never);
            _outputWriterMock.Verify(x => x.WriteNewLine(), Times.Never);
        }
Esempio n. 14
0
 public void TryShotResult(ShotResult shotResult)
 {
     if (shotResult.Result == Result.Goal)
     {
         SuccessfullyShotDone();
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Put a label on a board to show whether a shot was hit or miss
        /// </summary>
        /// <param name="coordinates"></param>
        /// <param name="result"></param>
        /// <param name="humanBoard"></param>
        public void showShotResult(Coordinates coordinates, ShotResult result, bool humanBoard = true)
        {
            Label lblShotResult = new Label();

            lblShotResult.Location = new Point(coordinates.Column * PANEL_SIZE, coordinates.Row * PANEL_SIZE);
            lblShotResult.Size     = new Size(PANEL_SIZE - 1, PANEL_SIZE - 1);
            if (result == ShotResult.Miss)
            {
                lblShotResult.Image     = Properties.Resources.circle_gray;
                lblShotResult.BackColor = CELL_COLOR;
            }
            else
            {
                lblShotResult.Image     = Properties.Resources.cancel_red;
                lblShotResult.BackColor = SHIP_COLOR;
            }

            if (humanBoard)
            {
                pnlGameBoard.Controls.Add(lblShotResult);
            }
            else
            {
                pnlFiringBoard.Controls.Add(lblShotResult);
            }
            lblShotResult.BringToFront();
            shotResultLabels.Add(lblShotResult);
        }
Esempio n. 16
0
        private void SetTable(ShotResult sr, AttackType at)
        {
            float       count = 0f;
            float       mod;
            CombatTable table;

            if (at.HasFlag(AttackType.Yellow))
            {
                foreach (AbilWrapper abil in GetDamagingAbilities())
                {
                    if (!abil.ability.Validated)
                    {
                        continue;
                    }
                    table  = abil.ability.RWAtkTable;
                    mod    = GetTableFromSwingResult(sr, table);
                    count += abil.numActivates * abil.ability.AvgTargets * abil.ability.SwingsPerActivate * mod;
                }
            }
            if (at.HasFlag(AttackType.White))
            {
                table  = WhiteAtks.RWAtkTable;
                mod    = GetTableFromSwingResult(sr, table);
                count += WhiteAtks.RwActivates * mod;
            }

            _atkOverDurs[(int)sr, (int)at] = count;
        }
Esempio n. 17
0
        public void DisplayResult_GoodCoordinatesWithSink_CoordinatesAreDisplayed()
        {
            _cursorHelperMock.Setup(x => x.GetLeftForCoordinate(new Coordinate('G', "7")))
            .Returns(33);
            _cursorHelperMock.Setup(x => x.GetLeftForCoordinate(new Coordinate('G', "8")))
            .Returns(33);
            _cursorHelperMock.Setup(x => x.GetLeftForCoordinate(new Coordinate('G', "9")))
            .Returns(33);
            _cursorHelperMock.Setup(x => x.GetTopForCoordinate(new Coordinate('G', "7")))
            .Returns(19);
            _cursorHelperMock.Setup(x => x.GetTopForCoordinate(new Coordinate('G', "8")))
            .Returns(20);
            _cursorHelperMock.Setup(x => x.GetTopForCoordinate(new Coordinate('G', "9")))
            .Returns(21);
            _outputWriterMock.Setup(x => x.SetCursorPosition(33, 19));
            _outputWriterMock.Setup(x => x.SetCursorPosition(33, 20));
            _outputWriterMock.Setup(x => x.SetCursorPosition(33, 21));
            _outputWriterMock.Setup(x => x.Write("#"));
            var shotResult = new ShotResult
            {
                Coordinate = new Coordinate('G', "8"), Kind = ShotResult.Kinds.Sink,
                SinkShip   = new List <Coordinate> {
                    new Coordinate('G', "7"), new Coordinate('G', "8"), new Coordinate('G', "9")
                },
                Description = "Shit has been sink."
            };

            _sut.PaintResult(shotResult);
        }
Esempio n. 18
0
        public ShotResult ShootAtOpponent(Guid shooterPlayerId, GridCoordinate coordinate)
        {
            if (this.IsStarted == true)
            {
                IPlayer shooter = this.GetPlayerById(shooterPlayerId);
                IPlayer victim  = this.GetOpponent(shooter);

                if (shooter.HasBombsLoaded)
                {
                    ShotResult result = shooter.ShootAt(victim, coordinate);
                    if (victim is ComputerPlayer)
                    {
                        ((ComputerPlayer)victim).ShootAutomatically(shooter);
                    }
                    return(result);
                }
                else
                {
                    return(ShotResult.CreateMisfire("Player has no bombs loaded"));
                }
            }
            else
            {
                return(ShotResult.CreateMisfire("Game has not begun"));
            }
        }
Esempio n. 19
0
        public void ShootAtOpponent_ShouldUseServiceToRegisterTheShot()
        {
            //Arrange
            Guid gameId = Guid.NewGuid();
            GridCoordinateModel coordinateModel = new GridCoordinateModelBuilder().Build();

            ShotResult expectedShotResult = ShotResult.CreateMissed();

            _gameServiceMock.Setup(service =>
                                   service.ShootAtOpponent(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <GridCoordinate>()))
            .Returns(expectedShotResult);

            //Act
            var result = _controller.ShootAtOpponent(gameId, coordinateModel).Result as OkObjectResult;

            //Assert
            Assert.That(result, Is.Not.Null, "An instance of 'OkObjectResult' should be returned.");

            _userManagerMock.Verify(manager => manager.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once,
                                    "The 'GetUserAsync' of the UserManager is not called");
            _gameServiceMock.Verify(service =>
                                    service.ShootAtOpponent(gameId, _loggedInUser.Id,
                                                            It.Is <GridCoordinate>(
                                                                gc => gc.Row == coordinateModel.Row && gc.Column == coordinateModel.Column)),
                                    Times.Once, "The 'ShootAtOpponent' of the IGameService is not called correctly.");

            Assert.That(result.Value, Is.SameAs(expectedShotResult));
        }
Esempio n. 20
0
        public void MarkShooted(Grid grid, Point point, ShotResult result)
        {
            switch (result)
            {
            case ShotResult.MISS:
                Dispatcher.Invoke(() => {
                    addLabel(grid, point, 'o');
                });
                break;

            case ShotResult.HIT:
                Dispatcher.Invoke(() => {
                    addLabel(grid, point, 'x');
                });
                break;

            case ShotResult.SUNK:
                Dispatcher.Invoke(() => {
                    addLabel(grid, point, 'v');
                });
                break;

            default:
                throw new Exception("Incorrect shotResult");
            }
        }
Esempio n. 21
0
 void stopBallTrail(ShotResult _shot)
 {
     if (currentBallTrail != null)
     {
         Destroy(currentBallTrail);
     }
 }
        public void DisplayResult_WrongCoordinates_CoordinatesAreNotDisplayed()
        {
            _cursorHelperMock.Setup(x => x.TextResultTop)
            .Returns(22);
            _outputWriterMock.Setup(x => x.SetCursorPosition(0, 22));
            _outputWriterMock.Setup(x => x.SetCursorPosition(0, 23));
            _outputWriterMock.Setup(x => x.SetCursorPosition(2, 23));
            _outputWriterMock.Setup(x => x.Write(It.IsAny <string>()));
            var shotResult = new ShotResult {
                Coordinate = null, Description = "Wrong coordinates.", Kind = ShotResult.Kinds.Exception
            };

            _sut.DisplayResult(shotResult);

            _cursorHelperMock.Verify(x => x.GetLeftForCoordinate(It.IsAny <Coordinate>()), Times.Never);
            _cursorHelperMock.Verify(x => x.GetTopForCoordinate(It.IsAny <Coordinate>()), Times.Never);
            _cursorHelperMock.Verify(x => x.TextResultTop, Times.Exactly(3));
            _outputWriterMock.Verify(x => x.SetCursorPosition(It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(3));
            _outputWriterMock.Verify(x => x.SetCursorPosition(0, 22), Times.Once);
            _outputWriterMock.Verify(x => x.SetCursorPosition(0, 23), Times.Once);
            _outputWriterMock.Verify(x => x.SetCursorPosition(2, 23), Times.Once);
            _outputWriterMock.Verify(x => x.Write(It.IsAny <string>()), Times.Exactly(4));
            _outputWriterMock.Verify(x => x.Write(It.Is <string>(y => y.Contains("->"))), Times.Never);
            _outputWriterMock.Verify(x => x.Write(It.Is <string>(y => y.Contains("Wrong coordinates."))), Times.Once);
            _outputWriterMock.Verify(x => x.Write(It.Is <string>(y => y.Contains("End"))), Times.Never);
            _outputWriterMock.Verify(x => x.WriteNewLine(), Times.Never);
        }
        public void ShotResultHitNotSank()
        {
            var sr = new ShotResult(true, false);

            Assert.IsFalse(sr.WasSank);
            Assert.IsTrue(sr.WasHit);
        }
Esempio n. 24
0
    private void ComputeDuelGameStats(ShotResult result)
    {
        if (GameplayService.networked)
        {
            switch (gpService.GetGameMode())
            {
            case GameMode.Shooter:
                DuelGameLocalShooterShots++;     // nuevo tiro como Lanzador
                if (result.Result == Result.Goal)
                {
                    DuelGameLocalShooterGoals++;     // win
                }
                break;

            case GameMode.GoalKeeper:
                DuelGameLocalGoalkeeperShots++;     // nuevo tiro como Portero
                if ((result.Result == Result.Saved) ||
                    (result.Result == Result.Stopped))
                {
                    DuelGameLocalGoalkeeperStops++;     // win
                }
                break;
            }
        }
    }
Esempio n. 25
0
        public void ShotResult(ShotResult shotResult)
        {
            lodPotopena = shotResult.ShipSunken;

            if (shotResult.Hit == true)
            {
                zasahStrela = shotResult.Position;
                listZasah.Add(zasahStrela);

                listVysledek.Add(1);
            }
            if (shotResult.Hit == false)
            {
                listVysledek.Add(0);
            }

            if (lodPotopena == true)
            {
                zmenasmeru = false;

                listVysledek.Add(0);
                listVysledek.Add(0);
                listVysledek.Add(0);
                listVysledek.Add(0);
                listVysledek.Add(0);
                listVysledek.Add(0);

                listZasah.Clear();

                listPrepinac.Add(1);

                listZasah.Add(new Position(0, 0));
                listZasah.Add(new Position(0, 0));
            }
        }
Esempio n. 26
0
 void Destroy(ShotResult _info)
 {
     GetComponent <Renderer>().enabled = true;
     transform.Find("trail").GetComponent <Renderer>().enabled = true;
     ServiceLocator.Request <IShotResultService>().UnregisterListener(Destroy);
     Destroy(this);
 }
Esempio n. 27
0
        public ShotResult TakeShot(Point shot)
        {
            ShotResult result = ShotResult.Miss;

            if (!shotsTaken.Contains(shot))
            {
                shotsTaken.Add(shot);
                Ship shipHit = ships.Find(x => x.CoordOverlap(shot));

                if (shipHit != null)
                {
                    result = ShotResult.HitWithoutSink;
                    if (shipHit.IsSunk(shotsTaken))
                    {
                        result = ShotResult.HitAndSink;
                    }
                }
            }

            return(result);


            // check if shot hits ship
            // if ship is hit, check if ship sinks and/or all ships have sunk
            //-for each ship in ships, check if shotsTaken contains every point making up ship


            // will need to store data for the shot
        }
        public void ShotResultMiss()
        {
            var sr = new ShotResult(false, false);

            Assert.IsFalse(sr.WasSank);
            Assert.IsFalse(sr.WasHit);
        }
Esempio n. 29
0
    public void MakeResult(bool _saved)
    {
        int points = 0;

        if (ServiceLocator.Request <IGameplayService>().GetGameMode() == GameMode.GoalKeeper)
        {
            if (lastPerfect)
            {
                points = perfectPoints;
            }
            else
            {
                points = normalPoints;
            }
        }
        ShotResult result = new ShotResult()
        {
            Result            = _saved ? Result.Saved : Result.Stopped,
            Point             = BallPhysics.instance.transform.position,
            Rebounded         = !_saved,
            ScorePoints       = points,
            Perfect           = lastPerfect,
            EffectBonusPoints = 0,
            Precision         = lastPrecision,
            DefenseResult     = lastResult
        };

        ServiceLocator.Request <IShotResultService>().OnShotEnded(result);
    }
Esempio n. 30
0
        //        public Boolean SetShips(int shipNumber, int key, int value)
        public IActionResult ShotEnemyShip(int?id, int x, int y)
        {
            Game        game        = _context.Game.Find(id);
            List <Move> allMoves    = _context.Move.ToList();
            List <Move> playerMoves = allMoves.FindAll(a => a.playerMove && a.gameId == game.gameId);
            List <Move> enemyMoves  = allMoves.FindAll(a => a.playerMove == false && a.gameId == game.gameId);
            Boolean     result      = Collision.CheckShotCollision(x, y, playerMoves) && playerMoves.Count == enemyMoves.Count;

            if (result)
            {
                Move move = new Move();
                move.y          = y;
                move.x          = x;
                move.playerMove = true;
                game.moves.Add(move);
                _context.Game.Update(game);
                _context.SaveChanges();
            }

            List <Ship> enemyShips = _context.Ship.ToList().FindAll(s => s.playerShip == false && s.gameId == game.gameId &&
                                                                    s.x == x && s.y == y);
//            Boolean shipShooted = Collision.CheckEnemyShipShooted(x, y, enemyShips);
            Boolean shipShooted = enemyShips.Count == 1;

            ShotResult finalResult = new ShotResult();

            finalResult.success = result;
            finalResult.hit     = shipShooted;

            return(Json(finalResult));
        }
Esempio n. 31
0
 public ShootEvent(int minute, int extended, Player shooter, Player opponent, ShotResult result)
 {
     Minute = minute;
     Extended = extended;
     Shooter = shooter;
     Opponent = opponent;
     Result = result;
 }
Esempio n. 32
0
 public void UpdateWithFeedback(int x, int y, ShotResult result)
 {
     if (result == ShotResult.Hit)
         MarkCurrentShipAsHit(x, y);
     if (result == ShotResult.HitAndSunk)
         MarkCurrentShipAsSunk(x, y);
     if (result == ShotResult.Miss)
         boardState[x, y] = CellStates.Water;
 }
Esempio n. 33
0
 public void UpdateWithFeedback(int x, int y, ShotResult result)
 {
     if (result == ShotResult.Hit)
         MarkShipAsHit(x, y);
     if (result == ShotResult.HitAndSunk)
         MarkShipAsSunk(x, y);
     if (result == ShotResult.Miss)
         MarkKnown(x, y);
 }
Esempio n. 34
0
        protected override void AddShotResult(int x, int y, ShotResult result)
        {
            base.AddShotResult(x, y, result);
            if (result == ShotResult.ShipDrowned)
            {
                _currentTarget.Add(new Point(x, y));
                ShipDrowned();
                return;
            }

            if (result == ShotResult.ShipHit)
            {
                _currentTarget.Add(new Point(x, y));
            }
        }
        public void OnShoot(Player shooter, Player assistant, Player opponent, Player goalkeeper, ShotResult result)
        {
            if (result == ShotResult.Scored)
            {
                AdjustLinearly(shooter, 0.100, 0.020);
                AdjustExponentiallyRight(assistant, 0.030, 0.070);
                AdjustExponentiallyLeft(opponent, -0.020, 0.040);
                AdjustExponentiallyLeft(goalkeeper, -0.020, 0.060);

                foreach (var player in shooter.Team.Squad)
                {
                    AdjustLinearly(player, 0.025, 0.010);
                }

                foreach (var player in opponent.Team.Squad)
                {
                    AdjustLinearly(player, -0.025, 0.010);
                }
            }
            else if (result == ShotResult.Blocked)
            {
                AdjustLinearly(shooter, -0.005, 0.005);
                AdjustExponentiallyRight(opponent, 0.030, 0.030);
            }
            else if (result == ShotResult.Missed)
            {
                AdjustExponentiallyLeft(shooter, 0.010, 0.020);
                AdjustExponentially(opponent, -0.005, 0.010);
            }
            else if (result == ShotResult.Saved)
            {
                AdjustExponentially(shooter, 0.010, 0.030);
                AdjustExponentially(opponent, -0.005, 0.010);
                AdjustExponentiallyRight(goalkeeper, 0.040, 0.040);
            }
            else
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Shot result {0} not supported", result));
            }
        }
Esempio n. 36
0
        private IEnumerable<IShotResult> GetShotsForClub(IClub club, int targetDistance)
        {
            var clubShotList = new ShotResultList(10);

            var shotTypes = Enum.GetValues(typeof(ShotType)).Cast<ShotType>();
            foreach (var shotType in shotTypes)
            {
                var windAdjuster = this.windAdjusterFactory.GetWindAdjuster(shotType);

                var stepCount = club.GetStepCountForShotType(shotType);

                for (var i = 0; i < stepCount; i++)
                {
                    var methods = new Func<ShotType, int, int>[] {club.GetDistance, club.GetHalfDistance };

                    for (var index = 0; index < methods.Length; index++)
                    {
                        var method = methods[index];
                        var distance = method(shotType, i);

                        var step = index == 1 ? i + 0.5d : i;
                        if (distance > 0)
                        {
                            var windAdjustedDistance = windAdjuster.GetWindAdjustedDistance(distance);
                            var distanceToTarget = Math.Abs(windAdjustedDistance - targetDistance);
                            var result = new ShotResult()
                            {
                                ClubName = club.Name,
                                Step = step,
                                ShotType = shotType,
                                Distance = distance,
                                WindDistance = windAdjustedDistance,
                                DistanceToTarget = distanceToTarget,
                                IsWithinRange = distanceToTarget <= MaximumDistance
                            };
                            clubShotList.AddCandidateShot(result);
                        }
                    }
                }
            }

            return clubShotList.Shots;
        }
Esempio n. 37
0
 public Shot(Player playerTakingShot, GeoCoordinate location, ShotResult shotResult)
 {
     PlayerTakingShot = playerTakingShot;
     Location = location;
     ShotResult = shotResult;
 }
Esempio n. 38
0
 protected virtual void AddShotResult(int x, int y, ShotResult result)
 {
     PastShots[new Point(x, y)] = result;
 }
Esempio n. 39
0
        public void OnShoot(Player opponent, ShotResult result)
        {
            events.Add(new ShootEvent(Minute, ExtendedMinute, CurrentPlayer, opponent, result));

            if (result == ShotResult.Scored)
            {
                IncreaseScore(CurrentPlayer.Team);
                events.Add(new GoalEvent(CurrentPlayer.Team == Team1, Minute, ExtendedMinute, CurrentPlayer, PreviousPlayer));
            }

            PreviousPlayer = CurrentPlayer;
            CurrentPlayer = null;
        }