using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class chu_center : MonoBehaviour
{
int flg=-1;int count=0;int spacewait=0;int level=0;int useobj=0;int kai;int score;
int px;int py;int mx;int my;int obx;int oby;int newx;int newy;int winx;int winy;
int i;int j;int k;int z;int zx;int zy;int r;int ee;int a;int aa;int aaa;int x;int y;int r1;int r2;int ax;int ay;
int xx;int yy;int ii;
int e;int e1;int a1;int a2;int moves;int muki;int mousex;int mousey;
float stimef;float ntimef;float xf;float yf;float stime2f;float ntime2f;float af;
string c1;string c2;string c3;string c4;string d1;
GUIStyle style1;GUIStyle style2;GUIStyle style3;
GameObject[] obj=new GameObject[2000];
AudioSource bgm1;AudioSource bgm2;AudioSource bgm3;
void Start()
{
obj[0]=GameObject.Find("ng-mes"); // 0 ng-mes
for (i=1;i<=4;i++) {obj[i]=GameObject.Find("chu-center-"+i);} // 1-4 main-obj
for (i=1;i<=3;i++) {obj[i+4]=GameObject.Find("chu-center-mes-"+i);} // 5-7 mes
for (i=1;i<=4;i++) {obj[i+7]=GameObject.Find("chu-center-"+i+"m");} // 8-11 mini-obj
obj[12]=GameObject.Find("chu-center-window"); // 12 window
obj[13]=GameObject.Find("chu-line-tate"); // 13 line-tate
obj[14]=GameObject.Find("chu-line-yoko"); // 14 line-yoko
obj[15]=GameObject.Find("chu-center-title"); // 15 title
obj[16]=GameObject.Find("ya-r-32x32"); // 16 ya-r
obj[17]=GameObject.Find("ya-u-32x32"); // 17 ya-u
for (i=0;i<=9;i++)
{
obj[i+100]=GameObject.Find("num-"+i+"-22x34"); // 100-109 nums-moto
obj[i+110]=Object.Instantiate(obj[i+100]) as GameObject; // 110-119 nums-copy
obj[i+120]=Object.Instantiate(obj[i+100]) as GameObject; // 120-129 nums-copy
}
obj[130]=GameObject.Find("num-00-22x34"); // 130 num-null
obj[131]=Object.Instantiate(obj[130]) as GameObject; // 120-129 nums-copy00
bgm1=obj[1].GetComponent();bgm2=obj[2].GetComponent();bgm3=obj[3].GetComponent();
style1=new GUIStyle();style1.fontSize=40;
style2=new GUIStyle();style2.fontSize=16;
style3=new GUIStyle();style3.fontSize=24;style3.normal.textColor=Color.red;
alldel();z=0;zx=-0;zy=0;objput();
count=500;flg=-1;
}
void Update ()
{
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)) {level=level-1;if (level<0) {level=7;}}
if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.Keypad2)) {level=level+1;if (level>7) {level=0;}}
if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.Keypad4)) {useobj=useobj-1;if (useobj<0) {useobj=3;}}
if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.Keypad6)) {useobj=useobj+1;if (useobj>3) {useobj=0;}}
if (Input.GetKeyDown(KeyCode.Space) && spacewait<=0) {gamestart();}
if (flg==0)
{
z=16;zx=(level/4)*210-200;zy=168-(level%4)*40;objput();
z=17;zx=useobj*74-111;zy=-65;objput();
}
}
if (flg==1)
{
obx=obx+mx;oby=oby+my;
if (muki==0) {winx=winx+mx;winy=winy+my;}
if (muki==1) {winx=winx-my;winy=winy+mx;}
if (muki==2) {winx=winx-mx;winy=winy-my;}
if (muki==3) {winx=winx+my;winy=winy-mx;}
z=useobj+1;zx=winx;zy=winy;objput();
// z=useobj+2;zx=obx;zy=oby;objput();
count=count+1;
if (count>=10) {flg=2;count=0;}
}
if (flg==2)
{
ntime2f=Time.time;
if (ntime2f-stime2f>=1.0f)
{
kai=kai+1;a=10;if (level<=3) {a=level+2;}
if (kai0) {spacewait=spacewait-1;}
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Keypad8)) {py=py+2;if (py>200) {py=200;}}
if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.Keypad2)) {py=py-2;if (py<-200) {py=-200;}}
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Keypad4)) {px=px-2;if (px<-400) {px=-400;}}
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.Keypad6)) {px=px+2;if (px>400) {px=400;}}
if (Input.GetKeyDown(KeyCode.Space) && spacewait<=0) {hantei();}
if (flg==3) {z=13;zx=px;zy=0;objput();z=14;zx=0;zy=py;objput();}
ntimef=Time.time;
if (ntimef-stimef>=27f) {bgm2.Play();stimef=Time.time;}
}
if (flg==4)
{
if (spacewait>0) {spacewait=spacewait-1;}
if (Input.GetKeyDown(KeyCode.Space) && spacewait<=0) {count=400;}
count=count+1;if (count>=400) {titleput();}
}
if (flg>=1) {if (Input.GetKeyDown(KeyCode.Escape)) {titleput();flg=0;spacewait=2;}}
}
void gamestart()
{
alldel();z=useobj+1;zx=0;zy=0;objput();z=12;objput();
z=5;zx=0;zy=-270;objput();
kai=0;count=0;px=0;py=0;mx=0;my=0;obx=0;oby=0;
movemake();bgmstop();bgm1.Play();
}
void movemake()
{
stime2f=Time.time;
z=useobj+1;zx=0;zy=0;objput();obj[useobj+1].transform.rotation=Quaternion.identity;
muki=0;
if (level==3 && kai==4) {muki=Random.Range(1,4);}
if (level==4 && kai==9) {muki=Random.Range(1,4);}
if (level==5 && kai%5==4) {muki=Random.Range(1,4);}
if (level==6 && kai%2==1) {muki=Random.Range(1,4);}
if (level==7) {muki=Random.Range(1,4);}
obj[useobj+1].transform.Rotate(0,0,90*muki);
newx=0;newy=0;mx=0;my=0;
for (ii=0;ii<=2;ii++)
{
r1=Random.Range(1,10);r2=Random.Range(0,2);
if (kai%2==0)
{
mx=r1;if (r2==1) {mx=r1*-1;}
newx=obx+mx*10;
}
else
{
my=r1;if (r2==1) {my=r1*-1;}
newy=oby+my*10;
}
if (newx<-330 || newx>330 || newy<-130 || newy>130) {ii=0;} else {break;}
}
winx=0;winy=0;
flg=1;count=0;
}
void hantei()
{
bgmstop();bgm3.Play();
z=useobj+1;zx=obx;zy=oby;objput();obj[useobj+1].transform.rotation=Quaternion.identity;
ax=Mathf.Abs(px-obx)/2;ay=Mathf.Abs(py-oby)/2;
score=100-ax-ay;if (score<0) {score=0;}
z=6;zx=-2000;zy=0;objput();z=7;zx=0;zy=-270;objput();
for (ii=100;ii<=129;ii++) {z=ii;zx=-1000;zy=0;objput();}
z=score/100+100;if (score<100) {z=130;}
zx=-228;zy=-250;objput();
z=(score%100)/10+110;if (score<10) {z=131;}
zx=-204;zy=-250;objput();
z=score%10+120;zx=-180;zy=-250;objput();
flg=4;count=0;spacewait=2;
}
void titleput()
{
alldel();z=15;zx=0;zy=0;objput();
for (i=0;i<=3;i++) {z=i+8;zx=i*74-111;zy=-16;objput();}
z=16;zx=(level/4)*210-200;zy=168-(level%4)*40;objput();z=17;zx=useobj*74-111;zy=-65;objput();
bgmstop();spacewait=2;flg=0;count=0;
}
void OnGUI()
{
GUI.Label (new Rect (900,200,100,30),c1,style2);
GUI.Label (new Rect (330,100,100,30),c2,style2);
GUI.Label (new Rect (330,200,100,30),c3,style1);
GUI.Label (new Rect (530,300,100,30),c4,style3);
}
void objput()
{
Vector3 pos=obj[z].transform.position;
pos.x=zx*0.01f;pos.y=zy*0.01f;
obj[z].transform.position=pos;
}
void bgmstop()
{
bgm1.Stop();bgm2.Stop();bgm3.Stop();
}
void alldel()
{
zx=-2000;zy=0;for (i=0;i<=17;i++) {z=i;objput();}
for (i=100;i<=131;i++) {z=i;objput();}
for (i=1;i<=4;i++) {obj[i].transform.rotation=Quaternion.identity;}
}
}