File indexing completed on 2021-12-21 12:50:20

0001 #include <stdio.h>
0002 #include <stdlib.h>
0003 #include "HtmlPrinter.h"
0004 
0005 void
0006 HtmlPrinter::wall (bool up, bool down, bool left, bool right)
0007 {
0008   switch ( (up!=0)           |
0009        ((down!=0)  << 1) |
0010        ((left!=0)  << 2) |
0011        ((right!=0) << 3)) {
0012   case 0:
0013   case 1:
0014   case 2:
0015   case 3:
0016     image ("vertiwall");
0017     break;
0018   case 4:
0019   case 5:
0020   case 6:
0021   case 7:
0022     image ("eastwall");
0023     break;
0024   case 8:
0025   case 9:
0026   case 10:
0027   case 11:
0028     image ("westwall");
0029     break;
0030   case 12:
0031   case 13:
0032   case 14:
0033   case 15:
0034     image ("horizwall");
0035     break;
0036 
0037   default:
0038     abort ();
0039   }
0040 }
0041 
0042 void
0043 HtmlPrinter::image (const char *name) {
0044   printf ("<td><img src=%s.gif width=40 height=40><br clear=all>\n", name);
0045 }
0046 
0047 void
0048 HtmlPrinter::empty () {
0049   printf ("<td>\n");
0050 }
0051 
0052 void
0053 HtmlPrinter::printSquare (LevelMap *lm, int x, int y) {
0054   if (lm->xpos () == x && lm->ypos () == y) {
0055     image (lm->goal (x, y) ? "saveman" : "man");
0056     return;
0057   }
0058   if (lm->empty (x, y)) {
0059     if (lm->floor (x, y)) {
0060       image (lm->goal (x, y) ? "goal" : "floor");
0061     } else {
0062       empty ();
0063     }
0064     return;
0065   }
0066   if (lm->wall (x, y)) {
0067     wall (lm->wallUp (x, y),
0068       lm->wallDown (x, y),
0069       lm->wallLeft (x, y),
0070       lm->wallRight (x, y));
0071     return;
0072   }
0073   if (lm->object (x, y)) {
0074     image (lm->goal (x, y) ? "treasure" : "object");
0075     return;
0076   }
0077 }
0078 
0079 void
0080 HtmlPrinter::printHtml (LevelMap *lm) {
0081   printf ("\
0082 <html>\n\
0083 <head>\n\
0084 <title>ksokoban level</title>\n\
0085 </head>\n\
0086 <body background=background.gif>\n\
0087 ");
0088   printf ("<table border=0 cellspacing=0 cellpadding=0>\n");
0089   for (int y=0; y<lm->height(); y++) {
0090     printf ("<tr>\n");
0091     for (int x=0; x<lm->width(); x++) {
0092       printSquare (lm, x, y);
0093     }
0094   }
0095   printf ("\
0096 </table>\n\
0097 </body>\n\
0098 </html>\n\
0099 ");
0100 }