Beispiel #1
0
 public Grid(uint colSize, uint rowSize)
 {
     // Adds dimesnions from parameters
     ColumnCount = Convert.ToInt32(colSize);
     RowCount    = Convert.ToInt32(rowSize);
     // Allows the buttons to change with size of the grid
     AutoSizeMode = AutoSizeMode.GrowAndShrink;
     AutoSize     = true;
     Dock         = DockStyle.Fill;
     // Names the object for referencing
     Name = "Grid";
     // Sets the location of the Grid
     Location = new Point(0, 50);
     // Eliminates seperation between buttons
     Margin = new Padding(0);
     // Sets the default size of the grid
     Size = new Size(512, 512);
     // Sets up the grid with the appropriate dimensions
     SetupGridStyles();
     // Initalises a 2D array to store each position
     PositionArray = new Position[colSize, rowSize];
     // Populates each position with buttons
     CreateBtnGrid();
     // Sets each square on the Grid's background colour to match a checkers board
     ResetSquareColor();
     // Sets up pieces on each side of the Grid to belong to each player
     SetupInitalPositions();
 }
Beispiel #2
0
        public static Block generateRandomBlock(Position[,] boardPositions)
        {
            switch (random.Next(0, 7))
            {
            case 0:
                return(new Block(generateBlock(boardPositions, oBlock, Color.Yellow)));

            case 1:
                return(new Block(generateBlock(boardPositions, iBlock, Color.Cyan)));

            case 2:
                return(new Block(generateBlock(boardPositions, sBlock, Color.Red)));

            case 3:
                return(new Block(generateBlock(boardPositions, zBlock, Color.Green)));

            case 4:
                return(new Block(generateBlock(boardPositions, lBlock, Color.Orange)));

            case 5:
                return(new Block(generateBlock(boardPositions, jBlock, Color.Blue)));

            case 6:
                return(new Block(generateBlock(boardPositions, tBlock, Color.Purple)));
            }
            return(null);
        }
Beispiel #3
0
        private static bool ApplyRulesPart2(Position[,] positions)
        {
            bool peopleMoved = false;

            for (var i = 0; i < positions.GetLength(0); i++)
            {
                for (var j = 0; j < positions.GetLength(1); j++)
                {
                    var position = positions[i, j];
                    if (position.State == PositionState.Floor)
                    {
                        continue;
                    }
                    var adjacents = GetFirstNotFloorAdjacents(positions, i, j);
                    if (position.State == PositionState.Empty && adjacents.Count(x => x.State == PositionState.Occupied) == 0)
                    {
                        peopleMoved          = true;
                        position.ChangeState = true;
                        continue;
                    }

                    if (position.State == PositionState.Occupied && adjacents.Count(x => x.State == PositionState.Occupied) >= 5)
                    {
                        peopleMoved          = true;
                        position.ChangeState = true;
                        continue;
                    }
                }
            }

            positions.ApplyChanges();

            return(peopleMoved);
        }
Beispiel #4
0
 internal Bsurface(Position[,] poles, double[] knotsU, double[] knotsV)
 {
     this.Poles   = poles;
     this.KnotsU  = knotsU;
     this.KnotsV  = knotsV;
     this.Weights = this.UnitWeights(this.OrderU, this.OrderV);
 }
Beispiel #5
0
        private static Position[,] SimulateRound(Position[,] before, int numberWhenPeopleLeave, Func <Position[, ], int, int, int> numberOfAdjacents)
        {
            Position[,] after = before.Clone() as Position[, ];

            for (int i = 0; i < before.GetLength(0); ++i)
            {
                for (int j = 0; j < before.GetLength(1); ++j)
                {
                    if (before[i, j] == Position.Floor)
                    {
                        continue;
                    }

                    int adjacents = numberOfAdjacents(before, i, j);

                    if (adjacents >= numberWhenPeopleLeave)
                    {
                        after[i, j] = Position.Empty;
                    }

                    if (adjacents == 0)
                    {
                        after[i, j] = Position.Occupied;
                    }
                }
            }

            return(after);
        }
Beispiel #6
0
 public Position[,] rotate(Position[,] boardPositions, Position[,] blocks)
 {
     initRotationVariables(blocks);
     for (int oldColumn = blocks.GetLength(1) - 1; oldColumn >= 0; oldColumn--)
     {
         resetRotationColumns(blocks);
         for (int oldRow = 0; oldRow < blocks.GetLength(0); oldRow++)
         {
             if (blocks[oldRow, oldColumn] != null)
             {
                 invalidRotation = checkForInvalidRotations(boardPositions, blockPivot.x + xRotationPos, blockPivot.y + yRotationPos);
                 if (!invalidRotation)
                 {
                     retrieveNewRotationBlock(boardPositions);
                 }
                 else
                 {
                     break;
                 }
             }
             incrementRotationColumns();
         }
         if (invalidRotation)
         {
             break;
         }
         incrementRotationRows();
     }
     if (invalidRotation)
     {
         return(blocks);
     }
     return(newRotationMatrix);
 }
Beispiel #7
0
        private void Fill(IEnumerable <Mine> mines, Exit exit, int sizeX, int sizeY)
        {
            try
            {
                Cells = new Position[sizeX, sizeY];

                for (int x = 0; x < sizeX; x++)
                {
                    for (int y = 0; y < sizeY; y++)
                    {
                        Cells[x, y] = new Position();
                    }
                }

                foreach (var mine in mines)
                {
                    Cells[mine.X, mine.Y] = new Mine();
                }

                Cells[exit.X, exit.Y] = new Exit();
            }
            catch (Exception ex)
            {
                throw new Exception("Error ocurred while filling the board.", ex);
            }
        }
Beispiel #8
0
 private void initRotationVariables(Position[,] blocks)
 {
     newRotationMatrix = new Position[blocks.GetLength(1), blocks.GetLength(0)];
     blockPivot        = blocks[blocks.GetLength(0) / 2, blocks.GetLength(1) / 2];
     newRotationColumn = 0; newRotationRow = 0; xRotationPos = -(blocks.GetLength(0) / 2); yRotationPos = 0;
     invalidRotation   = false;
 }
Beispiel #9
0
 public void rotate(Position[,] boardPositions, Position[,] placedBlocks)
 {
     if (canPerformRotation(boardPositions, placedBlocks))
     {
         blocks = blockRotation.rotate(boardPositions, blocks);
     }
 }
Beispiel #10
0
 public void handleMovement(Position[,] gameBoardPositions, List <Position> snakeBody)
 {
     handleMovement(gameBoardPositions, snakeBody, Keys.Up, 0, -1);
     handleMovement(gameBoardPositions, snakeBody, Keys.Down, 0, 1);
     handleMovement(gameBoardPositions, snakeBody, Keys.Left, -1, 0);
     handleMovement(gameBoardPositions, snakeBody, Keys.Right, 1, 0);
 }
Beispiel #11
0
        private int HardMode(Board board)
        {
            Position[,] grid = board.GetGrid();
            int spot;

            spot = TestWins(grid);
            if (spot != 0)
            {
                return(spot);
            }

            spot = TestLosses(grid);
            if (spot != 0)
            {
                return(spot);
            }

            List <int> ListSpots  = GetEmptys(board);
            int        listCount  = ListSpots.Count();
            Random     rnd        = new Random();
            int        listRandom = rnd.Next(1, listCount);

            int[] possibilities = ListSpots.ToArray();
            return(possibilities[listRandom - 1]);
        }
Beispiel #12
0
    // Use this for initialization
    void Start()
    {
        //Pega a matriz de jogo do nível atual
        Scene scene = SceneManager.GetActiveScene();

        gameController = GameObject.Find("GameController");
        lvl            = (LevelController)gameController.GetComponent("LevelController");
        gameVet        = lvl.GetGameVet(scene.name);
        gameVetProc    = lvl.GetGameProcVet(scene.name);
        gameMat        = lvl.GetGameMat(scene.name);

        //Busca os GameObjects para Proc
        panelProc      = GameObject.Find("ProcedurePanel");
        initialPosProc = GameObject.Find("InitialPosProc");

        //Busca os GameObjects para o Loop
        panelLoop      = GameObject.Find("LoopPanel");
        initialPosLoop = GameObject.Find("InitialPosLoop");

        //Busca os GameObjects para o Until
        panelUntil = GameObject.Find("UntilPanel");
        posUntil   = GameObject.Find("PosUntil");

        if (player == null)
        {
            player           = GameObject.Find("Player(Clone)");
            playerController = (PlayerController)player.GetComponent("PlayerController");
        }
    }
Beispiel #13
0
        internal static Snap.NX.Bsurface CreateBsurface(Position[,] poles, double[,] weights, double[] knotsU, double[] knotsV)
        {
            int num10;
            int num11;
            Tag tag;
            int length = poles.GetLength(0);
            int num2   = knotsU.Length;
            int ku     = num2 - length;
            int nv     = poles.GetLength(1);
            int num5   = knotsV.Length;
            int kv     = num5 - nv;

            double[] numArray = new double[(4 * length) * nv];
            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < nv; j++)
                {
                    int index = 4 * ((length * j) + i);
                    numArray[index]     = poles[i, j].X * weights[i, j];
                    numArray[index + 1] = poles[i, j].Y * weights[i, j];
                    numArray[index + 2] = poles[i, j].Z * weights[i, j];
                    numArray[index + 3] = weights[i, j];
                }
            }
            Globals.UFSession.Modl.CreateBsurf(length, nv, ku, kv, knotsU, knotsV, numArray, out tag, out num10, out num11);
            NXOpen.Body        objectFromTag = (NXOpen.Body)Snap.NX.NXObject.GetObjectFromTag(tag);
            Session.UndoMarkId undoMark      = Globals.Session.SetUndoMark(Session.MarkVisibility.Invisible, "");
            Globals.Session.UpdateManager.DoUpdate(undoMark);
            Globals.Session.DeleteUndoMark(undoMark, null);
            return(new Snap.NX.Bsurface(objectFromTag));
        }
Beispiel #14
0
        private static void PrintPositions(this Position[,] positions)
        {
            System.Console.WriteLine();
            for (var i = 0; i < positions.GetLength(0); i++)
            {
                var line = string.Empty;
                for (var j = 0; j < positions.GetLength(1); j++)
                {
                    switch (positions[i, j].State)
                    {
                    case PositionState.Floor:
                        line += '.';
                        break;

                    case PositionState.Empty:
                        line += 'L';
                        break;

                    case PositionState.Occupied:
                        line += '#';
                        break;
                    }
                }
                System.Console.WriteLine(line);
            }
            System.Console.WriteLine();
        }
Beispiel #15
0
 internal Bsurface(Position[,] poles, double[,] weights, double[] knotsU, double[] knotsV)
 {
     this.Poles   = poles;
     this.Weights = weights;
     this.KnotsU  = knotsU;
     this.KnotsV  = knotsV;
 }
Beispiel #16
0
 public GameLogic()
 {
     placedBlocks       = new Position[GameProperties.BOARD_X_SIZE, GameProperties.BOARD_Y_SIZE];
     board              = new Board(GameProperties.BOARD_X_SIZE, GameProperties.BOARD_Y_SIZE);
     blockMovementDelay = GameProperties.GAME_BLOCK_MOVEMENT;
     lvl     = GameProperties.GAME_INITIAL_LVL;
     nextLvl = GameProperties.GAME_INITAL_LINES_TO_NEXT_LVL;
 }
Beispiel #17
0
 private bool canPerformRotation(Position[,] boardPositions, Position[,] placedBlocks)
 {
     return(!blockCollision.checkCollisionWithWallsAndBottom(boardPositions, blocks, 1, 1) &&
            !blockCollision.checkCollisionWithWallsAndBottom(boardPositions, blocks, -1, 1) &&
            !blockCollision.checkCollisionWithPlacedBlocks(placedBlocks, blocks, 0, 1) &&
            !blockCollision.checkCollisionWithPlacedBlocks(placedBlocks, blocks, -1, 0) &&
            !blockCollision.checkCollisionWithPlacedBlocks(placedBlocks, blocks, 1, 0));
 }
Beispiel #18
0
 public Shape(Dimensions dimensions, Character character)
 {
     this.dimensions = dimensions;
     Columns         = dimensions.Columns;
     Rows            = dimensions.Rows;
     this.Positions  = new Position[Rows, Columns];
     this.character  = character;
     InitPositions(character);
 }
Beispiel #19
0
    //Posiciona o jogador na primeira tile do jogo
    void posicionaJogador(Position[,] gameMat)
    {
        //Sempre a posição do meio
        int i = gameMat.GetLength(0) - 1;

        lvl.atualizaPosPlayer(i, 1);
        lvl.setaPorIniPlayer(i, 1);
        //Instancia o jogador
        Instantiate(player, new Vector3(gameMat[i, 1].PosX, gameMat[i, 1].PosY, -1.2f), Quaternion.identity);
    }
Beispiel #20
0
 private static void ReadInput(this Position[,] positions, string[] lines)
 {
     for (var i = 0; i < lines.Length; i++)
     {
         var line = lines[i];
         for (var j = 0; j < line.Length; j++)
         {
             positions[i, j] = new Position(line[j]);
         }
     }
 }
Beispiel #21
0
            public static Position[] GetColumn(Position[,] a, int j)
            {
                int num = RowCount(a);

                Position[] positionArray = new Position[num];
                for (int i = 0; i < num; i++)
                {
                    positionArray[i] = a[i, j];
                }
                return(positionArray);
            }
Beispiel #22
0
            public static Position[] GetRow(Position[,] a, int i)
            {
                int num = ColumnCount(a);

                Position[] positionArray = new Position[num];
                for (int j = 0; j < num; j++)
                {
                    positionArray[j] = a[i, j];
                }
                return(positionArray);
            }
Beispiel #23
0
 public void Reset()
 {
     this.positions = new Position[Global.rowSize, Global.colSize];
     for (int r = 0; r < Global.rowSize; r++)
     {
         for (int c = 0; c < Global.colSize; c++)
         {
             this.positions[r, c] = new Position(r, c);
         }
     }
 }
Beispiel #24
0
 public Board()
 {
     backColor = Console.BackgroundColor;
     borderColor = ConsoleColor.Cyan;
     piecePlaceColor = ConsoleColor.Gray;
     textColor = ConsoleColor.Black;
     textBackColor = ConsoleColor.Cyan;
     width = Console.WindowWidth;
     height = Console.WindowHeight;
     spacer = Console.WindowHeight - marginLeft;
     positions = new Position[3, 8];
 }
Beispiel #25
0
        public Grid(int size)
        {
            points = new Position[size + 1, size + 1];

            for (int i = 0; i < points.GetLength(0); i++)
            {
                for (int j = 0; j < points.GetLength(1); j++)
                {
                    points[i, j] = new Position(i, j);
                }
            }
        }
Beispiel #26
0
 public Board()
 {
     backColor       = Console.BackgroundColor;
     borderColor     = ConsoleColor.Cyan;
     piecePlaceColor = ConsoleColor.Gray;
     textColor       = ConsoleColor.Black;
     textBackColor   = ConsoleColor.Cyan;
     width           = Console.WindowWidth;
     height          = Console.WindowHeight;
     spacer          = Console.WindowHeight - marginLeft;
     positions       = new Position[3, 8];
 }
Beispiel #27
0
        private int EasyMode(Board board)
        {
            Position[,] grid = board.GetGrid();
            int spot;

            List <int> ListSpots  = GetEmptys(board);
            int        listCount  = ListSpots.Count();
            Random     rnd        = new Random();
            int        listRandom = rnd.Next(1, listCount);

            int[] possibilities = ListSpots.ToArray();
            return(possibilities[listRandom - 1]);
        }
Beispiel #28
0
 public void moveSnake(Position[,] gameBoardPositions)
 {
     if (counterDelay >= delay)
     {
         counterDelay = 0;
         snakeMovement.handleMovement(gameBoardPositions, snakeBody);
         resizeSnake();
     }
     else
     {
         counterDelay++;
     }
 }
Beispiel #29
0
        public void InitializeGrid()
        {
            _grid = new Position[3, 3];

            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    _grid[x, y] = new Position();
                    _grid[x, y].SetMarker(new Marker(_blank));
                }
            }
        }
Beispiel #30
0
 private void handleMovement(Position[,] gameBoardPositions, List <Position> snakeBody, Keys keyToMove, int x, int y)
 {
     if (nextKeyMovement == keyToMove)
     {
         if (canMoveToPosition(keyToMove, gameBoardPositions.GetLength(0), snakeBody))
         {
             performMovement(gameBoardPositions, snakeBody, x, y);
         }
         else
         {
             snakeCollision = true;
         }
     }
 }
Beispiel #31
0
 public void Init()
 {
     _maze = new Position[Width, Height];
     for (int i = 0; i < Width; i++)
     {
         for (int j = 0; j < Height; j++)
         {
             _maze[i, j]      = new Position();
             _maze[i, j].X    = i;
             _maze[i, j].Y    = j;
             _maze[i, j].Type = Position.CellType.Empty;
         }
     }
 }
Beispiel #32
0
        // Load piece coordinates on the board
        public void LoadPiecesPositionsFromBoard(Board board)
        {
            int rectangleCount = board.positions.GetLength(0);
            int pointsCountInRect = board.positions.GetLength(1);

            positions = new Position[rectangleCount, pointsCountInRect];
            positionsOnBoard = new bool[rectangleCount, pointsCountInRect];

            for (int i = 0; i < rectangleCount; i++)
            {
                for (int j = 0; j < pointsCountInRect; j++)
                {
                    positions[i, j].x = board.positions[i, j].x;
                    positions[i, j].y = board.positions[i, j].y;
                }
            }
        }
Beispiel #33
0
 // Constructor
 public Piece()
 {
     piecesColor = ConsoleColor.Green;
     count = 9;
     positions = null;
 }
Beispiel #34
0
 private void clearBoard()
 {
     positions = new Position[16, 16];
 }