bool AddRandTile() { List <POINT2D> tempindexarr2 = new List <POINT2D>(); for (int y = 0; y < GRIDSIZE; y++) { for (int x = 0; x < GRIDSIZE; x++) { if (BoardTile[y, x] == 0) { tempindexarr2.Add(new POINT2D(x, y)); } } } if (tempindexarr2.Count <= 0) { // 게임오버가 되도록 Debug.WriteLine("오버 되었음 현재 게임 오버임 : "); return(false); } int index = DefaultGameSource.Range(tempindexarr2.Count); POINT2D temppos = tempindexarr2[index]; //tempindexarr2[DefaultGameSource.Range(tempindexarr2.Count)].x; //tempindexarr2[DefaultGameSource.Range(tempindexarr2.Count)].y; int persent = Range(100); BoardTile[temppos.y, temppos.x] = persent >= 80 ? 4 : 2; return(true); }
// 중복 되지 않는 랜덤 타일 적용하기 bool TempAddRandTile() { List <int> tempindexarr = new List <int>(); List <POINT2D> tempindexarr2 = new List <POINT2D>(); for (int y = 0; y < GRIDSIZE; y++) { for (int x = 0; x < GRIDSIZE; x++) { if (BoardTile[y, x] == 0) { tempindexarr2.Add(new POINT2D(x, y)); tempindexarr.Add(y * GRIDSIZE + x); } } } if (tempindexarr.Count <= 0) { return(false); } // 방법2 int randindex = DefaultGameSource.Range(tempindexarr.Count); int val = tempindexarr[randindex]; int indexy = (int)(val / GRIDSIZE); // 6 -> 1 int indexx = val % GRIDSIZE; // 6%4 -> 2 // 방법2 if (tempindexarr2.Count <= 0) { // 게임오버가 되도록 return(false); } randindex = DefaultGameSource.Range(tempindexarr2.Count); POINT2D temppos = tempindexarr2[randindex]; BoardTile[temppos.y, temppos.x] = 2; return(true); }