asdasd

sdsdasd
mail@pastecode.io avatar
unknown
plain_text
3 years ago
2.0 kB
1
Indexable
Never
import java.util.ArrayList;
import java.util.Random;
import java.util.List;

public class Main {

	public static void main(String[] args) {
		boolean gameActive = true;

		Participant player1 = new Participant("Batin", "Ana Maria");
		Participant player2 = new Participant("Dobre", "Maria");
		
		Partida game = new Partida(player1, player2);

		while(gameActive) {
			
			gameActive = game.mansa();
			if(gameActive == false)
				System.out.println("Castigatorul este: " + game.winner().nume);
			
		}
	}
	
	
	public static class Participant {
		String nume, prenume;
		int scor = 0;
		
		Participant(String t_nume, String t_prenume) {
			nume = t_nume;
			prenume = t_prenume;
		}
		
		Participant(Participant p) {
			nume = p.nume;
			prenume = p.prenume;
		}
		
		
		public String toString() {
			String r = "Numele participantului este: " + nume;
			r += " Prenumele participantului este: " + prenume;
			r += " Scorul participantului este: " + scor;
			
			System.out.println(r);
			
 			return r;
		}
		
		public void incrementareScor()
		{
			++scor;
		}
		
		public int numarRandom() {
			int randomNumber;
			Random rand = new Random();
			
			randomNumber = rand.nextInt(100);

			return randomNumber;
			
		}	
	}
	
	public static class Partida {
		String numeCastigator;
		Participant player1;
		Participant player2;
		
		Partida(Participant t_player1, Participant t_player2) {
			player1 = t_player1;
			player2 = t_player2;
		}
		
		public boolean mansa() {
			if(player1.scor == 10) {
				return false;
			}
			else if(player2.scor == 10) {
				return false;
			}
			
			if(player1.numarRandom() > player2.numarRandom()) 
				player1.incrementareScor();
			else 
				player2.incrementareScor();
			
			return true; // Pseudo Atribuire
		}
		
		public Participant winner() {
			if(player1.scor > player2.scor)
				return player1;
			else
				return player2;
		}
	}
}