Ejemplo n.º 1
0
 void Start()
 {
     string textContent = styles.text;
     string[] lines = textContent.Split ('\n');
     foreach (var lineStr in lines) {
         if(lineStr.Length > 0)
         {
             var tlist = new List<GRIDPOS>();
             allStyles.Add(tlist);
             string[] content = lineStr.Split(',');
             for(int i = 0 ;i < content.Length ; i+=2)
             {
                 int row;
                 int line;
                 if(int.TryParse(content[i],out row) && int.TryParse(content[i + 1],out line))
                 {
                     GRIDPOS tpos = new GRIDPOS();
                     tpos.line = line;
                     tpos.row = -row;
                     tlist.Add(tpos);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 private List<GRIDPOS> getAllPosEmpty()
 {
     List<GRIDPOS> tlist = new List<GRIDPOS>();
     for (int i = -GameConst.HALF_ROW; i <= GameConst.HALF_ROW; i++) {
         for(int j = -GameConst.HALF_LINE ; j <= GameConst.HALF_LINE; j++)
         {
             bool occupied = false;
             for(int m = 0 ; m < listSnake.Count ; m++)
             {
                 GRIDPOS tpos = GameConst.getLineAndRow(listSnake[m].trans.localPosition);
                 if(tpos.row == i && tpos.line == j)
                 {
                     occupied = true;
                     break;
                 }
             }
             for(int n = 0 ; n < listFood.Count ; n++)
             {
                 GRIDPOS tpos = GameConst.getLineAndRow(listFood[n].localPosition);
                 if(tpos.row == i && tpos.line == j)
                 {
                     occupied = true;
                     break;
                 }
             }
             if(!occupied)
             {
                 GRIDPOS t = new GRIDPOS();
                 t.row = i;
                 t.line = j;
                 tlist.Add(t);
             }
         }
     }
     return tlist;
 }
Ejemplo n.º 3
0
 public static void getPositionByLineRow(GRIDPOS rowLine,ref Vector3 target)
 {
     target.x = rowLine.line * GRID_SIZE;
     target.y = rowLine.row * GRID_SIZE;
 }
Ejemplo n.º 4
0
 //每次行走一格
 public void moveTo(GRIDPOS nextGrid,float zoff = 0f)
 {
     arrival = false;
     moveTime = 0;
     moveFromPos = trans.localPosition;
     GameConst.getPositionByLineRow (nextGrid,ref moveTargetPos);
     moveTargetPos.z = zoff;
 }