Hello people of Unity, I am beginner in JS(sorry, UnityScript) coding and Unity, and I have a very weird problem I’d like you to help me figure out.
first, a few comments about the upcoming piece of code-
It is a MineSweeper clone,
when the value of the rows and the columns is 10, and WidthHeight is 50 (since they are the same, I use one variable for both, i like this name better than “size” -.-)
The function doesn’t seem to draw any mines below the 8th row line, than it starts randomly drawing again when it gets somewhere around the 16th row line when I draw it on a 20 by 20 set.
for now, ignore the fact that mines can be drawn upon each-other and some other few minor details-
like the sphere’s position could be saved in a Vector2 and some other shit I’m too tired to optimize before I get the simple logic done.
The code-
function FixedUpdate () {
if(Bool == true)
{
DeployMineField(rows,columns);
Bool=false;
}
}
function DeployMineField(rows,columns)
{
NewPos.x = GameObject.Find("Sphere").transform.position.x ;
NewPos.y = GameObject.Find("Sphere").transform.position.y ;
NewPos.z = GameObject.Find("Sphere").transform.position.z ;
Random.seed = 51449*Random.Range(0,rows*columns);
//for bomb locations Random.Range(0,rows*columns);
for( i =0 ; i<bombs; i++)
{
BombPlace[i] = new Vector2(0,0);
BombPlace[i].x = (Random.Range(0 , columns));
NewPos.x =GameObject.Find("Sphere").transform.position.x + WidthHeight * (BombPlace[i].x);
BombPlace[i].y = Random.Range(0 , rows);
NewPos.y = GameObject.Find("Sphere").transform.position.y +WidthHeight * (BombPlace[i].y);
Instantiate(Bomb,NewPos,Quaternion.identity);
}
for(c=0; c<rows; c++)
{
for(i=0; i<(columns); i++)
{
IsItHotInFrance = false;
for(k=0;k<bombs; k++)
{
if(c==(BombPlace[k].y) i==(BombPlace[k].x))
{IsItHotInFrance = true;}
}
if(IsItHotInFrance == false)
{
NewPos.x =GameObject.Find("Sphere").transform.position.x + (WidthHeight*i);
NewPos.y = GameObject.Find("Sphere").transform.position.y + (WidthHeight*c);
//SetUp the tile's numeral representation
iterator = 0;
for(k=0;k<bombs; k++)
{
// + +
if((BombPlace[k].x==(((NewPos.x-GameObject.Find("Sphere").transform.position.x)/WidthHeight+1))(BombPlace[k].y==(NewPos.y-GameObject.Find("Sphere").transform.position.y)/WidthHeight+1)))
{iterator++;}
// - -
if((BombPlace[k].x==((NewPos.x-GameObject.Find("Sphere").transform.position.x)/WidthHeight-1)(BombPlace[k].y==(NewPos.y-GameObject.Find("Sphere").transform.position.y)/WidthHeight-1)))
{iterator++;}
// - +
if((BombPlace[k].x==((NewPos.x-GameObject.Find("Sphere").transform.position.x)/WidthHeight-1)(BombPlace[k].y==(NewPos.y-GameObject.Find("Sphere").transform.position.y)/WidthHeight+1)))
{iterator++;}
// + -
if((BombPlace[k].x==((NewPos.x-GameObject.Find("Sphere").transform.position.x)/WidthHeight)+1)(BombPlace[k].y==(NewPos.y-GameObject.Find("Sphere").transform.position.y)/WidthHeight-1))
{iterator++;}
// +
if((BombPlace[k].x==((NewPos.x-GameObject.Find("Sphere").transform.position.x)/WidthHeight)(BombPlace[k].y==(NewPos.y-GameObject.Find("Sphere").transform.position.y)/WidthHeight+1)))
{iterator++;}
// +
if((BombPlace[k].x==((NewPos.x-GameObject.Find("Sphere").transform.position.x)/WidthHeight+1)(BombPlace[k].y==((NewPos.y-GameObject.Find("Sphere").transform.position.y)/WidthHeight))))
{iterator++;}
// -
if((BombPlace[k].x==((NewPos.x-GameObject.Find("Sphere").transform.position.x)/WidthHeight)(BombPlace[k].y==(NewPos.y-GameObject.Find("Sphere").transform.position.y)/WidthHeight-1)))
{iterator++;}
// -
if((BombPlace[k].x==((NewPos.x-GameObject.Find("Sphere").transform.position.x)/WidthHeight-1)(BombPlace[k].y==((NewPos.y-GameObject.Find("Sphere").transform.position.y)/WidthHeight))))
{iterator++;}
}
switch(iterator)
{
case 0:
Roll =Blank;
break;
case 1:
Roll = Cube1;
break;
case 2:
Roll = Cube2;
break;
case 3:
Roll = Cube3;
break;
case 4:
Roll = Cube4;
break;
case 5:
Roll = Cube5;
break;
case 6:
Roll = Cube6;
break;
case 7:
Roll = Cube7;
break;
case 8:
Roll = Cube8;
break;
}
Instantiate(Roll,NewPos,Quaternion.identity);
}
}
}
//Iterate through all the tiles to create the minefield
}
note: full code, including variable declaration, can be found here http://pastebin.com/RTa6UVeM
The non-drawn parts seem to have something to do with the size of each block, when I decrease it to 20, it goes to line 12-ish than stops,
(so it is probably somewhere in the math).
Thanks you in advance,
Adar G.