Comments (6)
โ Field ์์น ์ ๋ณด ์ด๊ธฐํ ์๋จ
โ Clicked์ ๋ชจ๋ ๋ฐฐ์ด์ด ์ด๋ ค๋ฒ๋ฆฌ๋ ์ค๋ฅ
from opp-mine-sweeper-game.
๐ก Staticํจ์ ์์์ static์ด ์๋ ํจ์๋ฅผ ๋ถ๋ฌ์์ ๊ทธ๋ ๋ค!
์ด๋ป๊ฒ ํด๊ฒฐํ๋ฉด ์ข์์ง ๊ณ ๋ฏผํด๋ณด์!
from opp-mine-sweeper-game.
void Game2D::MouseEventProc(MOUSE_EVENT_RECORD mer)
ํจ์๋ฅผ unstatic์ผ๋ก ๋ง๋ค์๋๋ฐ, ๊ทธ๋๋ main.cpp์ ํจ์๋ฅผ ๋ค๋ฅธ .cpp์์ ์ฌ์ฉํ๋ ค๋ฉด main.h๊ฐ ํ์ํ๊ฒ ๋๋ค. ๊ทธ๋์ main.h๋ฅผ ๋ฐ๋ก ๋ง๋ค์๋๋ฐ? ์ ์ ์๋ ์ค๋ฅ๊ฐ ๋๋ค. ์๊ทธ๋ฐ์ง ์ด์ ๋ ๋ชป์ฐพ์.
๊ทธ๋์ Field๋ฅผ static ๋ณ์๋ก ๋ง๋ค๊ธฐ๋ก ํ๋ค.
from opp-mine-sweeper-game.
ํด๋์ค์ static ๋ณ์๋ ํด๋น ํด๋์ค์ ๋ฉค๋ฒ๋ณ์๋ก ์ํ์ง ์๊ธฐ ๋๋ฌธ์, ์์ฑ์์์ ์ด๊ธฐํ ํด์ค ์ ์์ด์, ์์ฑ์ ํจ์์ ์ด๊ธฐํ ํ๋ ์ฝ๋๋ฅผ ๋ฃ์์ง๋ง, ์์ ๊ฐ์ด ์ค๋ฅ๊ฐ ๋ฌ๋ค.
์ค๋ฅ๊ฐ ๋ ์ด์ ๋, ๋ค์๊ณผ ๊ฐ๋ค.
์ถ์ฒ
ํด๋์ค์์์ static๋ณ์๋ ๋ชจ๋ ํด๋์ค ์ธ๋ถ์์ ์ ์ธํด ์ฃผ์ด์ผ ํฉ๋๋ค.
๊ทธ ์ฑ์ง์ static๋ณ์๋ ์ ์ญ๋ณ์์ ๊ฐ์ง๋ง, ์ค์ฝํ๋ง ํด๋์ค ์ค์ฝํ์ ์์๋ ์ ์ญ๋ณ์๋ผ๊ณ ๋ณด๋ ๊ฒ์ด ํ๋นํฉ๋๋ค. ๋ฐ๋ผ์ ์ ์ญ๋ณ์์ ๊ฐ์ ์์น์์ ์ ์ธ๋๋ ๊ฒ์ด์ง์.
๊ทธ๋์ ์ธ๋ถ์ static์ ํ๋ฒ ์ ์ธํด์ฃผ์๋๋ ํด๊ฒฐ ๋์๋ค.
๐ก๊ทผ๋ฐ cpp๋ ๊ฐ์ฒด์งํฅ์ธ๋ฐ, ํด๋์ค ์์ ํด๋์ค์ static ์ ์ญ๋ณ์๋ฅผ ์ ์ธํ๋ฉด ์ค๋ฅ๊ฐ ๋๋์ง ๋ชจ๋ฅด๊ฒ ๋ค..
โField๋ฅผ static์ผ๋ก ํด์ฃผ๋ ๊ฒฝ์ฐ์ ๊ด๋ จ๋ ํจ์๋ static์ผ๋ก ๋ฐ๊ฟ์ผ ํ๊ณ , ์ฌ๋ฌ๋ชจ๋ก ๋ชจ๋ ๊ฒ์ ์ ์ญ๋ณ์๋ก ๋ฐ๊ฟ์ผ ๋๋ ์ํฉ์ด ์์ ์์ ์์ด๋์ด๋ ๋ชจ๋ ์ฒ ํํ๊ธฐ๋ก ํ๋ค.
from opp-mine-sweeper-game.
void update() override
{
Game2D::Update_UI(this->flag_count);
if (Game2D::IsMouseClicked)
{
for (int i = 0; i < 10*11; i++)
{
WindowPos fieldpos = fields[i].GetWinpos();//์ง์ญ๋ณ์
Borland::gotoxy(0, 20);
printf("Clicked %d %d\n%d %d", fieldpos.x, fieldpos.y, ClickedPos.x, ClickedPos.y);
Borland::gotoxy(0, 1);
if (fieldpos.x == ClickedPos.x && fieldpos.y == ClickedPos.y)
fields[i].Clicked();
}
}
draw(pos, fields);
render();
}
main.cpp ์์ ์
๋ ฅ ์ด๋ฒคํธ๊ฐ ์ผ์ด๋ ์ ์๊ฒ ๋ฐ๊พธ์๋ค.
๊ทธ๋ฐ๋ฐ, ๊ฐ๊ฐ ํ๋์ ์์น์ ๋ณด์ ์ด๊ธฐํ๊ฐ ์ ๋๋ก ์๋ ๊ฒ ๊ฐ๋ค..ใ
ใ
from opp-mine-sweeper-game.
๐ํด๊ฒฐ
void Init_Winpos(int _index)
{
Winpos.x = 3 + (_index - (_index / 11) * 11 - 1) * 4;
Winpos.y = _index / 11 + 2;
}
๋๋ฒ๊ฑฐ ๋๋ ค๋ณธ ๊ฒฐ๊ณผ ์์ ์ค๋ฅ ์์์.
void Clicked()
{
Isclicked = true;
Changestate(state);
}
Clickedํจ์์์ isclicked๋ง true๋ก ๋ฐ๊ฟ์ฃผ๊ณ , field์ shape ์ ์๋ฐ๊ฟ์ค์ ๋ชจ์ ์๋ฐ๋๊ฑฐ์์.
๋ชจ๋ ๋ฐฐ์ด์ด ์ด๋ ค๋ฒ๋ฆฌ๋ ์ค๋ฅ๊ฐ ์์ด์,,์ด์ ๋ ๋ชจ๋ฅด๊ฒ ์ง๋ง ใ
ใ
๊ทธ๋ฅ ํจ์์์ฒด๋ฅผ ์ธ๋ถ์ ์ ์ธํ์ง ์๊ณ ํด๋์ค ๋ด๋ถ์ ์ ์ธํ์. ์ด๊ฑด ๋์ค์ ๋ธ๋์น ๋ฐ๋ก ํ์ ์ง์ ํ์ธํด๋ด์ผ ํ ๊ฒ ๊ฐ๋ค. #9
from opp-mine-sweeper-game.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opp-mine-sweeper-game.