mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-30 06:31:46 -08:00
Removed spaces from top-level directory names.
Spaces tend to cause annoyances in a Unix-style shell environment. This change fixes that.
This commit is contained in:
7
12_Bombs_Away/README.md
Normal file
7
12_Bombs_Away/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
### Bombs Away
|
||||
|
||||
As published in Basic Computer Games (1978)
|
||||
https://www.atariarchives.org/basicgames/showpage.php?page=24
|
||||
|
||||
Downloaded from Vintage Basic at
|
||||
http://www.vintage-basic.net/games.html
|
||||
65
12_Bombs_Away/bombsaway.bas
Normal file
65
12_Bombs_Away/bombsaway.bas
Normal file
@@ -0,0 +1,65 @@
|
||||
8 PRINT "YOU ARE A PILOT IN A WORLD WAR II BOMBER."
|
||||
10 INPUT "WHAT SIDE -- ITALY(1), ALLIES(2), JAPAN(3), GERMANY(4)";A
|
||||
20 IF A>0 AND A<5 THEN 25
|
||||
22 PRINT "TRY AGAIN..." : GOTO 10
|
||||
25 ON A GOTO 30, 110, 200, 220
|
||||
30 INPUT "YOUR TARGET -- ALBANIA(1), GREECE(2), NORTH AFRICA(3)";B
|
||||
40 IF B>0 AND B<4 THEN 45
|
||||
42 PRINT "TRY AGAIN..." : GOTO 30
|
||||
45 PRINT : ON B GOTO 50, 80,90
|
||||
50 PRINT "SHOULD BE EASY -- YOU'RE FLYING A NAZI-MADE PLANE."
|
||||
60 GOTO 280
|
||||
80 PRINT "BE CAREFUL!!!" : GOTO 280
|
||||
90 PRINT "YOU'RE GOING FOR THE OIL, EH?" : GOTO 280
|
||||
110 INPUT "AIRCRAFT -- LIBERATOR(1), B-29(2), B-17(3), LANCASTER(4)";G
|
||||
120 IF G>0 AND G<5 THEN 125
|
||||
122 PRINT "TRY AGAIN..." : GOTO 110
|
||||
125 PRINT : ON G GOTO 130, 150, 170, 190
|
||||
130 PRINT "YOU'VE GOT 2 TONS OF BOMBS FLYING FOR PLOESTI." : GOTO 280
|
||||
150 PRINT "YOU'RE DUMPING THE A-BOMB ON HIROSHIMA." : GOTO 280
|
||||
170 PRINT "YOU'RE CHASING THE BISMARK IN THE NORTH SEA." : GOTO 280
|
||||
190 PRINT "YOU'RE BUSTING A GERMAN HEAVY WATER PLANT IN THE RUHR."
|
||||
195 GOTO 280
|
||||
200 PRINT "YOU'RE FLYING A KAMIKAZE MISSION OVER THE USS LEXINGTON."
|
||||
205 INPUT "YOUR FIRST KAMIKAZE MISSION(Y OR N)";F$
|
||||
207 IF F$="N" THEN S=0 : GOTO 358
|
||||
210 PRINT : IF RND(1)>.65 THEN 325
|
||||
215 GOTO 380
|
||||
220 PRINT "A NAZI, EH? OH WELL. ARE YOU GOING FOR RUSSIA(1),"
|
||||
230 INPUT "ENGLAND(2), OR FRANCE(3)";M : IF M>0 AND M<4 THEN 235
|
||||
232 PRINT "TRY AGAIN..." : GOTO 220
|
||||
235 PRINT : ON M GOTO 250, 260, 270
|
||||
250 PRINT "YOU'RE NEARING STALINGRAD." : GOTO 280
|
||||
260 PRINT "NEARING LONDON. BE CAREFUL, THEY'VE GOT RADAR." : GOTO 280
|
||||
270 PRINT "NEARING VERSAILLES. DUCK SOUP. THEY'RE NEARLY DEFENSELESS."
|
||||
280 PRINT
|
||||
285 INPUT "HOW MANY MISSIONS HAVE YOU FLOWN";D
|
||||
290 IF D<160 THEN 300
|
||||
292 PRINT "MISSIONS, NOT MILES..."
|
||||
295 PRINT "150 MISSIONS IS HIGH EVEN FOR OLD-TIMERS."
|
||||
297 PRINT "NOW THEN, "; : GOTO 285
|
||||
300 PRINT:IF D<100 THEN 310
|
||||
305 PRINT "THAT'S PUSHING THE ODDS!" : GOTO 320
|
||||
310 IF D<25 THEN PRINT "FRESH OUT OF TRAINING, EH?"
|
||||
320 PRINT : IF D<160*RND(1) THEN 330
|
||||
325 PRINT "DIRECT HIT!!!! "INT(100*RND(1))"KILLED."
|
||||
327 PRINT "MISSION SUCCESSFUL." : GOTO 390
|
||||
330 PRINT "MISSED TARGET BY"INT(2+30*RND(1))"MILES!"
|
||||
335 PRINT "NOW YOU'RE REALLY IN FOR IT !!" : PRINT
|
||||
340 INPUT "DOES THE ENEMY HAVE GUNS(1), MISSILES(2), OR BOTH(3)";R
|
||||
345 IF R>0 AND R<4 THEN 350
|
||||
347 PRINT "TRY AGAIN..." : GOTO 340
|
||||
350 PRINT : T=0 : IF R=2 THEN 360
|
||||
355 INPUT "WHAT'S THE PERCENT HIT RATE OF ENEMY GUNNERS (10 TO 50)";S
|
||||
357 IF S<10 THEN PRINT "YOU LIE, BUT YOU'LL PAY...": GOTO 380
|
||||
358 PRINT
|
||||
360 PRINT : IF R>1 THEN T=35
|
||||
365 IF S+T>100*RND(1) THEN 380
|
||||
370 PRINT "YOU MADE IT THROUGH TREMENDOUS FLAK!!" : GOTO 390
|
||||
380 PRINT "* * * * BOOM * * * *"
|
||||
384 PRINT "YOU HAVE BEEN SHOT DOWN....."
|
||||
386 PRINT "DEARLY BELOVED, WE ARE GATHERED HERE TODAY TO PAY OUR"
|
||||
387 PRINT "LAST TRIBUTE..."
|
||||
390 PRINT:PRINT:PRINT:INPUT "ANOTHER MISSION (Y OR N)";U$
|
||||
395 IF U$="Y" THEN 8
|
||||
400 PRINT "CHICKEN !!!" : PRINT : END
|
||||
3
12_Bombs_Away/csharp/README.md
Normal file
3
12_Bombs_Away/csharp/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Microsoft C#](https://docs.microsoft.com/en-us/dotnet/csharp/)
|
||||
3
12_Bombs_Away/java/README.md
Normal file
3
12_Bombs_Away/java/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Oracle Java](https://openjdk.java.net/)
|
||||
505
12_Bombs_Away/java/src/BombsAway.java
Normal file
505
12_Bombs_Away/java/src/BombsAway.java
Normal file
@@ -0,0 +1,505 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Game of Bombs Away
|
||||
*
|
||||
* Based on the Basic game of Bombs Away here
|
||||
* https://github.com/coding-horror/basic-computer-games/blob/main/12%20Bombs%20Away/bombsaway.bas
|
||||
*
|
||||
* Note: The idea was to create a version of the 1970's Basic game in Java, without introducing
|
||||
* new features - no additional text, error checking, etc has been added.
|
||||
*/
|
||||
public class BombsAway {
|
||||
|
||||
public static final int MAX_PILOT_MISSIONS = 160;
|
||||
public static final int MAX_CASUALTIES = 100;
|
||||
public static final int MISSED_TARGET_CONST_1 = 2;
|
||||
public static final int MISSED_TARGET_CONST_2 = 30;
|
||||
public static final int CHANCE_OF_BEING_SHOT_DOWN_BASE = 100;
|
||||
public static final double SIXTY_FIVE_PERCENT = .65;
|
||||
|
||||
private enum GAME_STATE {
|
||||
START,
|
||||
CHOOSE_SIDE,
|
||||
CHOOSE_PLANE,
|
||||
CHOOSE_TARGET,
|
||||
CHOOSE_MISSIONS,
|
||||
CHOOSE_ENEMY_DEFENCES,
|
||||
FLY_MISSION,
|
||||
DIRECT_HIT,
|
||||
MISSED_TARGET,
|
||||
PROCESS_FLAK,
|
||||
SHOT_DOWN,
|
||||
MADE_IT_THROUGH_FLAK,
|
||||
PLAY_AGAIN,
|
||||
GAME_OVER
|
||||
}
|
||||
|
||||
public enum SIDE {
|
||||
ITALY(1),
|
||||
ALLIES(2),
|
||||
JAPAN(3),
|
||||
GERMANY(4);
|
||||
|
||||
private final int value;
|
||||
|
||||
SIDE(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum TARGET {
|
||||
ALBANIA(1),
|
||||
GREECE(2),
|
||||
NORTH_AFRICA(3),
|
||||
RUSSIA(4),
|
||||
ENGLAND(5),
|
||||
FRANCE(6);
|
||||
|
||||
private final int value;
|
||||
|
||||
TARGET(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ENEMY_DEFENCES {
|
||||
GUNS(1),
|
||||
MISSILES(2),
|
||||
BOTH(3);
|
||||
|
||||
private final int value;
|
||||
|
||||
ENEMY_DEFENCES(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public enum AIRCRAFT {
|
||||
LIBERATOR(1),
|
||||
B29(2),
|
||||
B17(3),
|
||||
LANCASTER(4);
|
||||
|
||||
private final int value;
|
||||
|
||||
AIRCRAFT(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
// Used for keyboard input
|
||||
private final Scanner kbScanner;
|
||||
|
||||
// Current game state
|
||||
private GAME_STATE gameState;
|
||||
|
||||
private SIDE side;
|
||||
|
||||
private int missions;
|
||||
|
||||
private int chanceToHit;
|
||||
private int percentageHitRateOfGunners;
|
||||
|
||||
public BombsAway() {
|
||||
|
||||
gameState = GAME_STATE.START;
|
||||
|
||||
// Initialise kb scanner
|
||||
kbScanner = new Scanner(System.in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main game loop
|
||||
*
|
||||
*/
|
||||
public void play() {
|
||||
|
||||
do {
|
||||
switch (gameState) {
|
||||
|
||||
// Show an introduction the first time the game is played.
|
||||
case START:
|
||||
intro();
|
||||
chanceToHit = 0;
|
||||
percentageHitRateOfGunners = 0;
|
||||
|
||||
gameState = GAME_STATE.CHOOSE_SIDE;
|
||||
break;
|
||||
|
||||
case CHOOSE_SIDE:
|
||||
side = getSide("WHAT SIDE -- ITALY(1), ALLIES(2), JAPAN(3), GERMANY(4) ? ");
|
||||
if (side == null) {
|
||||
System.out.println("TRY AGAIN...");
|
||||
} else {
|
||||
// Different game paths depending on which side was chosen
|
||||
switch (side) {
|
||||
case ITALY:
|
||||
case GERMANY:
|
||||
gameState = GAME_STATE.CHOOSE_TARGET;
|
||||
break;
|
||||
case ALLIES:
|
||||
case JAPAN:
|
||||
gameState = GAME_STATE.CHOOSE_PLANE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CHOOSE_TARGET:
|
||||
String prompt;
|
||||
if (side == SIDE.ITALY) {
|
||||
prompt = "YOUR TARGET -- ALBANIA(1), GREECE(2), NORTH AFRICA(3) ? ";
|
||||
} else {
|
||||
// Germany
|
||||
System.out.println("A NAZI, EH? OH WELL. ARE YOU GOING FOR RUSSIA(1),");
|
||||
prompt = "ENGLAND(2), OR FRANCE(3) ? ";
|
||||
}
|
||||
TARGET target = getTarget(prompt);
|
||||
if (target == null) {
|
||||
System.out.println("TRY AGAIN...");
|
||||
} else {
|
||||
displayTargetMessage(target);
|
||||
gameState = GAME_STATE.CHOOSE_MISSIONS;
|
||||
}
|
||||
|
||||
case CHOOSE_MISSIONS:
|
||||
missions = getNumberFromKeyboard("HOW MANY MISSIONS HAVE YOU FLOWN? ");
|
||||
|
||||
if(missions <25) {
|
||||
System.out.println("FRESH OUT OF TRAINING, EH?");
|
||||
gameState = GAME_STATE.FLY_MISSION;
|
||||
} else if(missions < 100) {
|
||||
System.out.println("THAT'S PUSHING THE ODDS!");
|
||||
gameState = GAME_STATE.FLY_MISSION;
|
||||
} else if(missions >=160) {
|
||||
System.out.println("MISSIONS, NOT MILES...");
|
||||
System.out.println("150 MISSIONS IS HIGH EVEN FOR OLD-TIMERS.");
|
||||
System.out.println("NOW THEN, ");
|
||||
} else {
|
||||
// No specific message if missions is 100-159, but still valid
|
||||
gameState = GAME_STATE.FLY_MISSION;
|
||||
}
|
||||
break;
|
||||
|
||||
case CHOOSE_PLANE:
|
||||
switch(side) {
|
||||
case ALLIES:
|
||||
AIRCRAFT plane = getPlane("AIRCRAFT -- LIBERATOR(1), B-29(2), B-17(3), LANCASTER(4)? ");
|
||||
if(plane == null) {
|
||||
System.out.println("TRY AGAIN...");
|
||||
} else {
|
||||
switch(plane) {
|
||||
|
||||
case LIBERATOR:
|
||||
System.out.println("YOU'VE GOT 2 TONS OF BOMBS FLYING FOR PLOESTI.");
|
||||
break;
|
||||
case B29:
|
||||
System.out.println("YOU'RE DUMPING THE A-BOMB ON HIROSHIMA.");
|
||||
break;
|
||||
case B17:
|
||||
System.out.println("YOU'RE CHASING THE BISMARK IN THE NORTH SEA.");
|
||||
break;
|
||||
case LANCASTER:
|
||||
System.out.println("YOU'RE BUSTING A GERMAN HEAVY WATER PLANT IN THE RUHR.");
|
||||
break;
|
||||
}
|
||||
|
||||
gameState = GAME_STATE.CHOOSE_MISSIONS;
|
||||
}
|
||||
break;
|
||||
|
||||
case JAPAN:
|
||||
System.out.println("YOU'RE FLYING A KAMIKAZE MISSION OVER THE USS LEXINGTON.");
|
||||
if(yesEntered(displayTextAndGetInput("YOUR FIRST KAMIKAZE MISSION(Y OR N) ? "))) {
|
||||
if(randomNumber(1) > SIXTY_FIVE_PERCENT) {
|
||||
gameState = GAME_STATE.DIRECT_HIT;
|
||||
} else {
|
||||
// It's a miss
|
||||
gameState = GAME_STATE.MISSED_TARGET;
|
||||
}
|
||||
} else {
|
||||
gameState = GAME_STATE.PROCESS_FLAK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case FLY_MISSION:
|
||||
double missionResult = (MAX_PILOT_MISSIONS * randomNumber(1));
|
||||
if(missions > missionResult) {
|
||||
gameState = GAME_STATE.DIRECT_HIT;
|
||||
} else {
|
||||
gameState = GAME_STATE.MISSED_TARGET;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case DIRECT_HIT:
|
||||
System.out.println("DIRECT HIT!!!! " + (int) Math.round(randomNumber(MAX_CASUALTIES)) + " KILLED.");
|
||||
System.out.println("MISSION SUCCESSFUL.");
|
||||
gameState = GAME_STATE.PLAY_AGAIN;
|
||||
break;
|
||||
|
||||
case MISSED_TARGET:
|
||||
System.out.println("MISSED TARGET BY " + (int) Math.round(MISSED_TARGET_CONST_1 + MISSED_TARGET_CONST_2 * (randomNumber(1))) + " MILES!");
|
||||
System.out.println("NOW YOU'RE REALLY IN FOR IT !!");
|
||||
System.out.println();
|
||||
gameState = GAME_STATE.CHOOSE_ENEMY_DEFENCES;
|
||||
break;
|
||||
|
||||
case CHOOSE_ENEMY_DEFENCES:
|
||||
boolean bothWeapons = true;
|
||||
|
||||
ENEMY_DEFENCES enemyDefences = getEnemyDefences("DOES THE ENEMY HAVE GUNS(1), MISSILES(2), OR BOTH(3) ? ");
|
||||
if(enemyDefences == null) {
|
||||
System.out.println("TRY AGAIN...");
|
||||
} else {
|
||||
switch(enemyDefences) {
|
||||
case MISSILES:
|
||||
case GUNS:
|
||||
bothWeapons = false;
|
||||
|
||||
// fall through on purpose to BOTH since its pretty much identical code other than the chance to hit
|
||||
// increasing if both weapons are part of the defence.
|
||||
|
||||
case BOTH:
|
||||
percentageHitRateOfGunners = getNumberFromKeyboard("WHAT'S THE PERCENT HIT RATE OF ENEMY GUNNERS (10 TO 50)? ");
|
||||
if(percentageHitRateOfGunners < 10) {
|
||||
System.out.println("YOU LIE, BUT YOU'LL PAY...");
|
||||
}
|
||||
if(bothWeapons) {
|
||||
chanceToHit = 35;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
gameState = GAME_STATE.PROCESS_FLAK;
|
||||
|
||||
// Determine if the players airplan makes it through the Flak.
|
||||
case PROCESS_FLAK:
|
||||
double calc = (CHANCE_OF_BEING_SHOT_DOWN_BASE * randomNumber(1));
|
||||
|
||||
if ((chanceToHit + percentageHitRateOfGunners) > calc) {
|
||||
gameState = GAME_STATE.SHOT_DOWN;
|
||||
} else {
|
||||
gameState = GAME_STATE.MADE_IT_THROUGH_FLAK;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHOT_DOWN:
|
||||
System.out.println("* * * * BOOM * * * *");
|
||||
System.out.println("YOU HAVE BEEN SHOT DOWN.....");
|
||||
System.out.println("DEARLY BELOVED, WE ARE GATHERED HERE TODAY TO PAY OUR");
|
||||
System.out.println("LAST TRIBUTE...");
|
||||
gameState = GAME_STATE.PLAY_AGAIN;
|
||||
break;
|
||||
|
||||
case MADE_IT_THROUGH_FLAK:
|
||||
System.out.println("YOU MADE IT THROUGH TREMENDOUS FLAK!!");
|
||||
gameState = GAME_STATE.PLAY_AGAIN;
|
||||
break;
|
||||
|
||||
case PLAY_AGAIN:
|
||||
if(yesEntered(displayTextAndGetInput("ANOTHER MISSION (Y OR N) ? "))) {
|
||||
gameState = GAME_STATE.START;
|
||||
} else {
|
||||
System.out.println("CHICKEN !!!");
|
||||
gameState = GAME_STATE.GAME_OVER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (gameState != GAME_STATE.GAME_OVER) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a (brief) intro
|
||||
*/
|
||||
public void intro() {
|
||||
System.out.println("YOU ARE A PILOT IN A WORLD WAR II BOMBER.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the side the player is going to play on.
|
||||
* @param message displayed before the kb input
|
||||
* @return the SIDE enum selected by the player
|
||||
*/
|
||||
private SIDE getSide(String message) {
|
||||
int valueEntered = getNumberFromKeyboard(message);
|
||||
for(SIDE side : SIDE.values()) {
|
||||
if(side.getValue() == valueEntered) {
|
||||
return side;
|
||||
}
|
||||
}
|
||||
|
||||
// Input out of range
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the target the player is going for.
|
||||
* @param message displayed before the kb input
|
||||
* @return the TARGET enum selected by the player
|
||||
*/
|
||||
private TARGET getTarget(String message) {
|
||||
int valueEntered = getNumberFromKeyboard(message);
|
||||
|
||||
for(TARGET target : TARGET.values()) {
|
||||
if(target.getValue() == valueEntered) {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
// Input out of range
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the airplane the player is going to fly.
|
||||
* @param message displayed before the kb input
|
||||
* @return the AIRCRAFT enum selected by the player
|
||||
*/
|
||||
private AIRCRAFT getPlane(String message) {
|
||||
int valueEntered = getNumberFromKeyboard(message);
|
||||
|
||||
for(AIRCRAFT plane : AIRCRAFT.values()) {
|
||||
if(plane.getValue() == valueEntered) {
|
||||
return plane;
|
||||
}
|
||||
}
|
||||
|
||||
// Input out of range
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the type of enemy defences.
|
||||
*
|
||||
* @param message displayed before kb input
|
||||
* @return the ENEMY_DEFENCES enum as selected by player
|
||||
*/
|
||||
private ENEMY_DEFENCES getEnemyDefences(String message) {
|
||||
int valueEntered = getNumberFromKeyboard(message);
|
||||
for (ENEMY_DEFENCES enemyDefences : ENEMY_DEFENCES.values()) {
|
||||
if(enemyDefences.getValue() == valueEntered) {
|
||||
return enemyDefences;
|
||||
}
|
||||
}
|
||||
|
||||
// Input out of range
|
||||
return null;
|
||||
}
|
||||
|
||||
// output a specific message based on the target selected
|
||||
private void displayTargetMessage(TARGET target) {
|
||||
|
||||
switch (target) {
|
||||
|
||||
case ALBANIA:
|
||||
System.out.println("SHOULD BE EASY -- YOU'RE FLYING A NAZI-MADE PLANE.");
|
||||
break;
|
||||
case GREECE:
|
||||
System.out.println("BE CAREFUL!!!");
|
||||
break;
|
||||
case NORTH_AFRICA:
|
||||
System.out.println("YOU'RE GOING FOR THE OIL, EH?");
|
||||
break;
|
||||
case RUSSIA:
|
||||
System.out.println("YOU'RE NEARING STALINGRAD.");
|
||||
break;
|
||||
case ENGLAND:
|
||||
System.out.println("NEARING LONDON. BE CAREFUL, THEY'VE GOT RADAR.");
|
||||
break;
|
||||
case FRANCE:
|
||||
System.out.println("NEARING VERSAILLES. DUCK SOUP. THEY'RE NEARLY DEFENSELESS.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a string from the keyboard, and converts to an int
|
||||
*
|
||||
* @param message displayed text on screen before keyboard input
|
||||
*
|
||||
* @return the number entered by the player
|
||||
*/
|
||||
private int getNumberFromKeyboard(String message) {
|
||||
|
||||
String answer = displayTextAndGetInput(message);
|
||||
return Integer.parseInt(answer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether player entered Y or YES to a question.
|
||||
*
|
||||
* @param text player string from kb
|
||||
* @return true of Y or YES was entered, otherwise false
|
||||
*/
|
||||
private boolean yesEntered(String text) {
|
||||
return stringIsAnyValue(text, "Y", "YES");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a string equals one of a variable number of values
|
||||
* Useful to check for Y or YES for example
|
||||
* Comparison is case insensitive.
|
||||
*
|
||||
* @param text source string
|
||||
* @param values a range of values to compare against the source string
|
||||
* @return true if a comparison was found in one of the variable number of strings passed
|
||||
*/
|
||||
private boolean stringIsAnyValue(String text, String... values) {
|
||||
|
||||
// Cycle through the variable number of values and test each
|
||||
for(String val:values) {
|
||||
if(text.equalsIgnoreCase(val)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// no matches
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Print a message on the screen, then accept input from Keyboard.
|
||||
*
|
||||
* @param text message to be displayed on screen.
|
||||
* @return what was typed by the player.
|
||||
*/
|
||||
private String displayTextAndGetInput(String text) {
|
||||
System.out.print(text);
|
||||
return kbScanner.next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate random number
|
||||
* Used as a single digit of the computer player
|
||||
*
|
||||
* @return random number
|
||||
*/
|
||||
private double randomNumber(int range) {
|
||||
return (Math.random()
|
||||
* (range));
|
||||
}
|
||||
}
|
||||
8
12_Bombs_Away/java/src/BombsAwayGame.java
Normal file
8
12_Bombs_Away/java/src/BombsAwayGame.java
Normal file
@@ -0,0 +1,8 @@
|
||||
public class BombsAwayGame {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
BombsAway bombsAway = new BombsAway();
|
||||
bombsAway.play();
|
||||
}
|
||||
}
|
||||
3
12_Bombs_Away/javascript/README.md
Normal file
3
12_Bombs_Away/javascript/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Shells)
|
||||
9
12_Bombs_Away/javascript/bombsaway.html
Normal file
9
12_Bombs_Away/javascript/bombsaway.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>BOMBARDMENT</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="bombsaway.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
205
12_Bombs_Away/javascript/bombsaway.js
Normal file
205
12_Bombs_Away/javascript/bombsaway.js
Normal file
@@ -0,0 +1,205 @@
|
||||
// BOMBS AWAY
|
||||
//
|
||||
// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
|
||||
//
|
||||
|
||||
function print(str)
|
||||
{
|
||||
document.getElementById("output").appendChild(document.createTextNode(str));
|
||||
}
|
||||
|
||||
function input()
|
||||
{
|
||||
var input_element;
|
||||
var input_str;
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
input_element = document.createElement("INPUT");
|
||||
|
||||
print("? ");
|
||||
input_element.setAttribute("type", "text");
|
||||
input_element.setAttribute("length", "50");
|
||||
document.getElementById("output").appendChild(input_element);
|
||||
input_element.focus();
|
||||
input_str = undefined;
|
||||
input_element.addEventListener("keydown", function (event) {
|
||||
if (event.keyCode == 13) {
|
||||
input_str = input_element.value;
|
||||
document.getElementById("output").removeChild(input_element);
|
||||
print(input_str);
|
||||
print("\n");
|
||||
resolve(input_str);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function tab(space)
|
||||
{
|
||||
var str = "";
|
||||
while (space-- > 0)
|
||||
str += " ";
|
||||
return str;
|
||||
}
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
while (1) {
|
||||
print("YOU ARE A PILOT IN A WORLD WAR II BOMBER.\n");
|
||||
while (1) {
|
||||
print("WHAT SIDE -- ITALY(1), ALLIES(2), JAPAN(3), GERMANY(4)");
|
||||
a = parseInt(await input());
|
||||
if (a < 1 || a > 4)
|
||||
print("TRY AGAIN...\n");
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (a == 1) {
|
||||
while (1) {
|
||||
print("YOUR TARGET -- ALBANIA(1), GREECE(2), NORTH AFRICA(3)");
|
||||
b = parseInt(await input());
|
||||
if (b < 1 || b > 3)
|
||||
print("TRY AGAIN...\n");
|
||||
else
|
||||
break;
|
||||
}
|
||||
print("\n");
|
||||
if (b == 1) {
|
||||
print("SHOULD BE EASY -- YOU'RE FLYING A NAZI-MADE PLANE.\n");
|
||||
} else if (b == 2) {
|
||||
print("BE CAREFUL!!!\n");
|
||||
} else {
|
||||
print("YOU'RE GOING FOR THE OIL, EH?\n");
|
||||
}
|
||||
} else if (a == 2) {
|
||||
while (1) {
|
||||
print("AIRCRAFT -- LIBERATOR(1), B-29(2), B-17(3), LANCASTER(4)");
|
||||
g = parseInt(await input());
|
||||
if (g < 1 || g > 4)
|
||||
print("TRY AGAIN...\n");
|
||||
else
|
||||
break;
|
||||
}
|
||||
print("\n");
|
||||
if (g == 1) {
|
||||
print("YOU'VE GOT 2 TONS OF BOMBS FLYING FOR PLOESTI.\n");
|
||||
} else if (g == 2) {
|
||||
print("YOU'RE DUMPING THE A-BOMB ON HIROSHIMA.\n");
|
||||
} else if (g == 3) {
|
||||
print("YOU'RE CHASING THE BISMARK IN THE NORTH SEA.\n");
|
||||
} else {
|
||||
print("YOU'RE BUSTING A GERMAN HEAVY WATER PLANT IN THE RUHR.\n");
|
||||
}
|
||||
} else if (a == 3) {
|
||||
print("YOU'RE FLYING A KAMIKAZE MISSION OVER THE USS LEXINGTON.\n");
|
||||
print("YOUR FIRST KAMIKAZE MISSION(Y OR N)");
|
||||
str = await input();
|
||||
if (str == "N") {
|
||||
s = 0;
|
||||
} else {
|
||||
s = 1;
|
||||
print("\n");
|
||||
}
|
||||
} else {
|
||||
while (1) {
|
||||
print("A NAZI, EH? OH WELL. ARE YOU GOING FOR RUSSIA(1),\n");
|
||||
print("ENGLAND(2), OR FRANCE(3)");
|
||||
m = parseInt(await input());
|
||||
if (m < 1 || m > 3)
|
||||
print("TRY AGAIN...\n");
|
||||
else
|
||||
break;
|
||||
}
|
||||
print("\n");
|
||||
if (m == 1) {
|
||||
print("YOU'RE NEARING STALINGRAD.\n");
|
||||
} else if (m == 2) {
|
||||
print("NEARING LONDON. BE CAREFUL, THEY'VE GOT RADAR.\n");
|
||||
} else if (m == 3) {
|
||||
print("NEARING VERSAILLES. DUCK SOUP. THEY'RE NEARLY DEFENSELESS.\n");
|
||||
}
|
||||
}
|
||||
if (a != 3) {
|
||||
print("\n");
|
||||
while (1) {
|
||||
print("HOW MANY MISSIONS HAVE YOU FLOWN");
|
||||
d = parseInt(await input());
|
||||
if (d < 160)
|
||||
break;
|
||||
print("MISSIONS, NOT MILES...\n");
|
||||
print("150 MISSIONS IS HIGH EVEN FOR OLD-TIMERS.\n");
|
||||
print("NOW THEN, ");
|
||||
}
|
||||
print("\n");
|
||||
if (d >= 100) {
|
||||
print("THAT'S PUSHING THE ODDS!\n");
|
||||
} else if (d < 25) {
|
||||
print("FRESH OUT OF TRAINING, EH?\n");
|
||||
}
|
||||
print("\n");
|
||||
if (d >= 160 * Math.random())
|
||||
hit = true;
|
||||
else
|
||||
hit = false;
|
||||
} else {
|
||||
if (s == 0) {
|
||||
hit = false;
|
||||
} else if (Math.random() > 0.65) {
|
||||
hit = true;
|
||||
} else {
|
||||
hit = false;
|
||||
s = 100;
|
||||
}
|
||||
}
|
||||
if (hit) {
|
||||
print("DIRECT HIT!!!! " + Math.floor(100 * Math.random()) + " KILLED.\n");
|
||||
print("MISSION SUCCESSFUL.\n");
|
||||
} else {
|
||||
t = 0;
|
||||
if (a != 3) {
|
||||
print("MISSED TARGET BY " + Math.floor(2 + 30 * Math.random()) + " MILES!\n");
|
||||
print("NOW YOU'RE REALLY IN FOR IT !!\n");
|
||||
print("\n");
|
||||
while (1) {
|
||||
print("DOES THE ENEMY HAVE GUNS(1), MISSILE(2), OR BOTH(3)");
|
||||
r = parseInt(await input());
|
||||
if (r < 1 || r > 3)
|
||||
print("TRY AGAIN...\n");
|
||||
else
|
||||
break;
|
||||
}
|
||||
print("\n");
|
||||
if (r != 2) {
|
||||
print("WHAT'S THE PERCENT HIT RATE OF ENEMY GUNNERS (10 TO 50)");
|
||||
s = parseInt(await input());
|
||||
if (s < 10)
|
||||
print("YOU LIE, BUT YOU'LL PAY...\n");
|
||||
print("\n");
|
||||
}
|
||||
print("\n");
|
||||
if (r > 1)
|
||||
t = 35;
|
||||
}
|
||||
if (s + t <= 100 * Math.random()) {
|
||||
print("YOU MADE IT THROUGH TREMENDOUS FLAK!!\n");
|
||||
} else {
|
||||
print("* * * * BOOM * * * *\n");
|
||||
print("YOU HAVE BEEN SHOT DOWN.....\n");
|
||||
print("DEARLY BELOVED, WE ARE GATHERED HERE TODAY TO PAY OUR\n");
|
||||
print("LAST TRIBUTE...\n");
|
||||
}
|
||||
}
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("ANOTHER MISSION (Y OR N)");
|
||||
str = await input();
|
||||
if (str != "Y")
|
||||
break;
|
||||
}
|
||||
print("CHICKEN !!!\n");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
main();
|
||||
3
12_Bombs_Away/pascal/README.md
Normal file
3
12_Bombs_Away/pascal/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language))
|
||||
3
12_Bombs_Away/perl/README.md
Normal file
3
12_Bombs_Away/perl/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Perl](https://www.perl.org/)
|
||||
3
12_Bombs_Away/python/README.md
Normal file
3
12_Bombs_Away/python/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Python](https://www.python.org/about/)
|
||||
3
12_Bombs_Away/ruby/README.md
Normal file
3
12_Bombs_Away/ruby/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Ruby](https://www.ruby-lang.org/en/)
|
||||
3
12_Bombs_Away/vbnet/README.md
Normal file
3
12_Bombs_Away/vbnet/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original BASIC source [downloaded from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Visual Basic .NET](https://en.wikipedia.org/wiki/Visual_Basic_.NET)
|
||||
Reference in New Issue
Block a user