using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class screensize
{
[RuntimeInitializeOnLoadMethod]
static void OnRuntimeMethodLoad()
{
Screen.SetResolution(1280,720,false);
}
}
public class yonifuru : MonoBehaviour
{
int flg=-1;int count=0;int wait=0;int spacewait=0;int level=1;
int px=0;int py=0;int keywait=0;int clearflg=0;int score=15;
int[] hanac=new int[200];int[] hanam=new int[200];int[] marks=new int[200];
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 jj;int kk;int a1;int a2;int a3;
int e;int e1;int moves;int mousex;int mousey;
float stimef;float ntimef;float stime2f;float ntime2f;float stime3f;float ntime3f;float stime4f;float ntime4f;
float xf;float yf;float af;float kakuf;float axf;float ayf;
string c1;string c2;string c3;string c4;
string d1;string keyname2="bignyan_mousefix";string[] dts=new string[2];
int mfx=640;int mfy=360;
GUIStyle style1;GUIStyle style2;GUIStyle style3;
GameObject[] obj=new GameObject[5000];
AudioSource bgm1;AudioSource bgm2;
void Start()
{
dataload();
style1=new GUIStyle();style1.fontSize=40;
style2=new GUIStyle();style2.fontSize=16;
style3=new GUIStyle();style3.fontSize=24;style3.normal.textColor=Color.red;
obj[0]=GameObject.Find("ng-mes"); // 0 ng-mes
obj[1]=GameObject.Find("yonifuru-title"); // 1 title
obj[2]=GameObject.Find("gameclear-mes-3"); // 2 gameclear-mes-yellow
obj[3]=GameObject.Find("gameclear-mes-4"); // 3 gameclear-mes-orange
obj[4]=GameObject.Find("yonifuru-waku"); // 4 waku
obj[5]=GameObject.Find("yonifuru-marker-1"); // 5 marker-moto
obj[6]=GameObject.Find("yonifuru-uta-black-1"); // 6 uta-black-1
obj[7]=GameObject.Find("yonifuru-uta-black-2"); // 7 uta-black-2
obj[8]=GameObject.Find("hana"); // 8 hana-moto
for (i=1;i<=10;i++) {obj[i+8]=GameObject.Find("yonifuru-name-"+i);} // 9-18 name 1-10
for (i=0;i<=16;i++) {obj[i+19]=GameObject.Find("yonifuru-iro-"+i);} // 19-35 hana-colors-moto
for (i=0;i<=17;i++) {obj[i+36]=GameObject.Find("yonifuru-iro-a-"+i);} // 36-53 head-color 0-17
obj[96]=GameObject.Find("mousefix-1"); // 96 mousefix-black
obj[97]=GameObject.Find("mousefix-2"); // 97 mousefix-red
obj[98]=GameObject.Find("mousefix-moji"); // 98 mousefix-button
obj[99]=GameObject.Find("button-esc"); // 99 button-esc
for (i=0;i<=9;i++)
{
obj[i+100]=GameObject.Find("num-16a-"+i); // 100-109 nums-moto
for (j=1;j<=4;j++) {obj[j*10+i+100]=Object.Instantiate(obj[i+100]) as GameObject;} // 110-149 nums-copy
}
for (i=0;i<=16;i++)
{
for (j=0;j<=199;j++) {obj[i*200+j+200]=Object.Instantiate(obj[i+19]) as GameObject;} // 200-3599 hana-colors-copy
}
for (i=0;i<=199;i++) {obj[i+3600]=Object.Instantiate(obj[8]) as GameObject;} // 3600-3799 hana-copy
for (i=0;i<=199;i++) {obj[i+3800]=Object.Instantiate(obj[5]) as GameObject;} // 3800-3999 marker-copy
bgm1=obj[1].GetComponent();bgm2=obj[2].GetComponent();
alldel();
z=0;zx=0;zy=0;objput();
z=36;zx=-460;zy=-220;objput();z=10;zx=-212;zy=-284;objput();
z=6;zx=-640;zy=-230;objput();z=7;zx=-640;zy=-250;objput();
z=101;zx=-492;zy=-282;objput();z=105;zx=-474;zy=-282;objput();
count=500;flg=-1;
}
void Update()
{
Vector3 mpos=Input.mousePosition;
xf=mpos.x;yf=mpos.y;
if (flg>-9) {xf=xf*640/mfx;yf=yf*360/mfy;}
mousex=(int)xf;mousey=(int)yf;
// c1="X="+mousex.ToString()+" Y="+mousey.ToString();
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;
}
}
if (flg==0)
{
if (spacewait>0) {spacewait=spacewait-1;}
if (spacewait<=0)
{
if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.Keypad4))
{
level=level-1;if (level<0) {level=9;}
}
if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.Keypad6))
{
level=level+1;if (level>9) {level=0;}
}
if (Input.GetKeyDown(KeyCode.Space)) {gamestart();}
if (Input.GetKeyDown(KeyCode.M))
{
alldel();z=96;zx=0;zy=0;objput();z=97;objput();
flg=-9;spacewait=2;
}
if (Input.GetMouseButtonDown(0))
{
if (mousex>=495 && mousex<=529 && mousey>=400 && mousey<=434) {level=level-1;if (level<0) {level=9;}}
if (mousex>=551 && mousex<=585 && mousey>=400 && mousey<=434) {level=level+1;if (level>9) {level=0;}}
if (mousex>=495 && mousex<=584 && mousey>=344 && mousey<=378) {gamestart();}
if (mousex>=503 && mousex<=537 && mousey>=273 && mousey<=307)
{
alldel();z=96;zx=0;zy=0;objput();z=97;objput();
flg=-9;spacewait=2;
}
}
}
if (flg==0)
{
for (i=0;i<=9;i++) {z=i+9;zx=-2000;zy=0;objput();}
z=level+9;zx=-212;zy=-284;objput();
}
}
if (flg==1)
{
// uta-read
wait=wait-1;
if (wait<=0)
{
count=count+1;
if (count<480) {z=6;zx=count-640;zy=-230;objput();}
if (count>=480 && count<880) {z=7;zx=count-1120;zy=-250;objput();}
if (count%55==0)
{
for (i=0;i<=199;i++)
{
if (hanam[i]!=0)
{
z=hanac[i]*200+i+200;zx=-2000;zy=0;objput();
hanac[i]=hanac[i]+hanam[i];
if (hanac[i]==16 && hanam[i]==1) {hanam[i]=-1;}
if (hanac[i]==0 && hanam[i]==-1) {hanam[i]=1;}
x=i%20;y=i/20;
z=hanac[i]*200+i+200;zx=x*40-380;zy=180-y*40;objput();
}
}
}
if (count>=880)
{
z=6;zx=-640;zy=-230;objput();z=7;zx=-640;zy=-250;objput();
count=0;score=score+1;scoreput();
}
wait=1;
}
if (spacewait>0) {spacewait=spacewait-1;}
if (keywait>0) {keywait=keywait-1;}
// input
if (spacewait<=0)
{
if (Input.GetKeyDown(KeyCode.Space))
{
a=py*20+px;
if (hanac[a]>=0)
{
if (marks[a]==0)
{
z=a+3800;zx=zx=px*40-380;zy=180-py*40;objput();
marks[a]=1;
}
else {z=a+3800;zx=-2000;zy=0;objput();marks[a]=0;}
hantei();
}
}
}
if (keywait<=0)
{
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.Keypad6))
{
px=px+1;if (px>19) {px=0;}
keywait=4;
}
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Keypad4))
{
px=px-1;if (px<0) {px=19;}
keywait=4;
}
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Keypad8))
{
py=py-1;if (py<0) {py=9;}
keywait=4;
}
if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.Keypad2))
{
py=py+1;if (py>9) {py=0;}
keywait=4;
}
}
if (Input.GetMouseButtonDown(0) && spacewait<=0)
{
if (mousex>=240 && mousex<=1039 && mousey>=160 && mousey<=559)
{
px=(mousex-240)/40;py=9-(mousey-160)/40;
a=py*20+px;
if (hanac[a]>=0)
{
if (marks[a]==0)
{
z=a+3800;zx=zx=px*40-380;zy=180-py*40;objput();
marks[a]=1;
}
else {z=a+3800;zx=-2000;zy=0;objput();marks[a]=0;}
hantei();
}
}
}
z=4;zx=px*40-380;zy=180-py*40;objput();
}
if (flg>=1 && flg<9)
{
// bgm-replay
ntimef=Time.time;
if (ntimef-stimef>=22f) {bgm1.Play();stimef=stimef+22f;}
}
if (flg==9)
{
ntime2f=Time.time;
if (ntime2f-stime2f>=0.5f)
{
stime2f=stime2f+0.5f;count=count+1;
z=2;zx=-2000;zy=0;objput();z=3;objput();
z=count%2+2;zx=0;zy=0;objput();
if (count>=12) {titleput();}
}
}
if (flg>0)
{
if (Input.GetKeyDown(KeyCode.Escape)) {titleput();}
if (Input.GetMouseButtonDown(0))
{
if (mousex>=975 && mousex<=1043 && mousey>=115 && mousey<=145) {titleput();}
}
}
if (flg==-9)
{
if (spacewait>0) {spacewait=spacewait-1;}
if (Input.GetMouseButtonDown(0) && spacewait<=0)
{
mfx=mousex;mfy=mousey;
datasave();titleput();
}
}
}
void gamestart()
{
z=1;zx=-2000;zy=0;objput();z=99;zx=370;zy=-240;objput();
z=6;zx=-640;zy=-230;objput();z=7;zx=-640;zy=-250;objput();
px=0;py=0;keywait=0;spacewait=2;
z=4;zx=px*40-380;zy=180-py*40;objput();
score=15;scoreput();count=0;wait=1;
for (i=0;i<=199;i++)
{
hanac[i]=-1;hanam[i]=0;marks[i]=0;
}
for (i=0;i<=level;i++)
{
for (j=0;j<=9;j++)
{
r1=Random.Range(0,17);if (r1>16) {r1=0;}
hanac[i*20+j]=r1;hanam[i*20]=0;
}
r1=Random.Range(0,2);if (r1>1) {r1=0;}
if (r1==0) {hanam[i*20]=1;} else {hanam[i*20]=-1;}
if (hanac[i*20]==0) {hanam[i*20]=1;}
if (hanac[i*20]==16) {hanam[i*20]=-1;}
}
for (i=0;i<=1999;i++)
{
r1=Random.Range(0,200);if (r1>199) {r1=0;}
r2=Random.Range(0,200);if (r2>199) {r2=0;}
a=hanac[r1];hanac[r1]=hanac[r2];hanac[r2]=a;
a=hanam[r1];hanam[r1]=hanam[r2];hanam[r2]=a;
}
for (i=0;i<=199;i++)
{
x=i%20;y=i/20;
if (hanac[i]>=0)
{
z=i+3600;zx=x*40-380;zy=180-y*40;objput();
z=hanac[i]*200+i+200;objput();
}
}
stimef=Time.time;stime2f=Time.time;
bgmstop();bgm1.Play();
flg=1;spacewait=2;
}
void hantei()
{
clearflg=1;
for (ii=0;ii<=199;ii++)
{
if (hanac[ii]>=0)
{
if (hanam[ii]==0 && marks[ii]>0) {clearflg=0;}
if (hanam[ii]!=0 && marks[ii]==0) {clearflg=0;}
}
}
if (clearflg>0) {gameclear();}
}
void scoreput()
{
if (score<0) {score=0;}
if (score>999) {score=999;}
for (i=100;i<=149;i++) {z=i;zx=-2000;zy=0;objput();}
for (i=36;i<=53;i++) {z=i;zx=-2000;zy=0;objput();}
zy=-282;aa=0;
a=score/100;if (a>0) {aa=1;z=a+100;zx=-510;objput();}
a=(score%100)/10;if (a>0 || aa>0) {aa=1;z=a+110;zx=-492;objput();}
a=score%10;z=a+120;zx=-474;objput();
aa=(score-15)/5;if (aa<0) {aa=0;}
if (aa>17) {aa=17;}
z=aa+36;zx=-460;zy=-220;objput();
}
void gameclear()
{
z=6;zx=-640;zy=-230;objput();z=7;zx=-640;zy=-250;objput();
z=2;zx=0;zy=0;objput();
flg=9;stime2f=Time.time;count=0;
bgmstop();bgm2.Play();
}
void titleput()
{
alldel();bgmstop();flg=0;spacewait=2;
z=36;zx=-460;zy=-220;objput();z=level+9;zx=-212;zy=-284;objput();
z=6;zx=-640;zy=-230;objput();z=7;zx=-640;zy=-250;objput();
z=101;zx=-492;zy=-282;objput();z=105;zx=-474;zy=-282;objput();
z=1;zx=0;zy=0;objput();
}
void OnGUI()
{
GUI.Label (new Rect (300,80,100,30),c1,style1);
GUI.Label (new Rect (300,160,100,30),c2,style2);
GUI.Label (new Rect (300,240,100,30),c3,style1);
GUI.Label (new Rect (300,320,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();
}
void alldel()
{
zx=-2000;zy=0;
for (i=0;i<=53;i++) {z=i;objput();}
for (i=96;i<=99;i++) {z=i;objput();}
for (i=100;i<=149;i++) {z=i;objput();}
for (i=200;i<=3999;i++) {z=i;objput();}
}
void datasave()
{
d1=mfx.ToString()+"/"+mfy.ToString();
PlayerPrefs.SetString(keyname2,d1);
PlayerPrefs.Save();
}
void dataload()
{
d1=PlayerPrefs.GetString(keyname2,"nothing");
if (d1!="nothing")
{
dts=d1.Split('/');
mfx=int.Parse(dts[0]);mfy=int.Parse(dts[1]);
}
else
{
mfx=640;mfy=360;
}
}
}