Author: xor
Date: 2008-11-01 11:44:32 +0000 (Sat, 01 Nov 2008)
New Revision: 23270

Added:
   trunk/plugins/WoT/introduction/
   trunk/plugins/WoT/introduction/IntroductionPuzzle.java
   trunk/plugins/WoT/introduction/IntroductionPuzzleFactory.java
Log:
Design classes for generation of introduction puzzles. Feel free to suggest 
improvements.

Added: trunk/plugins/WoT/introduction/IntroductionPuzzle.java
===================================================================
--- trunk/plugins/WoT/introduction/IntroductionPuzzle.java                      
        (rev 0)
+++ trunk/plugins/WoT/introduction/IntroductionPuzzle.java      2008-11-01 
11:44:32 UTC (rev 23270)
@@ -0,0 +1,68 @@
+/*
+ * This code is part of WoT, a plugin for Freenet. It is distributed 
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT.introduction;
+
+import plugins.WoT.Identity;
+
+public class IntroductionPuzzle {
+       
+       enum PuzzleType {
+               Image,
+               Audio
+       };
+       
+       private final PuzzleType mType;
+       
+       private final byte[] mData;
+       
+       private final String mSolution;
+       
+       private final Identity mInserter;
+       
+       /**
+        * For construction from a received puzzle.
+        * @param newType
+        * @param newData
+        */
+       public IntroductionPuzzle(Identity newInserter, PuzzleType newType, 
byte[] newData) {
+               mInserter = newInserter;
+               mType = newType;
+               mData = newData;
+               mSolution = null; 
+       }
+       
+       /**
+        * For construction of a puzzle which is meant to be inserted.
+        * @param newType
+        * @param newData
+        */
+       public IntroductionPuzzle(Identity newInserter, PuzzleType newType, 
byte[] newData, String newSolution) {
+               mInserter = newInserter;
+               mType = newType;
+               mData = newData;
+               mSolution = newSolution; 
+       }
+       
+       public PuzzleType getPuzzleType() {
+               return mType;
+       }
+       
+       public byte[] getPuzzle() {
+               return mData;
+       }
+       
+       /**
+        * Get the solution of the puzzle. Null if the puzzle was received and 
not locally generated.
+        */
+       public String getSolution() {
+               assert(mSolution != null); /* Whoever uses this function should 
not need to call it when there is no solution available */
+               return mSolution;
+       }
+       
+       public Identity getInserter() {
+               return mInserter;
+       }
+}

Added: trunk/plugins/WoT/introduction/IntroductionPuzzleFactory.java
===================================================================
--- trunk/plugins/WoT/introduction/IntroductionPuzzleFactory.java               
                (rev 0)
+++ trunk/plugins/WoT/introduction/IntroductionPuzzleFactory.java       
2008-11-01 11:44:32 UTC (rev 23270)
@@ -0,0 +1,16 @@
+/*
+ * This code is part of WoT, a plugin for Freenet. It is distributed 
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT.introduction;
+
+/**
+ * @author xor
+ *
+ */
+public interface IntroductionPuzzleFactory {
+       
+       public IntroductionPuzzle generatePuzzle();
+
+}


Reply via email to