1-4. ํํ ์ค ์์ดํ ํ๋ ํ ๋ฐฉ ํ์ ( ๊ฐฏ์ ๋ฐ ์์น, ์ต์ 3x3 - ์ ํฌ์ฉ ๋ฐฉ๊ณผ๋ ์๊ฒน์น๊ฒ )
์ข์ ๋ฐฉ์๋ ์์ดํ ์ด ๋จ์ด์ ธ์์ด ์ฃผ์ธ ์ ์์ด์ผํ๋ค.
StoreBattleRoom() ํจ์์์ ์ฌ์ฉํ ์๋ฃ๊ตฌ์กฐ๋ฅผ private๋ฉค๋ฒ๋ก ์ฎ๊ฒผ์ต๋๋ค.
dicGroundExist๋ ํด๋น ์ขํ์ ๋ฐ๋ฅ์ด ์๋์งํ์ธํ๋๊ฑฐ๊ตฌ์
listBattleRoom์ ์ ํฌ์ฉ-๋ฐฉ์ย ํผ๋ด ์์น๋ฅผ ์ ์ฅํฉ๋๋ค
listItemRoom์ ์์ดํ ํ๋ / ์ด๋ฒคํธ์ฉ ๋ฐฉ์ ํผ๋ด์์น๋ฅผ ์ ์ฅํฉ๋๋ค.
isListRoomForBattle์ ์ ํฌ์ฉ ๋ฐฉ์ ๋ฐ๋ฅํ์ผ์ ๊ธฐ์ตํ๊ณ ์์ด์/ ๋ค๋ฅธ๋ฐฉ ์์ฑ์ ์ ํฌ์ฉ ๋ฐฉ๊ณผ ์์ญ์ด ๊ฒน์น๋์ง ํ์ธํ๋ ์ฉ๋์ ๋๋ค.
isListRoomForItem์ ๋ง์ฐฌ๊ฐ์ง์ง๋ง ์์ดํ ํ๋์ฉ ๋ฐฉ์ ๋ฐ๋ฅ์ ๊ธฐ์ตํ๊ณ ์์ด์ ๋ค๋ฅธ๋ฐฉ๊ณผ ๊ฒน์น๋์ง ํ์ธํ๋ ์ฉ๋์ ๋๋ค.
์ข์๋ฐฉ(์์ดํ ํ๋์ฉ๋ฐฉ)์์น ์ ์ฅ์ฉ ํจ์๋ย
StoreItemRoom()์ด๋ผ๋ ์ด๋ฆ์ผ๋ก ๋ง๋ค์์ต๋๋ค.
--- ์ ์ทจ์ ---
private void StoreItemRoom(){
int len = GroundBlocksArray.Count;
GameObject tmpObj;
Vector3 tmpVector;
Vector2 tmpPivotRoom;
int tmpVal;
bool? tmpPivotExist;
Vector2 tmpNewPivotRoom;
List<Vector2> listNewRoomGround;
for(int i = 0; i < len; i++){
tmpObj = GroundBlocksArray[i] as GameObject;
tmpVector = tmpObj.transform.position;
bool isAvailableSizeItemRoom ย = true;
for(int y = 0; (y < 3) && isAvailableSizeItemRoom; ++y){
for(int x = 0; (x < 3) && isAvailableSizeItemRoom; ++x){
if( !dicGroundExist.ContainsKey(tmpVector+new Vector3(x,y,0)) ){
isAvailableSizeItemRoom = false;
} else if (isInRoomForBattle.ContainsKey( ย new Vector2(tmpVector.x+x, tmpVector.y+y) ) ) {ย
// ์ ํฌ์ฉ ๋ฐฉ๊ณผ ๊ฒน์น๋ฉด ์ ์ธ
isAvailableSizeItemRoom = false;
}
}
}
if(isAvailableSizeItemRoom){
// ํ์ฌ ์์น tmpVector๊ฐ ์์ดํ ํ๋์ฉ๋งต์ ๋ง๋ค๊ธฐ์ ์ ์ ํ ์์์ง์ ์ ( ๋ฐ๋ฅ์ด ๋น์นธ์ด ์๋ )
// + ์ ํฌ์ฉ ๋งต๊ณผ ๊ฒน์น์ง ์์
// ์ด๋ฏธ ์ ํฌ์ฉ ๋งต๊ณผ์ ๊ฒน์นจ์ ํด๊ฒฐ๋์ด์ผ๋จย
tmpPivotRoom = new Vector2(tmpVector.x, tmpVector.y);
listNewRoomGround = new List<Vector2>();
if(!isInRoomForItem.ContainsKey(tmpPivotRoom)){
bool roomBoundColision = false;
for(int y = 0; y < 3; ++y){
for(int x = 0; x < 3; ++x){
tmpNewPivotRoom = new Vector2( tmpPivotRoom.x + x , tmpPivotRoom.y + y );
if( !isInRoomForItem.ContainsKey(tmpNewPivotRoom) ){
listNewRoomGround.Add(tmpNewPivotRoom);
} else {
roomBoundColision = true;
}
}
}
if(!roomBoundColision){
listItemRoom.Add(tmpPivotRoom);
for(int k = 0; k < listNewRoomGround.Count; ++k){
isInRoomForItem.Add( listNewRoomGround[k], true );
}
}
}
}
}
int length = listItemRoom.Count;
Vector3 tmpVector3 = new Vector3(0,0,0);
for(int i = 0; i < length; ++i){
tmpVector3.x = ((Vector2) listItemRoom[i]).x;
tmpVector3.y = ((Vector2) listItemRoom[i]).y;
tmpVector3.z = 0;
GameObject obj = (GameObject) GroundBlocksArray[dicGroundExist[tmpVector3]];
obj.GetComponent<SpriteRenderer>().color = new Color32(0,0,0,255);
obj.name = "Item";
}
}
---- ์ ์ทจ์ --- ํจ์ ๋
์ฐจ์ด๋๋ ๋ถ๋ถ์ ์ฒ์ ๋ฐฉ์ ๋์๋งํผ ๋ฐ๋ฅ์ด ์ถฉ๋ถํ ๊น๋ ธ๋์ง ( ํผ๋ด ๊ธฐ์ค์ผ๋ก 3x3์์น๊ฐ ๋ฐ๋ฅ์ด ์๋์ง )
ํ์ธํ ๋, ํด๋น ์์น๊ฐ ํน์ ์ ํฌ์ฉ๋ฐฉ์ ์์ญ์ธ์ง ์ฒดํฌํฉ๋๋ค
๊ทธ๋ค๋ก ๊ฑฐ์ ๊ฐ์ต๋๋ค. ์์ดํ ์ฉ ๋ฐฉ ์์น๋ฅผ ์ ์ก์๋์ง ํ์ธํ๊ธฐ ํธํ๊ฒ
ํด๋น ๊ฒ์์ค๋ธ์ ํธ์ ์ด๋ฆ์ Item์ผ๋ก ๋ฐ๊พธ๊ธฐ๋ก ํ์ต๋๋ค. ( ์์์ ํ๋์์ผ๋ก ํ๋ฉด ์ ์๋ณด์ฌ์ ๊ฒ์์์ผ๋ก )
์ ํฌ์ฉ ๋ฐฉ ํผ๋ด์ ๊ฒฝ์ฐ ์ด๋ฆ์ Battle๋ก ํ๊ตฌ์
์ด๋ ๊ฒ์.
๋ค์ ๋ชฉํ >ย ์ข์ ๋ฐฉ์๋ ์์ดํ ์ด ๋จ์ด์ ธ์์ด ์ฃผ์ธ ์ ์์ด์ผํ๋ค.
์๊ฐํด๋ณด๋ ์ด๊ฑด ์ง๊ธ ํ ์ ์๋๊ฒ ์๋๋ค์ ๋ณธ๊ฒ์์ด๋ ํฉ์ณ์ผ๋ง ๊ฐ๋ฅํ์ฃ . ์ฐ์ ์์ดํ ์ฉ๋ฐฉ์ ์์น๋ฅผ ์ก์๋ฐ์ ๋ง์กฑํฉ์๋ค.
์ขํ๋จ์ ๊ฒ์์ ๋ถ๋ถ์ด ์์ดํ
ํ๋์ฉ ๋ฐฉ์์น, ์ฐ์ธก์ ๋นจ๊ฐ์์ด ์ ํฌ์ฉ ๋ฐฉ ์์น์
๋๋ค.
๊ทผ๋ฐ ์ฌ๊ธฐ๊น์ง๋ง ํ๋ฉด ๊ทธ๋ฅ ์ด์ ๊ธ๊ณผ ๊ฑฐ์ ํก์ฌํ๋ ์ถ๊ฐ๋ก ๋ ๋ฃ์ด๋ด ์๋ค.
๋ฐ๋ก ํ ์คํธ ํ์ผ๋ก ์ ์ฅ์ธ๋ฐ์.
ํ ์คํธ ํ์ผ๋ก ์ ์ฅํ๋ ค๋ฉด ํ์ฌ์ ๊ฐ์ ๋ฒกํฐ ๋ฆฌ์คํธ๋ณด๋ค๋
๊ฐ๋ก ๋ช ์ธ๋ก ๋ช ๊ฐ์ ๊ตฌ์ญ์ ์๋ ์์ผ๋ก ์ ์ฅ๋๋ฉด ๋ ํธํ๊ฒ ์ฃ .
19,4
0000000000000010000
0000000000011111000
0000001111111010000
0000000000000010000
์์ ๋ฒฝ์ ๋ง๋ค๊ณ ํ๋๊ฒ ๋ ๋ซ๊ฒ ๋ค์
1์ ๋ฐ๋ฅ, 2๋ ๋ฒฝ, 3์ ์์์ , 4๋ ๋์
๊ทธ๋ฆฌ๊ณ ๋ค์๋ ์์ดํ ๋ฐฉ ์ขํ, ์ ํฌ๋ฐฉ ์ขํ๋ฅผ ๋จ๊ธฐ๋๊ฑฐ์ฃ
------ FILE ----
19,4
0000000000222232000
0000022222211111200
0000024111111212000
0000022222222212000
(14,1)
(16,3),(16,2)
์ด๋ ๊ฒ์
์ด๋ ๊ฒ ํ๋ ค๋ฉด ์ฐ์ ๋ฐ๋ฅ+๋ฒฝ ํ์ผ์
๊ฐ์ฅ์์ X,Y์ขํ, ๊ทธ๋ฆฌ๊ณ ๊ฐ์ฅํฐ X,Y์ขํ๋ฅผ ์์์
2์ฐจ์ ๋ฐฐ์ด ํํ๋ก ์ ์ฅ ๊ฐ๋ฅํด์ผ๊ฒ ์ฃ .
---- ์ค๊ฐ์ ์ฅ ----
๋น๋ฐ๋ฒํธ๋ฅผ ์์ด๋ฒ๋ ธ๋ค์. ๋ค์ํธ์ผ๋ก ์ฌ๋ฆฌ๊ฒ ์ต๋๋ค