diff --git a/19 Bunny/perl/bunny.pl b/19 Bunny/perl/bunny.pl new file mode 100644 index 00000000..21b65f2e --- /dev/null +++ b/19 Bunny/perl/bunny.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl +use strict; + +print ' 'x 33 . "BUNNY\n"; +print ' 'x 15 . "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n"; +print "\n"; print "\n"; print "\n"; +#REM "BUNNY" FROM AHL'$S 'BASIC COMPUTER GAMES'; + +# This data contains the letter Bunny A=1, B=2, C=3... +my @A= (2,21,14,14,25); + +# This data structure contains the pair of start and finish absolute position to show letters. +# -1 means next line, whatever more than 128 will stop the data read. +my @B= ( + 1,2,-1,0,2,45,50,-1,0,5,43,52,-1,0,7,41,52,-1, + 1,9,37,50,-1,2,11,36,50,-1,3,13,34,49,-1,4,14,32,48,-1, + 5,15,31,47,-1,6,16,30,45,-1,7,17,29,44,-1,8,19,28,43,-1, + 9,20,27,41,-1,10,21,26,40,-1,11,22,25,38,-1,12,22,24,36,-1, + 13,34,-1,14,33,-1,15,31,-1,17,29,-1,18,27,-1, + 19,26,-1,16,28,-1,13,30,-1,11,31,-1,10,32,-1, + 8,33,-1,7,34,-1,6,13,16,34,-1,5,12,16,35,-1, + 4,12,16,35,-1,3,12,15,35,-1,2,35,-1,1,35,-1, + 2,34,-1,3,34,-1,4,33,-1,6,33,-1,10,32,34,34,-1, + 14,17,19,25,28,31,35,35,-1,15,19,23,30,36,36,-1, + 14,18,21,21,24,30,37,37,-1,13,18,23,29,33,38,-1, + 12,29,31,33,-1,11,13,17,17,19,19,22,22,24,31,-1, + 10,11,17,18,22,22,24,24,29,29,-1, + 22,23,26,29,-1,27,29,-1,28,29,-1,4096 + ); + + +&ENTERS(); +my $L= 64; #REM ASCII LETTER CODE... +print "\n"; + +my $P=0; #Position read iterator +my $Line= ' 'x 60; +while (1) { + my $X= $B[$P]; $P++; #Read start position. + if ($X<0) { print "$Line\n";; $Line= ' 'x 60; next; } + if ($X>128) { last; } + my $Y= $B[$P]; $P++; #Read end position. + + for (my $I=$X; $I<=$Y; $I++) { my $J=$I-5*int($I/5); + substr($Line, $I, 1, chr($L+$A[$J])); #You can change $I for $X to get a nice bunny shadow. + } + } + +&ENTERS(); +exit; + + +sub ENTERS { #GOSUB 260 + for (my $I=1; $I<=6; $I++) { print chr(10); } + } diff --git a/31 Depth Charge/java/DepthCharge.java b/31 Depth Charge/java/DepthCharge.java new file mode 100644 index 00000000..bf17accc --- /dev/null +++ b/31 Depth Charge/java/DepthCharge.java @@ -0,0 +1,186 @@ +import java.util.Scanner; +import java.lang.Math; + +/** + * Game of Depth Charge + *

+ * Based on the BASIC game of Depth Charge here + * https://github.com/coding-horror/basic-computer-games/blob/main/31%20Depth%20Charge/depthcharge.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. + * + * Converted from BASIC to Java by Darren Cardenas. + */ + +public class DepthCharge { + + private final Scanner scan; // For user input + + public DepthCharge() { + + scan = new Scanner(System.in); + + } // End of constructor DepthCharge + + public void play() { + + showIntro(); + startGame(); + + } // End of method play + + private static void showIntro() { + + System.out.println(" ".repeat(29) + "DEPTH CHARGE"); + System.out.println(" ".repeat(14) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"); + System.out.println("\n\n"); + + } // End of method showIntro + + private void startGame() { + + int searchArea = 0; + int shotNum = 0; + int shotTotal = 0; + int shotX = 0; + int shotY = 0; + int shotZ = 0; + int targetX = 0; + int targetY = 0; + int targetZ = 0; + int tries = 0; + String[] userCoordinates; + String userResponse = ""; + + System.out.print("DIMENSION OF SEARCH AREA? "); + searchArea = Integer.parseInt(scan.nextLine()); + System.out.println(""); + + shotTotal = (int) (Math.log10(searchArea) / Math.log10(2)) + 1; + + System.out.println("YOU ARE THE CAPTAIN OF THE DESTROYER USS COMPUTER"); + System.out.println("AN ENEMY SUB HAS BEEN CAUSING YOU TROUBLE. YOUR"); + System.out.println("MISSION IS TO DESTROY IT. YOU HAVE " + shotTotal + " SHOTS."); + System.out.println("SPECIFY DEPTH CHARGE EXPLOSION POINT WITH A"); + System.out.println("TRIO OF NUMBERS -- THE FIRST TWO ARE THE"); + System.out.println("SURFACE COORDINATES; THE THIRD IS THE DEPTH."); + + // Begin outer while loop + while (true) { + + System.out.println(""); + System.out.println("GOOD LUCK !"); + System.out.println(""); + + targetX = (int) ((searchArea + 1) * Math.random()); + targetY = (int) ((searchArea + 1) * Math.random()); + targetZ = (int) ((searchArea + 1) * Math.random()); + + // Begin loop through all shots + for (shotNum = 1; shotNum <= shotTotal; shotNum++) { + + // Get user input + System.out.println(""); + System.out.print("TRIAL # " + shotNum + "? "); + userResponse = scan.nextLine(); + + // Split on commas + userCoordinates = userResponse.split(","); + + // Assign to integer variables + shotX = Integer.parseInt(userCoordinates[0].trim()); + shotY = Integer.parseInt(userCoordinates[1].trim()); + shotZ = Integer.parseInt(userCoordinates[2].trim()); + + // Win condition + if (Math.abs(shotX - targetX) + Math.abs(shotY - targetY) + + Math.abs(shotZ - targetZ) == 0) { + + System.out.println("B O O M ! ! YOU FOUND IT IN" + shotNum + " TRIES!"); + break; + + } + + this.getReport(targetX, targetY, targetZ, shotX, shotY, shotZ); + + System.out.println(""); + + } // End loop through all shots + + if (shotNum > shotTotal) { + + System.out.println(""); + System.out.println("YOU HAVE BEEN TORPEDOED! ABANDON SHIP!"); + System.out.println("THE SUBMARINE WAS AT " + targetX + "," + targetY + "," + targetZ); + } + + System.out.println(""); + System.out.println(""); + System.out.print("ANOTHER GAME (Y OR N)? "); + userResponse = scan.nextLine(); + + if (!userResponse.toUpperCase().equals("Y")) { + System.out.print("OK. HOPE YOU ENJOYED YOURSELF."); + return; + } + + } // End outer while loop + + } // End of method startGame + + public void getReport(int a, int b, int c, int x, int y, int z) { + + System.out.print("SONAR REPORTS SHOT WAS "); + + // Handle y coordinate + if (y > b) { + + System.out.print("NORTH"); + + } else if (y < b) { + + System.out.print("SOUTH"); + } + + // Handle x coordinate + if (x > a) { + + System.out.print("EAST"); + + } else if (x < a) { + + System.out.print("WEST"); + } + + if ((y != b) || (x != a)) { + + System.out.print(" AND"); + } + + // Handle depth + if (z > c) { + + System.out.println(" TOO LOW."); + + } else if (z < c) { + + System.out.println(" TOO HIGH."); + + } else { + + System.out.println(" DEPTH OK."); + } + + return; + + } // End of method getReport + + public static void main(String[] args) { + + DepthCharge game = new DepthCharge(); + game.play(); + + } // End of method main + +} // End of class DepthCharge diff --git a/41 Guess/perl/guess.pl b/41 Guess/perl/guess.pl new file mode 100644 index 00000000..f16a3e84 --- /dev/null +++ b/41 Guess/perl/guess.pl @@ -0,0 +1,52 @@ +#!/usr/bin/perl +use strict; + +my $L1; +while (1) { + print ' 'x 33 . "GUESS\n"; + print ' 'x 15 . "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n"; + print "\n"; print "\n"; print "\n"; + print "THIS IS A NUMBER GUESSING GAME. I'LL THINK\n"; + print "OF A NUMBER BETWEEN 1 AND ANY LIMIT YOU WANT.\n"; + print "THEN YOU HAVE TO GUESS WHAT IT IS.\n"; + print "\n"; + print "WHAT LIMIT DO YOU WANT"; + print "? "; chomp(my $L = ); + print "\n"; + $L1= int(log($L)/log(2))+1; + + while (1) { + print "I'M THINKING OF A NUMBER BETWEEN 1 AND $L\n"; + my $G=0; + print "NOW YOU TRY TO GUESS WHAT IT IS.\n"; + my $M=int($L*rand(1)+1); + my $N=0; + while (1) { + while (1) { + print "? "; chomp($N = ); + if ($N>0) { last; } + } + $G=$G+1; + if ($N==$M) { last; } + if ($N>$M) { print "TOO HIGH. TRY A SMALLER ANSWER.\n"; } + else { print "TOO LOW. TRY A BIGGER ANSWER.\n"; } + } + print "THAT'S IT! YOU GOT IT IN $G TRIES.\n"; + if ($G<$L1) { print "VERY "; } + if ($G<=$L1) { print "GOOD.\n"; } + if ($G>$L1) { print "YOU SHOULD HAVE BEEN ABLE TO GET IT IN ONLY $L1\n"; } + &ENTERS(); + } + } + +exit; + + +sub ENTERS { #GOSUB 70 + for (my $H=1; $H<=5; $H++) { + print "\n"; + } + return; + } + + diff --git a/70 Poetry/poetry.pl b/70 Poetry/poetry.pl new file mode 100644 index 00000000..610938b6 --- /dev/null +++ b/70 Poetry/poetry.pl @@ -0,0 +1,81 @@ +#!/usr/bin/perl +#use strict; +# Automatic converted by bas2perl.pl +# Too much spaguetti code to be properly converted. + + +print ' 'x 30 . "POETRY\n"; +print ' 'x 15 . "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n"; +print "\n"; print "\n"; print "\n"; +Line90: +if ($I==1) { goto Line100; } elsif ($I==2) { goto Line101; } elsif ($I==3) { goto Line102; } elsif ($I==4) { goto Line103; } elsif ($I==5) { goto Line104; } ; +Line100: +print "MIDNIGHT DREARY"; goto Line210; +Line101: +print "FIERY EYES"; goto Line210; +Line102: +print "BIRD OR FIEND"; goto Line210; +Line103: +print "THING OF EVIL"; goto Line210; +Line104: +print "PROPHET"; goto Line210; +Line110: +if ($I==1) { goto Line111; } elsif ($I==2) { goto Line112; } elsif ($I==3) { goto Line113; } elsif ($I==4) { goto Line114; } elsif ($I==5) { goto Line115; } ; +Line111: +print "BEGUILING ME"; $U=2; goto Line210; +Line112: +print "THRILLED ME"; goto Line210; +Line113: +print "STILL SITTING...."; goto Line212; +Line114: +print "NEVER FLITTING"; $U=2; goto Line210; +Line115: +print "BURNED"; goto Line210; +Line120: +if ($I==1) { goto Line121; } elsif ($I==2) { goto Line122; } elsif ($I==3) { goto Line123; } elsif ($I==4) { goto Line124; } elsif ($I==5) { goto Line125; } ; +Line121: +print "AND MY SOUL"; goto Line210; +Line122: +print "DARKNESS THERE"; goto Line210; +Line123: +print "SHALL BE LIFTED"; goto Line210; +Line124: +print "QUOTH THE RAVEN"; goto Line210; +Line125: +if ($U==0) { goto Line210; } +print "SIGN OF PARTING"; goto Line210; +Line130: +if ($I==1) { goto Line131; } elsif ($I==2) { goto Line132; } elsif ($I==3) { goto Line133; } elsif ($I==4) { goto Line134; } elsif ($I==5) { goto Line135; } ; +Line131: +print "NOTHING MORE"; goto Line210; +Line132: +print "YET AGAIN"; goto Line210; +Line133: +print "SLOWLY CREEPING"; goto Line210; +Line134: +print "...EVERMORE"; goto Line210; +Line135: +print "NEVERMORE"; +Line210: +if ($U==0 || rand(1)>.19) { goto Line212; } +print ","; $U=2; +Line212: +if (rand(1)>.65) { goto Line214; } +print " "; $U=$U+1; goto Line215; +Line214: +print "\n"; $U=0; +Line215: +$I=int(int(10*rand(1))/2)+1; +$J=$J+1; $K=$K+1; +if ($U>0 || int($J/2)!=$J/2) { goto Line240; } +print " "; +Line240: +if ($J==1) { goto Line90; } elsif ($J==2) { goto Line110; } elsif ($J==3) { goto Line120; } elsif ($J==4) { goto Line130; } elsif ($J==5) { goto Line250; } ; +Line250: +$J=0; print "\n"; if ($K>20) { goto Line270; } +goto Line215; +Line270: +print "\n"; $U=0; $K=0; goto Line110; +exit; + +