public void playRound() { _pile.reset(); int i = 0; while (_pile.getSize() < 4) { int cp = (i++ + _fp) % 4; askcontrat askcard = askCard(_players[cp].getId()); _pile.add_carte(_players[cp].PlayCard(_pile, askcard)); } }
public unsafe void askContract(int playerId, List <Contract> contracts) { Header h = new Header(); h.id_command = 2; askcontrat contract = newaskcontrat(); contract.turn = playerId; contract.contrats_pile = fillContracts(contract.contrats_pile, contracts); foreach (Player player in _players) { contract.deck = player.fillDeck(contract.deck); player.write <Header>(h); player.write <askcontrat>(contract); } }
public int AskCard(ConnectWork link) { askcontrat str = new askcontrat(); deck deck; played pile; responce res = new responce(); string saisie; bool turn = true; int i = 0; int numval = 0; str = getStruct <askcontrat>(Marshal.SizeOf(str)); deck = str.deck; pile = str.contrats_pile; if (str.turn == _ID) { Console.WriteLine("les cartes déjà jouer sont :"); for (int j = 0; j < 4; j++) { if (pile.value[j] != -1) { Console.WriteLine("la " + j + " em carte est un(e) " + (Type)pile.ids[j] + " de " + (Couleur)pile.couleur[j] + " qui vaut " + pile.value[j]); } } while (turn == true) { Console.WriteLine("Votre deck est composé de :"); i = print_deck(deck); Console.WriteLine("veulliez saisir l'index de la carte que vous voulez jouer"); saisie = Console.ReadLine(); if (saisie != "") { numval = Convert.ToInt32(saisie); if (numval < i && numval >= 0) { turn = false; } } } res.value = numval; res.couleur = -1; byte[] message = link.getBytes <responce>(res); link.getNetworkStream().Write(message, 0, message.Length); } return(0); }
public unsafe askcontrat newaskcontrat() { askcontrat contract = new askcontrat(); contract.contrats_pile = new played(); contract.deck = new deck(); for (int i = 0; i < 8; i++) { if (i < 4) { contract.contrats_pile.couleur[i] = -1; contract.contrats_pile.ids[i] = -1; contract.contrats_pile.value[i] = -1; } contract.deck.couleur[i] = -1; contract.deck.value[i] = -1; } return(contract); }
public unsafe Carte PlayCard(Deck pile, askcontrat askcard) { askcard.deck = fillDeck(askcard.deck); Header h = new Header(); h.id_command = 3; bool ok = false; responce responce = new responce(); while (!ok) { write <Header>(h); write <askcontrat>(askcard); responce = read <responce>(); Carte carte = deck.getElem(responce.value); ok = isGoodMove(carte, pile); } return(deck.PutCard(responce.value)); }
public askcontrat askCard(int playerId) { askcontrat askcard = newaskcontrat(); Header h = new Header(); h.id_command = 3; askcard.turn = playerId; askcard.contrats_pile = fillPile(askcard.contrats_pile); foreach (Player player in _players) { askcard.deck = player.fillDeck(askcard.deck); if (player.getId() != playerId) { askcard.deck = player.fillDeck(askcard.deck); player.write <Header>(h); player.write <askcontrat>(askcard); } } return(askcard); }
//public unsafe struct askcontrat //2 //3 public int AskContract(ConnectWork link) { bool turn = true; int stronger = 0; responce res = new responce(); // Console.WriteLine("AskContract"); played tmp; deck deck; askcontrat str = new askcontrat(); string saisie; int numval = 0; str = getStruct <askcontrat>(Marshal.SizeOf(str)); //Console.WriteLine("turn = " + str.turn); tmp = str.contrats_pile; deck = str.deck; res.couleur = -1; res.value = -1; for (int i = 0; i < 4; i++) { if (tmp.ids[i] != -1) { if (tmp.value[i] > stronger) { stronger = tmp.value[i]; } Console.WriteLine("le joueur " + tmp.ids[i] + " a fait un contrat de " + tmp.value[i] + " de la couleur " + (Couleur)tmp.couleur[i]); } } if (str.turn == _ID) { Console.WriteLine("A vous de proposer un contrat"); Console.WriteLine("Votre deck est composé de :"); print_deck(deck); while (turn == true) { Console.WriteLine("veuillez saisir le montant du contrat (il doit valoir 0 ou être suppérieur au plus haut des contrats, ce dernier vaut : " + stronger); saisie = Console.ReadLine(); if (saisie != "") { numval = Convert.ToInt32(saisie); if (numval == 0 || numval > stronger) { turn = false; } } } res.value = numval; turn = true; while (turn == true) { Console.WriteLine("veuillez la couleur du contrat: 0 -> carreau, 1 -> trèfle, 2 -> Pick, 3 -> Coeur"); saisie = Console.ReadLine(); if (saisie != "") { numval = Convert.ToInt32(saisie); if (numval <= 3 && numval >= 0) { turn = false; } } } res.couleur = numval; } if (res.couleur != -1 && res.value != -1) { byte[] message = link.getBytes <responce>(res); link.getNetworkStream().Write(message, 0, message.Length); } return(0); }