— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet145/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   141   142   143   144   145   146   147   148   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

the 
DotComBust 
code (the game)


get to know the 
Java API 
you are here
4
147
private void 
checkUserGuess
(String userGuess) {
numOfGuesses++;
String result = “miss”; 
for (DotCom dotComToTest : dotComsList) {
result = dotComToTest.checkYourself(userGuess);
if (result.equals(“hit”)) {
break;
}
if (result.equals(“kill”)) {
dotComsList.remove(dotComToTest); 
break;
}

// close for
System.out.println(result);

// close method
private void 
fi nishGame()
{
System.out.println(“All Dot Coms are dead! Your stock is now worthless.”);
if (numOfGuesses <= 18) {
System.out.println(“It only took you “ + numOfGuesses + “ guesses.”);
System.out.println(“ You got out before your options sank.”);
} else { 
System.out.println(“Took you long enough. “+ numOfGuesses + “ guesses.”);
System.out.println(“Fish are dancing with your options.”);
}

// close method
public static void 
main
(String[] args) {
DotComBust game = new DotComBust();
game.setUpGame();
game.startPlaying();

// close method
}
increment the number of guesses the user has made
assume it’s a ‘miss’, unless told otherwise
repeat with all DotComs in the list
ask the DotCom to check the user guess, 
looking for a hit (or kill)
get out of the loop 
early, no point in testing 
the others
this guy’s dead, so take him out of the 
DotComs list then get out of the loop
print the 
result for 
the user
print a message telling the 
user how he did in the game
tell the game object to start the main 
game play loop (keeps asking for user 
input and checking the guess)

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   141   142   143   144   145   146   147   148   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish