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
17916a2e sago007 2010-11-07 11:26 32
#ifndef REPLAY_H
17916a2e sago007 2010-11-07 11:26 33
#define REPLAY_H 1
17916a2e sago007 2010-11-07 11:26 34
89c4a3a6 sago007 2008-08-29 14:32 35
//constants - 3000 is 5 minutes
89c4a3a6 sago007 2008-08-29 14:32 36
#define FRAMESPERSEC 10
89c4a3a6 sago007 2008-08-29 14:32 37
89c4a3a6 sago007 2008-08-29 14:32 38
#include "SDL.h"
89c4a3a6 sago007 2008-08-29 14:32 39
#include <stdlib.h>
89c4a3a6 sago007 2008-08-29 14:32 40
#include <iostream>
89c4a3a6 sago007 2008-08-29 14:32 41
#include <fstream>
89c4a3a6 sago007 2008-08-29 14:32 42
#include <vector>
89c4a3a6 sago007 2008-08-29 14:32 43
89c4a3a6 sago007 2008-08-29 14:32 44
using namespace std;
89c4a3a6 sago007 2008-08-29 14:32 45
89c4a3a6 sago007 2008-08-29 14:32 46
//board_package, stores a board can be used for network play and replay
89c4a3a6 sago007 2008-08-29 14:32 47
struct boardPackage //92 bytes
89c4a3a6 sago007 2008-08-29 14:32 48
{
89c4a3a6 sago007 2008-08-29 14:32 49
    Uint32 time; //game time
89c4a3a6 sago007 2008-08-29 14:32 50
    Uint8 brick[6][13];
89c4a3a6 sago007 2008-08-29 14:32 51
    Uint8 pixels; //pixels pushed
89c4a3a6 sago007 2008-08-29 14:32 52
    Uint8 cursorX; //Cursor coordinate
89c4a3a6 sago007 2008-08-29 14:32 53
    Uint8 cursorY; // -||-
89c4a3a6 sago007 2008-08-29 14:32 54
    Uint32 score;
89c4a3a6 sago007 2008-08-29 14:32 55
    Uint8 speed;
89c4a3a6 sago007 2008-08-29 14:32 56
    Uint8 chain;
89c4a3a6 sago007 2008-08-29 14:32 57
    Uint8 result; //0=none,1=gameOver,2=winner,4=draw
89c4a3a6 sago007 2008-08-29 14:32 58
};
89c4a3a6 sago007 2008-08-29 14:32 59
89c4a3a6 sago007 2008-08-29 14:32 60
class Replay{
89c4a3a6 sago007 2008-08-29 14:32 61
private:
89c4a3a6 sago007 2008-08-29 14:32 62
//Our replay is stored in an array of TOTALFRAMES length
89c4a3a6 sago007 2008-08-29 14:32 63
    //boardPackage bps[TOTALFRAMES];
89c4a3a6 sago007 2008-08-29 14:32 64
    vector<boardPackage> bps;
89c4a3a6 sago007 2008-08-29 14:32 65
//The final package is not set to any specific time
89c4a3a6 sago007 2008-08-29 14:32 66
    boardPackage finalPack;
89c4a3a6 sago007 2008-08-29 14:32 67
//We store number of frames, so we know how long to read the array
89c4a3a6 sago007 2008-08-29 14:32 68
    Uint32 nrOfFrames;
89c4a3a6 sago007 2008-08-29 14:32 69
//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 70
    enum { gameOver=0, winner, looser, draw } theResult;
89c4a3a6 sago007 2008-08-29 14:32 71
//If we are loaded from a file, then we are read only
89c4a3a6 sago007 2008-08-29 14:32 72
    bool isLoaded;
89c4a3a6 sago007 2008-08-29 14:32 73
c96f480e sago007 2009-03-28 18:59 74
89c4a3a6 sago007 2008-08-29 14:32 75
public:
c96f480e sago007 2009-03-28 18:59 76
    
c96f480e sago007 2009-03-28 18:59 77
    //Store player name
c96f480e sago007 2009-03-28 18:59 78
    char name[30];
c96f480e sago007 2009-03-28 18:59 79
89c4a3a6 sago007 2008-08-29 14:32 80
    Replay(); //Constructor
89c4a3a6 sago007 2008-08-29 14:32 81
    Replay(const Replay& r); //Copy constructor
89c4a3a6 sago007 2008-08-29 14:32 82
    Uint32 getNumberOfFrames(); //Returns number of frames
89c4a3a6 sago007 2008-08-29 14:32 83
    void setFrameSecTo(Uint32,boardPackage); //Sets frame at a given time to the package
89c4a3a6 sago007 2008-08-29 14:32 84
    void setFinalFrame(boardPackage,int); //Sets the final package
89c4a3a6 sago007 2008-08-29 14:32 85
    boardPackage getFrameSec(Uint32);  //Gets a frame to a time
89c4a3a6 sago007 2008-08-29 14:32 86
    boardPackage getFinalFrame(); //Gets the last frame, that must remain
89c4a3a6 sago007 2008-08-29 14:32 87
    int getFinalStatus();	//Return the result: winner, looser, draw or gameOver
89c4a3a6 sago007 2008-08-29 14:32 88
    bool isFinnished(Uint32); //Returns true if we are done
89c4a3a6 sago007 2008-08-29 14:32 89
89c4a3a6 sago007 2008-08-29 14:32 90
//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 91
    bool saveReplay(string);	//Saves a replay
89c4a3a6 sago007 2008-08-29 14:32 92
    bool saveReplay(string,Replay p2); //saves a replay, plus another replay given as a parameter
89c4a3a6 sago007 2008-08-29 14:32 93
    bool loadReplay(string); //laods a replay
89c4a3a6 sago007 2008-08-29 14:32 94
    bool loadReplay2(string); //loads the second part of the replay file, if it exists, returns false otherwise
c96f480e sago007 2009-03-28 18:59 95
c96f480e sago007 2009-03-28 18:59 96
89c4a3a6 sago007 2008-08-29 14:32 97
};
17916a2e sago007 2010-11-07 11:26 98
17916a2e sago007 2010-11-07 11:26 99
#endif
1970-01-01 00:00 100