검색결과 리스트
글
[c] 매우 간단한 야구 게임
program/c
2012. 9. 28. 13:57
반응형
매우 간단한 야구게임이다.
2010년 프로그램을 막 시작했을 때 만든것 같다.
그러므로 매우 허접하다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <stdio.h> #include <stdlib.h> #include <time.h> int main(){ int answer[3], input[3], i, j, strike=0, ball=0, out=0, flag=0; srand ((unsigned int ) time (NULL)); while (1){ for (i=0; i<3; i++) answer[i] = rand () % 9 + 1; if (answer[0] == answer[1] || answer[0] == answer[2] || answer[1] == answer[2] || answer[2] == answer[0]) flag=0; else flag=1; if (flag) break ; } while (1){ printf ( "====== Answer Num ======\n%d %d %d\n" , answer[0], answer[1], answer[2]); printf ( "====== Input Num =======\n" ); for (i=0; i<3; i++) scanf ( "%d" , &input[i]); for (i=0; i<3; i++){ for (j=0; j<3; j++) if (i != j){ if (answer[i] == input[j]) ball++; } else if (answer[i] == input[j]) strike++; } out++; printf ( "======== Result ========\nBall : %d\nStrike : %d\nOut : %d\n\n" , ball, strike, out); if (strike == 3) break ; else if (out == 10){ printf ( "///////// 10 Out /////////\n///////// GameOver /////////\n" ); break ; } printf ( "\n\n\n\n\n\n\n\n\n\n\n\n" ); ball=0; strike=0; } }</ time .h></stdlib.h></stdio.h> |
반응형
'program > c' 카테고리의 다른 글
[c] Up & Down 게임 (0) | 2012.09.28 |
---|---|
[c] 사용자 입력 피라미드 별찍기 (0) | 2012.09.28 |
[c] 사용자 입력에 따라 변하는 별찍기 (0) | 2012.09.28 |