diff --git a/70 Poetry/java/Poetry.java b/70 Poetry/java/Poetry.java new file mode 100644 index 00000000..80be8f21 --- /dev/null +++ b/70 Poetry/java/Poetry.java @@ -0,0 +1,266 @@ +/** + * Game of Poetry + *
+ * Based on the BASIC game of Poetry here + * https://github.com/coding-horror/basic-computer-games/blob/main/70%20Poetry/poetry.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 Poetry { + + private final static double COMMA_RATE = 0.19; + private final static double SPACE_RATE = 0.65; + private final static int PARAGRAPH_RATE = 20; + + private enum Step { + WORD_GROUP1, WORD_GROUP2, WORD_GROUP3, WORD_GROUP4, RANDOMIZE_COMMA, + RANDOMIZE_WHITESPACE, RANDOMIZE_COUNTERS + } + + public void play() { + + showIntro(); + startGame(); + + } // End of method play + + private void showIntro() { + + System.out.println(" ".repeat(29) + "POETRY"); + System.out.println(" ".repeat(14) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"); + System.out.println("\n\n"); + + } // End of method showIntro + + private void startGame() { + + int groupIndex = 0; + int paragraphIndex = 0; + int punctuationIndex = 0; + int wordIndex = 1; + + Step nextStep = Step.WORD_GROUP1; + + // Begin outer while loop + while (true) { + + switch (nextStep) { + + case WORD_GROUP1: + + if (wordIndex == 1) { + + System.out.print("MIDNIGHT DREARY"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 2) { + + System.out.print("FIERY EYES"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 3) { + + System.out.print("BIRD OR FIEND"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 4) { + + System.out.print("THING OF EVIL"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 5) { + + System.out.print("PROPHET"); + nextStep = Step.RANDOMIZE_COMMA; + } + break; + + case WORD_GROUP2: + + if (wordIndex == 1) { + + System.out.print("BEGUILING ME"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 2) { + + System.out.print("THRILLED ME"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 3) { + + System.out.print("STILL SITTING...."); + nextStep = Step.RANDOMIZE_WHITESPACE; + + } else if (wordIndex == 4) { + + System.out.print("NEVER FLITTING"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 5) { + + System.out.print("BURNED"); + nextStep = Step.RANDOMIZE_COMMA; + } + break; + + case WORD_GROUP3: + + if (wordIndex == 1) { + + System.out.print("AND MY SOUL"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 2) { + + System.out.print("DARKNESS THERE"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 3) { + + System.out.print("SHALL BE LIFTED"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 4) { + + System.out.print("QUOTH THE RAVEN"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 5) { + + if (punctuationIndex != 0) { + + System.out.print("SIGN OF PARTING"); + } + + nextStep = Step.RANDOMIZE_COMMA; + } + break; + + case WORD_GROUP4: + + if (wordIndex == 1) { + + System.out.print("NOTHING MORE"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 2) { + + System.out.print("YET AGAIN"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 3) { + + System.out.print("SLOWLY CREEPING"); + nextStep = Step.RANDOMIZE_WHITESPACE; + + } else if (wordIndex == 4) { + + System.out.print("...EVERMORE"); + nextStep = Step.RANDOMIZE_COMMA; + + } else if (wordIndex == 5) { + + System.out.print("NEVERMORE"); + nextStep = Step.RANDOMIZE_COMMA; + } + break; + + case RANDOMIZE_COMMA: + + // Insert commas + if ((punctuationIndex != 0) && (Math.random() <= COMMA_RATE)) { + + System.out.print(","); + punctuationIndex = 2; + } + nextStep = Step.RANDOMIZE_WHITESPACE; + break; + + + case RANDOMIZE_WHITESPACE: + + // Insert spaces + if (Math.random() <= SPACE_RATE) { + + System.out.print(" "); + punctuationIndex++; + + } + // Insert newlines + else { + + System.out.println(""); + punctuationIndex = 0; + } + nextStep = Step.RANDOMIZE_COUNTERS; + break; + + case RANDOMIZE_COUNTERS: + + wordIndex = (int)((int)(10 * Math.random()) / 2) + 1; + + groupIndex++; + paragraphIndex++; + + if ((punctuationIndex == 0) && (groupIndex % 2 == 0)) { + + System.out.print(" "); + } + + if (groupIndex == 1) { + + nextStep = Step.WORD_GROUP1; + + } else if (groupIndex == 2) { + + nextStep = Step.WORD_GROUP2; + + } else if (groupIndex == 3) { + + nextStep = Step.WORD_GROUP3; + + } else if (groupIndex == 4) { + + nextStep = Step.WORD_GROUP4; + + } else if (groupIndex == 5) { + + groupIndex = 0; + System.out.println(""); + + if (paragraphIndex > PARAGRAPH_RATE) { + + System.out.println(""); + punctuationIndex = 0; + paragraphIndex = 0; + nextStep = Step.WORD_GROUP2; + + } else { + + nextStep = Step.RANDOMIZE_COUNTERS; + } + } + break; + + default: + System.out.println("INVALID STEP"); + break; + } + + } // End outer while loop + + } // End of method startGame + + public static void main(String[] args) { + + Poetry poetry = new Poetry(); + poetry.play(); + + } // End of method main + +} // End of class Poetry diff --git a/70 Poetry/perl/poetry.pl b/70 Poetry/perl/poetry.pl new file mode 100644 index 00000000..610938b6 --- /dev/null +++ b/70 Poetry/perl/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; + +