Created
February 11, 2013 17:47
-
-
Save mochja/4756106 to your computer and use it in GitHub Desktop.
Author: Jan Mochnak, 2012; Program, ktory simuluje hru na kos. N hracov hadze na kos ak hrac nehodi kos ale hrac pred nim kos hodi, tak aktualny hrac vypadava. Vitazi posledny hrac.
This file contains 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 <time.h> | |
// author: Jan Mochnak | |
int main () | |
{ | |
srand(time(NULL)); | |
printf("Welcome\nGame ver. 0.0.2\n===========================\n\n"); | |
int players; | |
do | |
{ | |
printf("Please, set count of playing players: "); | |
scanf("%d", &players); | |
} | |
while(players < 1); | |
system("clear"); | |
printf("======================================================\n"); | |
printf(" Loading new game....\n"); | |
printf("\tPlayers count: %d\n", players); | |
printf("======================================================\n"); | |
printf("\n The game is starting now!!\n\n"); | |
int player[players]; | |
int last = -1, ingame = players; | |
int i = 0; | |
// initial numbering... player[0] id 1st player.. | |
for(i = 0; i < players;i++) | |
player[i] = i+1; | |
while(ingame > 1) | |
{ | |
for(i = 0; i < players; i++) | |
{ | |
if (player[i] == -1) continue; | |
if( last == -1 ) | |
{ | |
last = rand()%2; | |
printf("Player %d %s!!\n", player[i], last ? "scored" : "is noob"); | |
continue; | |
} | |
int p = rand()%2; // sanca pre aktualneho hraca | |
printf("Player %d %s!!\n", player[i], p ? "scored" : "is noob"); | |
if( p == 0 && last == 1 ) | |
{ | |
printf("== Player %d is out!!\n", player[i]); | |
player[i] = -1; | |
ingame--; | |
} | |
if(ingame == 1) break; | |
last = p; | |
} | |
} | |
printf("\n========\n!![!CONGRATULATION!]!! to player "); | |
for(i = 0; i < players; i++) | |
if( player[i] != -1 ) | |
printf("%d is the winner!\n\n", player[i]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment