public void setJogar(Itens_Compartilhados.Jogador jogador) { for (int i = 0; i < jogadores.Length; i++) { if (jogadores[i].ID == jogador.ID) { if (jogadores[i].jogando) { jogadores[i].jogando = false; } else { jogadores[i].jogando = true; } } } }
private Itens_Compartilhados.Jogador[] embaralhar(int qtd) { int cartasCada = 32 / qtd; int cartasExtra = 32 % qtd; int numero; Boolean OK; Itens_Compartilhados.Jogador[] jogs = new Itens_Compartilhados.Jogador[8]; Itens_Compartilhados.Carta[] cartas = new Itens_Compartilhados.Carta[33]; jogs = this.jogadores; Random rnd = new Random(); resetJogada(); for (int i = 0; i < jogs.Length; i++) { for (int j = 0; j < jogs[i].cartas.Length; j++) { jogs[i].cartas[j].ativo = false; this.jogadores[i].cartas[j].ativo = false; } } if (!this.isEmbaralhado) { for (int i = 0; i < cartas.Length; i++) { cartas[i] = new Itens_Compartilhados.Carta(); cartas[i].ativo = false; } for (int i = 0; i < jogs.Length; i++) { if (jogs[i].conectado && jogs[i].jogando) { for (int j = 0; j < cartasCada; j++) { OK = false; while (!OK) { numero = rnd.Next(1, 33); if (!cartas[numero].ativo) { jogs[i].cartas[numero].ativo = true; cartas[numero].ativo = true; OK = true; } } } } } if (cartasExtra > 0) { List <int> lista = new List <int>(); lista.Clear(); for (int i = 0; i < cartasExtra; i++) { OK = false; while (!OK) { numero = rnd.Next(0, jogs.Length - 1); if (!lista.Contains(numero)) { if (jogs[numero].conectado && jogs[numero].jogando) { for (int j = 1; j < cartas.Length; j++) { if (!cartas[j].ativo) { jogs[numero].cartas[j].ativo = true; cartas[j].ativo = true; break; } } lista.Add(numero); OK = true; } } } } lista.Clear(); } } primeiroJogador(); return(jogs); }