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; }
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(); }
/// <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; }
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; } }
/// <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; } }
void GameStart() { MainGrid.Children.Clear(); myBoard = new Board(MainGrid); Timer.Start(); }
/// <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; }
/// <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(); }
//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(); }
/// <summary> /// Resets the game /// </summary> private void resetGame() { board = new Board(numberOfRows, numberOfColumns); tickTimer.Enabled = true; playing = true; }