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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| #include <stdio.h> #include <time.h> #include <stdlib.h>
void print() { printf("Power of Logic for Macintosh,Powered by Mimi 1984,Copyright(C)Mimi 1984\n"); printf("Version 0.9.0Beta2 CHEAT 0000 DEBUG 1111 INFO 2222\n"); printf("Thanks for using the Beta version!\n\n"); } int game() { int i, j, n, ref[8], a[4], b[4], times = 0; srand((unsigned int) time(0)); for (i = 0; i < 8; i++) ref[i] = i; i = 0; while (1) { n = rand() % 8; if (ref[n] != -1) { a[i] = n; ref[n] = -1; if (++i == 4) break; } } input: printf("Input your answer\n"); int x = 0, y = 0, error = 0; rewind(stdin); for (i = 0; i < 4; i++) { int check = scanf("%d", &b[i]); if (check != 1) error += 1; } if (error != 0) { printf("ERROR:Invalid input.\n"); goto input; } if (b[0] == 0 && b[1] == 0 && b[2] == 0 && b[3] == 0) { printf("The correct answer is:"); for (i = 0; i < 4; i++) { printf(" %d", a[i]); if (i == 3) printf("\n"); } goto output; } if (b[0] == 1 && b[1] == 1 && b[2] == 1 && b[3] == 1) { printf("DEBUG MODE.\nThe correct answer is:"); for (i = 0; i < 4; i++) { printf(" %d", a[i]); if (i == 3) printf("\n"); } goto input; } if (b[0] == 2 && b[1] == 2 && b[2] == 2 && b[3] == 2) { printf("Sorry.No English Version Provided.\n"); goto input; } for (i = 0; i < 3; i++) { for (j = i + 1; j < 4; j++) { if (b[i] == b[j]) { printf("ERROR:No duplicate numbers allowed.\n"); goto input; } } } for (i = 0; i < 3; i++) { if (b[i] <= -1 || b[i] >= 8) { printf("ERROR:Only number 0~7 are allowed.\n"); goto input; } } for (i = 0; i < 4; i++) { if (a[i] == b[i]) x++; } printf("%d ", x); for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { if (a[i] == b[j]) y++; } } y -= x; printf("%d\n", y); if (times == 10) printf("Come On!You have guessed for too many times!\n"); if (times == 15) { printf("Oh Fuck!You have guessed for TOO many times!\nThe correct answer is:"); for (i = 0; i < 4; i++) { printf(" %d", a[i]); if (i == 3) printf("\n"); } goto output; } if (x == 4) { printf("Bingo!\n"); times += 1; } else { times += 1; goto input; } output: printf("Have Fun!\n"); return times; } int main(void) { time_t start, end; int cost, times, score; print(); while (1) { printf("Press Enter To Start The Game.\n"); getchar(); time(&start); times = game(); time(&end); cost = difftime(end, start); score = 100 - cost / 10 - times * 2; if (score <= 0) score = 0; printf("Run Time:%d Seconds\n", cost); printf("Times You Guessed:%d\n", times); printf("Your Score:%d\n\n", score); } return 0; }
|