Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var inputCells = new List<Cell>();

            // row 0
            inputCells.Add(new Cell(ColourEnum.Blue, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Red));
            inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Blue, ColourEnum.Yellow));
            inputCells.Add(new Cell(ColourEnum.Blue, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Red));
            inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Blue, ColourEnum.Red, ColourEnum.Blue));

            // row 1
            inputCells.Add(new Cell(ColourEnum.Red, ColourEnum.Blue, ColourEnum.Red, ColourEnum.Blue));
            inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Blue, ColourEnum.Yellow, ColourEnum.Red));
            inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Red));
            inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Blue));

            // row 2
            inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Blue, ColourEnum.Blue, ColourEnum.Yellow));
            inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Blue));
            inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Red));
            inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Blue, ColourEnum.Blue, ColourEnum.Red));

            // row 3
            inputCells.Add(new Cell(ColourEnum.Blue, ColourEnum.Red, ColourEnum.Blue, ColourEnum.Yellow));
            inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Blue, ColourEnum.Blue, ColourEnum.Red));
            inputCells.Add(new Cell(ColourEnum.Blue, ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Red));
            inputCells.Add(new Cell(ColourEnum.Red, ColourEnum.Blue, ColourEnum.Yellow, ColourEnum.Blue));

            var grid = new Grid(6, true);
            grid.Fill(inputCells);

            Console.WriteLine(grid.Print());
        }
Ejemplo n.º 2
0
 // Like mini-AStar, maybe move to AStar??
 public static List<Tile> getMovementRange(Grid grid, Character character)
 {
     int max_dist = character.move_speed;
     List<Tile> stack = new List<Tile> (); // Like open set
     List<Tile> move_range = new List<Tile> (){character.current_tile};
     Dictionary<Tile, int> dist = new Dictionary<Tile, int> (); // Walking distance from character
     foreach (var tile in Grid.getNeighboringTiles(grid, character.current_tile)) {
         dist[tile] = 1;
         stack.Add(tile);
     }
     while (stack.Count > 0) {
         Tile tile = stack[0];
         stack.Remove(tile);
         if (!move_range.Contains(tile)) {
             move_range.Add(tile);
             if (dist[tile] < max_dist) {
                 foreach (var neighbor in Grid.getNeighboringTiles(grid, tile)) {
                     //TODO: Limit by vision
                     if (!move_range.Contains(neighbor)) {
                         dist[neighbor] = dist[tile] + 1;
                         stack.Add(neighbor);
                     }
                 }
             }
         }
     }
     return move_range;
 }
Ejemplo n.º 3
0
        public UIGridPath(ObjectFactory factory, Grid grid, List<Tile> path)
        {
            segments.Clear (); //TODO: ensure factory destroying of gameobjects
            // Assumptions:
            //  - Paths are at least 2 segments long
            //  - Segments are unilaterally adjacent
            foreach (var tile in path) {
                int index = path.IndexOf(tile);
                var segment = factory.createUIGridPathSegment(grid, tile.grid_x, tile.grid_y);
                UIGridPathSegment.Type type = UIGridPathSegment.Type.none;
                Direction dir_from = Direction.none;
                Direction dir_to = Direction.none;

                if (index != 0 ) {
                    dir_from = DirectionMethods.getDirection(tile, path[index - 1]);
                }
                if (index != path.Count - 1){
                    dir_to = DirectionMethods.getDirection(tile, path[index + 1]);
                }

                if (dir_to == Direction.none && dir_from == Direction.none) {
                    type = UIGridPathSegment.Type.singular;
                } else if (index == 0 || index == path.Count - 1) {
                    type = UIGridPathSegment.Type.terminal;
                } else if (dir_to == dir_from.rotate(ClockDirection.clockwise)
                        || dir_to == dir_from.rotate(ClockDirection.counterclockwise)) {
                    type = UIGridPathSegment.Type.bend;
                }  else {
                    type = UIGridPathSegment.Type.straight;
                }
                segment.setup(type, dir_to, dir_from);
                segments.Add(segment);
            }
        }
Ejemplo n.º 4
0
 // Move to UI Factory?
 public UIGridPathSegment createUIGridPathSegment(Grid grid, int x_pos, int y_pos)
 {
     GameObject segment_obj = Instantiate(UIGridPathSegment);
     UIGridPathSegment segment = segment_obj.GetComponent<UIGridPathSegment> ();
     UIObjects [segment] = segment_obj;
     segment.setGridPosition (grid, x_pos, y_pos);
     return segment;
 }
Ejemplo n.º 5
0
 public GameObject createCharacter(Grid grid, int x_pos, int y_pos)
 {
     var character = Instantiate (CharacterObject);
     character.GetComponent<Character> ().setGrid (grid);
     character.GetComponent<Character>().setGridPosition (grid, x_pos, y_pos);
     //setUpInformant (character); // for now the tile the char is in is handling all UI decisions
     return character;
 }
Ejemplo n.º 6
0
 public Tile createTile(Grid grid, int x_pos, int y_pos)
 {
     GameObject tile_obj = Instantiate(TileObject);
     Tile tile = tile_obj.GetComponent<Tile> ();
     tileObjects [tile] = tile_obj;
     tile.setGridPosition (grid, x_pos, y_pos);
     setUpInformant (tile);
     return tile;
 }
Ejemplo n.º 7
0
        public void FindGridItemNeighbor()
        {
            grid = CreateSlotGrid(3, 3);
            GameObject    currentSlotObject = GetSlotObjectByRowAndColumn(1, 1);
            GridItemMover slotGridItemMover = currentSlotObject.GetComponent <GridItemMover>();

            //List<GameObject> neighBors = grid.GetItemNeighbors(slotGridItemMover);
            List <GameObject> neighBors = slotGridItemMover.GetNeighbors();

            Assert.AreEqual(4, neighBors.Count);
        }
        public void NeigborOfSlotDifferentThanAGivenSlotTurnFixed()
        {
            Game.Grid                  grid                     = CreateSlotGrid();
            GameObject                 slotObject               = GetEmptySlotObjectFromGrid(grid);
            GridItemMover              slotMover                = slotObject.GetComponent <GridItemMover>();
            List <GameObject>          slotNeighbors            = slotMover.GetNeighbors();
            GameObject                 givenSlot                = slotNeighbors[0];
            SlotSelectionServer        givenSlotSelectionServer = givenSlot.GetComponent <SlotSelectionServer>();
            PieceDestinationController slot                     = slotObject.GetComponent <PieceDestinationController>();

            slot.TurnFixedAllNeighborButOne(givenSlotSelectionServer);
            TestNeighborsAreFixedButGivenOne(slotNeighbors, givenSlotSelectionServer);
        }
Ejemplo n.º 9
0
        public void WhenEmptyStateAllNeighBorAreMovable()
        {
            grid = CreateSlotGrid(3, 3);
            PieceDestinationController currentSlot    = GetSlotByRowAndColumn(1, 1);
            PieceDestinationController leftNeighbor   = GetSlotByRowAndColumn(1, 0);
            PieceDestinationController rightNeighbor  = GetSlotByRowAndColumn(1, 2);
            PieceDestinationController upNeighbor     = GetSlotByRowAndColumn(0, 1);
            PieceDestinationController bottomNeighbor = GetSlotByRowAndColumn(2, 1);

            currentSlot.SetEmpty();
            currentSlot.Clean();

            Assert.IsTrue(currentSlot.CanReceivePiece());
            Assert.IsTrue(leftNeighbor.CanMovePiece());
            Assert.IsTrue(upNeighbor.CanMovePiece());
            Assert.IsTrue(rightNeighbor.CanMovePiece());
            Assert.IsTrue(bottomNeighbor.CanMovePiece());
        }
Ejemplo n.º 10
0
        public void WhenEmptySlotReceivePieceItsNeighborShouldTurnFixed()
        {
            Game.Grid         grid              = CreateSlotGrid();
            GameObject        emptySlotObject   = GetEmptySlotObjectFromGrid(grid);
            GameObject        movableSlotObject = GetNeighborOfSlot(emptySlotObject);
            GridItemMover     slotMover         = emptySlotObject.GetComponent <GridItemMover>();
            List <GameObject> slotNeighbors     = slotMover.GetNeighbors();
            Slot emptySlot   = emptySlotObject.GetComponent <Slot>();
            Slot movableSlot = movableSlotObject.GetComponent <Slot>();
            SlotSelectionServer        givenSlotSelectionServer              = movableSlotObject.GetComponent <SlotSelectionServer>();
            PieceDestinationController emptySlotPieceDestinationController   = emptySlotObject.GetComponent <PieceDestinationController>();
            PieceDestinationController movableSlotPieceDestinationController = movableSlotObject.GetComponent <PieceDestinationController>();

            movableSlot.Touch();
            emptySlot.Touch();

            TestNeighborsAreFixedButGivenOne(slotNeighbors, givenSlotSelectionServer);
        }
Ejemplo n.º 11
0
 public static List<Tile> getNeighboringTiles(Grid grid, Tile tile)
 {
     List<Tile> neighbors = new List<Tile> ();
     int x = tile.grid_x, y = tile.grid_y;
     for (int i = x-1; i < x+2; i+=2) {
         //If within bounds of grid
         if (inBounds(grid, i, y)) {
     //					//TODO: Pathabilty
             neighbors.Add (grid.tiles[i][y]);
         }
     }
     for (int j = y-1; j < y+2; j+=2) {
         //If within bounds of grid
         if (inBounds(grid, x, j)) {
             //TODO: Pathabilty
             neighbors.Add (grid.tiles[x][j]);
         }
     }
     return neighbors;
 }
Ejemplo n.º 12
0
        public void ChangePieceParentToDestineSlotAfterMoving()
        {
            Game.Grid  grid              = CreateSlotGrid();
            GameObject emptySlotObject   = GetEmptySlotObjectFromGrid(grid);
            GameObject movableSlotObject = GetNeighborOfSlot(emptySlotObject);
            Slot       emptySlot         = emptySlotObject.GetComponent <Slot>();
            Slot       movableSlot       = movableSlotObject.GetComponent <Slot>();
            PieceDestinationController emptySlotPieceDestinationController   = emptySlotObject.GetComponent <PieceDestinationController>();
            PieceDestinationController movableSlotPieceDestinationController = movableSlotObject.GetComponent <PieceDestinationController>();

            GameObject movedPiece = movableSlotPieceDestinationController.Piece;

            Assert.IsNotNull(movedPiece);

            movableSlot.Touch();
            emptySlot.Touch();

            Assert.IsNotNull(movedPiece);
            Assert.IsNotNull(emptySlotObject.transform);
            Assert.AreEqual(emptySlotObject.transform, movedPiece.transform.parent);
            Assert.IsNotNull(emptySlotPieceDestinationController.Piece);
            Assert.AreEqual(null, movableSlotPieceDestinationController.Piece);
            Assert.AreEqual(movedPiece, emptySlotPieceDestinationController.Piece);
        }
Ejemplo n.º 13
0
 public OnShufflingState(FSM <StatesEnum> fsm, MainMenu mainMenu, Grid grid) : base(fsm)
 {
     m_Grid = grid;
     m_Grid.Configure(mainMenu.gridSide, mainMenu.moves, mainMenu.speed);
 }
Ejemplo n.º 14
0
 /* Think about how best to represent classes of characters,
  * should they extend this object? Or should Character be an interface, or should
  * it all be handled by like json...
 */
 // Use this for initialization
 void Start()
 {
     grid = createGrid (gridColCount, gridRowCount);
     characters = getCharacters ();
 }
Ejemplo n.º 15
0
        public Character character; //Make unit???

        #endregion Fields

        #region Constructors

        public Tile(Grid grid, int x_pos, int y_pos)
        {
            setGridPosition (grid, x_pos, y_pos);
        }
Ejemplo n.º 16
0
 public static bool inBounds(Grid grid, int x, int y)
 {
     return (grid.cols > x && grid.rows > y && x >= 0 && y >= 0);
 }
Ejemplo n.º 17
0
        private GameObject GetEmptySlotObjectFromGrid(Game.Grid grid)
        {
            SlotSorting slotSorting = CreateSlotSortingToGrid(grid);

            return(slotSorting.GetRandomEmptySlotObject());
        }
Ejemplo n.º 18
0
 private SlotSorting CreateSlotSortingToGrid(Game.Grid slotGrid)
 {
     return(new SlotSortingImplementation(slotGrid));
 }
Ejemplo n.º 19
0
 public void setGridPosition(Grid grid, int x, int y)
 {
     //TODO: Check if placement is legal
     this.grid_x = x;
     this.grid_y = y;
     if( typeof(Tile) != this.GetType()) {
         setTile(grid.getTile(x,y));
     }
     allignTranformPositionWithGridPosition ();
 }
Ejemplo n.º 20
0
 public void setGrid(Grid grid)
 {
     this.grid = grid;
 }