while(!gameover) //loops until gameover
{
if(first_player) //what happens if the player or eggman is chosen first
{
players[r] = 0; //eggman's turn
//attack damages
int E_attack1 = 5;
int E_attack2 = 10;
int E_attack3 = 15;
//attacks in an array
int[] attacks = { E_attack1, E_attack2, E_attack3 };
int A = attacks.length;
int p = (int) (Math.random() * A); //makes the attacks random
//the effects of what the damages will do to the Player's Life Points
if(attacks == E_attack1)
{
Player_LP -=E_attack1;
}
else
if(attacks == E_attack2)
{
Player_LP -=E_attack2;
}
else
if(attacks == E_attack3)
{
Player_LP -=E_attack3;
}
text.append("Eggman does "+ attacks + " damage." + "\n"); //the print out of the attack and damage
}
//players turn
else
{
//players attack damages
int attack1 = 5;
int attack2 = 10;
int attack3 = 15;
text.append( "Choose attack1 , attack2, or attack3: " + "\n"); //gives player a choice of attacks
inputField.getText(); //gets the text
text.getText(); //gets the text from the text area
//what happens when one of the attacks is chose
if(text.equals("attack1"))
{
//the effect of the attack on Eggman's life points
Eggman_LP -=attack1;
text.append( "\n" + "You attack with attack1 causing " + attack1 + " damage to Eggman."+"\n"); //the print out of the attack and the damage
}
else
if (text.equals("attack2"))
{
Eggman_LP -=attack2;
text.append( "\n" + "You attack with attack2 causing " + attack2 + " damage to Eggman."+"\n");
}
else
if(text.equals("attack3"))
{
Eggman_LP -=attack3;
text.append( "\n" + "You attack with attack3 causing " + attack3 + " damage to Eggman."+"\n");
}
}
first_player = !first_player; //make it turn base
//how to determine gameover
if (Player_LP <=0)
{
gameover = true;
text.append("Eggman Wins");
}
else
if (Eggman_LP <=0)
{
gameover = true;
text.append("You Win");
}
}
Quote: What is your player name: DKN You chose DKN as your player name. Your enemy will be Eggman. You and your opponent will have 100 life points. The player to lose all of their life points loses the game. You go first Choose attack1 , attack2, or attack3: Eggman does 10 damage. Choose attack1 , attack2, or attack3: Eggman does 5 damage. Choose attack1 , attack2, or attack3: Eggman does 5 damage. Choose attack1 , attack2, or attack3: Eggman does 10 damage. Choose attack1 , attack2, or attack3: Eggman does 5 damage. Choose attack1 , attack2, or attack3: Eggman does 5 damage. Choose attack1 , attack2, or attack3: Eggman does 5 damage. Choose attack1 , attack2, or attack3: Eggman does 5 damage. Choose attack1 , attack2, or attack3: Eggman does 15 damage. Choose attack1 , attack2, or attack3: Eggman does 5 damage. Choose attack1 , attack2, or attack3: Eggman does 15 damage. Choose attack1 , attack2, or attack3: Eggman does 5 damage. Choose attack1 , attack2, or attack3: Eggman does 5 damage. Choose attack1 , attack2, or attack3: Eggman does 15 damage. Eggman Wins[Edited by - Javacell on October 10, 2004 11:26:59 PM]