From: gitknilch Date: Sun, 24 Feb 2013 19:40:21 +0000 (+0100) Subject: initial commit, version from dropbox X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/FreeShisen/commitdiff_plain/c6f3dff3c5cfa05ad1ff2e0f58e3d006daf7ecf2 initial commit, version from dropbox --- c6f3dff3c5cfa05ad1ff2e0f58e3d006daf7ecf2 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..6c635c0 --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.classpath.sample b/.classpath.sample new file mode 100644 index 0000000..6c635c0 --- /dev/null +++ b/.classpath.sample @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..62ee6b3 --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + ShisenSho + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/.project.sample b/.project.sample new file mode 100644 index 0000000..62ee6b3 --- /dev/null +++ b/.project.sample @@ -0,0 +1,33 @@ + + + ShisenSho + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..6de4e1e --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/artwork/logo.png b/artwork/logo.png new file mode 100644 index 0000000..b5d6a6d Binary files /dev/null and b/artwork/logo.png differ diff --git a/artwork/screenshots/device-2013-01-16-011637.png b/artwork/screenshots/device-2013-01-16-011637.png new file mode 100644 index 0000000..75205c2 Binary files /dev/null and b/artwork/screenshots/device-2013-01-16-011637.png differ diff --git a/artwork/screenshots/device-2013-01-16-011744.png b/artwork/screenshots/device-2013-01-16-011744.png new file mode 100644 index 0000000..7fe59be Binary files /dev/null and b/artwork/screenshots/device-2013-01-16-011744.png differ diff --git a/artwork/screenshots/device-2013-01-16-011805.png b/artwork/screenshots/device-2013-01-16-011805.png new file mode 100644 index 0000000..ea4a108 Binary files /dev/null and b/artwork/screenshots/device-2013-01-16-011805.png differ diff --git a/artwork/screenshots/device-2013-01-16-011832.png b/artwork/screenshots/device-2013-01-16-011832.png new file mode 100644 index 0000000..689939d Binary files /dev/null and b/artwork/screenshots/device-2013-01-16-011832.png differ diff --git a/bin/AndroidManifest.xml b/bin/AndroidManifest.xml new file mode 100644 index 0000000..6de4e1e --- /dev/null +++ b/bin/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/classes/org/proofofconcept/shisensho/Board.class b/bin/classes/org/proofofconcept/shisensho/Board.class new file mode 100644 index 0000000..a0b35ff Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/Board.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/BuildConfig.class b/bin/classes/org/proofofconcept/shisensho/BuildConfig.class new file mode 100644 index 0000000..04c650e Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/BuildConfig.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/Line.class b/bin/classes/org/proofofconcept/shisensho/Line.class new file mode 100644 index 0000000..09fbc87 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/Line.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/Move.class b/bin/classes/org/proofofconcept/shisensho/Move.class new file mode 100644 index 0000000..fa50f5d Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/Move.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/Point.class b/bin/classes/org/proofofconcept/shisensho/Point.class new file mode 100644 index 0000000..b509f68 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/Point.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/R$array.class b/bin/classes/org/proofofconcept/shisensho/R$array.class new file mode 100644 index 0000000..479cbd3 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/R$array.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/R$attr.class b/bin/classes/org/proofofconcept/shisensho/R$attr.class new file mode 100644 index 0000000..1c8353d Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/R$attr.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/R$drawable.class b/bin/classes/org/proofofconcept/shisensho/R$drawable.class new file mode 100644 index 0000000..adf18b1 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/R$drawable.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/R$id.class b/bin/classes/org/proofofconcept/shisensho/R$id.class new file mode 100644 index 0000000..fd8dadc Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/R$id.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/R$layout.class b/bin/classes/org/proofofconcept/shisensho/R$layout.class new file mode 100644 index 0000000..eed0b20 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/R$layout.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/R$menu.class b/bin/classes/org/proofofconcept/shisensho/R$menu.class new file mode 100644 index 0000000..4eb9390 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/R$menu.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/R$string.class b/bin/classes/org/proofofconcept/shisensho/R$string.class new file mode 100644 index 0000000..02c5f86 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/R$string.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/R.class b/bin/classes/org/proofofconcept/shisensho/R.class new file mode 100644 index 0000000..97256fe Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/R.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenSho.class b/bin/classes/org/proofofconcept/shisensho/ShisenSho.class new file mode 100644 index 0000000..5920ff7 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenSho.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoActivity.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoActivity.class new file mode 100644 index 0000000..fdd4e27 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoActivity.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$1.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$1.class new file mode 100644 index 0000000..1ce231a Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$1.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$2.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$2.class new file mode 100644 index 0000000..e45c309 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$2.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$3.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$3.class new file mode 100644 index 0000000..38a5f5e Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$3.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$4.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$4.class new file mode 100644 index 0000000..93c638e Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity$4.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity.class new file mode 100644 index 0000000..cc2b546 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoOptionsActivity.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoView$1.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$1.class new file mode 100644 index 0000000..4da2e63 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$1.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoView$2.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$2.class new file mode 100644 index 0000000..05460fc Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$2.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoView$3.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$3.class new file mode 100644 index 0000000..405aac0 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$3.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoView$4.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$4.class new file mode 100644 index 0000000..c5a7c43 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$4.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoView$5.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$5.class new file mode 100644 index 0000000..2d4d502 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$5.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoView$StatePaint.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$StatePaint.class new file mode 100644 index 0000000..98c9d01 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$StatePaint.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoView$StatePlay.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$StatePlay.class new file mode 100644 index 0000000..4d501d2 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoView$StatePlay.class differ diff --git a/bin/classes/org/proofofconcept/shisensho/ShisenShoView.class b/bin/classes/org/proofofconcept/shisensho/ShisenShoView.class new file mode 100644 index 0000000..cf6bd08 Binary files /dev/null and b/bin/classes/org/proofofconcept/shisensho/ShisenShoView.class differ diff --git a/gen/org/proofofconcept/shisensho/BuildConfig.java b/gen/org/proofofconcept/shisensho/BuildConfig.java new file mode 100644 index 0000000..cc97654 --- /dev/null +++ b/gen/org/proofofconcept/shisensho/BuildConfig.java @@ -0,0 +1,6 @@ +/** Automatically generated file. DO NOT MODIFY */ +package org.proofofconcept.shisensho; + +public final class BuildConfig { + public final static boolean DEBUG = true; +} \ No newline at end of file diff --git a/gen/org/proofofconcept/shisensho/R.java b/gen/org/proofofconcept/shisensho/R.java new file mode 100644 index 0000000..f5ff840 --- /dev/null +++ b/gen/org/proofofconcept/shisensho/R.java @@ -0,0 +1,67 @@ +/* AUTO-GENERATED FILE. DO NOT MODIFY. + * + * This class was automatically generated by the + * aapt tool from the resource data it found. It + * should not be modified by hand. + */ + +package org.proofofconcept.shisensho; + +public final class R { + public static final class array { + public static final int difficulties=0x7f040001; + public static final int sizes=0x7f040000; + } + public static final class attr { + } + public static final class drawable { + public static final int icon=0x7f020000; + public static final int kshisen_bgnd=0x7f020001; + public static final int tileset=0x7f020002; + } + public static final class id { + public static final int about=0x7f070013; + public static final int clean=0x7f070011; + public static final int difficulty=0x7f070008; + public static final int difficultyLabel=0x7f070007; + public static final int gravity=0x7f07000b; + public static final int gravityLabel=0x7f07000a; + public static final int hint=0x7f07000f; + public static final int options=0x7f070012; + public static final int size=0x7f070005; + public static final int sizeLabel=0x7f070004; + public static final int tableLayout1=0x7f070000; + public static final int tableRow1=0x7f070001; + public static final int tableRow2=0x7f070003; + public static final int tableRow3=0x7f070006; + public static final int tableRow4=0x7f070009; + public static final int tableRow5=0x7f07000c; + public static final int timeCounter=0x7f07000e; + public static final int timeCounterLabel=0x7f07000d; + public static final int title=0x7f070002; + public static final int undo=0x7f070010; + } + public static final class layout { + public static final int main=0x7f030000; + public static final int options=0x7f030001; + } + public static final class menu { + public static final int menu=0x7f060000; + } + public static final class string { + public static final int about=0x7f050006; + public static final int aboutText=0x7f050007; + public static final int app_name=0x7f050001; + public static final int clean=0x7f050002; + public static final int difficulty=0x7f050009; + public static final int difficulty_label=0x7f05000b; + public static final int gravity_label=0x7f05000c; + public static final int hello=0x7f050000; + public static final int hint=0x7f050003; + public static final int options=0x7f050005; + public static final int size=0x7f050008; + public static final int size_label=0x7f05000a; + public static final int time_counter_label=0x7f05000d; + public static final int undo=0x7f050004; + } +} diff --git a/proguard.cfg b/proguard.cfg new file mode 100644 index 0000000..12dd039 --- /dev/null +++ b/proguard.cfg @@ -0,0 +1,36 @@ +-optimizationpasses 5 +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-dontpreverify +-verbose +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* + +-keep public class * extends android.app.Activity +-keep public class * extends android.app.Application +-keep public class * extends android.app.Service +-keep public class * extends android.content.BroadcastReceiver +-keep public class * extends android.content.ContentProvider +-keep public class * extends android.app.backup.BackupAgentHelper +-keep public class * extends android.preference.Preference +-keep public class com.android.vending.licensing.ILicensingService + +-keepclasseswithmembernames class * { + native ; +} + +-keepclasseswithmembernames class * { + public (android.content.Context, android.util.AttributeSet); +} + +-keepclasseswithmembernames class * { + public (android.content.Context, android.util.AttributeSet, int); +} + +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} diff --git a/project.properties b/project.properties new file mode 100644 index 0000000..b7c2081 --- /dev/null +++ b/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-10 diff --git a/res/drawable/icon.png b/res/drawable/icon.png new file mode 100644 index 0000000..ce0bab0 Binary files /dev/null and b/res/drawable/icon.png differ diff --git a/res/drawable/kshisen_bgnd.png b/res/drawable/kshisen_bgnd.png new file mode 100644 index 0000000..d1a7df7 Binary files /dev/null and b/res/drawable/kshisen_bgnd.png differ diff --git a/res/drawable/tileset.png b/res/drawable/tileset.png new file mode 100644 index 0000000..b4286a7 Binary files /dev/null and b/res/drawable/tileset.png differ diff --git a/res/layout/main.xml b/res/layout/main.xml new file mode 100644 index 0000000..3a5f117 --- /dev/null +++ b/res/layout/main.xml @@ -0,0 +1,12 @@ + + + + diff --git a/res/layout/options.xml b/res/layout/options.xml new file mode 100644 index 0000000..493b173 --- /dev/null +++ b/res/layout/options.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/menu/menu.xml b/res/menu/menu.xml new file mode 100644 index 0000000..804a1af --- /dev/null +++ b/res/menu/menu.xml @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml new file mode 100644 index 0000000..d24dbe9 --- /dev/null +++ b/res/values/arrays.xml @@ -0,0 +1,13 @@ + + + + Small + Medium + Large + + + Easy + Hard + + + diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 0000000..4011bc8 --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,24 @@ + + + Hello World, ShisenSho! + ShisenSho + Clean + Hint + Undo + Options + About + \n +(C) 2013 contact.proofofconcept@gmail.com\n +Images taken from kshisen (Shisen Sho 1.5.1), from the package kdegames\n +(C) 1997 Mario Weilguni\n +Distributed under GPL v2:\n +http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt\n +Get the source code: http://db.tt/Imh8zH4M + + Size + Difficulty + Size: + Difficulty: + Gravity: + Time counter: + diff --git a/src/org/proofofconcept/shisensho/Board.java b/src/org/proofofconcept/shisensho/Board.java new file mode 100644 index 0000000..436d187 --- /dev/null +++ b/src/org/proofofconcept/shisensho/Board.java @@ -0,0 +1,391 @@ +package org.proofofconcept.shisensho; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class Board { + private static String charpieces = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + + public int difficulty=1; // 1=Hard ... N=Easy + public boolean gravity=true; + public int [] boardSize; + public char[][] board; + public LinkedList history; + + // ---------------------- + // Public methods + // ---------------------- + + public Board() { + } + + // The board always has a 1-square width free rectangle that has + // to be taken into account when specifying the size + public void initialize(int sizeI, int sizeJ) { + boardSize = new int[2]; + boardSize[0]=sizeI; + boardSize[1]=sizeJ; + board = new char[boardSize[0]][boardSize[1]]; + for (int i=0;i(); + } + + public static String pieceToString(char piece) { + return charpieces.substring(piece,1); + } + + public static char StringToPiece(String piece) { + char upiece; + long charpiecesLen=charpieces.length(); + for(upiece=0;(upiece0) result+=" "; + result+=""+(j%10); + } + result+="\n "+StringRepeat("--",boardSize[1]); + for (int i=0;i0) result+=" "; + result+=charpieces.substring(board[i][j],board[i][j]+1); + } + result+=" |\n"; + if (i getPairs(int maxResults) { + List result=new ArrayList(); + List pieces=new ArrayList(); + List> piecePoints=new ArrayList>(); + for (int i=0;i points0=new ArrayList(); + points0.add(p); + pieces.add(piece); + piecePoints.add(points0); + + key=pieces.indexOf(piece); + piecePoints.get(key); + } else { + List points1=piecePoints.get(key); + points1.add(p); + } + } + + int nresults=0; + int k=0; + for (List points : piecePoints) { + int n=(int)points.size(); + for (int i=0;i path=getPath(a.copy(),b.copy()); + if (path!=null && path.size()>0) { + result.add(new Line(a,b)); + if (nresults++==maxResults) break; + } + } + if (nresults==maxResults) break; + } + k++; + if (nresults==maxResults) break; + } + return result; + } + + public int getNumPieces() { + int result=0; + for (int j=0;j getHorizontalLines(Point excludeA, Point excludeB) { + List result=new ArrayList(); + for (int i=0;i getVerticalLines(Point excludeA, Point excludeB) { + List result=new ArrayList(); + for (int j=0;j0;i--) board[i][p.j]=board[i-1][p.j]; + } + + private void undoGravity(Point p) { + if (gravity) for (int i=0;i=getMin().j && p.j<=getMax().j) + || (p.j==a.j && p.j==b.j && p.i>=getMin().i && p.i<=getMax().i); + } + + public Point cuts(Line l) { + if (isHorizontal() && l.isVertical() + && getMin().j<=l.a.j && getMax().j>=l.a.j + && l.getMin().i<=a.i && l.getMax().i>=a.i ) { + return new Point(a.i,l.a.j); + } else if (isVertical() && l.isHorizontal() + && getMin().i<=l.a.i && getMax().i>=l.a.i + && l.getMin().j<=a.j && l.getMax().j>=a.j ) { + return new Point(l.a.i,a.j); + } else return null; + } + + public Point getMin() { + if (a.ib.i || a.j>b.j) return a; + else return b; + } + + public String toString() { + return a+"-"+b; + } + + public Point a; + public Point b; +} diff --git a/src/org/proofofconcept/shisensho/Move.java b/src/org/proofofconcept/shisensho/Move.java new file mode 100644 index 0000000..1b51289 --- /dev/null +++ b/src/org/proofofconcept/shisensho/Move.java @@ -0,0 +1,17 @@ +package org.proofofconcept.shisensho; + +public class Move { + public Move(Point a, Point b, char piece) { + this.a=a; + this.b=b; + this.piece=piece; + } + + public String toString() { + return a+"-"+b+"("+Board.pieceToString(piece)+")"; + } + + public Point a; + public Point b; + public char piece; +} diff --git a/src/org/proofofconcept/shisensho/Point.java b/src/org/proofofconcept/shisensho/Point.java new file mode 100644 index 0000000..7771ef5 --- /dev/null +++ b/src/org/proofofconcept/shisensho/Point.java @@ -0,0 +1,30 @@ +package org.proofofconcept.shisensho; + +class Point { + public Point(int i, int j) { + this.i=i; + this.j=j; + } + + public boolean equals(Point p) { + return (i==p.i && j==p.j); + } + + public String toString() { + return "("+i+","+j+")"; + } + + public static Point fromString(String s) { + String[] ij=s.split(",",2); + int i=Integer.parseInt(ij[0]); + int j=Integer.parseInt(ij[1]); + return new Point(i,j); + } + + public int i; + public int j; + + public Point copy() { + return new Point(this.i,this.j); + } +} diff --git a/src/org/proofofconcept/shisensho/ShisenSho.java b/src/org/proofofconcept/shisensho/ShisenSho.java new file mode 100644 index 0000000..a7d29b4 --- /dev/null +++ b/src/org/proofofconcept/shisensho/ShisenSho.java @@ -0,0 +1,120 @@ +package org.proofofconcept.shisensho; + +import java.util.Observable; +import java.util.Observer; + +import android.app.Application; +import android.os.Bundle; +import android.util.Log; + +public class ShisenSho extends Application { + private static ShisenSho instance = null; + private ShisenShoView view = null; + public ShisenShoActivity activity = null; + + public Board board; + public int[] boardSize=new int[2]; + public int difficulty=1; // 1=Hard, 2=Easy + public int size=3; // 1=Small, 2=Medium, 3=Big + public boolean gravity=true; + public boolean timeCounter=true; + + public static void log(String msg) { + Log.w("ShisenSho", msg); + } + + public void newPlay() { + board = new Board(); + board.buildRandomBoard(boardSize[0],boardSize[1],difficulty,gravity); + } + + public void setSize(int s) { + switch (s) { + case 1: + size=1; + boardSize[0]=6+2; + boardSize[1]=8+2; + break; + case 2: + size=2; + boardSize[0]=6+2; + boardSize[1]=12+2; + break; + case 3: + default: + size=3; + boardSize[0]=6+2; + boardSize[1]=16+2; + break; + } + } + + public void sleep(int deciSeconds) { + try { + Thread.sleep(deciSeconds*100); + } catch (InterruptedException e) { } + } + + public ShisenSho() { + instance = this; + setSize(size); + } + + public static synchronized ShisenSho app() { + return instance; + } + + public ShisenShoView getView() { + if (view == null) view = new ShisenShoView(this); + return view; + } + + /** Called when the activity is first created. */ + @Override + public void onCreate() { + super.onCreate(); + } + + public Bundle getOptions() { + Bundle options = new Bundle(); + options.putInt("size", size); + options.putInt("difficulty", difficulty); + options.putBoolean("gravity", gravity); + options.putBoolean("timeCounter", timeCounter); + return options; + } + + public void setOptions(Bundle options) { + int size = options.getInt("size"); + int difficulty = options.getInt("difficulty"); + boolean gravity = options.getBoolean("gravity"); + boolean timeCounter = options.getBoolean("timeCounter"); + + boolean needsReset = false; + + if (size != this.size) { + setSize(size); + needsReset = true; + } + + if (difficulty != this.difficulty) { + this.difficulty = difficulty; + needsReset = true; + } + + if (gravity != this.gravity) { + this.gravity = gravity; + needsReset = true; + } + + if (timeCounter != this.timeCounter) { + this.timeCounter = timeCounter; + view.onTimeCounterActivate(); + } + + if (needsReset) { + view.reset(); + } + } + +} diff --git a/src/org/proofofconcept/shisensho/ShisenShoActivity.java b/src/org/proofofconcept/shisensho/ShisenShoActivity.java new file mode 100644 index 0000000..5036eb8 --- /dev/null +++ b/src/org/proofofconcept/shisensho/ShisenShoActivity.java @@ -0,0 +1,118 @@ +package org.proofofconcept.shisensho; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Intent; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.os.Bundle; +import android.text.SpannableString; +import android.text.util.Linkify; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.TextView; + +public class ShisenShoActivity extends Activity { + private ShisenShoView view; + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + requestWindowFeature(Window.FEATURE_NO_TITLE); + //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + // WindowManager.LayoutParams.FLAG_FULLSCREEN); + + view = ShisenSho.app().getView(); + ShisenSho.app().activity = this; + setContentView(view); + } + + @Override + protected void onDestroy() { + ViewGroup vg = (ViewGroup)(view.getParent()); + vg.removeView(view); + ShisenSho.app().activity = null; + super.onDestroy(); + } + + @Override + protected void onPause() { + if (view!=null) { + view.pauseTime(); + } + super.onPause(); + } + + @Override + protected void onResume() { + super.onResume(); + if (view!=null) { + view.resumeTime(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.menu, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle item selection + switch (item.getItemId()) { + case R.id.hint: + case R.id.undo: + case R.id.clean: + return view.onOptionsItemSelected(item); + case R.id.options: + startActivityForResult(new Intent("org.proofofconcept.shisensho.SETTINGS", null), 0); + return true; + case R.id.about: + onAboutActivate(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private void onAboutActivate() { + // Try to load the a package matching the name of our own package + PackageInfo pInfo; + try { + pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA); + String aboutTitle = String.format("About %s", getString(R.string.app_name)); + String versionString = String.format("Version: %s", pInfo.versionName); + String aboutText = getString(R.string.aboutText); + + // Set up the TextView + final TextView message = new TextView(this); + // We'll use a spannablestring to be able to make links clickable + final SpannableString s = new SpannableString(aboutText); + + // Set some padding + message.setPadding(5, 5, 5, 5); + // Set up the final string + message.setText(versionString + "\n" + s); + // Now linkify the text + Linkify.addLinks(message, Linkify.ALL); + + new AlertDialog.Builder(this) + .setTitle(aboutTitle) + .setCancelable(true) + .setIcon(R.drawable.icon) + .setPositiveButton(getString(android.R.string.ok), null) + .setView(message).create() + .show(); + } catch (NameNotFoundException e) { + e.printStackTrace(); + } + } +} diff --git a/src/org/proofofconcept/shisensho/ShisenShoOptionsActivity.java b/src/org/proofofconcept/shisensho/ShisenShoOptionsActivity.java new file mode 100644 index 0000000..87631bd --- /dev/null +++ b/src/org/proofofconcept/shisensho/ShisenShoOptionsActivity.java @@ -0,0 +1,99 @@ +package org.proofofconcept.shisensho; + +import java.io.Serializable; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.view.Window; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CompoundButton; +import android.widget.Spinner; +import android.widget.ToggleButton; + +public class ShisenShoOptionsActivity extends Activity { + + Bundle state; + ShisenSho app; + + private void appToState (boolean merge) { + String[] fields = { "size", "difficulty", "gravity", "timeCounter" }; + Bundle options = app.getOptions(); + if (state == null) state = new Bundle(); + for (int i=0; i arg0, View arg1, + int pos, long arg3) { + state.putInt("size", pos+1); + } + + public void onNothingSelected(AdapterView arg0) { } + }); + + s = (Spinner) findViewById(R.id.difficulty); + adapter = ArrayAdapter.createFromResource( + this, R.array.difficulties, android.R.layout.simple_spinner_item); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + s.setAdapter(adapter); + s.setSelection(2-state.getInt("difficulty")); + s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + public void onItemSelected(AdapterView arg0, View arg1, + int pos, long arg3) { + state.putInt("difficulty", 2-pos); + } + + public void onNothingSelected(AdapterView arg0) { } + }); + + tb = (ToggleButton) findViewById(R.id.gravity); + tb.setChecked(state.getBoolean("gravity")); + tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + public void onCheckedChanged(CompoundButton arg0, boolean arg1) { + state.putBoolean("gravity", arg1); + } + }); + + tb = (ToggleButton) findViewById(R.id.timeCounter); + tb.setChecked(state.getBoolean("timeCounter")); + tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + public void onCheckedChanged(CompoundButton arg0, boolean arg1) { + state.putBoolean("timeCounter", arg1); + } + }); + } + + @Override + public void onBackPressed() { + app.setOptions(state); + super.onBackPressed(); + } + +} diff --git a/src/org/proofofconcept/shisensho/ShisenShoView.java b/src/org/proofofconcept/shisensho/ShisenShoView.java new file mode 100644 index 0000000..1cc1e07 --- /dev/null +++ b/src/org/proofofconcept/shisensho/ShisenShoView.java @@ -0,0 +1,661 @@ +package org.proofofconcept.shisensho; + +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Paint.Align; +import android.graphics.Paint.Cap; +import android.graphics.Paint.Join; +import android.graphics.Paint.Style; +import android.graphics.Rect; +import android.graphics.Typeface; +import android.os.Handler; +import android.os.Message; +import android.view.MenuItem; +import android.view.MotionEvent; +import android.view.SurfaceHolder; +import android.view.SurfaceView; + +class ShisenShoView extends SurfaceView implements SurfaceHolder.Callback { + + private enum StatePlay { UNINITIALIZED, IDLE, SELECTED1, SELECTED2, GAMEOVER }; + private enum StatePaint { BOARD, SELECTED1, SELECTED2, MATCHED, WIN, LOSE, HINT, TIME }; + + private int screenWidth; + private int screenHeight; + private int tilesetRows; + private int tilesetCols; + private int tileHeight; + private int tileWidth; + private Bitmap bg; + private Bitmap tile[]; + private int[] selection1=new int[2]; + private int[] selection2=new int[2]; + private List path=null; + private List pairs=null; + private long startTime; + private long playTime; + private long baseTime; + private Timer timer; + private Handler timerHandler; + + private boolean timerRegistered=false; + private ShisenSho app; + private StatePlay cstate; + private StatePaint pstate; + private Canvas canvas = null; + private SurfaceHolder surfaceHolder = null; + private String debugMessage = ""; + + public ShisenShoView(ShisenSho shishenSho) { + super((Context)shishenSho); + this.app = shishenSho; + cstate = StatePlay.UNINITIALIZED; + surfaceHolder = getHolder(); + surfaceHolder.addCallback(this); + } + + private void paint(StatePaint pstate) { + this.pstate=pstate; + repaint(); + } + + private void control(StatePlay cstate) { + this.cstate=cstate; + } + + private void loadTileset() { + BitmapFactory.Options ops = new BitmapFactory.Options(); + ops.inScaled = false; + Bitmap tileset = BitmapFactory.decodeResource(getResources(), R.drawable.tileset, ops); + tileset.setDensity(Bitmap.DENSITY_NONE); + + // The tile set has 4 rows x 9 columns + tilesetRows = 4; + tilesetCols = 9; + tileWidth = tileset.getWidth()/tilesetCols; + tileHeight = tileset.getHeight()/tilesetRows; + tile = new Bitmap[tilesetRows*tilesetCols]; + int k=0; + for (int i=0; i0) { + Line pair=pairs.get(0); + Point a=pair.a; + Point b=pair.b; + path=app.board.getPath(a,b); + paint.setColor(orange); + paint.setStyle(Style.STROKE); + paint.setStrokeCap(Cap.ROUND); + paint.setStrokeJoin(Join.ROUND); + paint.setStrokeWidth(3); + + cbuffer.drawRect(new Rect( + x0+a.j*tileWidth-2, + y0+a.i*tileHeight-2, + x0+a.j*tileWidth-2+tileWidth+2*2, + y0+a.i*tileHeight-2+tileHeight+2*2), + paint); + + if (path!=null) { + Point p0=null; + for (Point p1 : path) { + if (p0!=null) { + cbuffer.drawLine( + x0+p0.j*tileWidth-2+(tileWidth/2), + y0+p0.i*tileHeight-2+(tileHeight/2), + x0+p1.j*tileWidth-2+(tileWidth/2), + y0+p1.i*tileHeight-2+(tileHeight/2), + paint); + } + p0=p1; + } + path=null; + } + + cbuffer.drawRect(new Rect( + x0+b.j*tileWidth-2, + y0+b.i*tileHeight-2, + x0+b.j*tileWidth-2+tileWidth+2*2, + y0+b.i*tileHeight-2+tileHeight+2*2), + paint); + } + break; + } + + // Win & loose notifications + switch (pstate) { + case WIN: + drawMessage(cbuffer, screenWidth/2,screenHeight/2,true,"You Win!", "#FFFFFF", 100); + break; + case LOSE: + drawMessage(cbuffer, screenWidth/2,screenHeight/2,true,"Game Over", "#FFFFFF", 100); + break; + } + + if (app.timeCounter) switch (pstate) { + case BOARD: + case SELECTED1: + case SELECTED2: + case MATCHED: + case WIN: + case LOSE: + case HINT: + case TIME: + updateTime(); + int hours=(int)(playTime/(60*60)); + int minutes=(int)((playTime/60)%60); + int seconds=(int)(playTime%60); + String time=String.format("%01d:%02d:%02d", hours, minutes, seconds); + + int timePosX=screenWidth-120; + int timePosY=screenHeight-10; + + drawMessage(cbuffer, timePosX+1,timePosY+1,false,time,"#000000",30); + drawMessage(cbuffer, timePosX,timePosY,false,time,"#FFFFFF",30); + break; + } + + // Debug messages + /* + debugMessage="StatePlay: "+cstate+"\n"+"StatePaint: "+pstate; + if (debugMessage!=null && debugMessage.length()>0) { + int l = 20; + String lines[] = debugMessage.split("\n"); + for (int i=0; i=0 && + i=0 && j=0 && i=0 && j0) { + app.board.play(a,b); + } + path=null; + paint(StatePaint.BOARD); + + pairs=app.board.getPairs(1); + if (pairs.size()==0) { + if (app.board.getNumPieces()==0) { + paint(StatePaint.WIN); + } else { + paint(StatePaint.LOSE); + } + control(StatePlay.GAMEOVER); + } else { + control(StatePlay.IDLE); + } + //undo.sensitive=app.board.getCanUndo(); + } + } + break; + case GAMEOVER: + reset(); + paint(StatePaint.BOARD); + break; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void surfaceChanged(SurfaceHolder holder, int format, int width, + int height) { + surfaceHolder = holder; + if (cstate!=StatePlay.GAMEOVER && app.timeCounter && !timerRegistered) { + registerTimer(); + } + repaint(); + } + + public void surfaceCreated(SurfaceHolder holder) { + surfaceHolder = holder; + repaint(); + } + + public void surfaceDestroyed(SurfaceHolder holder) { + surfaceHolder = null; + if (timerRegistered) { + unregisterTimer(); + } + } + + /* + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + if (!initialized) initialize(); + + long currTime = System.currentTimeMillis(); + + a = (float)(currTime - startTime) / (float)duration; + if (a > (float)1.0) a = (float)1.0; + + x = Math.round(nextx*a + prevx*(1-a)); + y = Math.round(nexty*a + prevy*(1-a)); + + if (a == (float)1.0) computeNextTarget(); + + int bgWidth = bg.getWidth(); + int bgHeight = bg.getHeight(); + for (int i=0; i