Giter Site home page Giter Site logo

Comments (2)

Yeram522 avatar Yeram522 commented on June 23, 2024

๐Ÿ’ก ์˜ˆ์ƒํ–ˆ๋˜ ๋Œ€๋กœ ์ค‘๋ณต์ด ๋ฌธ์ œ์˜€๋‹ค.
๋””๋ฒ„๊น… ์ „์— ๋Œ€์ถฉ "์ค‘๋ณต"๋ฌธ์ œ๋ผ๊ณ  ์˜ˆ์ƒํ•ด์„œ, ์ผ๋ถ€๋กœ ํ•จ์ˆ˜ ๋”ฐ๋กœ ๊ตฌํ˜„ํ•ด์„œ ํ–ˆ๋˜๊ฑด๋ฐ,,;;
์ค‘๊ฐ„์— ๋‚œ ์™œ ๋ˆˆ์น˜๋ฅผ ๋ชป์ฑ˜์ง€.. ํ•จ์ˆ˜ ๋กœ์ง ๋‹ค์‹œ ์‚ดํŽด๋ด์•ผ๊ฒ ๋‹ค.

image

void Screen::Set_Filed(const int _size, const int _spot, Field* _fields)//๋งค๊ฐœ๋ณ€์ˆ˜: ๋žœ๋ค ์ง€๋ขฐ๊ฐœ์ˆ˜.
{
	int placed_count= _spot;
	int* seeds = new int[_size]; //๋žœ๋ค๊ฐ’ ์ค‘๋ณต ๋ฐฉ์ง€๋ฅผ ์œ„ํ•ด ๊ฐ’ ์ €์žฅ.
	memset(seeds, -1, sizeof(seeds));
	while (placed_count > 0)
	{
		int i = (rand() % (_size-1) + 1);// 1 ~ size ๊นŒ์ง€

		if ((i >= 11 && i % 11 == 0) || Check_OverLap_Seed(seeds, i)) continue;
		seeds[_spot - placed_count] = i;
		_fields[i - 1].Changestate(STATE_SPOT);
		placed_count--;
	}
	
	delete[] seeds;
}
//randseed ์ค‘๋ณต ์ฒดํฌ ํ•จ์ˆ˜: ๊ฒ€์‚ฌํ•  ๊ฐ’์„ ๋„ฃ๊ณ  ์ค‘๋ณต์ด ์—†์œผ๋ฉด false๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
bool Screen::Check_OverLap_Seed(int* _seeds,const int _seed)
{
	for (int i = 0; i < sizeof(_seeds); i++)
	{
		if (_seeds[i] == _seed) return true;
	}

	return false;
}

from opp-mine-sweeper-game.

Yeram522 avatar Yeram522 commented on June 23, 2024

image

โœ… ๋””๋ฒ„๊ฑฐ๋กœ ๊ฐ’ ๋„ฃ์œผ๋ฉด์„œ ๋Œ๋ฆฐ ๊ฒฐ๊ณผ, seeds์˜ ๋ฐฐ์—ด์ด ์ œ๋Œ€๋กœ ์ดˆ๊ธฐํ™” ์•ˆ๋˜๋Š” ์ ์„ ๋ฐœ๊ฒฌํ–ˆ๋‹ค.
๊ทธ๋ž˜์„œ sizeof์˜ ๊ฐ’์„ ์ฐ์–ด๋ณด๋‹ˆ...ํฌ๊ธฐ๊ฐ€ 4๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฒƒ์ด๋‹ค.
sizeof ํ•จ์ˆ˜์˜ ์“ฐ์ž„์„ ์ œ๋Œ€๋กœ ์•Œ์ง€ ๋ชปํ•˜๊ณ  ์‚ฌ์šฉํ•œ ๋‚ด ์‹ค์ˆ˜์˜€๋‹ค.ใ… ใ… ใ… 
sizeof๊ฐ€ ์•„๋‹Œ ๋ฐฐ์—ด ์‚ฌ์ด์ฆˆ๋ฅผ ๋„ฃ์–ด์ฃผ๋‹ˆ, ์ œ๋Œ€๋กœ ์ดˆ๊ธฐํ™”๊ฐ€ -1๋กœ ๋˜์—ˆ๊ณ , ์ค‘๋ณต ๊ฒ€์‚ฌ ํ•จ์ˆ˜๋„ ๋ถˆํ•„์š”ํ•œ ํƒ์ƒ‰์„ ์ค„์ด๊ธฐ ์œ„ํ•ด์„œ
while๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ”๊พธ์—ˆ๋‹ค.

//randseed ์ค‘๋ณต ์ฒดํฌ ํ•จ์ˆ˜: ๊ฒ€์‚ฌํ•  ๊ฐ’์„ ๋„ฃ๊ณ  ์ค‘๋ณต์ด ์—†์œผ๋ฉด false๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
bool Screen::Check_OverLap_Seed(const int* _seeds,const int _seed)
{
	int i = 0;
	while (_seeds[i] != -1)
	{
		if (_seeds[i] == _seed) return true;
		i++;
	}

	return false;
}

from opp-mine-sweeper-game.

Related Issues (7)

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.