Ejemplo n.º 1
0
 protected virtual void OnEnable()
 {
     if (_boardController == null)
     {
         _boardController = GetComponent <IBoardController>();
     }
 }
Ejemplo n.º 2
0
 public FreestyleAC()
 {
     cubeController = new TestCubeController();
     board          = (IBoardController)GameObject.FindGameObjectWithTag("Board").GetComponentInChildren(typeof(IBoardController));
     board.DisplayMessage("DoIt!", new Color(0, 1, 0));
     moves = new List <Move>();
 }
Ejemplo n.º 3
0
        public void Draw_WhenNoPlayerWonAndAllPiecesTouched()
        {
            int              boardSize           = 3;
            IGameController  objectiveController = NSubstitute.Substitute.For <IGameController>();
            IBoardController boardController     = NSubstitute.Substitute.For <IBoardController>();

            /*
             * Board board = new Board(boardSize, objectiveController, boardController);
             * Icon player1Icon = new Icon();
             * Icon player2Icon = new Icon();
             *
             * board.GetPieceOnRowAndColumn(0, 0).PaintWithIcon(player1Icon);
             * board.GetPieceOnRowAndColumn(0, 1).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(0, 2).PaintWithIcon(player2Icon);
             *
             * board.GetPieceOnRowAndColumn(1, 0).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(1, 1).PaintWithIcon(player1Icon);
             * board.GetPieceOnRowAndColumn(1, 2).PaintWithIcon(player1Icon);
             *
             * board.GetPieceOnRowAndColumn(2, 0).PaintWithIcon(player1Icon);
             * board.GetPieceOnRowAndColumn(2, 1).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(2, 2).PaintWithIcon(player2Icon);
             *
             * Piece currentPieceTouched = board.GetPieceOnRowAndColumn(2, 2);
             * // check if no player has won yet.
             * Assert.AreEqual(currentPieceTouched.CheckPieceMatch(), false);
             * // check if amount of eaces untouched by players has achieved the maximum (all pieces were touched)
             * //Assert.LessOrEqual(board.AmountPiecesUntouched, 0);
             */
        }
        protected virtual void OnEnable()
        {
            if (_boardController == null)
            {
                _boardController = GetComponent <IBoardController>();
            }

            if (_boardFactory == null)
            {
                _boardFactory = GetComponent <IBoardFactory>();
            }

            (_boardModel, _boardView) = _boardFactory.GetBoard(_blockPrefab, _blocks, _blockScale, _swapBoardTransform, Utils.TetrominoUtils.MaxNumLinesPreview, Utils.TetrominoUtils.MaxNumColumnsPreview);

            // Draw Board
            for (int line = 0; line < _boardModel.NumLines; line++)
            {
                for (int column = 0; column < _boardModel.NumColumns; column++)
                {
                    _boardModel.Blocks[line, column] = TetrominoUtils.NoPiece;
                }
            }

            _boardView.UpdateView(_boardModel, _blocks);
        }
Ejemplo n.º 5
0
        public BoardControl(IBoardController boardController)
        {
            InitializeComponent();

            this.boardController = boardController;
            this.Controls.AddRange(GetSquares().ToArray());
        }
Ejemplo n.º 6
0
    // Use this for initialization
    void Start()
    {
        timer = GameObject.FindGameObjectWithTag("Timer");
        timer.SetActive(false);

        game = new GameController();

        board = (IBoardController)GameObject.FindGameObjectWithTag("Board").GetComponentInChildren(typeof(IBoardController));
        board.DisplayMessage("HELLO", new Color(1, 1, 0));
        //board.UpdateDescription("Hello", new Color(1, 1, 0));
        //board.AnimateDescription(true);

        studyingButton  = GameObject.FindGameObjectWithTag("StudyingButton");
        freestyleButton = GameObject.FindGameObjectWithTag("FreestyleButton");
        exitButton      = GameObject.FindGameObjectWithTag("ExitButton");
        keyboardButtons = GameObject.FindGameObjectWithTag("Keyboard");

        keyboard = (Keyboard)keyboardButtons.GetComponent(typeof(Keyboard));

        studyingButton.SetActive(true);
        freestyleButton.SetActive(true);
        exitButton.SetActive(false);
        keyboardButtons.SetActive(false);

        scoreboard = (scoreboard)GameObject.FindGameObjectWithTag("Scoreboard").GetComponentInChildren(typeof(scoreboard));

        currentState = GAME_STATE.START_STATE;

        finished = false;
    }
Ejemplo n.º 7
0
        public void InitializeTests()
        {
            this.Board         = new Game.Data.Contract.Board();
            this.RowController = new RowController();
            this.Recognizer    = new PatternRecognizer(this.Board, this.RowController);
            this.Analyzer      = new BoardAnalyzer(this.Board);
            this.Controller    = new BoardController(this.Board, this.Analyzer, this.Recognizer);
            this.Controller.Initialize();
            this.Player = new Player("Nerzal")
            {
                Color = Colors.White
            };
            this.Player2 = new Player("Wr4thon")
            {
                Color = Colors.Black
            };

            IMovementRules movementRules = new MovementRules(this.Analyzer, this.Board);
            IGameOverRules gameOverRules = new GameOverRules(this.Analyzer);
            IRuleSet       ruleSet       = new RuleSet(movementRules, gameOverRules);
            IHistory       history       = new History();

            this.MillRuleEvaluator = new Evaluator(ruleSet, this.Analyzer);
            IRowController     rowController     = new RowController();
            IPatternRecognizer patternRecognizer = new PatternRecognizer(this.Board, rowController);

            this.GameController = new GameController(this.MillRuleEvaluator, this.Board, history, this.Controller, patternRecognizer, rowController);
        }
Ejemplo n.º 8
0
 public LearningAC()
 {
     cubeAlgorithm  = new TestCubeAlgorithm();
     board          = (IBoardController)GameObject.FindGameObjectWithTag("Board").GetComponentInChildren(typeof(IBoardController));
     cubeController = new TestCubeController();
     UpdateData();
     board.ActivateAnimation(true);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="ruleEvaluator"></param>
 /// <param name="board"></param>
 /// <param name="history"></param>
 /// <param name="boardController"></param>
 /// <param name="recognizer"></param>
 /// <param name="rowController"></param>
 public GameController(IMillRuleEvaluator ruleEvaluator, IBoard board, IHistory history, IBoardController boardController, IPatternRecognizer recognizer, IRowController rowController)
 {
     this._ruleEvaluator   = ruleEvaluator;
     this._board           = board;
     this._history         = history;
     this._boardController = boardController;
     this._recognizer      = recognizer;
     this._rowController   = rowController;
 }
Ejemplo n.º 10
0
        public void Constructor_GivenNullBoardController_ShouldThrowError()
        {
            IBoardController    boardController    = null;
            ISequenceController sequenceController = new Mock <ISequenceController>().Object;
            IResultReporter     resultReporter     = new Mock <IResultReporter>().Object;

            var exception = Record.Exception(() => new TurtleGame(boardController, sequenceController, resultReporter));

            Assert.IsType <ArgumentNullException>(exception);
        }
Ejemplo n.º 11
0
        public void BoardGenerationWorks_WhenItIsInitiated()
        {
            int              boardSize           = 3;
            IGameController  objectiveController = NSubstitute.Substitute.For <IGameController>();
            IBoardController boardController     = NSubstitute.Substitute.For <IBoardController>();
            //TODO: use zenject to test
            //Board board = new Board(boardSize, objectiveController, boardController);

            //Assert.AreNotEqual(board.GetPieceOnRowAndColumn(1, 1), null);
        }
Ejemplo n.º 12
0
        public void PiecesWithCorrectBehavior_AfterInitialized()
        {
            int              boardSize           = 3;
            IGameController  objectiveController = NSubstitute.Substitute.For <IGameController>();
            IBoardController boardController     = NSubstitute.Substitute.For <IBoardController>();
            //Board board = new Board(boardSize, objectiveController, boardController);

            //Assert.AreEqual(board.GetPieceOnRowAndColumn(0, 1).Behaviors.Count, 1);
            //Assert.AreEqual(board.GetPieceOnRowAndColumn(1, 2).Behaviors.Count, 1);
            //Assert.AreEqual(board.GetPieceOnRowAndColumn(2, 0).Behaviors.Count, 2);
            //Assert.AreEqual(board.GetPieceOnRowAndColumn(1, 1).Behaviors.Count, 3);
        }
Ejemplo n.º 13
0
        public PromoteControl(int id, IBoardController boardController, bool isBlackToMove)
        {
            InitializeComponent();

            this.Id = id;
            this.boardController = boardController;
            IsBlackToMove        = isBlackToMove;
            AddPromoteButtons();

            this.DoubleBuffered = true;
            this.BackColor      = Color.Transparent;
        }
Ejemplo n.º 14
0
        public void ExecuteMoves_GivenBoardControllerAndMoves_ShouldMoveTurtle()
        {
            int sequenceId = 0;
            var moves      = new char[] { 'm', 'r', 'm' };

            Mock <IBoardController> mockBoardController = new Mock <IBoardController>();
            IBoardController        boardController     = mockBoardController.Object;

            var sut = new Sequence(sequenceId, moves);

            sut.ExecuteMoves(boardController);

            mockBoardController.Verify(m => m.MoveTurtle(), Times.Exactly(2));
            mockBoardController.Verify(m => m.RotateTurtle(), Times.Once);
        }
Ejemplo n.º 15
0
        public SquareControl(int id, IBoardController boardController)
        {
            InitializeComponent();

            this.Id = id;
            this.boardController = boardController;
            this.boardController.Register(this);

            SetBackColor();

            btnImage.Size = new Size(SquareWidth, SquareWidth);

            CreatePromoteControl();

            SetImage();
        }
    void CreateBoard(GameObject[,] slotContent)
    {
        BoardModelFactory modelFactory = new BoardModelFactory();

        boardModel = modelFactory.Create(new SlotModelFactory(), rows, columns);

        BoardViewFactory viewFactory = new BoardViewFactory();

        boardView = viewFactory.Create(new SlotViewFactory(), rows, columns, transform);

        BoardControllerFactory controllerFactory = new BoardControllerFactory();

        boardController = controllerFactory.Create(new SlotControllerFactory(), boardModel, boardView);

        boardModel.SetSlotsContent(slotContent);
    }
Ejemplo n.º 17
0
        public void ExecuteMoves_WhenMoveOutOfBoard_ReturnOutOfBoard()
        {
            int sequenceId  = 0;
            var moves       = new char[] { 'm' };
            var movesResult = MovesResultPossibilities.OutOfBoard;

            Mock <IBoardController> mockBoardController = new Mock <IBoardController>();

            mockBoardController.Setup(m => m.MoveTurtle()).Returns(movesResult);
            IBoardController boardController = mockBoardController.Object;

            var sut    = new Sequence(sequenceId, moves);
            var result = sut.ExecuteMoves(boardController);

            Assert.Equal(movesResult, result.Result);
        }
Ejemplo n.º 18
0
        protected virtual void OnEnable()
        {
            if (_levelController == null)
            {
                // Initializes level controller
                _levelController = GetComponent <ILevelController>();
                _levelController.AddClearedLines(0);
            }

            if (_boardController == null)
            {
                _boardController = GetComponent <IBoardController>();
                _boardController.Initialize();
            }

            _holdInputMaxTime = _levelController.GravityInterval / _boardController.BoardModel.NumColumns;
        }
Ejemplo n.º 19
0
        public ChessFrm()
        {
            InitializeComponent();

            this.loadFen.Hide();
            this.Size = new Size(this.Size.Width, FormHeight);

            this.boardController = new BoardController();
            this.boardController.Register(this);

            this.boardControl             = new BoardControl(this.boardController);
            this.boardControl.BackColor   = Color.SaddleBrown;
            this.boardControl.Size        = new Size(BoardWidth, BoardWidth);
            this.boardControl.Margin      = new Padding(0);
            this.boardControl.Location    = new Point(0, 33);
            this.boardControl.BorderStyle = BorderStyle.FixedSingle;

            this.BackColor = Color.Wheat;

            lblResult.Text     = string.Empty;
            lblResult.Font     = new Font(FontFamily.Families[0], 16, FontStyle.Regular);
            lblResult.Location = new Point(570, 43);
            lblResult.Size     = new Size(200, 23);

            lblCount.Text     = string.Empty;
            lblCount.Font     = new Font(FontFamily.Families[0], 16, FontStyle.Regular);
            lblCount.Location = new Point(570, 76);
            lblCount.Size     = new Size(200, 23);

            //MessageBox.Show($"X: {this.boardControl.Location.X} Y: {this.boardControl.Location.Y} W: {this.boardControl.Size.Width} H: {this.boardControl.Size.Height}");

            this.Controls.Add(this.boardControl);
            this.Controls.Add(lblResult);
            this.Controls.Add(lblCount);

            this.btnLoadFen.Image      = Fen();
            this.btnLoadPgn.Image      = Pgn();
            this.btnFirstMove.Image    = FirstMove(23, 22);
            this.btnPreviousMove.Image = PreviousMove(23, 22);
            this.btnNextMove.Image     = NextMove(23, 22);
            this.btnLastMove.Image     = LastMove(23, 22);
            this.btnReverseBoard.Image = TurnBoard();
            this.btnResign.Image       = ResignFlag();
            this.btnDraw.Image         = Draw50();
            UpdateView();
        }
Ejemplo n.º 20
0
 public void InitializeTests()
 {
     this.Board         = new Game.Data.Contract.Board();
     this.Analyzer      = new BoardAnalyzer(this.Board);
     this.RowController = new RowController();
     this.Recognizer    = new PatternRecognizer(this.Board, this.RowController);
     this.Recognizer.Initialize();
     this.Controller = new BoardController(this.Board, this.Analyzer, this.Recognizer);
     this.Controller.Initialize();
     this.Player = new Player("Nerzal")
     {
         Color = Colors.White
     };
     this.Player2 = new Player("Wr4th0n")
     {
         Color = Colors.Black
     };
 }
Ejemplo n.º 21
0
        public void ExecuteMoves_GivenBoardControllerAndMoves_ReturnResult()
        {
            int sequenceId  = 0;
            var moves       = new char[] { 'm', 'r', 'm' };
            var movesResult = MovesResultPossibilities.Success;

            Mock <IBoardController> mockBoardController = new Mock <IBoardController>();

            mockBoardController.Setup(m => m.GetResult()).Returns(movesResult);
            mockBoardController.Setup(m => m.MoveTurtle()).Returns(movesResult);
            IBoardController boardController = mockBoardController.Object;

            var sut    = new Sequence(sequenceId, moves);
            var result = sut.ExecuteMoves(boardController);

            Assert.Equal(movesResult, result.Result);
            Assert.Equal(sequenceId, result.SequenceId);
        }
Ejemplo n.º 22
0
        public void SetUp()
        {
            _fixture = Utils.GetFixture();
            _service = A.Fake <IBoardService>();
            _mapper  = A.Fake <IMapper>();

            _resourceManager = A.Fake <ResourceManager>();

            A.CallTo(() => _resourceManager.GetString(MSG_BOARDSAVED)).Returns(MSG_BOARDSAVED);
            A.CallTo(() => _resourceManager.GetString(MSG_BOARDRESUMED)).Returns(MSG_BOARDRESUMED);
            A.CallTo(() => _resourceManager.GetString(MSG_BOARDINITIALIZED)).Returns(MSG_BOARDINITIALIZED);
            A.CallTo(() => _resourceManager.GetString(MSG_INVALIDBOARD)).Returns(MSG_INVALIDBOARD);
            A.CallTo(() => _resourceManager.GetString(MSG_INVALIDBOARDFORCURRENTUSER)).Returns(MSG_INVALIDBOARDFORCURRENTUSER);
            A.CallTo(() => _resourceManager.GetString(MSG_INVALIDUSERNAME)).Returns(MSG_INVALIDUSERNAME);
            A.CallTo(() => _resourceManager.GetString(MSG_DEFAULTERRORMESSAGE)).Returns(MSG_DEFAULTERRORMESSAGE);
            A.CallTo(() => _resourceManager.GetString(MSG_INVALIDCELL)).Returns(MSG_INVALIDCELL);

            _servicesResourceManager = new ServicesResourceManager(_resourceManager);
            _controller = new BoardController(_service, _servicesResourceManager, _mapper);
        }
Ejemplo n.º 23
0
        public void Win_WhenMainDiagonalMatch()
        {
            int              boardSize           = 3;
            IGameController  objectiveController = NSubstitute.Substitute.For <IGameController>();
            IBoardController boardController     = NSubstitute.Substitute.For <IBoardController>();

            /*
             * Board board = new Board(boardSize, objectiveController, boardController);
             * Piece currentPieceTouched = board.GetPieceOnRowAndColumn(0, 0);
             * Assert.AreEqual(currentPieceTouched.Behaviors[1].ToString(), "TicTacToe.MainDiagonalPieceBehavior");
             * Icon player1Icon = new Icon();
             * Icon player2Icon = new Icon();
             *
             * // main diagonal with same Icon
             * board.GetPieceOnRowAndColumn(0, 0).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(1, 1).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(2, 2).PaintWithIcon(player2Icon);
             *
             * Assert.AreEqual(currentPieceTouched.CheckPieceMatch(), true);
             *
             * // main diagonal with one different element
             * board.GetPieceOnRowAndColumn(0, 0).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(1, 1).PaintWithIcon(player1Icon);
             * board.GetPieceOnRowAndColumn(2, 2).PaintWithIcon(player2Icon);
             *
             * Assert.AreEqual(currentPieceTouched.CheckPieceMatch(), false);
             *
             * // reset diagonal elements
             * board.GetPieceOnRowAndColumn(0, 0).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(1, 1).PaintWithIcon(player1Icon);
             * board.GetPieceOnRowAndColumn(2, 2).PaintWithIcon(player1Icon);
             *
             * Assert.AreEqual(currentPieceTouched.CheckPieceMatch(), false);
             *
             * // set vertical elements to be the same as currentPiece
             * board.GetPieceOnRowAndColumn(1, 0).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(2, 0).PaintWithIcon(player2Icon);
             *
             * Assert.AreEqual(currentPieceTouched.CheckPieceMatch(), true);
             */
        }
Ejemplo n.º 24
0
        public void Win_WhenVerticalMatch()
        {
            int              boardSize           = 3;
            IGameController  objectiveController = NSubstitute.Substitute.For <IGameController>();
            IBoardController boardController     = NSubstitute.Substitute.For <IBoardController>();

            /*
             * Board board = new Board(boardSize, objectiveController, boardController);
             * Piece currentPieceTouched = board.GetPieceOnRowAndColumn(2, 0);
             * Assert.AreEqual(currentPieceTouched.Behaviors[0].ToString(), "TicTacToe.NormalPieceBehavior");
             * Icon player1Icon = new Icon();
             * Icon player2Icon = new Icon();
             *
             * board.GetPieceOnRowAndColumn(0, 0).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(1, 0).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(2, 0).PaintWithIcon(player2Icon);
             * Assert.AreEqual(currentPieceTouched.CheckPieceMatch(), true);
             * board.GetPieceOnRowAndColumn(0, 0).PaintWithIcon(player2Icon);
             * board.GetPieceOnRowAndColumn(1, 0).PaintWithIcon(player1Icon);
             * board.GetPieceOnRowAndColumn(2, 0).PaintWithIcon(player2Icon);
             * Assert.AreEqual(currentPieceTouched.CheckPieceMatch(), false);
             */
        }
Ejemplo n.º 25
0
        public MovesResult ExecuteMoves(IBoardController board)
        {
            MovesResultPossibilities movesResult = board.GetResult();

            foreach (var move in _moves)
            {
                switch ((Moves)move)
                {
                case Moves.Move:
                    movesResult = board.MoveTurtle();
                    break;

                case Moves.Rotate:
                    board.RotateTurtle();
                    break;
                }
            }

            return(new MovesResult
            {
                SequenceId = SequenceId,
                Result = movesResult
            });
        }
Ejemplo n.º 26
0
 public TurtleGame(IBoardController boardController, ISequenceController sequenceController, IResultReporter resultReporter)
 {
     _boardController    = boardController ?? throw new System.ArgumentNullException(nameof(boardController));
     _sequenceController = sequenceController ?? throw new System.ArgumentNullException(nameof(sequenceController));
     _resultReporter     = resultReporter ?? throw new System.ArgumentNullException(nameof(resultReporter));
 }
Ejemplo n.º 27
0
 public void Init(IBoardController boardController)
 {
     _boardController = boardController;
 }
Ejemplo n.º 28
0
 public BoardBasedFsm(IBoardController Handler, IRuntimeBoard Board) : base(Handler)
 {
     handler = Handler;
     board   = Board;
     Initialize();
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Registers the controller reference to pass events.
 /// </summary>
 /// <param name="controller"></param>
 public void RegisterObserver(IBoardController controller)
 {
     this.controller = controller;
 }
Ejemplo n.º 30
0
 public GameController()
 {
     board = (IBoardController)GameObject.FindGameObjectWithTag("Board").GetComponentInChildren(typeof(IBoardController));
 }