243 lines
9.5 KiB
C#
243 lines
9.5 KiB
C#
using System.Net.NetworkInformation;
|
|
|
|
namespace squadre_calcio;
|
|
|
|
class Program {
|
|
static void Main(string[] args) {
|
|
Console.Clear();
|
|
int scelta;
|
|
Squadra[] squadre = null;
|
|
do {
|
|
Console.WriteLine("Scegliere un'opzione:");
|
|
Console.WriteLine("1. Inserisci un array di squadre");
|
|
Console.WriteLine("2. Stampa formazione di una squadra");
|
|
Console.WriteLine("3. Stampa tutte le squadre");
|
|
Console.WriteLine("4. Pulisci schermo");
|
|
Console.WriteLine("0. Esci");
|
|
Console.Write("Scelta: ");
|
|
scelta = Convert.ToInt32(Console.ReadLine());
|
|
|
|
switch (scelta) {
|
|
case 0:
|
|
break;
|
|
case 1:
|
|
squadre = CreaArraySquadre();
|
|
Pausa();
|
|
break;
|
|
case 2:
|
|
if (squadre == null) {
|
|
Console.WriteLine("Errore: è necessario creare l'array di squadre prima di poter stampare la formazione di una squadra");
|
|
}
|
|
else {
|
|
do {
|
|
Console.WriteLine("Per quale parametro scegliere la squadra? ");
|
|
Console.WriteLine("1. Nome");
|
|
Console.WriteLine("2. Città");
|
|
Console.WriteLine("3. Sponsor");
|
|
Console.WriteLine("4. Numero membri");
|
|
Console.Write("Scelta: ");
|
|
scelta = Convert.ToInt32(Console.ReadLine());
|
|
|
|
switch (scelta) {
|
|
case 1:
|
|
do {
|
|
Console.WriteLine("Scegliere un'opzione:");
|
|
for (int i = 0; i < squadre.Length; i++) {
|
|
Console.WriteLine($"{i}. {squadre[i].GetNome()}");
|
|
}
|
|
Console.Write("Scelta: ");
|
|
scelta = Convert.ToInt32(Console.ReadLine());
|
|
if (scelta < 0 || scelta >= squadre.Length) {
|
|
Console.WriteLine("Opzione non valida.");
|
|
Pausa();
|
|
}
|
|
}
|
|
while (scelta < 0 || scelta >= squadre.Length);
|
|
|
|
squadre[scelta].StampaSquadra();
|
|
|
|
scelta = -1;
|
|
break;
|
|
case 2:
|
|
do {
|
|
Console.WriteLine("Scegliere un'opzione:");
|
|
for (int i = 0; i < squadre.Length; i++) {
|
|
Console.WriteLine($"{i}. {squadre[i].GetCitta()}");
|
|
}
|
|
Console.Write("Scelta: ");
|
|
scelta = Convert.ToInt32(Console.ReadLine());
|
|
if (scelta < 0 || scelta >= squadre.Length) {
|
|
Console.WriteLine("Opzione non valida.");
|
|
Pausa();
|
|
}
|
|
}
|
|
while (scelta < 0 || scelta >= squadre.Length);
|
|
|
|
squadre[scelta].StampaSquadra();
|
|
|
|
scelta = -1;
|
|
break;
|
|
case 3:
|
|
do {
|
|
Console.WriteLine("Scegliere un'opzione:");
|
|
for (int i = 0; i < squadre.Length; i++) {
|
|
Console.WriteLine($"{i}. {squadre[i].GetSponsor()}");
|
|
}
|
|
Console.Write("Scelta: ");
|
|
scelta = Convert.ToInt32(Console.ReadLine());
|
|
if (scelta < 0 || scelta >= squadre.Length) {
|
|
Console.WriteLine("Opzione non valida.");
|
|
Pausa();
|
|
}
|
|
}
|
|
while (scelta < 0 || scelta >= squadre.Length);
|
|
|
|
squadre[scelta].StampaSquadra();
|
|
|
|
scelta = -1;
|
|
break;
|
|
case 4:
|
|
do {
|
|
Console.WriteLine("Scegliere un'opzione:");
|
|
for (int i = 0; i < squadre.Length; i++) {
|
|
Console.WriteLine($"{i}. {squadre[i].GetMembri().Length}");
|
|
}
|
|
Console.Write("Scelta: ");
|
|
scelta = Convert.ToInt32(Console.ReadLine());
|
|
if (scelta < 0 || scelta >= squadre.Length) {
|
|
Console.WriteLine("Opzione non valida.");
|
|
Pausa();
|
|
}
|
|
}
|
|
while (scelta < 0 || scelta >= squadre.Length);
|
|
|
|
squadre[scelta].StampaSquadra();
|
|
|
|
scelta = -1;
|
|
break;
|
|
default:
|
|
Console.WriteLine("Opzione non valida.");
|
|
Pausa();
|
|
break;
|
|
}
|
|
}
|
|
while(scelta != -1);
|
|
}
|
|
Pausa();
|
|
break;
|
|
case 3:
|
|
Pausa();
|
|
break;
|
|
case 4:
|
|
Console.Clear();
|
|
break;
|
|
default:
|
|
Console.WriteLine("Opzione non valida.");
|
|
Pausa();
|
|
break;
|
|
}
|
|
}
|
|
while (scelta != 0);
|
|
}
|
|
|
|
static void Pausa() {
|
|
Console.WriteLine("Premere un tasto per continuare. . .");
|
|
Console.ReadKey();
|
|
}
|
|
|
|
static Squadra[] CreaArraySquadre() {
|
|
Squadra[] ritorno;
|
|
int input;
|
|
string nome;
|
|
string citta;
|
|
string sponsor;
|
|
Giocatore[] membri;
|
|
|
|
|
|
|
|
do {
|
|
Console.Write("Quante squadre si vuole creare? ");
|
|
input = Convert.ToInt32(Console.ReadLine());
|
|
if (input <= 0) {
|
|
Console.WriteLine("Non è possibile creare meno di una squadra.");
|
|
Pausa();
|
|
}
|
|
}
|
|
while (input <= 0);
|
|
|
|
ritorno = new Squadra[input];
|
|
|
|
for (int i = 0; i < ritorno.Length; i++) {
|
|
Console.WriteLine($"Squadra n. {i + 1}:\n");
|
|
|
|
Console.Write("Nome della squadra: ");
|
|
nome = Console.ReadLine();
|
|
|
|
Console.Write("Città della squadra: ");
|
|
citta = Console.ReadLine();
|
|
|
|
Console.Write("Sponsor della squadra: ");
|
|
sponsor = Console.ReadLine();
|
|
|
|
|
|
membri = CreaArrayGiocatori();
|
|
|
|
ritorno[i] = new Squadra(nome, citta, sponsor, membri);
|
|
}
|
|
return ritorno;
|
|
}
|
|
|
|
static Giocatore[] CreaArrayGiocatori() {
|
|
Giocatore[] ritorno;
|
|
int input;
|
|
string nome;
|
|
string cognome;
|
|
string eta;
|
|
string nomeRuolo;
|
|
string numeroMaglia;
|
|
|
|
do {
|
|
Console.Write("Da quanti giocatori è formata la squadra? ");
|
|
input = Convert.ToInt32(Console.ReadLine());
|
|
if (input <= 0) {
|
|
Console.WriteLine("Non è possibile creare una squadra con meno di un giocatore.");
|
|
Pausa();
|
|
}
|
|
}
|
|
while (input <= 0);
|
|
ritorno = new Giocatore[input];
|
|
|
|
for (int i = 0; i < ritorno.Length; i++) {
|
|
Console.WriteLine($"Giocatore n. {i + 1}:\n");
|
|
|
|
Console.Write("Nome del giocatore: ");
|
|
nome = Console.ReadLine();
|
|
|
|
Console.Write("Cognome del giocatore: ");
|
|
cognome = Console.ReadLine();
|
|
|
|
do {
|
|
Console.Write("Età del giocatore: ");
|
|
input = Convert.ToInt32(Console.ReadLine());
|
|
if (input <= 0) {
|
|
Console.WriteLine("Non è possibile un giocatore con un'età inferiore a zero.");
|
|
Pausa();
|
|
}
|
|
}
|
|
while (input <= 0);
|
|
|
|
eta = Convert.ToString(input);
|
|
|
|
Console.Write("Ruolo del giocatore: ");
|
|
nomeRuolo = Console.ReadLine();
|
|
|
|
Console.Write("Numero di maglia del giocatore: ");
|
|
numeroMaglia = Convert.ToString(Convert.ToInt32(Console.ReadLine()));
|
|
|
|
ritorno[i] = new Giocatore(nome, cognome, eta, nomeRuolo, numeroMaglia);
|
|
}
|
|
|
|
return ritorno;
|
|
}
|
|
}
|