import cs101.terminal.*; import cs101.canvas.*; import java.awt.*; import java.awt.event.*; // Name: // Lab Section: // Primary TA: // Email: // Date: // CS101 Lab 6 // Startup.java // This is already set up to do self testing and play 10 games import java.awt.*; public class Startup implements Runnable { public void run() { if (! Lab6.isApplet) Terminal.startTranscript("transcript.txt"); Card.selfTest(); Deck.selfTest(); Deck cards = new Deck(); for (int i=1; i<=100; ++i) cards.shuffle(); for (int i=1; i<=10; ++i) { Terminal.println("\nGame " + i); oneGame(cards); } if (! Lab6.isApplet) Terminal.stopTranscript(); } private void oneGame(Deck cards) { Dealer dealer = new Dealer("Dealer Dorothy"); Customer customer = new Customer("Vegas Vinnie"); dealer.takeCard(cards.draw()); // Dealer, face up dealer.takeCard(cards.draw(), false); // Dealer, face down customer.takeCard(cards.draw()); // Two cards to the customer.takeCard(cards.draw()); // customer, both face up Terminal.println(dealer); // Show what the dealer has /* Draw customer cards as long as they are wanted and the customer has not busted. */ Terminal.println(customer); while (!customer.busted() && customer.wantsCard()) { customer.takeCard(cards.draw()); Terminal.println(customer); } dealer.showCards(); if (customer.busted()) { Terminal.println("You lose -- busted!"); } else { /* Turn the dealer's cards over and finish the dealer's hand */ Terminal.println(dealer); while (!dealer.busted() && dealer.wantsCard()) { dealer.takeCard(cards.draw()); Terminal.println(dealer); } if (dealer.busted()) Terminal.println("You win -- dealer busted"); else if (dealer.getHand().points() > customer.getHand().points()) Terminal.println("You lose -- dealer beat you"); else if (dealer.getHand().points() < customer.getHand().points()) Terminal.println("You win -- beat the dealer"); else Terminal.println("You push -- tied the dealer"); } customer.done(); dealer.done(); } }