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