I'm trying to make a program, which puts a given amount of players in a given amount of teams. Afterwards they should be randomly chosen (eg. you roll the "dice" and Team 3's Player 42 and shall fight against Team 4's Player 22 (All the players are randomly put in the different teams, which are limited to the choice of the Gamemaster)).
In my code I have the basic output and structure. It says something like:
Team 1 now owns Player 43 Team 2 now owns Player 12 Team 4 now owns Player 1 Team 3 now owns Player 54
But my question is, how - based on the code - I could save this information and how can I (afterwards) let the players randomly fight? Members of the same team should NOT be able to fight each other and after each fight I want the players (if they lose in what ever game this gets translated into) to be somehow on a "blacklist" where they can't be rolled anymore.
My code so far
#include<stdio.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int mitglieder, teams, teameins = 0, teamzwei = 0, teamdrei = 0, teamvier = 0;
printf("Teamcreation\n");
printf("\nNumber of Players: ");
scanf("%d", &mitglieder);
printf("\nNumber of Teams: ");
scanf("%d", &teams);
printf("\nThere are ");
printf("%d", mitglieder);
printf(" Player in ");
printf("%d", teams);
printf(" Teams. \n");
int array[mitglieder];
for (int i = 0; i < mitglieder; i++) { // fill array
array[i] = i;
}
printf("The Player are in the following Teams: \n ");
for (int i = 0; i < mitglieder; i++) { // shuffle array
int temp = array[i];
int randomIndex = rand() % mitglieder;
array[i] = array[randomIndex];
array[randomIndex] = temp;
}
for (int i = 0; i < mitglieder; i++) { // print array
int random_number = rand() % teams + 1;
int tp = random_number;
if(tp == 1) {
teameins+1;
}else
if(tp == 2 ) {
teamzwei+1;
}else
if(tp == 3 ) {
teamdrei+1;
}else
if(tp == 4 ) {
teamvier+1;
}
printf("Team %d - Spieler: %d\n ",random_number,array[i] + 1);
}
if( (teamvier == 0) && (teamdrei == 0) ) {
printf("\n%d Mitglieder in Team 1 und %d Mitglieder in Team2",teameins,teamzwei);
}else
if( (teamvier == 0) && (teamdrei < 0) ) {
printf("\n%d Mitglieder in Team 1, %d Mitglieder in Team2 und %d Mitglieder in Team3.",teameins,teamzwei,teamdrei);
}else
if(teamvier < 0) {
printf("\n%d Mitglieder in Team 1, %d Mitglieder in Team2, %d Mitglieder in Team 3 und %d Mitglieder in Team4.",teameins,teamzwei,teamdrei,teamvier);
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire