/**
Main class for Text Fighter
- 20070928, Cheung Ho Yin
*/
import java.util.Scanner;
import java.util.Random;
public class TextFighter {
private static Scanner input = new Scanner( System.in );
private static Player [] p
= { new Player(), new Player("Florence"),
new Player("Janice"), new Player("Justin") };
private static Random r = new Random();
// Methods
public static boolean gameOver() {
if(p[0].isDead()) return true;
int dead=0;
for(int i=0; i
=p.length-1)?true:false;
}
// Action taken by a human player
public static void humanAction( Player player ) {
System.out.printf( "\n%s's command > ", player.getName());
int command = input.nextInt();
if( command < 0 || command >= p.length ){
System.out.println("--> Invalid option!");
return;
}
player.attack( p[command] );
}
// Action taken by a computer player
public static void computerAction( Player player ) {
if(player.isDead()) return; // do nothing if already dead
int command = r.nextInt()%2+1;
System.out.println();
System.out.printf( "%s's command > Thinking... /\r", player.getName() ); sleep();
System.out.printf( "%s's command > Thinking... -\r", player.getName() ); sleep();
System.out.printf( "%s's command > Thinking... \\\r", player.getName() ); sleep();
System.out.printf( "%s's command > Thinking... |\r", player.getName() ); sleep();
System.out.printf( "%s's command > Thinking... /\r", player.getName() ); sleep();
System.out.printf( "%s's command > \r", player.getName() );
System.out.printf( "%s's command > %d\n", player.getName(), command );
player.attack( p[command] );
}
private static void sleep() {
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void printStatus() {
for(int i=0; i