MAINT: Apply pre-commit

Remove byte-order-marker pre-commit check as there would be
many adjustments necessary
This commit is contained in:
Martin Thoma
2022-03-05 09:29:23 +01:00
parent f5e33ae38f
commit e64fb6795c
536 changed files with 6267 additions and 5556 deletions

View File

@@ -31,7 +31,7 @@
150 PRINT "YOU LOST";INT(X/3);"MEN, BUT I LOST ";INT(2*D/3)
155 A=INT(A-X/3)
160 D=0
165 GOTO 500
165 GOTO 500
200 IF X>B THEN 20
210 IF X<E/3 THEN 230
215 IF X<2*E/3 THEN 250
@@ -85,7 +85,7 @@
1630 PRINT "I WIPED OUT YOUR ATTACK!"
1635 A=A-T
1640 GOTO 2000
1700 IF T>B THEN 1030
1700 IF T>B THEN 1030
1710 IF T<E/2 THEN 1750
1720 GOTO 1770
1750 PRINT "I SUNK TWO OF YOUR BATTLESHIPS, AND MY AIR FORCE"
@@ -98,8 +98,8 @@
1775 F=2*F/3
1780 E=(E/2)
1790 GOTO 2000
1800 IF T>C THEN 1030
1810 IF T>F/2 THEN 1830
1800 IF T>C THEN 1030
1810 IF T>F/2 THEN 1830
1820 GOTO 1850
1830 PRINT "MY NAVY AND AIR FORCE IN A COMBINED ATTACK LEFT"
1831 PRINT "YOUR COUNTRY IN SHAMBLES."

View File

@@ -9,52 +9,52 @@ import java.util.Scanner;
* <p>
* 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.
*
*
* Converted from BASIC to Java by Darren Cardenas.
*/
public class Combat {
private static final int MAX_UNITS = 72000; // Maximum number of total units per player
private final Scanner scan; // For user input
private boolean planeCrashWin = false;
private int usrArmy = 0; // Number of user Army units
private int usrNavy = 0; // Number of user Navy units
private int usrAir = 0; // Number of user Air Force units
private int cpuArmy = 30000; // Number of cpu Army units
private int cpuNavy = 20000; // Number of cpu Navy units
private int cpuAir = 22000; // Number of cpu Air Force units
public Combat() {
scan = new Scanner(System.in);
} // End of constructor Combat
scan = new Scanner(System.in);
} // End of constructor Combat
public void play() {
showIntro();
getForces();
attackFirst();
attackSecond();
} // End of method play
} // End of method play
private static void showIntro() {
System.out.println(" ".repeat(32) + "COMBAT");
System.out.println(" ".repeat(14) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println("\n\n");
System.out.println("I AM AT WAR WITH YOU.");
System.out.println("WE HAVE " + MAX_UNITS + " SOLDIERS APIECE.\n");
} // End of method showIntro
} // End of method showIntro
private void getForces() {
do {
System.out.println("DISTRIBUTE YOUR FORCES.");
System.out.println(" ME YOU");
@@ -63,24 +63,24 @@ public class Combat {
System.out.print("NAVY " + cpuNavy + " ? ");
usrNavy = scan.nextInt();
System.out.print("A. F. " + cpuAir + " ? ");
usrAir = scan.nextInt();
usrAir = scan.nextInt();
} while ((usrArmy + usrNavy + usrAir) > MAX_UNITS); // Avoid exceeding the maximum number of total units
} // End of method getForces
} // End of method getForces
private void attackFirst() {
int numUnits = 0;
int unitType = 0;
int unitType = 0;
do {
System.out.println("YOU ATTACK FIRST. TYPE (1) FOR ARMY; (2) FOR NAVY;");
System.out.println("AND (3) FOR AIR FORCE.");
System.out.print("? ");
unitType = scan.nextInt();
} while ((unitType < 1) || (unitType > 3)); // Avoid out-of-range values
do {
System.out.println("HOW MANY MEN");
System.out.print("? ");
@@ -93,15 +93,15 @@ public class Combat {
// Begin handling deployment type
switch (unitType) {
case 1: // Army deployed
if (numUnits < (usrArmy / 3.0)) { // User deployed less than one-third of their Army units
System.out.println("YOU LOST " + numUnits + " MEN FROM YOUR ARMY.");
usrArmy = usrArmy - numUnits;
usrArmy = usrArmy - numUnits;
}
else if (numUnits < (2.0 * usrArmy / 3.0)) { // User deployed less than two-thirds of their Army units
System.out.println("YOU LOST " + (int) Math.floor(numUnits / 3.0) + " MEN, BUT I LOST " + (int) Math.floor(2.0 * cpuArmy / 3.0));
usrArmy = (int) Math.floor(usrArmy - numUnits / 3.0);
cpuArmy = 0;
cpuArmy = 0;
}
else { // User deployed two-thirds or more of their Army units
System.out.println("YOU SUNK ONE OF MY PATROL BOATS, BUT I WIPED OUT TWO");
@@ -109,34 +109,34 @@ public class Combat {
usrArmy = (int) Math.floor(usrArmy / 3.0);
usrAir = (int) Math.floor(usrAir / 3.0);
cpuNavy = (int) Math.floor(2.0 * cpuNavy / 3.0);
}
}
break;
case 2: // Navy deployed
if (numUnits < (cpuNavy / 3.0)) { // User deployed less than one-third relative to cpu Navy units
System.out.println("YOUR ATTACK WAS STOPPED!");
usrNavy = usrNavy - numUnits;
}
usrNavy = usrNavy - numUnits;
}
else if (numUnits < (2.0 * cpuNavy / 3.0)) { // User deployed less than two-thirds relative to cpu Navy units
System.out.println("YOU DESTROYED " + (int) Math.floor(2.0 * cpuNavy / 3.0) + " OF MY ARMY.");
System.out.println("YOU DESTROYED " + (int) Math.floor(2.0 * cpuNavy / 3.0) + " OF MY ARMY.");
cpuNavy = (int) Math.floor(cpuNavy / 3.0);
}
}
else { // User deployed two-thirds or more relative to cpu Navy units
System.out.println("YOU SUNK ONE OF MY PATROL BOATS, BUT I WIPED OUT TWO");
System.out.println("OF YOUR AIR FORCE BASES AND 3 ARMY BASES.");
usrArmy = (int) Math.floor(usrArmy / 3.0);
usrAir = (int) Math.floor(usrAir / 3.0);
cpuNavy = (int) Math.floor(2.0 * cpuNavy / 3.0);
}
}
break;
case 3: // Air Force deployed
if (numUnits < (usrAir / 3.0)) { // User deployed less than one-third of their Air Force units
System.out.println("YOUR ATTACK WAS WIPED OUT.");
usrAir = usrAir - numUnits;
}
usrAir = usrAir - numUnits;
}
else if (numUnits < (2.0 * usrAir / 3.0)) { // User deployed less than two-thirds of their Air Force units
System.out.println("WE HAD A DOGFIGHT. YOU WON - AND FINISHED YOUR MISSION.");
cpuArmy = (int) Math.floor(2.0 * cpuArmy / 3.0);
@@ -145,22 +145,22 @@ public class Combat {
}
else { // User deployed two-thirds or more of their Air Force units
System.out.println("YOU WIPED OUT ONE OF MY ARMY PATROLS, BUT I DESTROYED");
System.out.println("TWO NAVY BASES AND BOMBED THREE ARMY BASES.");
System.out.println("TWO NAVY BASES AND BOMBED THREE ARMY BASES.");
usrArmy = (int) Math.floor(usrArmy / 4.0);
usrNavy = (int) Math.floor(usrNavy / 3.0);
cpuArmy = (int) Math.floor(2.0 * cpuArmy / 3.0);
}
break;
}
break;
} // End handling deployment type
} // End of method attackFirst
private void attackSecond() {
int numUnits = 0;
int unitType = 0;
int unitType = 0;
System.out.println("");
System.out.println(" YOU ME");
System.out.print("ARMY ");
@@ -169,14 +169,14 @@ public class Combat {
System.out.format("%-14s%s\n", usrNavy, cpuNavy);
System.out.print("A. F. ");
System.out.format("%-14s%s\n", usrAir, cpuAir);
do {
System.out.println("WHAT IS YOUR NEXT MOVE?");
System.out.println("ARMY=1 NAVY=2 AIR FORCE=3");
System.out.print("? ");
unitType = scan.nextInt();
} while ((unitType < 1) || (unitType > 3)); // Avoid out-of-range values
do {
System.out.println("HOW MANY MEN");
System.out.print("? ");
@@ -184,85 +184,85 @@ public class Combat {
} while ((numUnits < 0) || // Avoid negative values
((unitType == 1) && (numUnits > usrArmy)) || // Avoid exceeding the number of available Army units
((unitType == 2) && (numUnits > usrNavy)) || // Avoid exceeding the number of available Navy units
((unitType == 3) && (numUnits > usrAir))); // Avoid exceeding the number of available Air Force units
((unitType == 3) && (numUnits > usrAir))); // Avoid exceeding the number of available Air Force units
// Begin handling deployment type
switch (unitType) {
case 1: // Army deployed
if (numUnits < (cpuArmy / 2.0)) { // User deployed less than half relative to cpu Army units
System.out.println("I WIPED OUT YOUR ATTACK!");
usrArmy = usrArmy - numUnits;
usrArmy = usrArmy - numUnits;
}
else { // User deployed half or more relative to cpu Army units
System.out.println("YOU DESTROYED MY ARMY!");
cpuArmy = 0;
}
}
break;
case 2: // Navy deployed
if (numUnits < (cpuNavy / 2.0)) { // User deployed less than half relative to cpu Navy units
System.out.println("I SUNK TWO OF YOUR BATTLESHIPS, AND MY AIR FORCE");
System.out.println("WIPED OUT YOUR UNGUARDED CAPITOL.");
usrArmy = (int) Math.floor(usrArmy / 4.0);
usrNavy = (int) Math.floor(usrNavy / 2.0);
}
usrNavy = (int) Math.floor(usrNavy / 2.0);
}
else { // User deployed half or more relative to cpu Navy units
System.out.println("YOUR NAVY SHOT DOWN THREE OF MY XIII PLANES,");
System.out.println("AND SUNK THREE BATTLESHIPS.");
cpuAir = (int) Math.floor(2.0 * cpuAir / 3.0);
cpuNavy = (int) Math.floor(cpuNavy / 2.0);
}
cpuNavy = (int) Math.floor(cpuNavy / 2.0);
}
break;
case 3: // Air Force deployed
if (numUnits > (cpuAir / 2.0)) { // User deployed more than half relative to cpu Air Force units
System.out.println("MY NAVY AND AIR FORCE IN A COMBINED ATTACK LEFT");
System.out.println("YOUR COUNTRY IN SHAMBLES.");
usrArmy = (int) Math.floor(usrArmy / 3.0);
usrNavy = (int) Math.floor(usrNavy / 3.0);
usrAir = (int) Math.floor(usrAir / 3.0);
}
}
else { // User deployed half or less relative to cpu Air Force units
System.out.println("ONE OF YOUR PLANES CRASHED INTO MY HOUSE. I AM DEAD.");
System.out.println("MY COUNTRY FELL APART.");
planeCrashWin = true;
}
}
break;
} // End handling deployment type
// Suppress message for plane crashes
if (planeCrashWin == false) {
System.out.println("");
System.out.println("FROM THE RESULTS OF BOTH OF YOUR ATTACKS,");
}
// User wins
if ((planeCrashWin == true) ||
if ((planeCrashWin == true) ||
((usrArmy + usrNavy + usrAir) > ((int) Math.floor((3.0 / 2.0 * (cpuArmy + cpuNavy + cpuAir)))))) {
System.out.println("YOU WON, OH! SHUCKS!!!!");
System.out.println("YOU WON, OH! SHUCKS!!!!");
}
// User loses
else if ((usrArmy + usrNavy + usrAir) < ((int) Math.floor((2.0 / 3.0 * (cpuArmy + cpuNavy + cpuAir))))) { // User loss
else if ((usrArmy + usrNavy + usrAir) < ((int) Math.floor((2.0 / 3.0 * (cpuArmy + cpuNavy + cpuAir))))) { // User loss
System.out.println("YOU LOST-I CONQUERED YOUR COUNTRY. IT SERVES YOU");
System.out.println("RIGHT FOR PLAYING THIS STUPID GAME!!!");
}
// Peaceful outcome
else {
else {
System.out.println("THE TREATY OF PARIS CONCLUDED THAT WE TAKE OUR");
System.out.println("RESPECTIVE COUNTRIES AND LIVE IN PEACE.");
}
}
} // End of method attackSecond
public static void main(String[] args) {
Combat combat = new Combat();
combat.play();
} // End of method main
} // End of class Combat
} // End of class Combat

View File

@@ -12,10 +12,10 @@ 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");

View File

@@ -44,17 +44,21 @@ def attackFirst():
while True:
print("YOU ATTACK FIRST. TYPE (1) FOR ARMY; (2) FOR NAVY;")
print("AND (3) FOR AIR FORCE.")
print("?", end=' ')
print("?", end=" ")
unitType = int(input())
if not (unitType < 1 or unitType > 3):
break
while True:
print("HOW MANY MEN")
print("?", end=' ')
print("?", end=" ")
numUnits = int(input())
if not ((numUnits < 0) or ((unitType == 1) and (numUnits > usrArmy)) or (
(unitType == 2) and (numUnits > usrNavy)) or ((unitType == 3) and (numUnits > usrAir))):
if not (
(numUnits < 0)
or ((unitType == 1) and (numUnits > usrArmy))
or ((unitType == 2) and (numUnits > usrNavy))
or ((unitType == 3) and (numUnits > usrAir))
):
break
if unitType == 1:
@@ -62,7 +66,12 @@ def attackFirst():
print("YOU LOST " + str(numUnits) + " MEN FROM YOUR ARMY.")
usrArmy = usrArmy - numUnits
elif numUnits < (2 * usrArmy / 3):
print("YOU LOST " + str(int(numUnits / 3)) + " MEN, BUT I LOST " + str(int(2 * cpuArmy / 3)))
print(
"YOU LOST "
+ str(int(numUnits / 3))
+ " MEN, BUT I LOST "
+ str(int(2 * cpuArmy / 3))
)
usrArmy = int(usrArmy - (numUnits / 3))
cpuArmy = 0
else:
@@ -123,39 +132,44 @@ def attackSecond():
unitType = int(input())
if not ((unitType < 1) or (unitType > 3)):
break
while True:
print("HOW MANY MEN")
print("? ", end="")
numUnits = int(input())
if not((numUnits < 0) or ((unitType == 1) and (numUnits > usrArmy)) or ((unitType == 2) and (numUnits > usrNavy)) or ((unitType == 3) and (numUnits > usrAir))):
if not (
(numUnits < 0)
or ((unitType == 1) and (numUnits > usrArmy))
or ((unitType == 2) and (numUnits > usrNavy))
or ((unitType == 3) and (numUnits > usrAir))
):
break
if unitType == 1:
if numUnits < (cpuArmy/2):
if numUnits < (cpuArmy / 2):
print("I WIPED OUT YOUR ATTACK!")
usrArmy = usrArmy - numUnits
else:
print("YOU DESTROYED MY ARMY!")
cpuArmy = 0
elif unitType == 2:
if numUnits < (cpuNavy/2):
if numUnits < (cpuNavy / 2):
print("I SUNK TWO OF YOUR BATTLESHIPS, AND MY AIR FORCE")
print("WIPED OUT YOUR UNGUARDED CAPITOL.")
usrArmy = int(usrArmy/4)
usrNavy = int(usrNavy/2)
usrArmy = int(usrArmy / 4)
usrNavy = int(usrNavy / 2)
else:
print("YOUR NAVY SHOT DOWN THREE OF MY XIII PLANES,")
print("AND SUNK THREE BATTLESHIPS.")
cpuAir = int(2*cpuAir/3)
cpuNavy = int(cpuNavy/2)
cpuAir = int(2 * cpuAir / 3)
cpuNavy = int(cpuNavy / 2)
elif unitType == 3:
if numUnits > (cpuAir/2):
if numUnits > (cpuAir / 2):
print("MY NAVY AND AIR FORCE IN A COMBINED ATTACK LEFT")
print("YOUR COUNTRY IN SHAMBLES.")
usrArmy = int(usrArmy/3)
usrNavy = int(usrNavy/3)
usrAir = int(usrAir/3)
usrArmy = int(usrArmy / 3)
usrNavy = int(usrNavy / 3)
usrAir = int(usrAir / 3)
else:
print("ONE OF YOUR PLANES CRASHED INTO MY HOUSE. I AM DEAD.")
print("MY COUNTRY FELL APART.")
@@ -165,9 +179,11 @@ def attackSecond():
print("")
print("FROM THE RESULTS OF BOTH OF YOUR ATTACKS,")
if (planeCrashWin == True) or ((usrArmy + usrNavy + usrAir) > (int(3/2*(cpuArmy + cpuNavy + cpuAir)))):
if (planeCrashWin == True) or (
(usrArmy + usrNavy + usrAir) > (int(3 / 2 * (cpuArmy + cpuNavy + cpuAir)))
):
print("YOU WON, OH! SHUCKS!!!!")
elif (usrArmy + usrNavy + usrAir) < int(2/3*(cpuArmy + cpuNavy + cpuAir)):
elif (usrArmy + usrNavy + usrAir) < int(2 / 3 * (cpuArmy + cpuNavy + cpuAir)):
print("YOU LOST-I CONQUERED YOUR COUNTRY. IT SERVES YOU")
print("RIGHT FOR PLAYING THIS STUPID GAME!!!")
else:
@@ -180,6 +196,7 @@ def main():
getForces()
attackFirst()
attackSecond()
if __name__ == '__main__':
main()
if __name__ == "__main__":
main()