Skip to content

Instantly share code, notes, and snippets.

@nappa7878
Created December 2, 2012 06:28
Show Gist options
  • Save nappa7878/4187317 to your computer and use it in GitHub Desktop.
Save nappa7878/4187317 to your computer and use it in GitHub Desktop.
九九ランダム表示(iPad PR0C0D1N6用)
/*****************************************
* 九九ランダム表示 (iPad PR0C0D1N6用)
* 横置き
* ボタンクリックで表示の切替
* Hiroyuki Nakano
* 2012.12.02
*****************************************/
String[] Quest = new String[81];
int[] Ans = new int[81];
int[] rS = new int[81];
int dflag = -1;
int qCount = 0;
PFont font=createFont("FFScala", 32);
void setup() {
size(screen.width,screen.height);
colorMode(RGB, 100);
randSeed(rS);
QuestionMake();
}
void draw(){
switch (dflag){
case -1:
background(255,255,255);
Start();
break;
case 0:
background(255,255,255);
Question();
break;
case 1:
background(255,255,255);
Answer();
break;
case 2:
background(255,255,255);
End();
break;
}
}
void Start(){
float fontSize = 150;
fill(0,255,0);
textFont(font,fontSize);
text("はじめるよ!" , screen.width / 2 - fontSize * 2, screen.height / 2);
}
void End(){
float fontSize = 150;
fill(255,0,0);
textFont(font,fontSize);
text("がんばった!" , screen.width / 2 - fontSize * 2, screen.height / 2);
}
void QuestionMake(){
for(int i=1;i<10;i++){
for(int j=1;j<10;j++){
Quest[qCount] = i+"×"+j;
Ans[qCount] = i * j;
qCount++;
}
}
qCount = -1;
}
void Question(){
float fontSize = 500;
fill(0,0,0);
textFont(font,fontSize);
text(Quest[rS[qCount]] , screen.width / 2 - fontSize / 2, screen.height / 2);
}
void Answer(){
float fontSize = 500;
fill(0,0,255);
textFont(font,fontSize);
text(Ans[rS[qCount]] , screen.width / 2 - fontSize / 2 + 150, screen.height / 2);
}
void mousePressed(){
dflag++;
dflag = dflag % 2;
if(dflag == 0) qCount++;
if(qCount == 81) dflag = 2;
}
void randSeed(int rS[]){
int dummy;
randomSeed(second());
for(int i=0;i<rS.length;i++){
rS[i] = i;
}
for(int j=0;j<10000;j++){
int r1 = (int) random(0,81);
int r2 = (int) random(0,81);
dummy = rS[r1];
rS[r1] = rS[r2];
rS[r2] = dummy;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment