DiogoSequeira Posted May 11, 2012 at 06:27 PM Report #454717 Posted May 11, 2012 at 06:27 PM Boas pessoal. Estou a fazer um trabalho em JAVA, e é para ser executado em AGUIAJ. Eu tenho de fazer um jogo de cartas... Para tal eu já construí o baralho e já o baralhei, o que não consigo é distribui as cartas pela nº de jogadores (variável que o utilizador coloca, entre 2 e 8 )... Alguém me pode ajudar? Obrigado desde já!
KTachyon Posted May 11, 2012 at 06:59 PM Report #454726 Posted May 11, 2012 at 06:59 PM É só tirares cartas do baralho. Se estiveres a utilizar um stack para simular o baralho não é suposto teres grandes dificuldades. Se não estás, então é porque não escolheste bem a estrutura que devias utilizar. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
DiogoSequeira Posted May 11, 2012 at 07:08 PM Author Report #454732 Posted May 11, 2012 at 07:08 PM Eu tenho uma coisa deste género, o que sobrar da distribuição é que vou meter num stack para simular o monte de bisca! mas este código dá-me um erro na parte : "jogadores[a] = new Jogador (a, maoJogador); maos[a] = jogadores[a].ObterMaoDoJogador();" public static CardHand[] DarCartas(int nJogadores) { Card[] baralho = Baralhar(Baralho()); CardHand[] maos = new CardHand[nJogadores]; CardHand maoJogador; for(int a = 0; a < nJogadores; a++){ maoJogador = new CardHand(); for(int i = 0; i < 5; i++) maoJogador.add(baralho[i]); for(int j = 0; j < baralho.length-1;j++) baralho[j] = baralho[j+1]; jogadores[a] = new Jogador (a, maoJogador); maos[a] = jogadores[a].ObterMaoDoJogador(); } return maos; } Se me conseguires explicar como devo usar o stack agradecia!
lesiano16 Posted May 12, 2012 at 12:00 AM Report #454798 Posted May 12, 2012 at 12:00 AM Utiliza isto http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Stack.html. Stack<Object> stack; // criar stack stack.push(Object) // meter obj no top da stack Object o = stack.pop(); // retirar um obj do top da stack
chalkos Posted May 16, 2012 at 10:37 AM Report #455998 Posted May 16, 2012 at 10:37 AM O link que o lesiano16 queria dizer era http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Stack.html 😛
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now