All pastes #783939 Raw Copy code Copy link Edit

Unnamed

public java v1 · immutable
#783939 ·published 2007-11-19 13:20 UTC
rendered paste body
import java.util.Random;public class FightersUniverse{	Player players[];	Random generator;	//define how many players in the battle	private static final int MAX_PLAYERS_SIZE=4;	private int target=0,attacker=0;	//identify which round is it	private int Round=0;	//identify how many players is already died	private int deadNumber=0;	public FightersUniverse()	{		generator=new Random();		players=new Player[MAX_PLAYERS_SIZE];		//call 4 players(Object) to this battle		players[0]=new BossPlayer("Boss Florence");		players[1]=new BossPlayer("Boss Janice");		players[2]=new Player("Potato HoYin");		players[3]=new Player("Potato Justin");	}		public void Attack()	{	do	{		//use a random number (0-MAX_PLAYERS_SIZE) for attacker and target		attacker=generator.nextInt(MAX_PLAYERS_SIZE);		target=generator.nextInt(MAX_PLAYERS_SIZE);		//if the attacker is dead then choose another one		while (players[attacker].isDead)		{			attacker=generator.nextInt(MAX_PLAYERS_SIZE);		}		//if the target is dead or he is attacker then choose another one		while (target==attacker || players[target].isDead)		{			target=generator.nextInt(MAX_PLAYERS_SIZE);		}		Round++;		players[attacker].Round=Round;		//attacker attack target		players[attacker].Attack(players[target]);		if (players[target].isDead || players[attacker].isDead)		deadNumber++;	}	while	(deadNumber<MAX_PLAYERS_SIZE-1);	System.out.println("----Game Over-----");	for (int i=0;i<MAX_PLAYERS_SIZE;i++)	{		System.out.printf("**** %s power = %d \n",players[i].getName(),players[i].getPower());	}	}					public static void main(String argv[])	{		FightersUniverse main=new FightersUniverse();		main.Attack();		}}