- TextFighter.java
- Wednesday, October 17th, 2007 at 7:21:51am MDT
- /**
- Main class for Text Fighter
- - 20070928, Cheung Ho Yin
- */
- import java.util.Scanner;
- import java.util.Random;
- public class TextFighter {
- private static Player [] p
- = { new Player(), new Player("Florence"),
- new Player("Janice"), new Player("Justin") };
- // Methods
- public static boolean gameOver() {
- if(p[0].isDead()) return true;
- int dead=0;
- for(int i=0; i<p.length; i++){
- if(p[i].isDead()) dead++;
- }
- return (dead>=p.length-1)?true:false;
- }
- // Action taken by a human player
- public static void humanAction( Player player ) {
- int command = input.nextInt();
- if( command < 0 || command >= p.length ){
- 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;
- player.attack( p[command] );
- }
- private static void sleep() {
- try {
- e.printStackTrace();
- }
- }
- public static void printStatus() {
- for(int i=0; i<p.length; i++){
- }
- }
- // Main program
- int counter=0;
- p[0].setName( input.nextLine() );
- do {
- // Print heading information
- printStatus();
- // Human player
- humanAction(p[0]);
- // Computer players
- for(int i=1; i<p.length; i++) { computerAction(p[i]); }
- } while(!gameOver());
- printStatus();
- }
- }
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.