Пример #1
0
        public static Block CreateBlockRandom(DrawerUtil drawer, int x, int y)
        {
            Random rnd  = new Random();
            Type   type = (Type)rnd.Next(0, 4);

            return(CreateBlock(drawer, type, x, y));
        }
Пример #2
0
        private bool[,] Cells; //Holds all (4x4) shape information about the block

        public Block(DrawerUtil drawer, int posX, int posY, bool[,] cells)
        {
            Drawer = drawer;
            PosX   = posX;
            PosY   = posY;
            Cells  = cells;
        }
Пример #3
0
        private bool[,] Map; //info where the cells are filled

        public GameMap(DrawerUtil drawer, int sizeX, int sizeY)
        {
            Drawer = drawer;
            SizeX  = sizeX;
            SizeY  = sizeY;
            Map    = new bool[sizeX, sizeY];
        }
Пример #4
0
        public MainWindow()
        {
            InitializeComponent();
            #if DEBUG
            this.AttachDevTools();
            #endif

            Canv = this.Get <Canvas>("canvas");
            var foxDraw = new FoxDraw(Canv);

            //Add key callback function
            this.KeyUp += MainWindow_KeyUp;

            //Create drawing, map, game control setup
            DrawerUtil draw = new DrawerUtil(foxDraw, 20, 50, 50);
            GameMap    map  = new GameMap(draw, 10, 20);
            Controller = new GameControl(draw, map);

            for (int i = 0; i < 6; i++)
            {
                Controller.Move(Block.Direction.Down);
            }

            //Draw for the first time
            Controller.Draw();
        }
Пример #5
0
        private Block CurrentBlock; //Currently "playable" block

        public GameControl(DrawerUtil drawer, GameMap map)
        {
            Drawer = drawer;
            Map    = map;
            //Create first block to start the game
            GenerateNewBlock();
        }
Пример #6
0
        //Block object builder function
        public static Block CreateBlock(DrawerUtil drawer, Type type, int x, int y)
        {
            var cells = new bool[4, 4];

            switch (type)
            {
            case Type.Square:
            {
                cells[0, 0] = true;
                cells[0, 1] = true;
                cells[1, 0] = true;
                cells[1, 1] = true;
            }
            break;

            case Type.LPiece:
            {
                cells[0, 0] = true;
                cells[0, 1] = true;
                cells[1, 0] = true;
                cells[0, 2] = true;
            }
            break;

            case Type.Line:
            {
                cells[0, 0] = true;
                cells[0, 1] = true;
                cells[0, 2] = true;
                cells[0, 3] = true;
            }
            break;

            case Type.TPiece:
            {
                cells[0, 0] = true;
                cells[1, 0] = true;
                cells[2, 0] = true;
                cells[1, 1] = true;
            }
            break;

            case Type.Zigzag:
            {
                cells[1, 0] = true;
                cells[2, 0] = true;
                cells[0, 1] = true;
                cells[1, 1] = true;
            }
            break;
            }
            return(new Block(drawer, x, y, cells));
        }