Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <conio.h>
- #define P1 1
- #define P2 2
- int main () {
- int start, dest; // start & destination of game
- int turn; // determine who has first turn
- int total, jump; // total point, jump of user
- int isEven = -1, // previous jump is even or not?
- isInvalid, // user input is invalid or not?
- isOut = 0, // End game?
- Winner = 0; // Save who win
- printf("..:: ICT GAME CENTER - SMART STRATEGY ::..\n\n");
- printf("> Start: ");
- scanf("%d", &start);
- total = start;
- do {
- printf("> Destination: ");
- scanf("%d", &dest);
- if (dest <= start) {
- printf("!!! Please enter destination bigger than start (%d)", start);
- }
- } while (dest <= start);
- srand(time(NULL));
- turn = rand() % 2 + 1;
- printf("> Who play first (randomly): %d", turn);
- putchar('\n');
- do {
- if (turn == P1) {
- printf("\n+ P1 - turn:\n");
- }
- else {
- printf("\n+ P2 - turn:\n");
- }
- do {
- printf(" > Choose a number: ");
- scanf("%d", &jump);
- if (jump > 5) {
- printf(" ! invalid - greater than 5 !\n");
- isInvalid = 1;
- } else if (jump < 1) {
- printf(" ! invalid - smaller than 1 !\n");
- isInvalid = 1;
- } else if (isEven == 0 && (jump % 2)) {
- printf(" ! invalid - odd as previous selected !\n");
- isInvalid = 1;
- } else if (isEven == 1 && !(jump % 2)) {
- printf(" ! invalid - even as previous selected !\n");
- isInvalid = 1;
- } else {
- isInvalid = 0;
- isEven = !(jump % 2);
- }
- } while (isInvalid);
- total += jump;
- printf("-> Now the value is %d\n", total);
- if (total >= dest) {
- if (turn == P1) {
- printf("\n!!! P1 WIN. CONGRATULATION !!!\n");
- Winner = P1;
- } else {
- printf("\n!!! P2 WIN. CONGRATULATION !!!\n");
- Winner = P2;
- }
- isOut = 1;
- }
- if (turn == P1) {
- turn = P2;
- }
- else {
- turn = P1;
- }
- } while (!isOut);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement