Ejemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            BlockSize = Sheet.Width / 10;

            Draft = new Bitmap(Sheet.Width, Sheet.Height);
            painter = new Painter(Draft, BlockSize, Sheet.Width, Sheet.Height);


            board = new Board(Sheet.Height / BlockSize, Sheet.Width / BlockSize);

            StartPoint = new Point(4 * BlockSize, 0);

            RandomBlock = rand.Next(0, 4);
            GetRandomBlock();
            RandomBlock = rand.Next(0, 4);
            RImage = DrawRandomBlock();

            Board.ArrivedAtBottom += Board_ArrivedAtBottom;



            timer1.Interval = 700;
            timer1.Enabled = false;

        }
Ejemplo n.º 2
0
        public T_Block(Point Location, int position, int BlockSize, Board board)
        {
            this.BlockSize = BlockSize;

            this.Location = Location;

            this.Position = position;
            this.board = board;
            BoardLocation = new Point(Location.X / BlockSize, Location.Y / BlockSize);

            ChangeCoordinates();
            SetMeasurements();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Default contructor for the Tetris class
 /// </summary>
 public Tetris()
 {
     InitializeComponent();
     this.DoubleBuffered = true;
     this.highScore = 0;
     this.textBoxHighScore.Text = this.highScore.ToString();
     this.currentTickInterval = this.baseTickInterval;
     this.paused = false;
     this.board = new Board();
     this.drawBackgroundBoard();
     wplayer.URL = "tetris.mp3";
     wplayer.settings.setMode("loop", true);
     wplayer.settings.volume = 20;
 }
Ejemplo n.º 4
0
        public Block(int TypeBlock,Point Location,Board board)
        {
            this.board = board;
            this.d = Location;
           
            this.TypeBlock = TypeBlock;
            switch(typeBlock)
            {
                case 0://T-Block
                       skeleton =new bool[3,3]{
                           { false,false,false},
                           { true,true,true},
                           { false,true,false}, 
                       };

                    unit = Resources.Blue;
                    break;
                case 1://O-Block

                    skeleton = new bool[2, 2]{
                           { true,true},
                           { true,true}
                       };
                    unit = Resources.Orange;
                    break;
                case 2://I-Block
                    skeleton = new bool[4, 4]{
                        { false,false,false,false},
                        { true,true,true,true},
                        { false,false,false,false},
                        { false,false,false,false}
                    };
                    unit = Resources.Yellow;
                    break;
                case 3://S-Block
 
                    skeleton = new bool[3, 3]{
                           { false,false,false},
                           { false,true,true},
                           { true,true,false},
                       };
                    unit = Resources.BlueGreen;
                    break;
                case 4://Z-Block
                    skeleton = new bool[3, 3]{
                           { false,false,false},
                           { true,true,false},
                           { false,true,true},
                       };
                    unit = Resources.Gray;
                    break;
                case 5://L-Block
                    skeleton = new bool[3, 3]{
                           { false,false,false},
                           { true,true,true},
                           { true,false,false},
                       };
                    unit = Resources.Strongblue;
                    break;
                case 6://J-Block

                    skeleton = new bool[3, 3]{
                           { false,false,false},
                           { true,true,true},
                           { false,false,true},
                       };
                    unit = Resources.Purple;
                    break;
            }

        }
Ejemplo n.º 5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Add the SpriteBatch service
            Services.AddService(typeof(SpriteBatch), spriteBatch);            

            //Load 2D textures
            tetrisBackground = Content.Load<Texture2D>("background");
            tetrisTextures = Content.Load<Texture2D>("tetris");

            // Load game font
            gameFont = Content.Load<SpriteFont>("font");

            // Create game field
            board = new Board(this, ref tetrisTextures, blockRectangles);
            board.Initialize();
            Components.Add(board);

            // Save player's score and game level
            score = new Score(this, gameFont);
            score.Initialize();
            Components.Add(score);

            // Load game record
            using (StreamReader streamReader = File.OpenText("record.dat"))
            {
                string player = null;
                if ((player = streamReader.ReadLine()) != null)
                    score.RecordPlayer = player;
                int record = 0;
                if ((record = Convert.ToInt32(streamReader.ReadLine())) != 0)
                    score.RecordScore = record;
            }
        }
Ejemplo n.º 6
0
 void GameStart()
 {
     MainGrid.Children.Clear();
     myBoard = new Board(MainGrid);
     Timer.Start();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Resets the game
 /// </summary>
 private void reset()
 {
     this.resetTextFields();
     this.board = new Board();
     this.currentLevel = board.currentLevel;
     this.playing = true;
     this.tickTimer.Interval = this.baseTickInterval;
     this.tickTimer.Enabled = true;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Loads a game
 /// </summary>
 private void loadGame()
 {
     Stream instream;
     BinaryFormatter bin_format = new BinaryFormatter();
     OpenFileDialog open_dialog = new OpenFileDialog();
     ArrayList list;
     //deserialize objects
     if (open_dialog.ShowDialog() == DialogResult.OK)
         if ((instream = open_dialog.OpenFile()) != null)
         {
             list = (ArrayList)bin_format.Deserialize(instream);
             instream.Close();
             //set up objects
             this.board = (Board)list[0];
         }
     this.updateGameBoard();
     this.pauseGame();
 }
Ejemplo n.º 9
0
 //Run to start/reset the game
 public static void Start()
 {
     PlayerBoard = new Board(new Rectangle((screenWidth - (boardWidth * gridSize)) / 2,
             (screenHeight - (boardHeight * gridSize)) / 2, boardWidth * gridSize, boardHeight * gridSize));
     GameBoards.Add(PlayerBoard);
     gameState = GameState.Play;
     PlayerBoard.fillUpcomingPieces();
     PlayerBoard.changeCurrentPiece();
     Highscore.ReadFromFile();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Resets the game
 /// </summary>
 private void resetGame()
 {
     board = new Board(numberOfRows, numberOfColumns);
     tickTimer.Enabled = true;
     playing = true;
 }