git repos / blockattack-game

blame: source/code/replay.h

normal view · raw

89c4a3a6 sago007 2008-08-29 14:32 1
/*
89c4a3a6 sago007 2008-08-29 14:32 2
replay.h
89c4a3a6 sago007 2008-08-29 14:32 3
Copyright (C) 2005 Poul Sander
89c4a3a6 sago007 2008-08-29 14:32 4
89c4a3a6 sago007 2008-08-29 14:32 5
    This program is free software; you can redistribute it and/or modify
89c4a3a6 sago007 2008-08-29 14:32 6
    it under the terms of the GNU General Public License as published by
89c4a3a6 sago007 2008-08-29 14:32 7
    the Free Software Foundation; either version 2 of the License, or
89c4a3a6 sago007 2008-08-29 14:32 8
    (at your option) any later version.
89c4a3a6 sago007 2008-08-29 14:32 9
89c4a3a6 sago007 2008-08-29 14:32 10
    This program is distributed in the hope that it will be useful,
89c4a3a6 sago007 2008-08-29 14:32 11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
89c4a3a6 sago007 2008-08-29 14:32 12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
89c4a3a6 sago007 2008-08-29 14:32 13
    GNU General Public License for more details.
89c4a3a6 sago007 2008-08-29 14:32 14
89c4a3a6 sago007 2008-08-29 14:32 15
    You should have received a copy of the GNU General Public License
89c4a3a6 sago007 2008-08-29 14:32 16
    along with this program; if not, write to the Free Software
89c4a3a6 sago007 2008-08-29 14:32 17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
89c4a3a6 sago007 2008-08-29 14:32 18
89c4a3a6 sago007 2008-08-29 14:32 19
    Poul Sander
89c4a3a6 sago007 2008-08-29 14:32 20
    R�veh�jvej 36, V. 1111
89c4a3a6 sago007 2008-08-29 14:32 21
    2800 Kgs. Lyngby
89c4a3a6 sago007 2008-08-29 14:32 22
    DENMARK
89c4a3a6 sago007 2008-08-29 14:32 23
    blockattack@poulsander.com
89c4a3a6 sago007 2008-08-29 14:32 24
*/
89c4a3a6 sago007 2008-08-29 14:32 25
89c4a3a6 sago007 2008-08-29 14:32 26
//headerfile for replay.h
89c4a3a6 sago007 2008-08-29 14:32 27
/*
89c4a3a6 sago007 2008-08-29 14:32 28
replay is used to save a replay, there is saved 10 moves per second, should be
89c4a3a6 sago007 2008-08-29 14:32 29
able to give a realistic replay
89c4a3a6 sago007 2008-08-29 14:32 30
*/
89c4a3a6 sago007 2008-08-29 14:32 31
89c4a3a6 sago007 2008-08-29 14:32 32
//constants - 3000 is 5 minutes
89c4a3a6 sago007 2008-08-29 14:32 33
#define FRAMESPERSEC 10
89c4a3a6 sago007 2008-08-29 14:32 34
89c4a3a6 sago007 2008-08-29 14:32 35
#include "SDL.h"
89c4a3a6 sago007 2008-08-29 14:32 36
#include <stdlib.h>
89c4a3a6 sago007 2008-08-29 14:32 37
#include <iostream>
89c4a3a6 sago007 2008-08-29 14:32 38
#include <fstream>
89c4a3a6 sago007 2008-08-29 14:32 39
#include <vector>
89c4a3a6 sago007 2008-08-29 14:32 40
89c4a3a6 sago007 2008-08-29 14:32 41
using namespace std;
89c4a3a6 sago007 2008-08-29 14:32 42
89c4a3a6 sago007 2008-08-29 14:32 43
//board_package, stores a board can be used for network play and replay
89c4a3a6 sago007 2008-08-29 14:32 44
struct boardPackage //92 bytes
89c4a3a6 sago007 2008-08-29 14:32 45
{
89c4a3a6 sago007 2008-08-29 14:32 46
    Uint32 time; //game time
89c4a3a6 sago007 2008-08-29 14:32 47
    Uint8 brick[6][13];
89c4a3a6 sago007 2008-08-29 14:32 48
    Uint8 pixels; //pixels pushed
89c4a3a6 sago007 2008-08-29 14:32 49
    Uint8 cursorX; //Cursor coordinate
89c4a3a6 sago007 2008-08-29 14:32 50
    Uint8 cursorY; // -||-
89c4a3a6 sago007 2008-08-29 14:32 51
    Uint32 score;
89c4a3a6 sago007 2008-08-29 14:32 52
    Uint8 speed;
89c4a3a6 sago007 2008-08-29 14:32 53
    Uint8 chain;
89c4a3a6 sago007 2008-08-29 14:32 54
    Uint8 result; //0=none,1=gameOver,2=winner,4=draw
89c4a3a6 sago007 2008-08-29 14:32 55
};
89c4a3a6 sago007 2008-08-29 14:32 56
89c4a3a6 sago007 2008-08-29 14:32 57
class Replay{
89c4a3a6 sago007 2008-08-29 14:32 58
private:
89c4a3a6 sago007 2008-08-29 14:32 59
//Our replay is stored in an array of TOTALFRAMES length
89c4a3a6 sago007 2008-08-29 14:32 60
    //boardPackage bps[TOTALFRAMES];
89c4a3a6 sago007 2008-08-29 14:32 61
    vector<boardPackage> bps;
89c4a3a6 sago007 2008-08-29 14:32 62
//The final package is not set to any specific time
89c4a3a6 sago007 2008-08-29 14:32 63
    boardPackage finalPack;
89c4a3a6 sago007 2008-08-29 14:32 64
//We store number of frames, so we know how long to read the array
89c4a3a6 sago007 2008-08-29 14:32 65
    Uint32 nrOfFrames;
89c4a3a6 sago007 2008-08-29 14:32 66
//An enumerator, so we know how it ends! (should be removed then boardPackage is the 92 byte version)
89c4a3a6 sago007 2008-08-29 14:32 67
    enum { gameOver=0, winner, looser, draw } theResult;
89c4a3a6 sago007 2008-08-29 14:32 68
//If we are loaded from a file, then we are read only
89c4a3a6 sago007 2008-08-29 14:32 69
    bool isLoaded;
89c4a3a6 sago007 2008-08-29 14:32 70
89c4a3a6 sago007 2008-08-29 14:32 71
public:
89c4a3a6 sago007 2008-08-29 14:32 72
    Replay(); //Constructor
89c4a3a6 sago007 2008-08-29 14:32 73
    Replay(const Replay& r); //Copy constructor
89c4a3a6 sago007 2008-08-29 14:32 74
    Uint32 getNumberOfFrames(); //Returns number of frames
89c4a3a6 sago007 2008-08-29 14:32 75
    void setFrameSecTo(Uint32,boardPackage); //Sets frame at a given time to the package
89c4a3a6 sago007 2008-08-29 14:32 76
    void setFinalFrame(boardPackage,int); //Sets the final package
89c4a3a6 sago007 2008-08-29 14:32 77
    boardPackage getFrameSec(Uint32);  //Gets a frame to a time
89c4a3a6 sago007 2008-08-29 14:32 78
    boardPackage getFinalFrame(); //Gets the last frame, that must remain
89c4a3a6 sago007 2008-08-29 14:32 79
    int getFinalStatus();	//Return the result: winner, looser, draw or gameOver
89c4a3a6 sago007 2008-08-29 14:32 80
    bool isFinnished(Uint32); //Returns true if we are done
89c4a3a6 sago007 2008-08-29 14:32 81
89c4a3a6 sago007 2008-08-29 14:32 82
//Ok, I'll ignore this for some time, and just save to file, if however, we ever use a dynamic saving structure, we are fucked
89c4a3a6 sago007 2008-08-29 14:32 83
    bool saveReplay(string);	//Saves a replay
89c4a3a6 sago007 2008-08-29 14:32 84
    bool saveReplay(string,Replay p2); //saves a replay, plus another replay given as a parameter
89c4a3a6 sago007 2008-08-29 14:32 85
    bool loadReplay(string); //laods a replay
89c4a3a6 sago007 2008-08-29 14:32 86
    bool loadReplay2(string); //loads the second part of the replay file, if it exists, returns false otherwise
89c4a3a6 sago007 2008-08-29 14:32 87
    
89c4a3a6 sago007 2008-08-29 14:32 88
};
1970-01-01 00:00 89