Brian S
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Clearing Lines In order to implement Clearing Lines we must first create a new method called __clearLines()__. I think this should be part of the __mergeMatrix()__ method where it will be called. __clearLines()__ will implement another method called __checkForLines()__ which will check to see if any of the lines (that encompass the x axis length of the brick just placed) are now apart of a full line in the Board Matrix. __clearLines()__ will also implement the method __lowerBricks()__. __lowerBricks()__ will go the length of the y axis and check every position of the x axis (from the position of the cleared line) and lower all bricks above the position a set amount of length. # A Detailed Look Clearing Lines is fairly simple but it has a lot of moving parts. The bricks move around the board matrix until they reach the bottom of the board or until they encounter another brick.[^1] If this creates a full row of bricks then the row is cleared. To implement this behavior we need a couple of methods: 1. __mergeMatrix()__ ```java public static int[][] mergeMatrix(int[][] filledFields, int[][] brick, int x, int y) { int[][] copy = copyMatrix(filledFields); for (int i = 0; i < brick.length; i++) { for (int j = 0; j < brick[i].length; j++) { int targetX = x + i; int targetY = y + j; if (brick[j][i] != 0) { copy[targetY][targetX] = brick[j][i]; } } } return copy; } ``` __mergeMatrix()__ is the method used to fuse a brick with the game board. This is already in the overall Java project but it needs to be updated. This is where we will add in the __clearLines()__ method. This is TBD because the clear lines method can appear in other places especially if we want to create pacing for presenting visually all the different effects (the lines clearing visual, scoring visual, bricks falling visual, etc.) 2. __clearLines()__ ```java public void clearLines(){ int linesToBeCleared[] = mainBoard.checkForLines(); //will check to see if there are any lines that need to be cleared and return those lines x axis value into an array //we then will clear the lines from the board looping through the array //to achieve this we simply need to go to those rows in the board matrix and then change the whole row to 0s int numLinesCleared = linesToBeCleared.length; lowerBricks(linesToBeCleared); } ``` __clearLines()__ is the method that will be ran to check if any of the lines in which the brick that was just placed in will be cleared and thus scored. It will check all the rows that the brick just placed spans and then check to see if every x unit on the y axis is occupied. If it is then the line is cleared and added to an int variable (int __numLinesCleared)__. This int will be used for scoring. 3. __checkForlines()__ ```java /* This method will need to be ran on the background board that is used to maintain the status of the bricks that have already been placed. We can also use this method to then get the length of the array we return for use in calculating the score multiplier. (length of the array would = lines cleared) The Array we return will never be over 4 since no brick is over 4 spaces in length */ @Override public int[] checkForLines() { ArrayList<Integer> rowsToClear = new ArrayList<Integer>(); //I do not believe you can return an ArrayList so this is used to have a dynamic array we can add to for(int i = 0; i < currentGameMatrix.length; i++){ boolean full = false; //will be made True if the row is full int numUsed = 0; //this variable will track to see how much of the row is full for(int y = 0; y < currentGameMatrix[i].length; y++){ if (currentGameMatrix[i][y] > 0) { numUsed++; } } if(numUsed == currentGameMatrix[i].length){ //check to see if the whole array is full full = true; } if(full == true){ //if the row is full then add it to the list rowsToClear.add(i); } } if(rowsToClear.size() == 0){ //if there are no rows to be cleared then we return null return null; } int rowsToClearArray[] = new int[rowsToClear.size()]; //create an array that we can return to be used in another method for(int i = 0; i < rowsToClearArray.length; i++){ //add the elements of our ArrayList to the array we will return rowsToClearArray[i] = rowsToClear.get(i); } return rowsToClearArray; } } ``` __checkForLines()__ is a method that will go through all of the rows in the board matrix and put into an array all of the x values of the lines on the board that are full. This will tell the method __clearLines()__ which rows in the board matrix need to be cleared. #### Update #1 checkForLines() will return null if there are no lines to be cleared in the board. This is also not the most efficient way to check for lines because this method goes through all of the rows in the board. To make this more efficient we would need to only check the rows in which the most recent brick was placed. 4. __lowerBricks()__ ```java public void lowerBricks(int[] linesToBeCleared){ //this will lower all the bricks above the last element of the lines cleared //we will do something similiar to the other methods and loop through the board matrix //this will be a loop that will go through all the rows above the first line cleared and //lower all bricks until they come in contact with the bottom of the board or another row with bricks } ``` __lowerBricks()__ will take the array that has the rows that will be cleared (at this point already cleared) and lower all the bricks that are above that point down until it reaches another brick or the floor. It accomplishes this row by row.[^2] [^1]: An interesting note about this behavior is how this works in an actual Tetris game. In an actual Tetris game the brick does not merge or become part of the game board for a second after it commits a movement. One can move the brick left and right and even change it's rotation before merging for a couple seconds. This specific behavior is a bit complex to recreate. [^2]: Notice that all of the methods including mergeMatrix() loop through the board matrix. This can mean that all methods could be implemented at once and not as seperate methods to improve efficency. This would require some more advanced techniques (Recursion possibly?). Currently this implementation is inefficient as we loop through the board matrix ==four times(!)== every time a brick is placed.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully