Project #48297 - Java HW

RPGPlayer IO

 

Objective:

 

Write a two classes:  One class draws a square, and an exception that occurs when the user puts in an invalid dimension.

 

 

Example Dialog:

Simple PVP Game

Player 1

The player  Travis the Immortal!

HP: 100

Strength: 15

Speed: 2.0

Weapon:  Board with a nail

 

Player 2

The player Bob

HP: 100

Strength: 10

Speed: 5.5

Weapon: Rat on a Stick

 Travis the Immortal! attacks with  Board with a nail

Bob now has 85 HP

 

Bob attacks with Rat on a Stick

 Travis the Immortal! now has 90 HP

 

 Travis the Immortal! attacks with  Board with a nail

Bob now has 70 HP

 

Bob attacks with Rat on a Stick

 Travis the Immortal! now has 80 HP

 

 Travis the Immortal! attacks with  Board with a nail

Bob now has 55 HP

 

Bob attacks with Rat on a Stick

 Travis the Immortal! now has 70 HP

 

 Travis the Immortal! attacks with  Board with a nail

Bob now has 40 HP

 

Bob attacks with Rat on a Stick

 Travis the Immortal! now has 60 HP

 

 Travis the Immortal! attacks with  Board with a nail

Bob now has 25 HP

 

Bob attacks with Rat on a Stick

 Travis the Immortal! now has 50 HP

 

 Travis the Immortal! attacks with  Board with a nail

Bob now has 10 HP

 

Bob attacks with Rat on a Stick

 Travis the Immortal! now has 40 HP

 

 Travis the Immortal! attacks with  Board with a nail

Bob now has -5 HP

 

The battle is over!

 Travis the Immortal! has won!

 

The player was cloned after the battle and has the following stats

The player   Travis the Immortal!

HP: 40

Strength: 15

Speed: 2.0

Weapon:   Board with a nail

Finally:

Upload RPGPlayer file to the dropbox

 

 

 

Text Files:

Name Travis the Immortal!
HP 100
Strength 15
Speed 2.0
Weapon Board with a nail

 

LAB20Files:

 

public class SimplePVPGame {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("Simple PVP Game");
		RPGPlayer p1 = new RPGPlayer("player1.txt");
		RPGPlayer p2 = new RPGPlayer("Bob", 100, 10, 5.5,"Rat on a Stick");
		
		System.out.println("Player 1");
		p1.printInfo();
		System.out.println();
		System.out.println("Player 2");
		p2.printInfo();
		
		boolean gameOver = false;
		boolean isPlayer1sTurn = true;
		while(gameOver == false)
		{
			//The winning condition
			if(p1.getHP()<=0||p2.getHP()<=0)
			{
				System.out.println("The battle is over!");
				if(p1.getHP()<=0)
					System.out.println(p2.getName()+" has won!");
				else
					System.out.println(p1.getName()+" has won!");
				break;
			}
			else if(isPlayer1sTurn)
			{
				Turn(p1,p2);
				isPlayer1sTurn = false;
			}
			else
			{
				Turn(p2,p1);
				isPlayer1sTurn = true;
			}
			System.out.println();
		}
		p1.writePlayerFile("results.txt");
		
		RPGPlayer p1Clone = new RPGPlayer("results.txt");
		System.out.println();
		System.out.println("The player was cloned after the battle and has the following stats");
		p1Clone.printInfo();
	}
	public static void Turn(RPGPlayer player, RPGPlayer opponent)
	{
		//Try to run away!
		if(player.getHP()<10)
		{
			if(player.getSpeed()>opponent.getSpeed())
			{
				System.out.println(player.getName()+" has run away! And falling rocks killed "+opponent.getName());
				opponent.setHP(0);
			}
			else
			{
				System.out.println(player.getName()+" cannot run away "+opponent.getName()+" is too fast!");
			}
		}
		else//ATTACK!
		{
			System.out.println(player.name + " attacks with "+player.getWeapon());
			opponent.setHP(opponent.getHP()- player.getStrength());
			System.out.println(opponent.getName()+" now has "+opponent.getHP()+" HP");
		}
	}

}

 

Subject Computer
Due By (Pacific Time) 11/19/2014 11:30 pm
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy