splitted out parts of server.c to game.c and asciiart.c, rewritten the asciiart part a bit. things still seem to work
This commit is contained in:
111
src/asciiart.c
Normal file
111
src/asciiart.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/* -*- c-basic-offset: 4 -*- */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "game.h"
|
||||
#include "asciiart.h"
|
||||
|
||||
#define SMALL_WIDTH ASCIIART_SMALL_BOARD_WIDTH
|
||||
#define SMALL_HEIGHT ASCIIART_SMALL_BOARD_HEIGHT
|
||||
|
||||
char asciiart_small_blank_board[] =
|
||||
"red \n"
|
||||
" | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9| \n"
|
||||
"--+--+--+--+--+--+--+--+--+--+--+--\n"
|
||||
" A| | | | | | | | | | |A \n"
|
||||
"--+--+--+--+--+--+--+--+--+--+--+--\n"
|
||||
" B| | | | | | | | | | |B \n"
|
||||
"--+--+--+--+--+--+--+--+--+--+--+--\n"
|
||||
" C| | | | | | | | | | |C \n"
|
||||
"--+--+--+--+--+--+--+--+--+--+--+--\n"
|
||||
" D| | | | | | | | | | |D \n"
|
||||
"--+--+--+--+--+--+--+--+--+--+--+--\n"
|
||||
" E| | | | | | | | | | |E \n"
|
||||
"--+--+--+--+--+--+--+--+--+--+--+--\n"
|
||||
" F| | | | | | | | | | |F \n"
|
||||
"--+--+--+--+--+--+--+--+--+--+--+--\n"
|
||||
" G| | | | | | | | | | |G \n"
|
||||
"--+--+--+--+--+--+--+--+--+--+--+--\n"
|
||||
" H| | | | | | | | | | |H \n"
|
||||
"--+--+--+--+--+--+--+--+--+--+--+--\n"
|
||||
" | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9| \n"
|
||||
" silver\n"
|
||||
;
|
||||
|
||||
char asciiart_small_pieces[] =
|
||||
" " // NONE
|
||||
"SSSSSSSSRRRRRRRR"
|
||||
",'`.,'`..\"\"..\"\"." // DJHED
|
||||
"`/\\'/.,\\\"/\\\"/==\\" // PYRAMID
|
||||
". . . . = = = = " // OBELISK
|
||||
"........========" // OBELISK2
|
||||
;
|
||||
|
||||
int
|
||||
asciiart_small_square_index(int x, int y)
|
||||
{
|
||||
return SMALL_WIDTH*(y*2+3)+(x*3+3);
|
||||
}
|
||||
|
||||
void
|
||||
asciiart_small_draw_piece(char *buf, int x, int y, square_t square)
|
||||
{
|
||||
int piece_index = (square.piece*4*2 + square.side*4 + square.dir) * 2;
|
||||
int buf_index = asciiart_small_square_index(x, y);
|
||||
buf[buf_index] = asciiart_small_pieces[piece_index];
|
||||
buf[buf_index+1] = asciiart_small_pieces[piece_index+1];
|
||||
}
|
||||
|
||||
void
|
||||
asciiart_small_draw_grid(char *buf)
|
||||
{
|
||||
strcpy(buf, asciiart_small_blank_board);
|
||||
}
|
||||
|
||||
void
|
||||
asciiart_small_draw_laserhit(char *buf, game_t *game)
|
||||
{
|
||||
int x, y, i;
|
||||
|
||||
x = game->laser_pos[0];
|
||||
y = game->laser_pos[1];
|
||||
|
||||
if (x == -1 && y == -1) return;
|
||||
|
||||
i = asciiart_small_square_index(x, y);
|
||||
if (x == -1 || x == BOARD_WIDTH) {
|
||||
buf[i] = '#';
|
||||
} else {
|
||||
if (y == -1)
|
||||
i += SMALL_WIDTH;
|
||||
else if (y == BOARD_HEIGHT)
|
||||
i -= SMALL_WIDTH;
|
||||
buf[i] = buf[i+1] = '#';
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
asciiart_small_draw_board(char *buf, game_t *game)
|
||||
{
|
||||
int x, y;
|
||||
asciiart_small_draw_grid(buf);
|
||||
for (y = 0; y < BOARD_HEIGHT; y++) {
|
||||
for (x = 0; x < BOARD_WIDTH; x++) {
|
||||
asciiart_small_draw_piece(buf, x, y, game->board[x][y]);
|
||||
}
|
||||
}
|
||||
asciiart_small_draw_laserhit(buf, game);
|
||||
}
|
||||
|
||||
/*
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("%d, %d\n", strlen(asciiart_small_blank_board), SMALL_WIDTH*SMALL_HEIGHT);
|
||||
char buf[SMALL_WIDTH*SMALL_HEIGHT+1];
|
||||
asciiart_small_draw_board(buf);
|
||||
printf("+++\n%s+++\n", buf);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user