2014-10-17 HW

posted Oct 17, 2014, 8:38 AM by Samuel Konstantinovich   [ updated Oct 17, 2014, 9:59 AM ]
I need volunteers (goons, or minions) for Parent Teacher Conferences in exchange for reasonable quality noms (snacks). Please email me with subject line "PTC Volunteer!" and tell me which day you can come:
Thursday (Evening approximately~5-8pm) 
Friday (Afternoon approximately ~12-3pm)
Also tell me if you are able to bring your laptop.

Homework Due Sunday 11:59pm on the homework server! (zip all of your JAVA files together)
Step 1.
Make sure your Adventurer, Warrior, Wizard, and Rogue work using my driver (included at end of post)

Step 2.
Learn the Scanner class.
http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html

Example:
Scanner in = new Scanner(System.in);
System.out.println("Type something:");
String line = in.nextLine();
System.out.println("You typed: <"+line+"> without the <>");
    

Step 3.

3.1 Make a new driver: Game.java

3.2 Create variables for the player controlled character, and their opponent:
Adventurer player,opponent;

3.3 Prompt the user which class they would like to be:
Choose a class:
A : Warrior
B : Wizard
C : Rogue

3.4 Read a value from the scanner then initialize player with the appropriate Adventurer type. If the user types an invalid choice, ask them to type it again.

3.5 Initialize the opponent to be a regular Adventurer.

3.6 Now allow the player to combat the opponent. 
You can decide how to figure out who goes first, the player or the opponent.
You can decide how the opponent attacks the player.

3.6.1
You must repeatedly get input and decide what to do, each round 
a) Print the player + opponent stats.
b) prompt the user:
Choose an action:
A : attack
S : special attack
G : give up

You would then want to read what the user types, and use the appropriate attack, or end the match.

3.6.2
You must decide when to end the match. When either the player or opponent have less than 1 HP, OR the player gives up, you should end the match, and display information about the results.


3.7 Improve your game by adding some extra features: (this will save you time later)
3.7.1
-Allow the opponent to be randomly chosen as Warrior/Wizard/Rogue/Adventurer.
-Allow the opponents to use their special attacks ONLY when they have enough resources. Adventurers have no special resource, therefore should randomly choose.
3.7.2
-Allow the user to create their character by allocating 30 stat points between their STR/DEX/INT.
-This requires that you learn to convert the user input into integers. Look at   Integer.parseInt()  OR   Scanner.nextInt()







Sample Driver:

public class Driver{
    public static void main(String[]args){
Adventurer p1 =new Adventurer("Chadwick");
Warrior p2 =new Warrior("Grobnar");
p2.setRage(20);
Wizard p3 = new Wizard("Merlin");
Rogue p4 = new Rogue("Inigo Montoya");

System.out.println(p1.getStats());
System.out.println(p2.getStats());
System.out.println(p3.getStats());
System.out.println(p4.getStats());
System.out.println();

p1.attack(p2);
p1.specialAttack(p2);
System.out.println();

p2.attack(p3);
p2.specialAttack(p3);
System.out.println();

p3.attack(p4);
p3.specialAttack(p4);
System.out.println();

p4.attack(p1);
p4.specialAttack(p1);
System.out.println();

System.out.println(p1.getStats());
System.out.println(p2.getStats());
System.out.println(p3.getStats());
System.out.println(p4.getStats());
System.out.println();
    }
}

Sample Output:
~APCS/stuyablo $ java Driver 
Chadwick        20HP 10STR 10DEX 10INT
Grobnar         30HP 14STR 6DEX 10INT 20RAGE
Merlin          20HP 6STR 8DEX 18INT 25MANA
Inigo Montoya   20HP 8STR 14DEX 10INT 25STAMINA

Chadwick attacks Grobnar
and hits for 3 points of damage
Chadwick furiously attacks Grobnar
and hits for 3 points of damage

Grobnar attacks Merlin
and hits for 3 points of damage
Grobnar unleashes the fury of his barbarian ancestors Merlin
and hits for 9 points of damage

Merlin attacks Inigo Montoya
and misses...
Merlin hurls fire at Inigo Montoya
and burns for 13 points of damage

Inigo Montoya attacks Chadwick
and hits for 1 points of damage
Inigo Montoya backstabs Chadwick
and hits for 5 points of damage

Chadwick        14HP 10STR 10DEX 10INT
Grobnar         24HP 14STR 6DEX 10INT 20RAGE
Merlin          8HP 6STR 8DEX 18INT 15MANA
Inigo Montoya   7HP 8STR 14DEX 10INT 15STAMINA

Comments