Skip to content

Instantly share code, notes, and snippets.

@grvcoelho
Last active September 26, 2015 02:18
Show Gist options
  • Save grvcoelho/109baf48ffe9a21cbbd8 to your computer and use it in GitHub Desktop.
Save grvcoelho/109baf48ffe9a21cbbd8 to your computer and use it in GitHub Desktop.
Implementação de Rouba Monte em Java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package main;
import API.*;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author guilherme
*/
public class RoubaMonte {
private Scanner sc;
private Baralho baralho;
private int numJogadores;
private ArrayList<Mao> jogadores;
public RoubaMonte() {
baralho = new Baralho();
baralho.embaralhar();
sc = new Scanner(System.in);
jogadores = new ArrayList<>();
}
/**
* Inicia o jogo
*/
public void jogar() {
this.defineJogadores();
this.distribueCartas();
}
/**
* Define quantos jogadores terá o jogo
*/
private void defineJogadores() {
System.out.println("Quantos jogadores? [2-4]");
numJogadores = sc.nextInt();
for (int i = 0; i < numJogadores; i++) {
System.out.println("Nome do jogador " + (i + 1) + ":");
String nomeJogador = sc.next();
jogadores.add(new Mao(nomeJogador));
}
}
/**
* Divide as cartas igualmente entre cada jogador
*/
private void distribueCartas() {
for (int i = 0; baralho.getDisponiveis() > 0; i++) {
if (i == jogadores.size()) {
i = 0;
}
jogadores.get(i).receberCarta(baralho.getCarta());
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new RoubaMonte().jogar();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment