77 lines
1.0 KiB
C
77 lines
1.0 KiB
C
#include<stdlib.h>
|
|
#include<stdio.h>
|
|
#include"conf.h"
|
|
#include"input_output.h"
|
|
|
|
|
|
void build_horizon(char *** horizon)
|
|
{
|
|
char ** h = calloc(sizeof(char * ), LINES);
|
|
int i, j;
|
|
for(i = 0; i < LINES; i++)
|
|
{
|
|
h[i] = calloc(sizeof(char), WIDTH);
|
|
for(j = 0; j < WIDTH; j++)
|
|
{
|
|
h[i][j] = ' ';
|
|
}
|
|
putc('\n', stdout); // make space for the game
|
|
}
|
|
*horizon = h;
|
|
}
|
|
|
|
void horizon_drop_one_line(char ** horizon)
|
|
{
|
|
|
|
int i, j;
|
|
for(i = LINES - 1; i >= 1; i--)
|
|
{
|
|
for(j = 0; j < WIDTH; j++)
|
|
{
|
|
horizon[i][j] = horizon[i - 1][j];
|
|
}
|
|
}
|
|
}
|
|
|
|
void print_horizon(char ** horizon)
|
|
{
|
|
int i;
|
|
putc('+', stdout);
|
|
for(i = 0; i < WIDTH ; i++)
|
|
{
|
|
putc('-', stdout);
|
|
}
|
|
putc('+', stdout);
|
|
putc('\n', stdout);
|
|
|
|
for(i = 0; i < LINES; i++)
|
|
{
|
|
put_line(horizon[i]);
|
|
}
|
|
}
|
|
|
|
void delete_horizon(char ** horizon)
|
|
{
|
|
int i;
|
|
for(i = 0; i < LINES; i++)
|
|
{
|
|
free(horizon[i]);
|
|
}
|
|
free(horizon);
|
|
}
|
|
|
|
|
|
|
|
char * allocate_playfield(size_t width)
|
|
{
|
|
char * field = calloc(sizeof(char), width);
|
|
|
|
size_t i;
|
|
for(i = 0; i < width; i++)
|
|
{
|
|
field[i] = ' ';
|
|
}
|
|
return field;
|
|
}
|
|
|