SlideShare a Scribd company logo
(Visual C++) 오목게임제작
제작자 : 쿠디(cooddy)
제작자 Blog =
Tistory : http://cooddy.tistory.com/
NAVER : http://blog.naver.com/cluedevil
게임 개요
• 1. 게임 시작 전 창 사이즈에 따라 오목판을 임의로 변경할 수 있다.
• 2. 마우스 오른쪽 클릭시 게임이 실행되며 게임 실행 후에는 한번 변경한 오목판을
다시 변경할 수 없다.
• 3. 마우스 오른쪽 클릭시 게임이 실행되고 오목을 실행한다.
• 4. 오(5)목이므로 육(‘6’)목 이상은 승리로 판정이 되지 않는다.
• 5. 한쪽이 5개의 돌을 나열시 승리로 판정이 된다.
[게임 스크린샷(Screen Shot)]
창 사이즈에 따라 오목판 그려주기
• WM_SIZE 메시지의 콜백 함수인 void OnSize(UNIT nType, int cx, int cy)를 사용
• 인자(parameter)인 cx와 cy인 창 크기에서 가로 크기와 세로크기를 나타낸다
• 가로 길이(cx)와 세로길이(cy) 인자를 전역 변수로 가져온다(전역변수 CPoint m_pt)
• m_pt.x = cx; (x축 길이를 전역변수로 가져옴)
• m_pt.y = cy; (y축 길이를 전역변수로 가져옴)
cy
cx
창 사이즈에 따라 오목판 그려주기
• 전역변수에 저장한 창 사이즈를 이용하여 오목판을 그려주기 위해서 변환을 가해준다
• Grid_X = (m_pt.x/30)-1;
Grid_Y = (m_pt.y/30)-1;
• 그려주는 오목판 한 칸의 길이를 30으로 할 것이기 때문에 전체 길이를 30으로 나눠주어 나온
갯수를 이용하여 그 갯수만큼 사각형을 그려준다
• for(y=0; y<Grid_Y; y++)
for(x=0;x<Grid_X; x++)
dc.Rectangle(20+30*x, 20+30*y, x*30+(20+30), y*30+(20+30));
• 처음 Rectangle()함수에서 각각 x와 y에 20을 더해준 이유는 처음 시작 원점을 (20,20)으로 하기 위함이고 뒤의 두
변수에 30씩을 더해준 이유는 사각형 한변의 길이를 30으로 할 것이기 때문
• 이렇게 그려주기 되면 창을 늘리거나 줄일 때 마다 동적으로 사각형의 칸이 변하는 것을 볼
수 있다.
오목판에 놓은 돌들을 2차원 동적 배열로 할당
• 오목판에 돌을 놓을 시, 해당 위치의 돌을 2차원 배열을 사용하여 저장함
• 여기서 2차원 배열은 동적으로 할당해준다
• ※2차원 배열 동적 할당 방법
• int **m_stone_pos;
m_stone_pos = (int**)malloc(sizeof(int*)*M_X);
for(int i=0; i<M_X;i++)
m_stone_pos[i] = (int*)malloc(sizeof(int)*M_X);
• 여기서 M_X는 그냥 내가 동적으로 할당하고 싶은 숫자입니다
m_stone_pos
M_X개 만큼 할당
M_X개 만큼 할당
M_X개 만큼 할당
M_X개 만큼 할당
M_X개 만큼 할당
M_X개 만큼 할당
M_X개 만큼 할당
[0][ ]
[1][ ]
[2][ ]
[3][ ]
[4][ ]
[5][ ]
오목판에 놓은 돌들을 2차원 동적 배열로 할당
• 배열을 동적으로 할당하는 이유는필요없는 메모리 낭비를 막고 싶기 때문
• 배열의 동적 할당은 처음 게임 시작전 화면의 사이즈로부터 배열의 크기를 가져와야 함
1. 사이즈로 부터 메모리를 동적으로 할당해준다
2. 동적으로 메모리를
할당해준다
3. 할당된 메모리를 전부 0으로 초기화 시켜준다
본격 게임시작
• 게임이 시작되고 돌을 놓게 되면 그 위치의 배열에 특정 값을 넣어준다
• 흰 돌 : m_stone_pos[x][y] = 1;
• 검은 돌 : m_stone_pos[x][y] = 6;
• 승리 조건은 돌 5개가 나란히 위치해 있는 것이므로 바둑 판을 스캔해서 돌 5개를 찾아야 함
• 총 4가지 방법의 스캔을 이용하여 나란히 놓여 있는 돌5개를 찾아야 함
• 가로,세로,대각선-1,대각선-2
1
2
3
4
승리 판단을 위한 4가지 방법
• 가로, 세로, 대각선-1, 대각선-2
• 1. 가로판정
• 가로의 경우 배열의 두번째는 변하지 않고 첫번째 경우가 증가하는 것을 볼 수 있음
• 즉, 배열의 2번째는 고정시키고 첫번째를 증가시켜 같은 숫자 5개가 있는 경우 승리로 판정 됨
• 하얀돌의 경우 1이 다섯개, 검은돌의 경우 6이 다섯개 인경우
• 2. 세로판정
• 세로의 경우, 배열의 첫번째는 변하지 않고 두번째 경우가 증가하는 것을 볼 수 있음
• 즉, 배열의 첫번째는 고정시키고 두번째를 증가시켜 같은 숫자 5개가 있는 경우 승리로 판정하면 됨
[0,0] [1,0] [2,0]
[0,1] [1,1] [2,1]
[0,2] [1,2] [2,2]
x-axis
y-axis
승리 판단을 위한 4가지 방법
• 3. 대각선 - 1
• 첫번째 대각선의 경우 배열의 첫번째는 증가하지만 두번째는 감소하는 것을 볼 수 있음
• 4. 대각선 – 2
• 두번째 대각선의 경우 배열의 첫번째와 두번째가 모두 증가하는 것을 볼 수 있음
[0,0] [1,0] [2,0]
[0,1] [1,1] [2,1]
[0,2] [1,2] [2,2]
x-axis
y-axis
Thank you

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
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
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
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...
 

Visual c++ 오목게임제작

  • 1. (Visual C++) 오목게임제작 제작자 : 쿠디(cooddy) 제작자 Blog = Tistory : http://cooddy.tistory.com/ NAVER : http://blog.naver.com/cluedevil
  • 2. 게임 개요 • 1. 게임 시작 전 창 사이즈에 따라 오목판을 임의로 변경할 수 있다. • 2. 마우스 오른쪽 클릭시 게임이 실행되며 게임 실행 후에는 한번 변경한 오목판을 다시 변경할 수 없다. • 3. 마우스 오른쪽 클릭시 게임이 실행되고 오목을 실행한다. • 4. 오(5)목이므로 육(‘6’)목 이상은 승리로 판정이 되지 않는다. • 5. 한쪽이 5개의 돌을 나열시 승리로 판정이 된다. [게임 스크린샷(Screen Shot)]
  • 3. 창 사이즈에 따라 오목판 그려주기 • WM_SIZE 메시지의 콜백 함수인 void OnSize(UNIT nType, int cx, int cy)를 사용 • 인자(parameter)인 cx와 cy인 창 크기에서 가로 크기와 세로크기를 나타낸다 • 가로 길이(cx)와 세로길이(cy) 인자를 전역 변수로 가져온다(전역변수 CPoint m_pt) • m_pt.x = cx; (x축 길이를 전역변수로 가져옴) • m_pt.y = cy; (y축 길이를 전역변수로 가져옴) cy cx
  • 4. 창 사이즈에 따라 오목판 그려주기 • 전역변수에 저장한 창 사이즈를 이용하여 오목판을 그려주기 위해서 변환을 가해준다 • Grid_X = (m_pt.x/30)-1; Grid_Y = (m_pt.y/30)-1; • 그려주는 오목판 한 칸의 길이를 30으로 할 것이기 때문에 전체 길이를 30으로 나눠주어 나온 갯수를 이용하여 그 갯수만큼 사각형을 그려준다 • for(y=0; y<Grid_Y; y++) for(x=0;x<Grid_X; x++) dc.Rectangle(20+30*x, 20+30*y, x*30+(20+30), y*30+(20+30)); • 처음 Rectangle()함수에서 각각 x와 y에 20을 더해준 이유는 처음 시작 원점을 (20,20)으로 하기 위함이고 뒤의 두 변수에 30씩을 더해준 이유는 사각형 한변의 길이를 30으로 할 것이기 때문 • 이렇게 그려주기 되면 창을 늘리거나 줄일 때 마다 동적으로 사각형의 칸이 변하는 것을 볼 수 있다.
  • 5. 오목판에 놓은 돌들을 2차원 동적 배열로 할당 • 오목판에 돌을 놓을 시, 해당 위치의 돌을 2차원 배열을 사용하여 저장함 • 여기서 2차원 배열은 동적으로 할당해준다 • ※2차원 배열 동적 할당 방법 • int **m_stone_pos; m_stone_pos = (int**)malloc(sizeof(int*)*M_X); for(int i=0; i<M_X;i++) m_stone_pos[i] = (int*)malloc(sizeof(int)*M_X); • 여기서 M_X는 그냥 내가 동적으로 할당하고 싶은 숫자입니다 m_stone_pos M_X개 만큼 할당 M_X개 만큼 할당 M_X개 만큼 할당 M_X개 만큼 할당 M_X개 만큼 할당 M_X개 만큼 할당 M_X개 만큼 할당 [0][ ] [1][ ] [2][ ] [3][ ] [4][ ] [5][ ]
  • 6. 오목판에 놓은 돌들을 2차원 동적 배열로 할당 • 배열을 동적으로 할당하는 이유는필요없는 메모리 낭비를 막고 싶기 때문 • 배열의 동적 할당은 처음 게임 시작전 화면의 사이즈로부터 배열의 크기를 가져와야 함 1. 사이즈로 부터 메모리를 동적으로 할당해준다 2. 동적으로 메모리를 할당해준다 3. 할당된 메모리를 전부 0으로 초기화 시켜준다
  • 7. 본격 게임시작 • 게임이 시작되고 돌을 놓게 되면 그 위치의 배열에 특정 값을 넣어준다 • 흰 돌 : m_stone_pos[x][y] = 1; • 검은 돌 : m_stone_pos[x][y] = 6; • 승리 조건은 돌 5개가 나란히 위치해 있는 것이므로 바둑 판을 스캔해서 돌 5개를 찾아야 함 • 총 4가지 방법의 스캔을 이용하여 나란히 놓여 있는 돌5개를 찾아야 함 • 가로,세로,대각선-1,대각선-2 1 2 3 4
  • 8. 승리 판단을 위한 4가지 방법 • 가로, 세로, 대각선-1, 대각선-2 • 1. 가로판정 • 가로의 경우 배열의 두번째는 변하지 않고 첫번째 경우가 증가하는 것을 볼 수 있음 • 즉, 배열의 2번째는 고정시키고 첫번째를 증가시켜 같은 숫자 5개가 있는 경우 승리로 판정 됨 • 하얀돌의 경우 1이 다섯개, 검은돌의 경우 6이 다섯개 인경우 • 2. 세로판정 • 세로의 경우, 배열의 첫번째는 변하지 않고 두번째 경우가 증가하는 것을 볼 수 있음 • 즉, 배열의 첫번째는 고정시키고 두번째를 증가시켜 같은 숫자 5개가 있는 경우 승리로 판정하면 됨 [0,0] [1,0] [2,0] [0,1] [1,1] [2,1] [0,2] [1,2] [2,2] x-axis y-axis
  • 9. 승리 판단을 위한 4가지 방법 • 3. 대각선 - 1 • 첫번째 대각선의 경우 배열의 첫번째는 증가하지만 두번째는 감소하는 것을 볼 수 있음 • 4. 대각선 – 2 • 두번째 대각선의 경우 배열의 첫번째와 두번째가 모두 증가하는 것을 볼 수 있음 [0,0] [1,0] [2,0] [0,1] [1,1] [2,1] [0,2] [1,2] [2,2] x-axis y-axis