Last active
October 31, 2015 09:12
-
-
Save Nia-TN1012/1eb3a3f7a470ded595c2 to your computer and use it in GitHub Desktop.
プロ生勉強会 第36回@恵比寿のLTで使用した「大小推測ゲーム」と「フラッシュナンバーズ」のソースコードです。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include<time.h> | |
#define num 100 | |
int main(void) | |
{ | |
int a,b,ans,c,game=0,win=0; | |
do{ | |
game++; | |
srand((unsigned)time(NULL)); // rand()の初期化 | |
printf("大小推測ゲーム(範囲:1~%d)\n",num); | |
do{ | |
a=rand()%num+1; | |
b=rand()%num+1; | |
if(a!=b) break; | |
}while(a==b); | |
printf("\nA……%d\nB……?? ← Big or Small?\n",a); | |
do{ | |
printf("(Big…1/Small…2):"); | |
scanf("%d",&ans); | |
if(ans>0 && ans<=2) break; | |
}while(ans<=0 || ans>2); | |
printf("\n"); | |
printf("A……%d\n",a); | |
printf("B……%d\n",b); | |
switch(ans){ | |
case 1: | |
if(a<b) {puts("Good job!"); win++;} | |
else puts("You failed..."); | |
break; | |
case 2: | |
if(a>b) {puts("Good job!"); win++;} | |
else puts("You failed..."); | |
break; | |
} | |
printf("\nTry Again?(Y…0/N…9):"); | |
scanf("%d",&c); | |
printf("\n"); | |
}while(c==0); | |
printf("あなたは%d回中、%d回クリアしました。\n",game,win); | |
return(0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <windows.h> | |
int main(void) | |
{ | |
int qs[2]={0},solve[2]={0},lv=1,lvl,i,range,ranges,win=0; | |
puts("フラッシュナンバーズ LITE (C言語バージョン)"); | |
while(1){ | |
lvl=lv/6+1; | |
if(lv>10) break; // レベル10まで | |
srand((unsigned)time(NULL)); // rand()の初期化 | |
for(i=0;i<lvl;i++){ | |
qs[i]=rand()%900+100; // 3桁 | |
} | |
printf("Level:%d\n",lv); | |
switch(lv/6){ | |
case 0: // Lv1~Lv5 | |
printf("次の数値を記憶してください。:%d",qs[0]); | |
fflush(stdout); | |
Sleep(1000); | |
printf("\r次の数値を記憶してください。:---\n"); | |
printf("記憶した数値を入力してください。:"); | |
scanf("%d",&solve[0]); | |
printf("Ans=%d\n",qs[0]); | |
Sleep(500); | |
if(solve[0]==qs[0]) {win++; puts("○正解です。");} | |
else puts("×違います。"); | |
Sleep(1000); | |
printf("\n"); | |
break; | |
case 1: | |
printf("次の2つの数値を記憶してください。①:%d,②:%d",qs[0],qs[1]); | |
fflush(stdout); | |
Sleep(1000); | |
printf("\r次の2つの数値を記憶してください。①:---,②:---\n"); | |
printf("記憶した数値を入力してください。\n"); | |
for(i=0;i<lvl;i++){ | |
printf("[%d]=",i+1); scanf("%d",&solve[i]); | |
} | |
printf("Ans・・・①:%d,②:%d\n",qs[0],qs[1]); | |
Sleep(500); | |
if(solve[0]==qs[0] && solve[1]==qs[1]) {win++; puts("○正解です。");} | |
else puts("×違います。"); | |
Sleep(1000); | |
printf("\n"); | |
break; | |
} | |
lv++; | |
} | |
printf("あなたは10問中、%d問正解しました。\n",win); | |
if(win==10) printf("おめでとう!パーフェクトです!"); | |
puts("約3秒後に終了します。"); | |
Sleep(3000); | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment