vendredi 23 octobre 2015

random numbers in function wont reset

i want to creat a Programm that play scissor paper lizard.. . So far everything works, but if it gets to a draw i dont really know how to restart the game. i tried it this way: IF player1 and 2 are showing the same thing it will just repeat it over and over again without reshuffeling payer 1/2

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
enum variablen {scissor=1, paper, rock, lizard, spock} ;
int i;
const char * vergleich(int random) {
switch(random) {
    case scissor: return "Siccor";
    case paper: return "Paper";
    case rock: return "Rock";
    case lizard: return "Lizard";
    case spock: return "Spock";
    default: break;
}
return "";
}

int new_game() {
srand(time(NULL));
int s1 = rand() % 5+1;
int s2 = rand() % 5+1;
printf("player1 shows %s", vergleich(s1));
printf("\n\tif Player 2 plays %s or %s Player1 wins\n", vergleich(s1+1), vergleich(s1+3));
printf("player2 shows: %s\n", vergleich(s2));
if(s2 == s1 + 1 || s2 == s1 +3 || s1 == s2) {
    if(s1==s2) {
            printf("draw \n");
            i = 0;
    }else{printf("player1 wins"); i = 4;}
}else{printf("player2 wins"); i = 4;}
return 0;
}



int main() {
printf("Welcome\n");
            while(i == 0) {new_game();}
return 0;
}




Aucun commentaire:

Enregistrer un commentaire