Skip to content

Instantly share code, notes, and snippets.

@paulera
Last active March 20, 2018 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulera/bc934e1da56bca9175d01d8d33731425 to your computer and use it in GitHub Desktop.
Save paulera/bc934e1da56bca9175d01d8d33731425 to your computer and use it in GitHub Desktop.
This is the Java implementation of Pink Floyd's song "Chapter 24"
/* This is the Java implementation of the song
Chapter 24, by Pink Floyd.
Album: The Piper at the Gates of Dawn
Year: 1967
References:
https://en.wikipedia.org/wiki/Chapter_24
https://www.youtube.com/watch?v=CqMBQptI7Nk
It expects that some external object call
the notifyDarknessChange() method, so when it
is increased by one the young light is formed
and all movement can be accomplished
Compiled in https://ideone.com/xW54vj
@author: github.com/paulera
*/
import java.util.*;
import java.io.*;
public class Main {
public static void main (String[] args) {
/* The time is with the month of winter solstice
When the change is due to come. */
Chapter24 crazyTune = new Chapter24(new Date(2016, 12, 31));
}
}
class Chapter24 {
private Map<String, Light> lights = null;
private int currentStage = 0;
private Boolean movementAccomplished = false;
private int initialDarkness;
public int heavenDirection;
public int thunderDirection;
public Chapter24(Date timeOfTheYear) {
if (timeOfTheYear.getMonth() == 1) {
change();
}
this.lights = new HashMap<String, Light>(2);
this.lights.put("old", new Light(70));
this.initialDarkness = Piper.getDarkness();
/* hold on loop waiting for the movement to be accomplished */
while (!(this.movementAccomplished = this.doMovement())) {
}
}
public Boolean canDestroy() {
/* Thunder in the other course of heaven. */
if (this.thunderDirection == (this.heavenDirection * -1)) {
/* Things cannot be destroyed once and for all. */
return false;
}
return true;
}
public Boolean doMovement() {
if (this.lights.containsKey("young")) {
while (this.executeStage() < ((Light)this.lights.get("young")).number) {
if (this.currentStage == ((Light)this.lights.get("young")).number - 1) {
/* All movement is accomplished in six stages */
this.movementAccomplished = true;
}
}
/* And the seventh brings return. */
return true;
}
return false;
}
private int executeStage() {
return ++this.currentStage;
}
public void notifyDarknessChange (int darknessLevel) {
if (darknessLevel == this.initialDarkness + 1) {
/* The seven is the number of the young light
It forms when darkness is increased by one. */
this.lights.put("young", new Light(7));
}
}
public String change() {
try {
/* Going */
this.go();
/* and coming */
this.come();
} catch (Exception ex) {} // without error
/* Change returns success */
return "success";
}
/* Action brings good fortune. */
public int action() {
return 7;
}
/* Sunset */
private void go() {
System.out.println("Sunset");
}
/* Sunrise */
private void come() {
System.out.println("Sunrise");
}
}
class Light {
public int number = -1;
public Light(int lightNumber) {
this.number = lightNumber;
}
}
class Piper {
public static int getDarkness() {
// TODO: implement darkness level getter
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment