SlideShare a Scribd company logo
TETRIS!
In MATLAB
진재훈 최두영
이하영 윤지혜
Supporter : 전유림
조교님
개요
실제 TETRIS MATLAB 에서 만든
TETRIS
TETRIS BOARD
HIGHEST
SCORE BOARD
SCORE BOARD
INPUT PLAYER
NAME
GAME
START / PAUSE
BGM SETTING
/ BGM PLAY
GAME
RESET
DIFFICULTY SETTING
PROJECT NAME
기능
TETRIS 의 RULE
① 총 7가지 block 이 랜덤하게 생성
② 생성된 block이 한 칸씩 내려옴
③ 좌우 버튼으로 block 위치를 옮김
④ 위 방향키로 block을 회전함
⑤ 바닥이나 다른 block에 의해 막히면
그 block이 멈추고 다음 block 이 내
려옴
⑥ 한 줄이 block으로 꽉 차면 그 줄이
사라짐
⑦ 쌓인 block이 맨 윗줄에 닿으면
Game Over 가 됨
추가 FUNCTION
① BGM 선택 , 반복 PLAY 기능
② 난이도 선택 기능
③ 점수/플레이어 표시 기능
④ 최고 기록의 점수/플레이어 표시
기능
⑤ 오류 대비나 빠른 재시작을 위한
RESET 기능
Coding – 보드 세팅
TETRIS BOARD
SETTING (틀 그려놓기),
axes 설정
테트리스 판을
미리 그려놓음
테트리스의 block 상태를 나타내
주는 행렬을 만듬.
Coding - 게임시작
SET으로 TIMER의 간격을 조절
함으로써 난이도 설정
Coding – BGM(1)
존재하는 파일을 audioread로
읽어옴
BGM의 PLAY 시간을 공식을 이용하
여 bgm.time 에 저장
BGM이 끝나면 다시 틀어줄
Timer를 생성
소리 정보를 audioplayer에 저장
Coding – BGM(2)
Play 시간을 공식으로 가져올 경우 자리수가 소수점 셋째자리를 넘어
가면 이러한 경고가 뜨므로 ceil을 통해 올림하여 사용한다.
Coding Coding – BGM(3)
AudioPlayer에 들어가는
값과, 반복 시간만 바꾸면
어떤 BGM이라도 사용 가
능
SET으로 TIMER를 재설정 하기
이전에 timer와 audioplayer를
멈춰야함
음악이 PLAY되고 있다면 그
음악을 종료하고 바뀐 노래를
재생
Coding – GAME RULE
Handles.board.data – 이 값이 바뀌면 그림으로 나타남
handles.board.state 변수를 사용함으로
써 한 함수로 여러 기능을 할 수 있게 함
Coding – Game Rule
Board.data 의 정보를 그림으로
표현
Board.data 의 값에 따라 색깔이
변화함
(0 이면 하얀색이라 보이지 않고,
6이면 ‘y’이므로 그 칸을 노란색
으로 칠함)
Disp_board 함수를 따로 만듦으로써 여러 함수에
서 board.data 가 바뀌면 별도의 코드를 작성할
필요 없이 이 함수를 실행시키면 되게 하였다.
CodingCoding – Game Rule
Board.rx와 board.ry는 각각 움직
이는 block이 현재 위치한 x좌표
와 y좌표, board.sb는
board.block의 행렬의 크기
Board.random을 곱해줌으로
써 각 모양이 다른 색깔을 띄
도록 해줌
이 함수에서 만들어진 Block에
관한 값들을 이용하여 블록을
왼쪽, 오른쪽, 아래로 이동시키
고 회전시키는 작업을 진행
Board.state 가 0 이면 실행 – 실
행완료후 board.state 1로 이동
Coding – Game Rule
(코드가 길고 반복적이라 일부
만 가져옴)
Board.ry가 1 즉, block 이 맨 아래칸에 있을 경우에는 아래
칸과 비교를 시도할 경우 오류가 나므로 if문을 사용
Switch문과 if 문을 반복적으로 사용하여
코드가 길어졌지만, 오류를 줄임.
원리 : 이 함수가 실행됐을 때, 각 세로열
의 가장 맨 아래 블록의 아래에 block이
있다면 이동을 멈추고 board.state가 변
화함
각 세로열의 맨 아래블
록을 알아보기 위해 a1,
a2, a3를 사용
A1=2 A2=0
Board.state 가 2이거나 아
래 버튼을 눌렀을 경우 실
행 – state가 실행가능하면
다시 2번, 불가능하면 3번
으로 이동
CodingCoding – Game Rule
CodingCoding – Game Rule
사용한 비교문과, 블록 이동을 살펴보기 위해 move_right의 코드를 가져옴
우선, 블록이 오른쪽 벽에 닿아있을 때 실행
하면 오류가 나므로 if문을 이용하여 그 경우
실행이 되지 않게 한다.
Board.sb(2) – block의 높이를 switch문에 넣
어 비교
각 블록을 하나하나 비교하여 오른쪽에 block이 없을 경우에만 실행되도
록 조건을 작성
CodingCoding – Game Rule
우선 기존 board.data에 있던 block을 지우기 전에 a에 저장한다.
새 data를 넣기 위해 Board.data에 저장되어있던 Block의 정보를 지운
다.(뺀다)
X위치데이터가 바뀐 새 Block을 Board.data에 다시 저장한다.(더한다)
바뀐 Block 정보만큼 handles.board.rx(보드의 x위치 정보)를 갱신한다.
총 네 STEP으로 Board 데이터 갱신을 완료하였다.
Coding – Game Rule
블록 돌리기도 마찬가지로 조건이 성립된다면 4 STEP의 DATA 갱신 과
정을 거친다.
Coding – Game Rule
Board.State 가 3이면 실행
(블록 아래로 내리기가 완료되면 새 블록을 만들
기 전에 실행)
만약 한 줄이 다 차면 그 줄의 위치를
clr에 저장한다.
만약 clr이 0이 아닐 경우( 다 찬 줄이
있을 경우) 그 줄을 지우고 그 위의
줄들을 한 칸씩 내린다. 또한, 점수를
100점 추가한다.
만약 20번째 (맨 위) 줄에 block 이
있다면 게임을 종료하기 위해 state 2
로 간다.
정상적으로 종료되었다면 다시 block
을 만들기 위해 state 0으로 간다.
Coding – Game Rule
State 가 2가 되거나 reset
버튼을 누르면 게임이 종
료된다.
START 버튼의 string 이
GAME OVER로 바뀌고,
모든 값이 초기값으로 변
한다.
최고기록과 점수를 비교하여 최고기록보다 높
으면 최고점수/플레이어를 갱신한다.
Coding – Game Rule
Set_board와 마찬가지로 다
른 함수를 실행하기 위한 중
간함수
게임이 Play중일 때만 동작하
도록 전체에 if문을 걸고 조건
으로 timer가 돌고 있을 때
실행되도록 주었다.
위 버튼은 block 돌리기,
아래 버튼은 block 내리기,
좌우 버튼은 각각 block을 좌
우로 이동시키는 버튼이다.
이는 모두 block이 내려오고
있을 때만 의미가 있으므로
board.state가 1일 때만 동작
하도록 하였다.
Q&A
THE END
~감사합니다~

More Related Content

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 

Featured (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Matlab tetris

  • 1. TETRIS! In MATLAB 진재훈 최두영 이하영 윤지혜 Supporter : 전유림 조교님
  • 2. 개요 실제 TETRIS MATLAB 에서 만든 TETRIS
  • 3. TETRIS BOARD HIGHEST SCORE BOARD SCORE BOARD INPUT PLAYER NAME GAME START / PAUSE BGM SETTING / BGM PLAY GAME RESET DIFFICULTY SETTING PROJECT NAME
  • 4. 기능 TETRIS 의 RULE ① 총 7가지 block 이 랜덤하게 생성 ② 생성된 block이 한 칸씩 내려옴 ③ 좌우 버튼으로 block 위치를 옮김 ④ 위 방향키로 block을 회전함 ⑤ 바닥이나 다른 block에 의해 막히면 그 block이 멈추고 다음 block 이 내 려옴 ⑥ 한 줄이 block으로 꽉 차면 그 줄이 사라짐 ⑦ 쌓인 block이 맨 윗줄에 닿으면 Game Over 가 됨 추가 FUNCTION ① BGM 선택 , 반복 PLAY 기능 ② 난이도 선택 기능 ③ 점수/플레이어 표시 기능 ④ 최고 기록의 점수/플레이어 표시 기능 ⑤ 오류 대비나 빠른 재시작을 위한 RESET 기능
  • 5. Coding – 보드 세팅 TETRIS BOARD SETTING (틀 그려놓기), axes 설정 테트리스 판을 미리 그려놓음 테트리스의 block 상태를 나타내 주는 행렬을 만듬.
  • 6. Coding - 게임시작 SET으로 TIMER의 간격을 조절 함으로써 난이도 설정
  • 7. Coding – BGM(1) 존재하는 파일을 audioread로 읽어옴 BGM의 PLAY 시간을 공식을 이용하 여 bgm.time 에 저장 BGM이 끝나면 다시 틀어줄 Timer를 생성 소리 정보를 audioplayer에 저장
  • 8. Coding – BGM(2) Play 시간을 공식으로 가져올 경우 자리수가 소수점 셋째자리를 넘어 가면 이러한 경고가 뜨므로 ceil을 통해 올림하여 사용한다.
  • 9. Coding Coding – BGM(3) AudioPlayer에 들어가는 값과, 반복 시간만 바꾸면 어떤 BGM이라도 사용 가 능 SET으로 TIMER를 재설정 하기 이전에 timer와 audioplayer를 멈춰야함 음악이 PLAY되고 있다면 그 음악을 종료하고 바뀐 노래를 재생
  • 10. Coding – GAME RULE Handles.board.data – 이 값이 바뀌면 그림으로 나타남 handles.board.state 변수를 사용함으로 써 한 함수로 여러 기능을 할 수 있게 함
  • 11. Coding – Game Rule Board.data 의 정보를 그림으로 표현 Board.data 의 값에 따라 색깔이 변화함 (0 이면 하얀색이라 보이지 않고, 6이면 ‘y’이므로 그 칸을 노란색 으로 칠함) Disp_board 함수를 따로 만듦으로써 여러 함수에 서 board.data 가 바뀌면 별도의 코드를 작성할 필요 없이 이 함수를 실행시키면 되게 하였다.
  • 12. CodingCoding – Game Rule Board.rx와 board.ry는 각각 움직 이는 block이 현재 위치한 x좌표 와 y좌표, board.sb는 board.block의 행렬의 크기 Board.random을 곱해줌으로 써 각 모양이 다른 색깔을 띄 도록 해줌 이 함수에서 만들어진 Block에 관한 값들을 이용하여 블록을 왼쪽, 오른쪽, 아래로 이동시키 고 회전시키는 작업을 진행 Board.state 가 0 이면 실행 – 실 행완료후 board.state 1로 이동
  • 13. Coding – Game Rule (코드가 길고 반복적이라 일부 만 가져옴) Board.ry가 1 즉, block 이 맨 아래칸에 있을 경우에는 아래 칸과 비교를 시도할 경우 오류가 나므로 if문을 사용 Switch문과 if 문을 반복적으로 사용하여 코드가 길어졌지만, 오류를 줄임. 원리 : 이 함수가 실행됐을 때, 각 세로열 의 가장 맨 아래 블록의 아래에 block이 있다면 이동을 멈추고 board.state가 변 화함 각 세로열의 맨 아래블 록을 알아보기 위해 a1, a2, a3를 사용 A1=2 A2=0 Board.state 가 2이거나 아 래 버튼을 눌렀을 경우 실 행 – state가 실행가능하면 다시 2번, 불가능하면 3번 으로 이동
  • 15. CodingCoding – Game Rule 사용한 비교문과, 블록 이동을 살펴보기 위해 move_right의 코드를 가져옴 우선, 블록이 오른쪽 벽에 닿아있을 때 실행 하면 오류가 나므로 if문을 이용하여 그 경우 실행이 되지 않게 한다. Board.sb(2) – block의 높이를 switch문에 넣 어 비교 각 블록을 하나하나 비교하여 오른쪽에 block이 없을 경우에만 실행되도 록 조건을 작성
  • 16. CodingCoding – Game Rule 우선 기존 board.data에 있던 block을 지우기 전에 a에 저장한다. 새 data를 넣기 위해 Board.data에 저장되어있던 Block의 정보를 지운 다.(뺀다) X위치데이터가 바뀐 새 Block을 Board.data에 다시 저장한다.(더한다) 바뀐 Block 정보만큼 handles.board.rx(보드의 x위치 정보)를 갱신한다. 총 네 STEP으로 Board 데이터 갱신을 완료하였다.
  • 17. Coding – Game Rule 블록 돌리기도 마찬가지로 조건이 성립된다면 4 STEP의 DATA 갱신 과 정을 거친다.
  • 18. Coding – Game Rule Board.State 가 3이면 실행 (블록 아래로 내리기가 완료되면 새 블록을 만들 기 전에 실행) 만약 한 줄이 다 차면 그 줄의 위치를 clr에 저장한다. 만약 clr이 0이 아닐 경우( 다 찬 줄이 있을 경우) 그 줄을 지우고 그 위의 줄들을 한 칸씩 내린다. 또한, 점수를 100점 추가한다. 만약 20번째 (맨 위) 줄에 block 이 있다면 게임을 종료하기 위해 state 2 로 간다. 정상적으로 종료되었다면 다시 block 을 만들기 위해 state 0으로 간다.
  • 19. Coding – Game Rule State 가 2가 되거나 reset 버튼을 누르면 게임이 종 료된다. START 버튼의 string 이 GAME OVER로 바뀌고, 모든 값이 초기값으로 변 한다. 최고기록과 점수를 비교하여 최고기록보다 높 으면 최고점수/플레이어를 갱신한다.
  • 20. Coding – Game Rule Set_board와 마찬가지로 다 른 함수를 실행하기 위한 중 간함수 게임이 Play중일 때만 동작하 도록 전체에 if문을 걸고 조건 으로 timer가 돌고 있을 때 실행되도록 주었다. 위 버튼은 block 돌리기, 아래 버튼은 block 내리기, 좌우 버튼은 각각 block을 좌 우로 이동시키는 버튼이다. 이는 모두 block이 내려오고 있을 때만 의미가 있으므로 board.state가 1일 때만 동작 하도록 하였다.
  • 21. Q&A