/* * RedmondScoreBoardBuggyDemo.java * * Created on April 4, 2002, 1:41 PM */ /** * * @author Dr. Michael Redmond * @version 1.0 * * Demonstrate use of a class - by building a game around the scoreboard class */ public class RedmondScoreboardBuggyDemo { /** Creates new RedmondScoreBoardBuggyDemo */ public RedmondScoreboardBuggyDemo() { } /** * @param args the command line arguments */ public static void main (String args[]) { // set up game based on user input and known info ScoreBoardBuggy game1 = new ScoreBoardBuggy(); System.out.println("Who is the home team?"); String home = SavitchIn.readLine(); System.out.println(home); System.out.println("Who is the away team?"); String away = SavitchIn.readLine(); System.out.println(away); game1.beginGame(home,away); System.out.println("At Start of Game: " + game1.toString()); // shorten the game on purpose for student convenience game1.adjustClock(-900); // find out easy way to refer to teams - using one letter // get first character in each teams name, and make sure it is capitalized // if they are the same, try the second letter for the away team String tempTeam; char homeChar = home.charAt(0); homeChar = Character.toUpperCase(homeChar); char awayChar = away.charAt(0); awayChar = Character.toUpperCase(awayChar); if (homeChar == awayChar) { awayChar = away.charAt(1); awayChar = Character.toUpperCase(awayChar); } /// find out who wins the jump ball System.out.println("Who gets the ball first? (" + homeChar + " for " + game1.getHomeName() + " or " + awayChar + " for " + game1.getAwayName() ); char team = SavitchIn.readLineNonwhiteChar(); // ensure valid answer while ((team != homeChar) && (team != awayChar) ) { System.out.println("Who gets the ball first? (" + homeChar + " for " + game1.getHomeName() + " or " + awayChar + " for " + game1.getAwayName() ); team = SavitchIn.readLineNonwhiteChar(); } System.out.println(" " + team); String teamBall; String teamDefense; // determine team with ball - make other team on defense if (team == homeChar) { teamBall = game1.getHomeName(); teamDefense = game1.getAwayName(); } else { teamBall = game1.getAwayName(); teamDefense = game1.getHomeName(); } // take some time off the clock for the jump ball game1.adjustClock(-5); // initialize variable for whether game is over (should be false at first) boolean over = game1.endGame(); //char answ = 'N'; //while (answ == 'N') { // loop while the game is not over while (!over) { // find out what happends on this possession - and validate System.out.println("What happens with " + teamBall); System.out.println("0) No Hoop; 1) One Free Throw Made; 2) 2-pt Field Goal; 3) 3-pt Field Goal "); int choice = SavitchIn.readLineInt(); // ensure valid input while ((choice < 0) || (choice > 3)) { System.out.println("What happens with " + teamBall); System.out.println("0) No Hoop; 1) One Free Throw Made; 2) 2-pt Field Goal; 3) 3-pt Field Goal "); choice = SavitchIn.readLineInt(); } System.out.println(" " + choice); // randomly take off up to 5 seconds // eliminated random to make easier to debug //int rand = (int)Math.round(Math.random()* 5); //game1.adjustClock(0-rand); //System.out.print(" rand: " + rand); // handle any choice made by the users switch (choice) { case 0: // no basket game1.adjustClock(-27); // arbitrarily take average amount of time off clock break; case 1: // free throw made game1.adjustClock(-21); // arbitrarily take average amount of time off clock game1.makeFoulShot(teamBall); // check if a second free throw was made System.out.println("Do they make the second (Y or N)? "); char answ = SavitchIn.readLineNonwhiteChar(); System.out.println(" " + answ); if ((answ == 'Y') || (answ == 'y') ) { game1.makeFoulShot(teamBall); } else { // missed free throw - take a little time off clock for rebound game1.adjustClock(-6); } break; case 2: // field goal made game1.adjustClock(-19); // arbitrarily take average amount of time off clock game1.makeTwoPoint(teamBall); break; case 3: // three pointer made game1.adjustClock(-26); // arbitrarily take average amount of time off clock game1.makeThreePoint(teamBall); break; } // swap who has the ball tempTeam = teamBall; teamBall = teamDefense; teamDefense = tempTeam; // check if period over if (game1.endPeriod() ) { // move to next period game1.nextPeriod(); // shorten the game on purpose for student convenience game1.adjustClock(-900); } System.out.println("game1: " + game1.toString()); // see if game continues // now - do using time instead of asking user over = game1.endGame(); // leave out for bug? //System.out.println("Is the game over (Y or N)?"); //answ = SavitchIn.readLineNonwhiteChar(); // ensure valid answer //while ((answ != 'n') && (answ != 'N') // && (answ != 'y') && (answ != 'Y') ) { // System.out.println("Is the game over (Y or N)?"); // answ = SavitchIn.readLineNonwhiteChar(); //} //// convert to upper case for consistency //if (answ == 'n') { // answ = 'N'; //} } // end while System.out.println("Game over"); System.out.println("game1: " + game1.toString()); System.out.println("Winner: " + game1.getLeadingTeam()); System.out.println("Margin: " + game1.getCurrMargin()); } }