root/board_text.c

Revision 106, 2.7 kB (checked in by ng, 5 years ago)

mise a jour licence

Line 
1 /***************************************************************************
2  *   This file is part of the 'gemmes' project                             *
3  *                                                                         *
4  *                                                                         *
5  *   Copyright (C) 2007 by                                                 *
6  *         GARCH Soufiane                                                  *
7  *         GUILLAUME Nicolas <ng@ngsoft-fr.com>                            *
8  *                                                                         *
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; version 2 of the License only.          *
13  *   See the COPYING file.                                                 *
14  ***************************************************************************/
15
16
17 #include "board.h"
18 #include "assert.h"
19 #include "font_text.h"
20
21 font_t * font = NULL;
22
23 /* print the board with small letters */
24 void board_print_small(board_t b);
25
26 /* print the board with big letters using font f */
27 void board_print_big(board_t b);
28
29
30 void board_print(board_t b)
31 {
32     c_assert(b);
33
34     if(b->silent)
35         return;
36
37     if(font)
38         board_print_big(b);
39     else
40         board_print_small(b);
41
42 }
43
44 void board_print_big(board_t b)
45 {
46     int x, y;
47
48     fputs("\nBoard:  +", stdout);
49     for(x = 0; x < b->xsize; ++x)
50         printf("-%c-+", 'a' + x);
51
52     printf("       Score: %d\n", b->score);
53
54     for(y = 0; y < b->ysize; ++y)
55     {
56         int i;
57
58         for(i = 0; i < 3; ++i)
59         {
60             if(i == 1)
61                 printf("     %2d |", y + 1);
62             else
63                 fputs("        |", stdout);
64             for(x = 0; x < b->xsize; ++x)
65             {
66                 char c = board_pos(b, x, y);
67                 if(c == ' ')
68                     fputs("   ", stdout);
69                 else
70                     fputs(text_font_get_line(*font, c, i), stdout);
71                 putchar('|');
72             }
73             if(i == 1)
74                 printf(" %d", y + 1);
75             putchar('\n');
76         }
77
78         fputs("        +", stdout);
79         for(x = 0; x < b->xsize; ++x)
80             printf("-%c-+", 'a' + x);
81         putchar('\n');
82     }
83
84     putchar('\n');
85
86 }
87
88 void board_print_small(board_t b)
89 {
90
91         int i,j;
92
93         printf("\t\t   ");
94         for(i=0;i<b->xsize;i++)
95                 printf("%c ",'a'+i);
96
97         fputs("\nBoard:\t\t  +", stdout);
98         for(i=0;i<b->xsize;i++)
99                 fputs("--", stdout);
100         printf("+\t Score: %d\n",b->score);
101
102         for(i=0;i<(b->ysize);i++)
103         {
104                 printf("\t\t%2d|",i+1);
105                 for(j=0;j<(b->xsize);j++)
106                         printf("%c ",board_pos(b,j,i));
107                 printf("|%d\n",i+1);
108         }
109         fputs("\t\t  +", stdout);
110         for(i=0;i<b->xsize;i++)
111                 fputs("--", stdout);
112         fputs("+\n\t\t   ", stdout);
113
114         for(i=0;i<b->xsize;i++)
115                 printf("%c ",'a'+i);
116
117         fputs("\n", stdout);
118 }
Note: See TracBrowser for help on using the browser.