Advertisement
ptnega

BoardController

May 29th, 2015
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. public class BoardController : MonoBehaviour {
  6.  
  7.     public int[][] value;
  8.     public GameObject[][] Cells;
  9.     public GameObject init;
  10.     public bool[][] ck;
  11.     public GameObject parents;
  12.  
  13.     void SetPosition(int x,int y){
  14.         Cells [x] [y].transform.position = new Vector3 (5.0f * x, 0.0f, (-5.0f) * y);
  15.     }
  16.  
  17.     void Awake(){
  18.  
  19.         //Random.seed = 5;
  20.  
  21.         value = new int[5][];
  22.         ck = new bool[5][];
  23.  
  24.         for (int i = 0; i < 5; i ++) {
  25.             value[i] = new int[5];
  26.             ck[i] = new bool[5];
  27.             for (int j = 0; j < 5; j ++){
  28.                 value [i] [j] = 0;
  29.                 ck[i][j] = false;
  30.             }
  31.         }
  32.  
  33.         Cells = new GameObject[4][];
  34.         for (int i = 0; i < 4; i ++) {
  35.             Cells[i] = new GameObject[4];
  36.             for (int j = 0 ; j < 4 ; j ++ ){
  37.                 Cells[i][j] = Instantiate(init);
  38.                 Cells[i][j].SetActive(false);
  39.                 Cells [i] [j].transform.position = new Vector3 (5.0000000000000f * i, 0.00000000000000f, (-5.000000000000000000f) * j);
  40.                 Cells[i][j].transform.parent = parents.transform;
  41.             }
  42.         }
  43.  
  44.         int k1 = (int)Random.Range (0, 16);
  45.         Debug.Log (k1);
  46.         int k2;
  47.         do {
  48.             k2 = (int)Random.Range (0, 16);
  49.         } while(k1 == k2);
  50.         Debug.Log (k2);
  51.  
  52.         int ix = (int)(k1 % 4);
  53.         int iy = (int)(k1 / 4);
  54.  
  55.         Cells [ix] [iy].SetActive (true);
  56.         //SetPosition (ix, iy);
  57.  
  58.         ix = (int)(k2 % 4);
  59.         iy = (int)(k2 / 4);
  60.         Cells [ix] [iy].SetActive (true);
  61.         //SetPosition (ix, iy);
  62.         //Cells [ix] [iy].transform.position += new Vector3 (2, 0, -2);
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement