view demo.c @ 12:b405fe1a6920

*** empty log message ***
author gongo
date Sat, 04 Nov 2006 08:55:26 +0000
parents 0fae5658fb0b
children
line wrap: on
line source

/*
 * $Id$
 */
#include <stdio.h>
#include <stdlib.h>

#include <libps2.h>
#include <ps2util.h>
#include "col.h"
#include "field.h"
#include "car.h"
#include "game.h"

#define BUFSIZE 256


static FILE *fp;
extern FILE *main_fp;
extern Game game;

char *filename[3] = {
    "demo_log1.dat", "demo_log2.dat", "demo_log3.dat"};

static char* bufp;

void
demo_closeFp()
{
    if (fp) {
	fclose(fp);
#ifdef DEBUG
	fprintf(main_fp, "FILE pointer %x is close\n", (int)fp);
#endif
	fp = NULL;
    }
    bufp = NULL;
}

void
demo_openFp(int i)
{
#ifdef DEMO_CREATE
    fp = fopen(filename[i], "w");
#else
    char buff[BUFSIZE];
    fp = fopen(filename[i], "r");
    
    if ((bufp = fgets(buff, BUFSIZE, fp)) != NULL) {
        sscanf(bufp, "%d %d\n", &game.car_id, &game.course_id);
    }
#endif

#ifdef DEBUG
    fprintf(main_fp, "FILE pointer %x is open\n", (int)fp);
#endif
}

#ifdef DEMO_CREATE
void
setPadValue(int pad)
{
    fprintf(fp, "%d\n", pad);
}
#endif

int
getPadValue()
{
    char buff[BUFSIZE];
    int pad;

    if ((bufp = fgets(buff, BUFSIZE, fp)) != NULL) {
        sscanf(bufp, "%d\n", &pad);
    }

    return pad;
}