using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class door_open : MonoBehaviour
{
 int flg=0;int count=0;int wait=0;int spacewait=0;
 int[] p=new int[100];int[] cleared=new int[100];string[] datas=new string[100];
 int i;int j;int z;int zx;int zy;int r;int ee;int a;int aa;int x;int y;int r1;int r2;
 int ii;int jj;int e1;int e2;int n1;int n2;int ax;int ay;int aax;int aay;int cx;int cy;
 int a1;int a2;int a3;int mx;int my;int mt;int mc;int mxx;int myy;
 int px;int py;int stage=-1;int moves;
 float xf;float yf;
 float stimef;float ntimef;
 string c1;string c2;string c3;string d;string d1;string d2;string savedata;string keyname;
 GUIStyle style1;GUIStyle style2;
 GameObject[] obj=new GameObject[1600];
 AudioSource bgm1;AudioSource bgm2;AudioSource bgm3;

 void Start()
 {
  obj[0]=GameObject.Find("ng-mes-1"); // 0  ng-mes
  obj[1]=GameObject.Find("dooropen-stagemoji-1"); // 1  stage-select
  obj[2]=GameObject.Find("dooropen-stagemoji-2"); // 2  stage-
  for (i=0;i<=37;i++) {obj[i+3]=GameObject.Find("dooropen-"+i);} // 3 - 40  chara-moto
  for (i=0;i<=9;i++) {obj[i+41]=GameObject.Find("dooropen-num-"+i);} // 41 - 50  num-moto
  obj[51]=GameObject.Find("dooropen-panel-1"); // 51  panel-g-moto
  obj[52]=GameObject.Find("dooropen-panel-2"); // 52  panel-y-moto
  obj[53]=GameObject.Find("dooropen-panel-waku"); // 53  panel-waku
  obj[54]=GameObject.Find("dooropen-button-1"); // 54  button-retry
  obj[55]=GameObject.Find("dooropen-button-2"); // 55  button-title
  obj[56]=GameObject.Find("dooropen-button-3"); // 56  button-reset
  obj[57]=GameObject.Find("stageclear-mes-1"); // 57  stageclear-blue
  obj[58]=GameObject.Find("stageclear-mes-2"); // 58  stageclear-green
  for (i=1;i<=11;i++)
  {
   for (j=0;j<=99;j++) {obj[i*100+j]=Object.Instantiate(obj[i+3]) as GameObject;} // 100 - 1199  chara-copy
  }
  for (i=1;i<=2;i++)
  {
   for (j=0;j<=99;j++) {obj[i*100+j+1100]=Object.Instantiate(obj[i+50]) as GameObject;} // 1200 - 1399  panel-copy
  }
  for (i=0;i<=9;i++)
  {
   for (j=0;j<=19;j++) {obj[i*20+j+1400]=Object.Instantiate(obj[i+41]) as GameObject;} // 1400 - 1599  num-copy
  }

 for (i=0;i<=99;i++) {cleared[i]=0;datas[i]="";}
// for (i=0;i<=99;i++) {cleared[i]=0;datas[i]="A";}
// datas[0]="1111111111/1000040901/1008010001/1000010001/1000010001/1113111121/1000010001/50A0010071/1000010001/1111111111/88";
// datas[1]="1131211161/1000000006/1000000B01/2000700001/1000000001/3080009004/1000000001/1000A00005/6000000001/1611514111/45";
 datas[0]="0000000000/0000000000/0000000000/0000000000/0000000000/0000000000/1111111111/1000000001/2000007001/1111111111/88";
 datas[1]="0000000000/0000000000/0000000000/0000000000/0000000000/0000000000/1111111111/1000000001/1007000002/1111111111/18";
 datas[2]="0000001111/0000001001/0000001001/0000001071/0000001001/0000001001/0000001001/0000001001/0000001001/0000001121/81";
 datas[3]="0000001121/0000001001/0000001001/0000001001/0000001001/0000001001/0000001071/0000001001/0000001001/0000001111/88";
 datas[4]="0000001311/0000001001/0000001001/0000001001/0000001001/0000001001/1111111001/3000000801/1000000001/1111111111/88";
 datas[5]="0000001411/0000001001/0000001001/0000001001/0000001001/0000001001/1111111001/4000000901/1000000001/1111111111/88";
 datas[6]="0000001511/0000001001/0000001001/0000001001/0000001001/0000001001/1111111001/5000000A01/1000000001/1111111111/88";
 datas[7]="0000001611/0000001001/0000001001/0000001B01/0000001001/0000001001/1111111001/600B000701/1000000001/1111111111/88";
 datas[8]="0000001211/0000001001/0000001001/0000001001/0000001001/0000001701/1111111001/2000070701/1000000001/1111111111/88";
 datas[9]="0001234561/0111000001/0100000001/110B000001/2000700001/3000080001/4000009001/5000000A01/6000000001/1111111111/88";
 datas[10]="0000000000/0000000000/0000000000/0000000000/0000000000/0000011110/1111110011/1000070001/2000000001/1111111111/88";
 datas[11]="0000000000/0000000000/0000000000/0000000000/0000000000/0000000000/1111111111/1000700001/2070007001/1111111111/88";
 datas[12]="0000000000/0000000000/0000000000/0000000000/0000000000/0000000000/0111111111/1100000001/2300807001/1111111111/88";
 datas[13]="0000000000/0000000000/0000000000/0000000000/0000000000/0000000000/0111111111/1100000001/2600B07001/1111111111/88";
 datas[14]="0000000000/0000000000/0000000000/0000000000/0000011111/0000110001/0111100001/110000B701/3600080001/1111111111/88";
 datas[15]="0000000000/0000000000/0000000000/0000011111/0000010001/0000010701/1111113131/1000000801/2000000001/1111111111/88";
 datas[16]="0000000000/0000000000/0000000000/0000011111/0000010001/0000010701/1111118001/3000000001/1000000001/1111111111/88";
 datas[17]="0000000000/0000000000/0000000000/0000000000/0000111110/0111100011/1100107001/1000000901/1101111001/0141001111/88";
 datas[18]="0000000000/0000000000/0000000000/0000000000/0001111100/1111000111/10A0A00A01/5000000001/1000001001/1111111111/88";
 datas[19]="1111111111/1000107001/10A0000001/1001111801/1111001001/0000001001/1111111001/5000000901/1111110001/0000011111/88";

  bgm1=obj[1].GetComponent();bgm2=obj[2].GetComponent();
  bgm3=obj[3].GetComponent();
  style1=new GUIStyle();
  style1.fontSize=80;
  style2=new GUIStyle();
  style2.fontSize=24;
  c1="";c2="";c3="";
  z=0;zx=0;zy=0;objput();
  dataload();
  count=500;flg=-1;
 }

 void Update ()
 {
  Vector3 mpos=Input.mousePosition;
  xf=mpos.x;yf=mpos.y;
  if (flg==-1)
  {
   count=count-1;
   if (Input.GetMouseButtonDown(0)) {count=0;}
   if (Input.GetMouseButtonDown(1)) {count=0;}
   if (Input.GetKeyDown(KeyCode.Space)) {count=0;spacewait=2;}
   if (Input.GetKeyDown(KeyCode.Return)) {count=0;}
   if (count<=0)
   {
    titleput();
    flg=0;spacewait=2;
   }
  }
  if (flg==0)
  {
   if (spacewait>0) {spacewait=spacewait-1;}
   if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.Keypad8))
   {
    cy=cy-1;
    if (cy<0) {cy=9;}
   }
    if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.Keypad2))
   {
    cy=cy+1;
    if (cy>9) {cy=0;}
   }
    if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.Keypad4))
   {
    cx=cx-1;
    if (cx<0) {cx=9;}
   }
    if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.Keypad6))
   {
    cx=cx+1;
    if (cx>9) {cx=0;}
   }
   if (Input.GetKeyDown(KeyCode.Space))
   {
    if (spacewait<=0)
    {
     a=cy*10+cx;
     if (datas[a]!="") {stage=a;newstage();}
    }
   }
   if (Input.GetMouseButtonDown(0))
   {
    if (spacewait<=0)
    {
     x=Mathf.FloorToInt(xf);y=Mathf.FloorToInt(yf);
     if (x>=483 && x<=797 && y>=202 && y<=516)
     {
      ax=(x-483)%32;ay=(y-202)%32;
      if (ax<=28 && ay<=28)
      {
       aay=(y-202)/32;aax=(x-483)/32;
       a=(9-aay)*10+aax;
       if (datas[a]!="") {stage=a;newstage();}
      }
     }
     if (x>=815 && x<=870 && y>=192 && y<=211)
     {
      for (i=0;i<=99;i++) {cleared[i]=0;}
      datasave();stage=-1;titleput();
     }
    }
   }
   if (flg==0)
   {
    z=53;zx=cx*32-144;zy=144-cy*32;objput();
   }
   ntimef=Time.time;
   if (ntimef-stimef>=33f)
   {
    stimef=Time.time;bgm1.Play();
   }
  }
  if (flg==1)
  {
   moves=0;
   if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.Keypad6)) {moves=1;}
   if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.Keypad4)) {moves=2;}
   if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.Keypad8)) {moves=3;}
   if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.Keypad2)) {moves=4;}
   if (moves>0)
   {
    charaput(py*10+px,0);
    if (moves==1)
    {
     a1=p[py*10+px+1];a2=0;a3=0;
     if (px<=7) {a2=p[py*10+px+2];} else {a2=1;}
     if (px<=6) {a3=p[py*10+px+3];} else {a3=1;}
     if (a1==0) {px=px+1;}
     if (a1==7 || a1==8)
     {
      if (a2==0 || a2==a1-5 || (a2==11 && (a3==0 || a3==6)))
      {
       px=px+1;
       if (a2==0) {p[py*10+px]=0;p[py*10+px+1]=a1;charaput(py*10+px+1,a1);}
       if (a2==a1-5)
       {
        p[py*10+px]=0;mx=px+1;my=py;mt=a2;mc=0;charaput(my*10+mx,0);wait=1;flg=3;
       }
       if (a2==11 && (a3==0 || a3==6))
       {
        p[py*10+px]=0;p[py*10+px+1]=a1;charaput(py*10+px+1,a1);
        if (a3==0) {p[py*10+px+2]=11;charaput(py*10+px+2,11);}
        if (a3==6) {mx=px+2;my=py;mt=6;mc=0;charaput(my*10+mx,0);wait=1;flg=3;}
       }
      }
     }
     if (a1==9 || a1==10)
     {
      if (a2==0 || a2==a1-5 || (a2==11 && (a3==0 || a3==6)))
      {
       px=px+1;
       if (a2==0)
       {
        p[py*10+px]=0;p[py*10+px+1]=a1;charaput(py*10+px+1,a1);
        if (a3==0 || a3==a1-5) {p[py*10+px+1]=0;mx=px+1;my=py;mxx=1;myy=0;mt=a1;flg=2;}
       }
       if (a2==a1-5)
       {
        p[py*10+px]=0;mx=px+1;my=py;mt=a2;mc=0;charaput(my*10+mx,0);wait=1;flg=3;
       }
       if (a2==11 && (a3==0 || a3==6))
       {
        p[py*10+px]=0;p[py*10+px+1]=a1;charaput(py*10+px+1,a1);
        if (a3==0) {p[py*10+px+2]=11;charaput(py*10+px+2,11);}
        if (a3==6) {mx=px+2;my=py;mt=6;mc=0;charaput(my*10+mx,0);wait=1;flg=3;}
       }
      }
     }
    }
    if (moves==2)
    {
     a1=p[py*10+px-1];a2=0;a3=0;
     if (px>=2) {a2=p[py*10+px-2];} else {a2=1;}
     if (px>=3) {a3=p[py*10+px-3];} else {a3=1;}
     if (a1==0) {px=px-1;}
     if (a1==7 || a1==8)
     {
      if (a2==0 || a2==a1-5 || (a2==11 && (a3==0 || a3==6)))
      {
       px=px-1;
       if (a2==0) {p[py*10+px]=0;p[py*10+px-1]=a1;charaput(py*10+px-1,a1);}
       if (a2==a1-5)
       {
        p[py*10+px]=0;mx=px-1;my=py;mt=a2;mc=0;charaput(my*10+mx,0);wait=1;flg=3;
       }
       if (a2==11 && (a3==0 || a3==6))
       {
        p[py*10+px]=0;p[py*10+px-1]=a1;charaput(py*10+px-1,a1);
        if (a3==0) {p[py*10+px-2]=11;charaput(py*10+px-2,11);}
        if (a3==6) {mx=px-2;my=py;mt=6;mc=0;charaput(my*10+mx,0);wait=1;flg=3;}
       }
      }
     }
     if (a1==9 || a1==10)
     {
      if (a2==0 || a2==a1-5 || (a2==11 && (a3==0 || a3==6)))
      {
       px=px-1;
       if (a2==0)
       {
        p[py*10+px]=0;p[py*10+px-1]=a1;charaput(py*10+px-1,a1);
        if (a3==0 || a3==a1-5) {p[py*10+px-1]=0;mx=px-1;my=py;mxx=-1;myy=0;mt=a1;flg=2;}
       }
       if (a2==a1-5)
       {
        p[py*10+px]=0;mx=px-1;my=py;mt=a2;mc=0;charaput(my*10+mx,0);wait=1;flg=3;
       }
       if (a2==11 && (a3==0 || a3==6))
       {
        p[py*10+px]=0;p[py*10+px-1]=a1;charaput(py*10+px-1,a1);
        if (a3==0) {p[py*10+px-2]=11;charaput(py*10+px-2,11);}
        if (a3==6) {mx=px-2;my=py;mt=6;mc=0;charaput(my*10+mx,0);wait=1;flg=3;}
       }
      }
     }
    }
    if (moves==3)
    {
     a1=p[py*10+px-10];a2=0;a3=0;
     if (py>=2) {a2=p[py*10+px-20];} else {a2=1;}
     if (py>=3) {a3=p[py*10+px-30];} else {a3=1;}
     if (a1==0) {charaput(py*10+px,0);py=py-1;}
     if (a1==7 || a1==9)
     {
      if (a2==0 || a2==a1-5 || (a2==11 && (a3==0 || a3==6)))
      {
       py=py-1;
       if (a2==0) {p[py*10+px]=0;p[py*10+px-10]=a1;charaput(py*10+px-10,a1);}
       if (a2==a1-5)
       {
        p[py*10+px]=0;mx=px;my=py-1;mt=a2;mc=0;charaput(my*10+mx,0);wait=1;flg=3;
       }
       if (a2==11 && (a3==0 || a3==6))
       {
        p[py*10+px]=0;p[py*10+px-10]=a1;charaput(py*10+px-10,a1);
        if (a3==0) {p[py*10+px-20]=11;charaput(py*10+px-20,11);}
        if (a3==6) {mx=px;my=py-2;mt=6;mc=0;charaput(my*10+mx,0);wait=1;flg=3;}
       }
      }
     }
     if (a1==8 || a1==10)
     {
      if (a2==0 || a2==a1-5 || (a2==11 && (a3==0 || a3==6)))
      {
       py=py-1;
       if (a2==0)
       {
        p[py*10+px]=0;p[py*10+px-10]=a1;charaput(py*10+px-10,a1);
        if (a3==0 || a3==a1-5) {p[py*10+px-10]=0;mx=px;my=py-1;mxx=0;myy=-1;mt=a1;flg=2;}
       }
       if (a2==a1-5)
       {
        p[py*10+px]=0;mx=px;my=py-1;mt=a2;mc=0;charaput(my*10+mx,0);wait=1;flg=3;
       }
       if (a2==11 && (a3==0 || a3==6))
       {
        p[py*10+px]=0;p[py*10+px-10]=a1;charaput(py*10+px-10,a1);
        if (a3==0) {p[py*10+px-20]=11;charaput(py*10+px-20,11);}
        if (a3==6) {mx=px;my=py-2;mt=6;mc=0;charaput(my*10+mx,0);wait=1;flg=3;}
       }
      }
     }
    }
    if (moves==4)
    {
     a1=p[py*10+px+10];a2=0;a3=0;
     if (py<=7) {a2=p[py*10+px+20];} else {a2=1;}
     if (py<=6) {a3=p[py*10+px+30];} else {a3=1;}
     if (a1==0) {py=py+1;}
     if (a1==7 || a1==9)
     {
      if (a2==0 || a2==a1-5 || (a2==11 && (a3==0 || a3==6)))
      {
       py=py+1;
       if (a2==0) {p[py*10+px]=0;p[py*10+px+10]=a1;charaput(py*10+px+10,a1);}
       if (a2==a1-5)
       {
        p[py*10+px]=0;mx=px;my=py+1;mt=a2;mc=0;charaput(my*10+mx,0);wait=1;flg=3;
       }
       if (a2==11 && (a3==0 || a3==6))
       {
        p[py*10+px]=0;p[py*10+px+10]=a1;charaput(py*10+px+10,a1);
        if (a3==0) {p[py*10+px+20]=11;charaput(py*10+px+20,11);}
        if (a3==6) {mx=px;my=py+2;mt=6;mc=0;charaput(my*10+mx,0);wait=1;flg=3;}
       }
      }
     }
     if (a1==8 || a1==10)
     {
      if (a2==0 || a2==a1-5 || (a2==11 && (a3==0 || a3==6)))
      {
       py=py+1;
       if (a2==0)
       {
        p[py*10+px]=0;p[py*10+px+10]=a1;charaput(py*10+px+10,a1);
        if (a3==0 || a3==a1-5) {p[py*10+px+10]=0;mx=px;my=py+1;mxx=0;myy=1;mt=a1;flg=2;}
       }
       if (a2==a1-5)
       {
        p[py*10+px]=0;mx=px;my=py+1;mt=a2;mc=0;charaput(my*10+mx,0);wait=1;flg=3;
       }
       if (a2==11 && (a3==0 || a3==6))
       {
        p[py*10+px]=0;p[py*10+px+10]=a1;charaput(py*10+px+10,a1);
        if (a3==0) {p[py*10+px+20]=11;charaput(py*10+px+20,11);}
        if (a3==6) {mx=px;my=py+2;mt=6;mc=0;charaput(my*10+mx,0);wait=1;flg=3;}
       }
      }
     }
    }
    charaput(py*10+px,0);moves=0;
   }
   if (px==0 || px==9 || py==0 || py==9)
   {
    stimef=Time.time;bgm1.Stop();bgm2.Stop();bgm3.Play();
    z=57;zx=0;zy=0;objput();
    flg=4;wait=360;
   }
   if (Input.GetMouseButtonDown(0))
   {
    x=Mathf.FloorToInt(xf);y=Mathf.FloorToInt(yf);
    if (x>=815 && x<=904 && y>=240 && y<=279) {newstage();}
    if (x>=815 && x<=904 && y>=192 && y<=231) {titleput();flg=0;}
   }
   if (flg>0) {z=15;zx=px*32-144;zy=144-py*32;objput();}
  }
  if (flg==2)
  {
   wait=wait-1;
   if (wait<=0)
   {
    charaput(my*10+mx,0);wait=5;
    mx=mx+mxx;my=my+myy;ee=1;
    charaput(my*10+mx,mt);
    if (mx==9 && mxx==1) {ee=0;}
    if (mx==0 && mxx==-1) {ee=0;}
    if (my==9 && myy==1) {ee=0;}
    if (my==0 && myy==-1) {ee=0;}
    if (ee>0)
    {
     a=(my+myy)*10+mx+mxx;aa=p[a];
     if (aa!=0 && aa!=mt-5) {ee=0;}
    }
    if (p[my*10+mx]==mt-5) {mt=mt-5;mc=0;charaput(my*10+mx,0);wait=1;flg=3;ee=-1;}
    if (ee==0) {p[my*10+mx]=mt;flg=1;}
   }
  }
  if (flg==3)
  {
   wait=wait-1;
   if (wait<=0)
   {
    for (i=16;i<=40;i++) {z=i;zx=-1000;zy=0;objput();}
    mc=mc+1;
    if (mc<=5)
    {
     z=mt*5+mc+5;
     zx=mx*32-144;zy=144-my*32;objput();
     wait=10;
    }
    else {p[my*10+mx]=0;flg=1;}
   }
  }
  if (flg>=1 && flg<=3)
  {
   ntimef=Time.time;
   if (ntimef-stimef>=39f)
   {
    stimef=Time.time;bgm2.Play();
   }
  }
  if (flg==4)
  {
   wait=wait-1;
   if (wait%10==0)
   {
    if (wait%20==10) {z=57;zx=-1000;zy=0;objput();z=58;zx=0;objput();}
    else {z=58;zx=-1000;zy=0;objput();z=57;zx=0;objput();}
   }
   if (wait<=0)
   {
    if (cleared[stage]<1) {cleared[stage]=1;datasave();}
    stage=stage+1;if (stage>99) {stage=0;}
    if (datas[stage]=="") {stage=0;}
    flg=0;titleput();
   }
  }
 }

 void newstage()
 {
  stimef=Time.time;bgm1.Stop();bgm2.Play();bgm3.Stop();
  alldel();z=54;zx=220;zy=-100;objput();z=55;zy=-148;objput();z=2;zx=-70;zy=184;objput();
  z=(stage/10)*20+1400;zx=-66;zy=184;objput();z=(stage%10)*20+1401;zx=-54;objput();
  d=datas[stage];
  for (i=0;i<=9;i++)
  {
   for (j=0;j<=9;j++)
   {
    d1=d.Substring(i*11+j,1);aa=-1;
    if (d1=="A") {aa=10;}
    if (d1=="B") {aa=11;}
    if (aa<0) {aa=int.Parse(d1);}
    charaput(i*10+j,aa);p[i*10+j]=aa;
   }
  }
  d1=d.Substring(110,1);d2=d.Substring(111,1);
  if (d1=="-") {px=-1;py=-1;}
  else
  {
   px=int.Parse(d1);py=int.Parse(d2);
   z=15;zx=px*32-144;zy=144-py*32;objput();
  }
  flg=1;
 }

 void titleput()
 {
  stimef=Time.time;bgm1.Play();bgm2.Stop();bgm3.Stop();
  alldel();z=1;zx=-70;zy=184;objput();z=56;zx=220;zy=-168;objput();
  for (i=0;i<=99;i++)
  {
   a=13;
   if (cleared[i]<1 || datas[i]=="") {a=12;}
   charaput(i,a);
   if (datas[i]!="")
   {
    y=i/10;x=i%10;
    z=1400+y*20+x;zx=x*32-150;zy=144-y*32;objput();
    z=1400+x*20+y+10;zx=x*32-138;zy=144-y*32;objput();
   }
  }
  cx=0;cy=0;
  for (i=0;i<=99;i++)
  {
   if (cleared[i]<1) {cx=i%10;cy=i/10;break;}
  }
  if (stage>=0) {cx=stage%10;cy=stage/10;}
 }

 void OnGUI()
 {
  GUI.Label (new Rect (320,560,100,30),c1,style2);
  GUI.Label (new Rect (955,268,100,30),c2,style2);
  GUI.Label (new Rect (540,470,100,30),c3,style1);
 }

 void charaput(int n1,int n2)
 {
  for (ii=1;ii<=13;ii++) {z=ii*100+n1;zx=-1000;zy=0;objput();}
  if (n2>=1 && n2<=13)
  {
   y=n1/10;x=n1%10;
   z=n2*100+n1;zx=x*32-144;zy=144-y*32;objput();
  }
 }

 void objput()
 {
  Vector3 pos=obj[z].transform.position;
  pos.x=zx*0.01f;pos.y=zy*0.01f;
  obj[z].transform.position=pos;
 }

 void objput2()
 {
  Vector3 pos=obj[z].transform.position;
  pos.x=xf*0.01f;pos.y=yf*0.01f;
  obj[z].transform.position=pos;
 }

 void alldel()
 {
  z=0;zx=-2000;zy=0;objput();
  for (i=1;i<=58;i++) {z=i;zx=-1000;zy=0;objput();}
  for (i=100;i<=1599;i++) {z=i;zx=-1000;zy=0;objput();}
 }

 void datasave()
 {
  savedata="";
  for (i=0;i<=99;i++) {savedata=savedata+cleared[i].ToString();}
  keyname="bignyan-dooropen";
  PlayerPrefs.SetString(keyname,savedata);
  PlayerPrefs.Save();
 }

 void dataload()
 {
  keyname="bignyan-dooropen";
  savedata=PlayerPrefs.GetString(keyname,"nothing");
  if (savedata=="nothing")
  {
   savedata="";
   for (i=0;i<=99;i++) {savedata=savedata+"0";}
  }
  for (i=0;i<=99;i++)
  {
   d1=savedata.Substring(i,1);a1=int.Parse(d1);
   cleared[i]=a1;
  }
 }
}