forked from nakidai/csnake
Add files
commit
03481db05f
|
@ -0,0 +1,2 @@
|
|||
obj/
|
||||
game
|
|
@ -0,0 +1,27 @@
|
|||
OUT = game
|
||||
CFLAGS =
|
||||
LDFLAGS =
|
||||
INCLUDE = -Iinclude
|
||||
CC = cc
|
||||
LD = ld
|
||||
RM = rm -f
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
SRC = main.c screen.c
|
||||
OBJ = $(addprefix $(OBJDIR)/,$(SRC:.c=.o))
|
||||
|
||||
default: $(OUT)
|
||||
|
||||
obj:
|
||||
mkdir obj
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.c
|
||||
$(CC) -c -o $@ $< $(CFLAGS) $(INCLUDE)
|
||||
|
||||
$(OUT): obj $(OBJ)
|
||||
$(CC) -o $@ $(OBJ) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(OUT) $(OBJDIR)/*
|
||||
|
||||
.PHONY: default clean
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef __SCREEN_H__
|
||||
#define __SCREEN_H__
|
||||
|
||||
typedef struct screen_t
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
char *screen;
|
||||
} Screen;
|
||||
typedef char Point;
|
||||
|
||||
Screen *screenCreate(int width, int height, Point fill_value);
|
||||
void screenFree(Screen *screen);
|
||||
|
||||
Point *screenGetPoint(Screen *screen, int x, int y);
|
||||
void screenShow(Screen *screen);
|
||||
|
||||
#endif /* __SCREEN_H__ */
|
|
@ -0,0 +1,8 @@
|
|||
#include "screen.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Screen *screen = screenCreate(5, 5, '#');
|
||||
screenShow(screen);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
#include "screen.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
Screen *screenCreate(int width, int height, Point fill_value)
|
||||
{
|
||||
Point *screen = malloc(width * height * sizeof(Point));
|
||||
memset(screen, fill_value, width * height * sizeof(Point));
|
||||
|
||||
Screen *out = malloc(sizeof(Screen));
|
||||
out->width = width;
|
||||
out->height = height;
|
||||
out->screen = screen;
|
||||
return out;
|
||||
}
|
||||
|
||||
void screenFree(Screen *screen)
|
||||
{
|
||||
free(screen->screen);
|
||||
free(screen);
|
||||
}
|
||||
|
||||
Point *screenGetPoint(Screen *screen, int x, int y)
|
||||
{
|
||||
return screen->screen + x + (y * screen->width);
|
||||
}
|
||||
|
||||
void screenShow(Screen *screen)
|
||||
{
|
||||
int x, y, i;
|
||||
int width = screen->width;
|
||||
int height = screen->height;
|
||||
Point point;
|
||||
|
||||
for (y = 0; y < height; ++y)
|
||||
{
|
||||
for (x = 0; x < width; ++x)
|
||||
{
|
||||
point = *screenGetPoint(screen, x, y);
|
||||
for (i = 0; i < 2; ++i) putchar(point);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue