示例#1
0
    public void ShouldRenderFloatingTextWhenDelete()
    {
        IFloatingTextRenderer floatingTextRenderer = Substitute.For <IFloatingTextRenderer>();

        setting.FloatingTextRenderer = floatingTextRenderer;
        var gridFactory = new GridFactory(setting, groupFactory);

        grid = gridFactory.Create();
        grid.NewGame();

        Assert.IsTrue(grid.AddGroup(group));
        Assert.IsTrue(group.Location.Equals(setting.BlockSpawnPoint));
        grid.FixGroup();
        Assert.IsTrue(grid.DropBlocks());

        grid.SetState(GridStates.Dropped);
        Assert.IsNotNull(grid[3, 1]);
        Assert.IsNotNull(grid[3, 0]);
        grid.OnUpdate();
        Assert.IsTrue(grid.CurrenteStateName == GridStates.Deleting);
        grid.OnUpdate();
        Assert.IsNull(grid[3, 1]);
        Assert.IsNull(grid[3, 0]);
        Assert.IsTrue(grid.CurrenteStateName == GridStates.Deleted);

        floatingTextRenderer.Received().RenderText(Arg.Any <Vector2>(), Arg.Any <string>());
    }
示例#2
0
        public void CreateGame_FailsWith_LowerThanThresholdSecondsPerRound()
        {
            Mock <IEventPublisher> eventPublisher = new Mock <IEventPublisher>();
            Grid grid = new GridFactory().BuildWithClassicDice();

            Assert.Throws <ArgumentOutOfRangeException>(() => new Game(eventPublisher.Object, grid, 5, 2));
        }
示例#3
0
        private PlayerMove RunGame(PlayerMove userInputMove, IGameGrid currentGameGrid, bool runAtGameStart)
        {
            var cellUpdater      = Factory.NewCellUpdater();
            var mineUpdater      = MineFactory.NewMineChecker();
            var mineGeneration   = MineFactory.NewMineLocations();
            var gameGridDisplay  = GridFactory.NewDisplayGrid();
            var convertUserInput = Factory.NewUserInputConverter();

            if (runAtGameStart)
            {
                mineUpdater.UpdateCellWithMineStatus(mineGeneration.MineLocations(currentGameGrid.Size), currentGameGrid);
                cellUpdater.UpdateAdjacentMineTotalAtGameStart(currentGameGrid);
            }

            do
            {
                Console.Clear();
                Console.WriteLine(gameGridDisplay.GenerateGameDisplay(currentGameGrid));

                var inputMove = _gameMessageDisplay.ShowUserInputMessage(currentGameGrid.Size);

                userInputMove = convertUserInput.ConvertInputToUserMove(inputMove);
            } while (_userInputValidation.IsCellRevealed(currentGameGrid, userInputMove));

            cellUpdater.UpdateDisplayStatusAfterUserMove(userInputMove, currentGameGrid);

            return(userInputMove);
        }
示例#4
0
        public List <Cell> MineLocations(int gridSize)
        {
            var generatedMineList = new List <Cell>();
            var gameGrid          = GridFactory.NewGameGrid(gridSize);

            for (var row = 0; row < gameGrid.Size; row++)
            {
                for (var column = 0; column < gameGrid.Size; column++)
                {
                    generatedMineList.Add(gameGrid.GeneratedGameCell[row, column]);
                    gameGrid.GeneratedGameCell[row, column].IsMine = true;
                }
            }

            var selectedMineLocations = new List <Cell>();

            for (var cell = 0; cell < gameGrid.Size; cell++)
            {
                var rnd        = new Random();
                var randomMine = generatedMineList.Count;
                var mine       = rnd.Next(randomMine);
                selectedMineLocations.Add(generatedMineList[mine]);
                generatedMineList.Remove(generatedMineList[mine]);
            }

            return(selectedMineLocations);
        }
示例#5
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        polyGrid = (PolyGrid)target;

        tab = GUILayout.Toolbar(tab, typeNames);

        if (polyGrid.NumFaces() == 0)
        {
            if (GUILayout.Button("Create Grid"))
            {
                GridFactory.PopulateSquareGrid(ref polyGrid);
            }
        }

        showGridProperties = EditorGUILayout.Foldout(showGridProperties, "Grid Properties");
        if (showGridProperties)
        {
            ShowGridProps();
        }


        showAdvancedOptions = EditorGUILayout.Foldout(showAdvancedOptions, "Advanced");
        if (showAdvancedOptions)
        {
            ShowAdvancedOptions();
        }
    }
示例#6
0
        public void Grid_With_Valid_Id_Renders_Correctly()
        {
            // Arrange
            var testData = new[]
            {
                new { Name = "Name 1", Id = 1 },
                new { Name = "Name 2", Id = 2 }
            };

            var grid = GridFactory.CreateGrid <object>("TestId", testData);

            // Act
            var markup = grid.ToHtmlString();

            // Assert
            Assert.True(markup.Contains(@"<table>
    <thead>
        <tr>
            <th>Name</th><th>Id</th>
        </tr>
    </thead>
    <tbody data-bind=""foreach: seats"">
        <tr>
            <td data-bind=""text: Name""></td><td data-bind=""text: Id""></td>
        </tr>    
    </tbody>
</table>"));
        }
示例#7
0
        public async Task <IResponse> CreateGridParameters(GridTemplate gridTemplate)
        {
            var newGrid = new GridFactory(gridTemplate.Vertexes, gridTemplate.Edges).Create();

            newGrid.OwnerId = gridTemplate.OwnerId;
            return(await base.CreateResource(newGrid));
        }
示例#8
0
        public void CreateGame_SucceedsWith_ValidInput()
        {
            Mock <IEventPublisher> eventPublisher = new Mock <IEventPublisher>();
            Grid grid = new GridFactory().BuildWithClassicDice();

            new Game(eventPublisher.Object, grid);
        }
示例#9
0
        public void CreateGame_FailsWith_NegativeRoundsToPlay()
        {
            Mock <IEventPublisher> eventPublisher = new Mock <IEventPublisher>();
            Grid grid = new GridFactory().BuildWithClassicDice();

            Assert.Throws <ArgumentOutOfRangeException>(() => new Game(eventPublisher.Object, grid, -9));
        }
示例#10
0
 void GenerateGrid( )
 {
     if (grid == null)
     {
         grid = GridFactory.GenerateOuterUShape(gridSize, dir);
         //grid = GridFactory.GenerateInnerUShape (gridSize, dir);
     }
 }
示例#11
0
        public void BuildGrid_SucceedsWith_16PopulatedDice()
        {
            var  factory = new GridFactory();
            Grid grid    = factory.BuildWithClassicDice();

            Assert.NotNull(grid);
            Assert.Equal(16, grid.Dice.Count);
        }
        private void CreateGridColumns(IGrid grid)
        {
            try
            {
                grid.BeginInit();

                grid.Columns.Clear();

                foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(grid.GridName))
                {
                    // 有些列是要设置值但不可见的,例如Id
                    //if (!Authority.AuthorizeByRule(info.ColumnVisible))
                    //    continue;

                    switch (info.GridColumnType)
                    {
                    case GridColumnType.Normal:
                    {
                        Xceed.Grid.Column column;
                        if (grid.Columns[info.GridColumnName] != null)
                        {
                            throw new ArgumentException("there have already exist column " + info.GridColumnName);
                        }
                        else
                        {
                            column = new Xceed.Grid.Column(info.GridColumnName, GridColumnInfoHelper.CreateType(info));
                        }

                        UnBoundGridExtention.SetColumnProperties(column, info, grid);

                        GridFactory.CreateCellViewerManager(column, info, this.ControlManager.DisplayManager);

                        bool readOnly = Authority.AuthorizeByRule(info.ReadOnly);
                        if (!readOnly)
                        {
                            GridFactory.CreateCellEditorManager(column, info, this.ControlManager.DisplayManager);
                        }

                        grid.Columns.Add(column);
                    }
                    break;

                    default:
                        break;
                        //default:
                        //    throw new InvalidOperationException("Invalide gridcolumnType of " + info.GridColumnType + " in " + info.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionProcess.ProcessWithNotify(ex);
            }
            finally
            {
                grid.EndInit();
            }
        }
示例#13
0
        public MainWindow(IGame game, GridFactory gridFactory, IGraphicsGridDrawer gridDrawer)
        {
            _game        = game;
            _gridFactory = gridFactory;
            _gridDrawer  = gridDrawer;
            _grid        = gridFactory(Settings.Default.DefaultWidth, Settings.Default.DefaultHeight);

            InitializeComponent();
        }
示例#14
0
        public void ValidState_SucceedsWith_NoRoundsPlayed()
        {
            Mock <IEventPublisher> eventPublisher = new Mock <IEventPublisher>();
            Grid grid = new GridFactory().BuildWithClassicDice();

            var game = new Game(eventPublisher.Object, grid);

            Assert.Equal(0, game.NumberOfPlayedRounds);
        }
示例#15
0
        public ScratchpadPageTemplate()
        {
            this.Name = "Scratchpad";

            this.Width  = 750;
            this.Height = 600;

            // containers
            this.Grid = new XContainer()
            {
                Styles = new ObservableCollection <IStyle>(),
                Shapes = new ObservableCollection <IShape>()
            };

            this.Table = new XContainer()
            {
                Styles = new ObservableCollection <IStyle>(),
                Shapes = new ObservableCollection <IShape>()
            };

            this.Frame = new XContainer()
            {
                Styles = new ObservableCollection <IStyle>(),
                Shapes = new ObservableCollection <IShape>()
            };

            // styles
            var gridStyle = new XStyle()
            {
                Name = "Grid",
                Fill = new XColor()
                {
                    A = 0x00, R = 0x00, G = 0x00, B = 0x00
                },
                Stroke = new XColor()
                {
                    A = 0xFF, R = 0xD3, G = 0xD3, B = 0xD3
                },
                Thickness = 1.0
            };

            this.Grid.Styles.Add(gridStyle);

            // grid
            var settings = new GridFactory.GridSettings()
            {
                StartX = 0.0,
                StartY = 0.0,
                Width  = this.Width,
                Height = this.Height,
                SizeX  = 30.0,
                SizeY  = 30.0
            };

            GridFactory.Create(this.Grid.Shapes, gridStyle, settings);
        }
示例#16
0
        public void GenerateABoardOfTheCorrectSize(int size, int expected)
        {
            //Arrange

            //Act
            var result = GridFactory.NewGameGrid(size);

            //Assert
            Assert.Equal(expected, result.Size);
        }
示例#17
0
        public static GridFactory GetInstance()
        {
            if (instance == null)
            {
                instance = new GridFactory();
                instance.InitGrid(4, 4);
            }

            return(instance);
        }
示例#18
0
    void CreateGrid()
    {
        if (GridFactory != null)
        {
            var grid = GridFactory.Create();
            _grid = grid;

            currentControl = _grid;
        }
    }
        public DefenseGrid GET()
        {
            DefenseGrid     dg   = new GridFactory().Create("Defense", 15, 15) as DefenseGrid;
            BuildingFactory art  = new BuildingFactory();
            Block           blks = dg.grid[5, 5];

            blks.building = art.Create("Artillery", "Art1");
            blks.state    = State.Healthy;
            return(dg);
        }
示例#20
0
        public static IEnumerable <object[]> TestData()
        {
            var grid = GridFactory.Produce(new[]
            {
                "S 1 1",
                "1 W 1",
                "1 1 F"
            }, GridType.Horizontal);

            yield return(new object[] { grid, grid[0, 0], new Position[] { new(0, 1), new(1, 0) } });
示例#21
0
        public Grid Update(Grid g)
        {
            Grid newgrid = GridFactory.GetGrid(g.Size);

            for (uint i = 1; i < g.Size - 1; ++i)
            {
                for (uint j = 1; j < g.Size - 1; ++j)
                {
                    int nbAlive = 0;
                    if (g.Cells[i - 1, j - 1].Alive)
                    {
                        nbAlive++;
                    }
                    if (g.Cells[i - 1, j].Alive)
                    {
                        nbAlive++;
                    }
                    if (g.Cells[i - 1, j + 1].Alive)
                    {
                        nbAlive++;
                    }
                    if (g.Cells[i, j - 1].Alive)
                    {
                        nbAlive++;
                    }
                    if (g.Cells[i, j + 1].Alive)
                    {
                        nbAlive++;
                    }
                    if (g.Cells[i + 1, j - 1].Alive)
                    {
                        nbAlive++;
                    }
                    if (g.Cells[i + 1, j].Alive)
                    {
                        nbAlive++;
                    }
                    if (g.Cells[i + 1, j + 1].Alive)
                    {
                        nbAlive++;
                    }

                    if (0 < nbAlive && nbAlive < 3)
                    {
                        newgrid.Cells[i, j] = CellFactory.GetAlive();
                    }
                    if (nbAlive > 5 || nbAlive == 0)
                    {
                        newgrid.Cells[i, j] = CellFactory.GetDead();
                    }
                }
            }
            return(newgrid);
        }
示例#22
0
        public string EndGameMessage(IGameGrid currentGameGrid, PlayerMove userInputMove)
        {
            var gameGridDisplay  = GridFactory.NewDisplayGrid();
            var revealedGameGrid = gameGridDisplay.GameOverGridDisplay(currentGameGrid);

            var message = currentGameGrid.GeneratedGameCell[userInputMove.Row, userInputMove.Column]
                          .IsMine
                    ? $"Sorry, you have lost.{Environment.NewLine}Game over!"
                    : $"Congrats!{Environment.NewLine}You have won!";

            return(revealedGameGrid + message);
        }
示例#23
0
        public void DisplayABoardWithTheCorrectDimensions(int size, string expected)
        {
            //Arrange
            var newDisplay = GridFactory.NewDisplayGrid();
            var gameGrid   = GridFactory.NewGameGrid(size);

            //Act
            var result = newDisplay.GenerateGameDisplay(gameGrid);

            //Assert
            Assert.Equal(expected, result);
        }
        public GridSwitcher(IList <GridConfig> gridConfigs, GridFactory gridFactory, WindowsOnGridController windowsOnGridController)
        {
            InitializeComponent();

            _gridConfigs             = gridConfigs;
            _gridFactory             = gridFactory;
            _windowsOnGridController = windowsOnGridController;

            _gridList.SelectedIndexChanged += LoadNewSelectedGrid;

            SetupGridList();
        }
示例#25
0
        public async Task FinishedState_SucceedsWith_NotAllRoundsPlayed()
        {
            Mock <IEventPublisher> eventPublisher = new Mock <IEventPublisher>();
            Grid grid = new GridFactory().BuildWithClassicDice();

            var game = new Game(eventPublisher.Object, grid, 3);
            await game.NextRoundAsync();

            await game.FinishGameAsync();

            Assert.Equal(WordGrid.Core.Models.State.Finished, game.State);
        }
示例#26
0
        public void UpdateTheStatusOfACellToRecordAMineAsFalse()
        {
            //Arrange
            var gridSize         = 2;
            var newGame          = GridFactory.NewGameGrid(gridSize);
            var updateMineStatus = new MineUpdater();
            var mineStub         = new StubForMineLocationZeroZero();

            //Act
            updateMineStatus.UpdateCellWithMineStatus(mineStub.MineLocations(newGame.Size), newGame);

            //Assert
            Assert.False(newGame.GeneratedGameCell[1, 1].IsMine);
        }
示例#27
0
        public async Task ValidState_SucceedsWith_ThreeRoundsPlayed()
        {
            Mock <IEventPublisher> eventPublisher = new Mock <IEventPublisher>();
            Grid grid = new GridFactory().BuildWithClassicDice();

            var game = new Game(eventPublisher.Object, grid);
            await game.NextRoundAsync();

            await game.NextRoundAsync();

            await game.NextRoundAsync();

            Assert.Equal(3, game.NumberOfPlayedRounds);
        }
示例#28
0
        public void Can_Create_Grid()
        {
            //arrange
            var cellsState = new[, ] {
                { 0, 0, 0, 1 }, { 1, 1, 0, 1 }, { 1, 0, 1, 1 }, { 1, 1, 0, 0 }
            };

            //act

            var grid = GridFactory.CreateBoundaryLessGrid(cellsState);


            //assert
            Assert.IsNotNull(grid);
        }
示例#29
0
        public void Passing_Id_And_Data_Creates_Grid_With_Matching_Id()
        {
            // Arrange
            var testData = new[]
            {
                new { Name = "Name 1", Id = 1 },
                new { Name = "Name 2", Id = 2 }
            };

            // Act
            var grid = GridFactory.CreateGrid("TestId", testData);

            // Assert
            Assert.Equal("TestId", grid.Id);
        }
示例#30
0
        public Simulation(SimulationConfiguration config, IPresenter presenter, ITimer timer)
        {
            _generationCount = 0;
            _config          = config;
            _presenter       = presenter;
            _timer           = timer;

            var gridFactory = new GridFactory();
            var grid        = gridFactory.Create(config.GridType, config.Height, config.Width);

            var ruleSetFactory = new RuleSetFactory();
            var ruleset        = ruleSetFactory.Create(config.RuleSetType);

            _board = new Board(ruleset, grid);
        }
示例#31
0
    public void ShouldRenderFloatingTextWhenDelete()
    {
        IFloatingTextRenderer floatingTextRenderer = Substitute.For<IFloatingTextRenderer>();
        setting.FloatingTextRenderer = floatingTextRenderer;
        var gridFactory = new GridFactory(setting, groupFactory);
        grid = gridFactory.Create();
        grid.NewGame();

        Assert.IsTrue(grid.AddGroup(group));
        Assert.IsTrue(group.Location.Equals(setting.BlockSpawnPoint));
        grid.FixGroup();
        Assert.IsTrue(grid.DropBlocks());

        grid.SetState(GridStates.Dropped);
        Assert.IsNotNull(grid[3, 1]);
        Assert.IsNotNull(grid[3, 0]);
        grid.OnUpdate();
        Assert.IsTrue(grid.CurrenteStateName == GridStates.Deleting);
        grid.OnUpdate();
        Assert.IsNull(grid[3, 1]);
        Assert.IsNull(grid[3, 0]);
        Assert.IsTrue(grid.CurrenteStateName == GridStates.Deleted);

        floatingTextRenderer.Received().RenderText(Arg.Any<Vector2>(), Arg.Any<string>());
    }