Giter Site home page Giter Site logo

tetris's Introduction

테트리스 게임 [Tetris]

Vanilla JS 미니 프로젝트

source : 추억의 게임! 테트리스 HTML, Javascript로 만들기

실행

Screen Shot 2022-10-12 at 3 06 40 PM

Gameover

Screen Shot 2022-10-12 at 3 04 26 PM

실행과정 코드 설명

게임 실행

  1. init 함수 실행 시, 블럭의 타입, 방향, 좌표를 저장한 변수를 임시 저장한다.

Screen Shot 2022-10-12 at 3 13 47 PM

  1. prependNewLine 함수는 테트리스의 칸을 초기화해준다.

Screen Shot 2022-10-12 at 3 14 59 PM

  1. generateNewBlock 함수는 하나의 블럭의 움직임이 종료되면 다음 블럭을 생성해준다. 이때, 초기 변수값 duration의 속도로 블럭이 y축으로 1칸씩 움직이게 설정한다. BLOCKS 파일에 저장된 블럭의 유형을 랜덤으로 선정하여 movingItem에 저장하고 블럭의 초기값을 tempMovingItem에 저장한다. 이후 renderBlocks 함수로 블럭의 생성 및 움직임을 제어한다.

Screen Shot 2022-10-12 at 3 22 08 PM

블럭 움직임 조건

  1. renderBlocks 함수는 tempMovingItem에 저장된 변수 중 type 변수에 저장된 블럭이 실제로 이동했을 때 지정된 공간을 벗어나는지, 존재하는 블럭인지 등을 파악하여 가동 블럭인지 파악한다.(checkEmpty 함수를 사용)

Screen Shot 2022-10-12 at 3 33 08 PM

가동 블럭이라면, moving 타입을 부여하고 가동블럭이 아니고, retry 타입이라면 멈출 블럭인지 게임오버 상황인지 판단한다. 이때, 정지할 블럭은 타입을 seized로 바꿔준다.

Screen Shot 2022-10-12 at 3 44 18 PM

만약, 블럭이 정지했을 때, 같은 횡의 블럭이 모두 seized라면 그 줄의 블럭을 삭제하고 새로운 줄을 생성하면서 점수를 1점 증가시킨다.

Screen Shot 2022-10-12 at 3 48 04 PM

조건을 만족한 경우 movingItem에 좌표와 방향을 저장한다. Screen Shot 2022-10-12 at 3 42 59 PM

기타 조작

  1. 조작키 설정

Screen Shot 2022-10-12 at 3 49 41 PM

  1. restart 버튼 설정

Screen Shot 2022-10-12 at 3 51 00 PM

tetris's People

Contributors

hoya324 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.