Esempio n. 1
0
        public void Update(LevelImp level, float elapsed)
        {
            if (!IsAlive)
            {
                return;
            }

            if (_punishedType != PunishedType.None)
            {
                _punishedTime += elapsed;
                if (_punishedTime >= PunishedDuration)
                {
                    _punishedType = PunishedType.None;
                }
            }

            FigureController?.Update(elapsed);

            Move(level, elapsed);
            HandleItemCollection(level);
            HandleHitByFire(level);
            HandlePlaceBomb(level);

            FigureController?.Reset();
        }
Esempio n. 2
0
        public async Task ShouldStorePassedFigure()
        {
            const long figureId = 42;

            var repository = Substitute.For <IFigureRepository>();

            repository.StoreAsync(Arg.Any <IFigure>()).Returns(Task.FromResult(figureId));

            var controller = new FigureController(repository);

            var result = await controller.StoreFigureAsync(new TriangleDto
            {
                A = 3,
                B = 4,
                C = 5
            }).ConfigureAwait(false);

            result.ShouldNotBeNull();
            result.Id.ShouldBe(figureId);

            await repository.Received(1).StoreAsync(Arg.Is <Triangle>(t =>
                                                                      Math.Abs(t.A - 3) < Precision && Math.Abs(t.B - 4) < Precision &&
                                                                      Math.Abs(t.C - 5) < Precision))
            .ConfigureAwait(false);
        }
Esempio n. 3
0
    bool IsCanPlaceFigure(int x, int y, FigureController figureController)
    {
        Quaternion rotation = figureController.transform.localRotation;

        Vector2 minPosition = new Vector2(float.MaxValue, float.MaxValue);

        foreach (Brick brick in figureController.bricks)
        {
            Vector2 localPosition = rotation * brick.GetComponent <RectTransform>().anchoredPosition;

            minPosition.x = Mathf.Min(minPosition.x, localPosition.x);
            minPosition.y = Mathf.Min(minPosition.y, localPosition.y);
        }

        foreach (Brick brick in figureController.bricks)
        {
            RectTransform rectTransform = brick.GetComponent <RectTransform>();

            Vector2 position = rotation * rectTransform.anchoredPosition;
            position -= minPosition;

            Vector2Int coords = Vector2Int.RoundToInt(position / rectTransform.rect.size);
            coords.x += x;
            coords.y += y;

            if (coords.x < 0 || coords.y < 0 || coords.x >= bricksCount.x || coords.y >= bricksCount.y ||
                field[coords.x, coords.y] != null)
            {
                return(false);
            }
        }

        return(true);
    }
Esempio n. 4
0
        static double CalcTriangle(double[] sides)
        {
            FigureController controller = new FigureController();

            controller.CreateTriangle(sides);
            return(controller.Figure.CalcArea());
        }
Esempio n. 5
0
        static double CalcCircle(double r)
        {
            FigureController controller = new FigureController();

            controller.CreateCircle(r);
            return(controller.Figure.CalcArea());
        }
Esempio n. 6
0
    void CreateNewFigure()
    {
        int index = Random.Range(0, Figures.Length);
        FigureController figure = Instantiate(Figures[index]);

        figure.SetFigure(new Vector2(X_field, 0), gameModel.CubeColor[index]);
        fieldController.AddNewFigure(figure);
    }
 /// <summary>
 /// Invoked after cess piece was placed on board
 /// </summary>
 /// <param name="controller">Chess pieces controller</param>
 /// <param name="startPosition">Position of piece</param>
 /// <param name="figureRange">Range of attack</param>
 private void OnFigureOnBoard(FigureController controller, Vector3 startPosition, int figureRange)
 {
     if (figures.Contains(controller))
     {
         OnFigureOnBoardAction(controller, figureRange);
         SpawnNewFigure(controller, startPosition);
     }
 }
Esempio n. 8
0
    /// <summary>
    /// Invoked after chess piece was placed on board
    /// </summary>
    /// <param name="figure">Chess piece controller</param>
    /// <param name="figureRange">Chess piece range</param>
    public void OnFigureEnteredOnBoard(FigureController figure, int figureRange)
    {
        BoardPointController        figurePoint = boardPointControllers.Find(x => x.GetTransform().position == figure.transform.position);
        List <BoardPointController> pointsInRange;
        List <BoardPointController> pointsInRangeInPath;

        (pointsInRange, pointsInRangeInPath) = GetPointsInRange(figure.transform.position, figureRange);
        figure.SetPointsForShoting(pointsInRange, pointsInRangeInPath);
    }
        public async Task CreateFigureAsyncWithInvalidData_ShouldThrowException(FigureRequest request, Type expectedException)
        {
            //arrange
            var figureRepository = new FigureRepository(null);
            var figureService    = new FigureService(figureRepository);
            var controller       = new FigureController(figureService);

            //act & assert
            var exception = await Assert.ThrowsAsync(expectedException, async() => await controller.CreateFigureAsync(request));
        }
Esempio n. 10
0
        public async Task Get__ShouldCalculateTriangleArea__Returns15_0()
        {
            var controller = new FigureController(_mediatorMock.Object);

            var expected = 15.0;
            var actual   = await controller.Get(3);

            Assert.Equal(expected, actual);
            _mediatorMock.Verify(x => x.Send(It.IsAny <GetFigureAreaByIdQuery>(), CancellationToken.None), Times.Once);
        }
Esempio n. 11
0
        protected FigureControllerTestsAbstract()
        {
            var figureRecord  = GetQueryableMockDbSet(_records, x => x.Id = _currentId);
            var dbContextMock = new Mock <IDatabaseContext>();

            dbContextMock.SetupGet(x => x.Figures).Returns(figureRecord);

            var figureRepository = new FigureRepository(dbContextMock.Object);
            var figureService    = new FigureService(figureRepository);

            _controller = new FigureController(figureService);
        }
Esempio n. 12
0
        public virtual void ExecuteMovement()
        {
            Figure.setPosition(Destination);
            FigureController fc = GameObject.FindGameObjectsWithTag("Figure")
                                  .Select(f => f.GetComponent <FigureController>())
                                  .Where(c => c.Figure.Equals(Figure))
                                  .FirstOrDefault();

            fc.SetTargetPosition(Destination);
            Board.isCheck();
            Figure.PossibleMoves.Clear();
        }
Esempio n. 13
0
 public void AddNewFigure(FigureController figure)
 {
     currentFigure = figure;
     if (IsGameOver())
     {
         GameOver?.Invoke();
     }
     else
     {
         State.State = FigureStates.Moving;
     }
 }
Esempio n. 14
0
 public bool CanMove(FigureController figure, int x, int y)
 {
     if (x + figure.Form.GetLength(1) > Width || x < 0)
     {
         return(false);
     }
     if (y + figure.Form.GetLength(0) > Height || y < 0)
     {
         return(false);
     }
     return(true);
 }
Esempio n. 15
0
        public override void ExecuteMovement()
        {
            rook.setPosition(rookDestination);
            FigureController fc = GameObject.FindGameObjectsWithTag("Figure")
                                  .Select(f => f.GetComponent <FigureController>())
                                  .Where(c => c.Figure.Equals(Rook))
                                  .FirstOrDefault();

            fc.SetTargetPosition(RookDestination);

            Figure.PossibleMoves.Clear();
            base.ExecuteMovement();
        }
Esempio n. 16
0
 public void ReSpawn()
 {
     IsAlive                  = true;
     Speed                    = BaseSpeed;
     BombExplosionRange       = 1;
     PlacableBombCount        = 1;
     CurrentPlacableBombCount = PlacableBombCount;
     WalkDirection            = Vector2.Zero;
     Direction                = FigureDirection.Down;
     CollectedItems.Clear();
     ActiveBombType = BombType.Normal;
     FigureController?.ResetInputs();
 }
Esempio n. 17
0
        public async Task ShouldReturnFiguresArea()
        {
            var repository = Substitute.For <IFigureRepository>();

            repository.GetByIdAsync <IFigure>(Arg.Any <long>()).Returns(new Triangle(3, 4, 5));

            var controller = new FigureController(repository);

            var result = await controller.GetFigureAreaAsync(42).ConfigureAwait(false);

            result.ShouldNotBeNull();
            Math.Abs(result.Area - 6).ShouldBeLessThan(Precision);
        }
    /// <summary>
    /// Moves chess piece to given tile
    /// </summary>
    /// <param name="endPosition">End of moving position</param>
    /// <param name="point">Tile on map</param>
    /// <param name="onSuccesFigureMoving">Callback to succesful figure movement</param>
    public void OnPointOnBoardClicked(Vector3 endPosition, BoardPointController point, Action <BoardPointController> onSuccesFigureMoving)
    {
        if (figureToPlace != null)
        {
            if (figureToPlace.CanMoveFigure() && pointValuesController.RemovePoints(figureToPlace.FigureCost))
            {
                figureToPlace.StartMoveFigure(endPosition, OnFigureOnBoard, curve);
                onSuccesFigureMoving(point);
            }

            figureToPlace = null;
        }
    }
    /// <summary>
    /// Spawns new figure on scene
    /// </summary>
    /// <param name="controller">Chess piece controller</param>
    /// <param name="startPosition">Piece starting position</param>
    private void SpawnNewFigure(FigureController controller, Vector3 startPosition)
    {
        Material standardMaterial = Resources.Load <Material>("Light");

        controller.GetComponent <MeshRenderer>().sharedMaterial = standardMaterial;

        string     prefabName = figuresNames.Find(x => controller.name.Contains(x));
        GameObject newFigure  = Instantiate(Resources.Load <GameObject>(prefabName));

        newFigure.name = prefabName + figures.Count.ToString();
        newFigure.transform.position = startPosition;
        newFigure.transform.SetParent(this.gameObject.transform);

        figures.Add(newFigure.GetComponent <FigureController>());
    }
Esempio n. 20
0
 public void Destroy(FigureController figure, int x, int y)
 {
     for (var j = 0; j < figure.Form.GetLength(0); j++)
     {
         for (var i = 0; i < figure.Form.GetLength(1); i++)
         {
             if (figure.Form[j, i])
             {
                 Instantiate(Block, Transform(new Vector3(SpawnX + x + i, SpawnY - y - j, 0)), Quaternion.identity);
             }
         }
     }
     figure.gameObject.active = false;
     CreateFigure();
 }
Esempio n. 21
0
    private List <FigureController> SpawnFigures(GameObject figurePrefab, int figureNumber, float speed, IHideInputWrapper hideInputWrapper)
    {
        List <FigureController> figures = new List <FigureController>();

        for (int i = 0; i < figureNumber; i++)
        {
            GameObject       spawnedFigureObject = Instantiate(figurePrefab);
            FigureController figureController    = spawnedFigureObject.GetComponent <FigureController>();
            figures.Add(figureController);
            figureController.Initialize(speed, hideInputWrapper);
            spawnedFigureObject.transform.position = GetRandomPositionWithinConstraints();
        }

        return(figures);
    }
Esempio n. 22
0
        public async Task Post__ShouldCreateFigure__Returns3()
        {
            var controller = new FigureController(_mediatorMock.Object);
            var shape      = new Triangle()
            {
                Height = 5.0,
                Base   = 6.0
            };

            var expected = 3;
            var actual   = await controller.Post(shape);

            Assert.Equal(expected, actual);
            _mediatorMock.Verify(x => x.Send(It.IsAny <CreateFigureCommand>(), CancellationToken.None), Times.Once);
        }
Esempio n. 23
0
        void LateUpdate()
        {
            if (clickEventControllerState == ClickEventControllerStates.None)
            {
                return;
            }

            if (Input.GetButtonDown("Fire1"))
            {
                if (IsPointerOverUIElement())
                {
                    return;
                }

                clickDownPosition = GetMousePos();

                clickFigure = CheckRayCast(GetMousePos(), Vector3.forward);
                clickFigure?.SetRotate(true);
                clickEventControllerState = ClickEventControllerStates.WaitUnpress;
            }


            if (Input.GetButtonUp("Fire1"))
            {
                if (clickFigure != null)
                {
                    clickFigure.SetRotate(false);
                }

                if (clickEventControllerState == ClickEventControllerStates.WaitUnpress)
                {
                    var clickUpPosition = GetMousePos();

                    if (Vector3.Distance(clickDownPosition, clickUpPosition) < 0.001f)
                    {
                        PointCut(clickDownPosition);
                    }
                    else
                    {
                        //Закоментил. тк для косой разрезающей не до конца реализован алгоритм.
                        //SlideCut(clickDownPosition, clickUpPosition);
                    }
                }

                clickEventControllerState = ClickEventControllerStates.CatchClicks;
            }
        }
        public ClientInputMessageBase(double timeStamp, byte clientId, FigureController controller)
            : base(timeStamp, clientId)
        {
            if (controller.ActionDone && controller.DirectionChanged)
            {
                Action = InputAction.MoveDirectonChangedAndAction;
            }
            else if (controller.ActionDone)
            {
                Action = InputAction.Action;
            }
            else
            {
                Action = InputAction.MoveDirectionChanged;
            }

            MoveDirection = controller.MoveDirection;
        }
    /// <summary>
    /// Invoked after clicking o chess piece detection, highlights clicked piece
    /// </summary>
    /// <param name="objectName">Clicked object</param>
    public void OnClickDetected(string objectName)
    {
        Material standardMaterial = Resources.Load <Material>("Light");

        figures.ForEach((x) =>
        {
            if (!x.IsMoving)
            {
                x.GetComponent <MeshRenderer>().sharedMaterial = standardMaterial;
            }
            ;
        });

        if (figures.Exists(x => x.name == objectName) && !figures.Exists(x => x.IsMoving))
        {
            figureToPlace = figures.Find(x => x.name == objectName);
            figureToPlace.GetComponent <MeshRenderer>().sharedMaterial = Resources.Load <Material>("HightlightLight");
        }
    }
Esempio n. 26
0
    void SpawnFigure(FigureController figureController, int figureIndex, float rotation)
    {
        figureController.transform.localRotation = Quaternion.identity;

        int colorIndex = Random.Range(0, 6);

        int[,] figure = Figures1010.Figures[figureIndex];
        for (int i = 0; i < figure.GetLength(0); i++)
        {
            for (int j = 0; j < figure.GetLength(1); j++)
            {
                if (figure[figure.GetLength(0) - i - 1, j] == 0)
                {
                    continue;
                }

                NumberedBrick brick = Instantiate(brickPrefab, figureController.transform);
                figureController.bricks.Add(brick);

                RectTransform brickRectTransform = brick.GetComponent <RectTransform>();

                brickRectTransform.anchorMin = new Vector2(0.5f, 0.5f);
                brickRectTransform.anchorMax = new Vector2(0.5f, 0.5f);

                Rect    rect      = figureController.GetComponent <RectTransform>().rect;
                Vector2 brickSize = new Vector2
                {
                    x = rect.width / 4,
                    y = rect.height / 4
                };

                Vector2 coords        = new Vector2(j - figure.GetLength(1) / 2f, i - figure.GetLength(0) / 2f);
                Vector2 brickPosition = Vector2.Scale(coords, brickSize);
                brickPosition += Vector2.Scale(brickSize, brickRectTransform.pivot);
                brick.GetComponent <RectTransform>().anchoredPosition = brickPosition;

                brick.ColorIndex = colorIndex;
            }
        }

        figureController.transform.localRotation = Quaternion.Euler(0f, 0f, rotation);
    }
Esempio n. 27
0
        public void SetUp()
        {
            var boardModel = Substitute.For <IBoardModel>();

            GameModel = Substitute.For <IGameModel>();
            var figureModel = Substitute.For <IFigureModel>();
            var figurePostTurnLogicManager = Substitute.For <IFigurePostTurnLogicManager>();
            var gameMoveTurnManager        = Substitute.For <IGameMoveTurnManager>();

            var figureController = new FigureController(figureModel);

            GameMaster = new GameMaster(figureController, boardModel, GameModel, figurePostTurnLogicManager,
                                        gameMoveTurnManager);

            _figure = new FigureEntity(Substitute.For <IFigureDef>(), GameTeam.White);
            _cell   = new BoardCell(BoardCellCol.ColA, BoardCellRow.Row1, 0, 0)
            {
                Figure = _figure
            };
            _moveToCell = new BoardCell(BoardCellCol.ColA, BoardCellRow.Row2, 0, 0)
            {
                Status = BoardCellStatus.AvailableForMove
            };
        }
Esempio n. 28
0
 void Awake()
 {
     figure = GetComponent<Motion>().figure;
 }
Esempio n. 29
0
 public GameSessionClient(Game2D game, NetClient client, byte clientId)
 {
     _clientId         = clientId;
     _netClient        = client;
     _figureController = PlayerController.CreateNet(game, InputDeviceType.Keyboard);
 }
Esempio n. 30
0
    //public void CheckTransitionTo3D()
    //{
    //    for (int i = 0; i < players.Count; i++)
    //    {
    //        players[i].Initialize3D();
    //    }
    //    axis = Vector3.zero;
    //    axisRight = Vector3.zero;
    //    axisLeft = Vector3.zero;
    //    axisBack = Vector3.zero;
    //}

    public void CreateFigure(ControllerManager _player)
    {
        Vector3 figurePostion = _player.transform.position;        //players[0].transform.position;//Camera.main.transform.position + (Camera.main.transform.forward * Camera.main.GetComponent<CameraController> ().distance2D);

        currentFigure = Instantiate(figure, figurePostion, /*Quaternion.LookRotation(players[0].transform.forward)*//*players[0].transform.rotation*/ _player.transform.rotation).GetComponent <FigureController>();
    }
Esempio n. 31
0
 // Update is called once per frame
 void Update()
 {
     figureC = GameObject.FindGameObjectsWithTag("Figure")
               .Select(f => f.GetComponent <FigureController>())
               .FirstOrDefault(f => f.GetPosition() == "H7");
 }