Giter Site home page Giter Site logo

samcode011 / project-tetris Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 2.89 MB

Educational repository for continuous learning, focused on enhancing JavaScript language skills.

Home Page: https://samcode011.github.io/Project-Tetris/

HTML 28.87% CSS 71.13%

project-tetris's Introduction

Tetris project

I've enhanced my JavaScript skills by incorporating the following functions and techniques into my code:

  • querySelector()
  • addEventListener()
  • Array.from()
  • Math.floor()
  • forEach()
  • classList
  • setInterval()
  • clearInterval()
  • style.backgroundImage
  • getElementByClassName()
  • splice()
  • some()
  • concat()
  • appendChild()
  • Arrow Functions

These tools have allowed me to develop more efficient and cleaner code, improving the quality and functionality of my projects.

Project Presentation

Important Notes

  • Application of Two-Dimensional Tetrominos in Programming
const lTectromino = [
    [1 ,GRID_WIDTH +1 ,GRID_WIDTH *2 +1 ,2],
    [GRID_WIDTH,GRID_WIDTH +1,GRID_WIDTH+2,GRID_WIDTH*2+2],
    [1,GRID_WIDTH+1,GRID_WIDTH*2+1,GRID_WIDTH*2],
    [GRID_WIDTH,GRID_WIDTH*2,GRID_WIDTH*2+1,GRID_WIDTH*2+2]
]
const zTetromino = [
    [0, GRID_WIDTH, GRID_WIDTH + 1, GRID_WIDTH * 2 + 1],
    [GRID_WIDTH + 1, GRID_WIDTH + 2, GRID_WIDTH * 2, GRID_WIDTH * 2 + 1],
    [0, GRID_WIDTH, GRID_WIDTH + 1, GRID_WIDTH * 2 + 1],
    [GRID_WIDTH + 1, GRID_WIDTH + 2, GRID_WIDTH * 2, GRID_WIDTH * 2 + 1]
  ]
  const tTetromino = [
    [1, GRID_WIDTH, GRID_WIDTH + 1, GRID_WIDTH + 2],
    [1, GRID_WIDTH + 1, GRID_WIDTH + 2, GRID_WIDTH * 2 + 1],
    [GRID_WIDTH, GRID_WIDTH + 1, GRID_WIDTH + 2, GRID_WIDTH * 2 + 1],
    [1, GRID_WIDTH, GRID_WIDTH + 1, GRID_WIDTH * 2 + 1]
  ]

const oTetromino = [
    [0, 1, GRID_WIDTH, GRID_WIDTH + 1],
    [0, 1, GRID_WIDTH, GRID_WIDTH + 1],
    [0, 1, GRID_WIDTH, GRID_WIDTH + 1],
    [0, 1, GRID_WIDTH, GRID_WIDTH + 1]
  ]
  const iTetromino = [
    [1, GRID_WIDTH + 1, GRID_WIDTH * 2 + 1, GRID_WIDTH * 3 + 1],
    [GRID_WIDTH, GRID_WIDTH + 1, GRID_WIDTH + 2, GRID_WIDTH + 3],
    [1, GRID_WIDTH + 1, GRID_WIDTH * 2 + 1, GRID_WIDTH * 3 + 1],
    [GRID_WIDTH, GRID_WIDTH + 1, GRID_WIDTH + 2, GRID_WIDTH + 3]
  ]

const theTetrominoes =[lTectromino,zTetromino,tTetromino,oTetromino,iTetromino]
  • Handling Keyboard Events for Movement Control in a Game
function control(e) {
   if (e.key === "ArrowRight")
   moveright()
else if (e.key === "ArrowUp")
rotate()
else if (e.key === "ArrowLeft")
moveleft()
else if (e.key === "ArrowDown")
moveDown()
}
  • Horizontal Movement Functions with Collision Prevention in a Game
 function moveright() {
   undraw()
   const isAtRightEdge = current.some(index => (currentPosition + index) % width === width - 1)
   if (!isAtRightEdge) currentPosition += 1
   if (current.some(index => squares[currentPosition + index].classList.contains('block2'))) {
     currentPosition -= 1
   }
   draw()
 }

 
 function moveleft() {
   undraw()
   const isAtLeftEdge = current.some(index => (currentPosition + index) % width === 0)
   if (!isAtLeftEdge) currentPosition -= 1
   if (current.some(index => squares[currentPosition + index].classList.contains('block2'))) {
     currentPosition += 1
   }
   draw()
 }
  • These notes are intended to assist you with any questions regarding the game's functionality. While there are other important components, I've chosen to emphasize these points as they were areas that I personally found challenging to grasp.

Tetris-CSS

I will focus solely on the use of global styles in CSS

.block {
    background-image:url(../images/blue_block.png) ;
}
.block2 {
    background-image: url(../images/purple_block.png);
}
.block3 {
    background-image: url(../images/green_block.png);
}
.block4 {
    background-image: url(../images/navy_block.png);
}
.block5 {
     background-image: url(../images/pink_block.png);
}
.end {
    background-color: #d8edea;
}

CopyRight (c) 2020-2023 Ania Kubow-SamFlores

This project is undertaken for educational and learning purposes, contributing to my professional development. I hope it serves as a guide for your personal projects and professional growth.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

*Translation: Ofcourse you can use this for you project! Just make sure to say where you got this from

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

project-tetris's People

Contributors

samcode011 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.