ascii-game/playfield.c

115 lines
2.6 KiB
C

/*
* Copyright(c) 2017 Daniel Knüttel
*/
/* This program is free software.
* Anyways if you think this program is worth it
* and we meet shout a drink for me.
*/
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
* der GNU Affero General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* Dieses Programm wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU Affero General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU Affero General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*/
#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;
}