summaryrefslogtreecommitdiffstats
path: root/ksokoban/HtmlPrinter.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitc90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch)
tree6d8391395bce9eaea4ad78958617edb20c6a7573 /ksokoban/HtmlPrinter.cpp
downloadtdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz
tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksokoban/HtmlPrinter.cpp')
-rw-r--r--ksokoban/HtmlPrinter.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/ksokoban/HtmlPrinter.cpp b/ksokoban/HtmlPrinter.cpp
new file mode 100644
index 00000000..26e7207f
--- /dev/null
+++ b/ksokoban/HtmlPrinter.cpp
@@ -0,0 +1,100 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "HtmlPrinter.h"
+
+void
+HtmlPrinter::wall (bool up, bool down, bool left, bool right)
+{
+ switch ( (up!=0) |
+ ((down!=0) << 1) |
+ ((left!=0) << 2) |
+ ((right!=0) << 3)) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ image ("vertiwall");
+ break;
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ image ("eastwall");
+ break;
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ image ("westwall");
+ break;
+ case 12:
+ case 13:
+ case 14:
+ case 15:
+ image ("horizwall");
+ break;
+
+ default:
+ abort ();
+ }
+}
+
+void
+HtmlPrinter::image (const char *name) {
+ printf ("<td><img src=%s.gif width=40 height=40><br clear=all>\n", name);
+}
+
+void
+HtmlPrinter::empty () {
+ printf ("<td>\n");
+}
+
+void
+HtmlPrinter::printSquare (LevelMap *lm, int x, int y) {
+ if (lm->xpos () == x && lm->ypos () == y) {
+ image (lm->goal (x, y) ? "saveman" : "man");
+ return;
+ }
+ if (lm->empty (x, y)) {
+ if (lm->floor (x, y)) {
+ image (lm->goal (x, y) ? "goal" : "floor");
+ } else {
+ empty ();
+ }
+ return;
+ }
+ if (lm->wall (x, y)) {
+ wall (lm->wallUp (x, y),
+ lm->wallDown (x, y),
+ lm->wallLeft (x, y),
+ lm->wallRight (x, y));
+ return;
+ }
+ if (lm->object (x, y)) {
+ image (lm->goal (x, y) ? "treasure" : "object");
+ return;
+ }
+}
+
+void
+HtmlPrinter::printHtml (LevelMap *lm) {
+ printf ("\
+<html>\n\
+<head>\n\
+<title>ksokoban level</title>\n\
+</head>\n\
+<body background=background.gif>\n\
+");
+ printf ("<table border=0 cellspacing=0 cellpadding=0>\n");
+ for (int y=0; y<lm->height(); y++) {
+ printf ("<tr>\n");
+ for (int x=0; x<lm->width(); x++) {
+ printSquare (lm, x, y);
+ }
+ }
+ printf ("\
+</table>\n\
+</body>\n\
+</html>\n\
+");
+}