- Untitled
- Monday, November 19th, 2007 at 6:19:00am MST
- import java.util.Random;
- public class Player
- {
- //define Power and Difference and Round
- protected int Power=10,Difference,Round=1;
- //define the Player Name
- //define the Player is dead or not
- protected boolean isDead=false;
- Random randomNumber;
- {
- //將傳回的Name傳給這個類別的Name
- //call a Object from Random
- }
- //call a method for setting the Power for the players after each round
- public void setPower(int Power,int Difference)
- {
- this.Power=(Power+Difference);
- }
- //call a method to get the value of power each round
- public int getPower()
- {
- return Power;
- }
- //call a method to get the name from the Players
- {
- return Name;
- }
- //call a method for attacking the Players
- public void Attack(Player A)
- {
- int temp=getPower(),temp1=A.getPower();
- if (Difference==0)
- Difference=1;
- //print out which round for this attack
- //print out who attacks who
- //to define a player have 50% chance of winning the battle
- if (randomNumber.nextDouble() <= 0.5 )
- {
- setPower(Power,Difference);
- A.setPower(A.getPower(),-Difference);
- }
- else
- {
- //vice versa
- setPower(getPower(),-Difference);
- A.setPower(A.getPower(),Difference);
- }
- if (A.getPower()<=0)
- {
- A.isDead=true;
- }
- if (getPower()<=0)
- {
- isDead=true;
- }
- //show out players hp at last
- }
- }
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.