git repos / blockattack-game

blame: source/code/replay.h

normal view · raw

89c4a3a6 sago007 2008-08-29 14:32 1
/*
c53e6443 sago007 2012-04-17 11:04 2
===========================================================================
c53e6443 sago007 2012-04-17 11:04 3
blockattack - Block Attack - Rise of the Blocks
c53e6443 sago007 2012-04-17 11:04 4
Copyright (C) 2005-2012 Poul Sander
c53e6443 sago007 2012-04-17 11:04 5
c53e6443 sago007 2012-04-17 11:04 6
This program is free software: you can redistribute it and/or modify
c53e6443 sago007 2012-04-17 11:04 7
it under the terms of the GNU General Public License as published by
c53e6443 sago007 2012-04-17 11:04 8
the Free Software Foundation, either version 2 of the License, or
c53e6443 sago007 2012-04-17 11:04 9
(at your option) any later version.
c53e6443 sago007 2012-04-17 11:04 10
c53e6443 sago007 2012-04-17 11:04 11
This program is distributed in the hope that it will be useful,
c53e6443 sago007 2012-04-17 11:04 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
c53e6443 sago007 2012-04-17 11:04 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c53e6443 sago007 2012-04-17 11:04 14
GNU General Public License for more details.
c53e6443 sago007 2012-04-17 11:04 15
c53e6443 sago007 2012-04-17 11:04 16
You should have received a copy of the GNU General Public License
c53e6443 sago007 2012-04-17 11:04 17
along with this program.  If not, see http://www.gnu.org/licenses/
c53e6443 sago007 2012-04-17 11:04 18
c53e6443 sago007 2012-04-17 11:04 19
Source information and contacts persons can be found at
c53e6443 sago007 2012-04-17 11:04 20
http://blockattack.sf.net
c53e6443 sago007 2012-04-17 11:04 21
===========================================================================
89c4a3a6 sago007 2008-08-29 14:32 22
*/
89c4a3a6 sago007 2008-08-29 14:32 23
89c4a3a6 sago007 2008-08-29 14:32 24
//headerfile for replay.h
89c4a3a6 sago007 2008-08-29 14:32 25
/*
89c4a3a6 sago007 2008-08-29 14:32 26
replay is used to save a replay, there is saved 10 moves per second, should be
89c4a3a6 sago007 2008-08-29 14:32 27
able to give a realistic replay
89c4a3a6 sago007 2008-08-29 14:32 28
*/
89c4a3a6 sago007 2008-08-29 14:32 29
17916a2e sago007 2010-11-07 11:26 30
#ifndef REPLAY_H
17916a2e sago007 2010-11-07 11:26 31
#define REPLAY_H 1
17916a2e sago007 2010-11-07 11:26 32
89c4a3a6 sago007 2008-08-29 14:32 33
89c4a3a6 sago007 2008-08-29 14:32 34
#include "SDL.h"
89c4a3a6 sago007 2008-08-29 14:32 35
#include <stdlib.h>
89c4a3a6 sago007 2008-08-29 14:32 36
#include <iostream>
89c4a3a6 sago007 2008-08-29 14:32 37
#include <fstream>
89c4a3a6 sago007 2008-08-29 14:32 38
#include <vector>
89c4a3a6 sago007 2008-08-29 14:32 39
89c4a3a6 sago007 2008-08-29 14:32 40
using namespace std;
89c4a3a6 sago007 2008-08-29 14:32 41
89c4a3a6 sago007 2008-08-29 14:32 42
//board_package, stores a board can be used for network play and replay
89c4a3a6 sago007 2008-08-29 14:32 43
struct boardPackage //92 bytes
89c4a3a6 sago007 2008-08-29 14:32 44
{
c53e6443 sago007 2012-04-17 11:04 45
	Uint32 time; //game time
c53e6443 sago007 2012-04-17 11:04 46
	Uint8 brick[6][13];
c53e6443 sago007 2012-04-17 11:04 47
	Uint8 pixels; //pixels pushed
c53e6443 sago007 2012-04-17 11:04 48
	Uint8 cursorX; //Cursor coordinate
c53e6443 sago007 2012-04-17 11:04 49
	Uint8 cursorY; // -||-
c53e6443 sago007 2012-04-17 11:04 50
	Uint32 score;
c53e6443 sago007 2012-04-17 11:04 51
	Uint8 speed;
c53e6443 sago007 2012-04-17 11:04 52
	Uint8 chain;
c53e6443 sago007 2012-04-17 11:04 53
	Uint8 result; //0=none,1=gameOver,2=winner,4=draw
89c4a3a6 sago007 2008-08-29 14:32 54
};
89c4a3a6 sago007 2008-08-29 14:32 55
d12916ab sago007 2012-04-19 23:30 56
struct Action
d12916ab sago007 2012-04-19 23:30 57
{
79d3c1d3 sago007 2012-05-05 15:54 58
	Sint32 time;
6c9b4cd7 sago007 2012-05-01 19:34 59
	int action;
6c9b4cd7 sago007 2012-05-01 19:34 60
	string param;
d12916ab sago007 2012-04-19 23:30 61
};
d12916ab sago007 2012-04-19 23:30 62
c53e6443 sago007 2012-04-17 11:04 63
class Replay
c53e6443 sago007 2012-04-17 11:04 64
{
89c4a3a6 sago007 2008-08-29 14:32 65
private:
d12916ab sago007 2012-04-19 23:30 66
	vector<Action> actions;
89c4a3a6 sago007 2008-08-29 14:32 67
//If we are loaded from a file, then we are read only
c53e6443 sago007 2012-04-17 11:04 68
	bool isLoaded;
6c9b4cd7 sago007 2012-05-01 19:34 69
//Store player name
6c9b4cd7 sago007 2012-05-01 19:34 70
	string name;
c96f480e sago007 2009-03-28 18:59 71
89c4a3a6 sago007 2008-08-29 14:32 72
public:
c53e6443 sago007 2012-04-17 11:04 73
6c9b4cd7 sago007 2012-05-01 19:34 74
	
c53e6443 sago007 2012-04-17 11:04 75
c53e6443 sago007 2012-04-17 11:04 76
	Replay(); //Constructor
c53e6443 sago007 2012-04-17 11:04 77
	Replay(const Replay& r); //Copy constructor
d12916ab sago007 2012-04-19 23:30 78
	
6c9b4cd7 sago007 2012-05-01 19:34 79
	//New replay type 2.0.0+:
6c9b4cd7 sago007 2012-05-01 19:34 80
	void addAction(int tick, int action, string param);
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
c53e6443 sago007 2012-04-17 11:04 83
	bool saveReplay(string);	//Saves a replay
c53e6443 sago007 2012-04-17 11:04 84
	bool saveReplay(string,Replay p2); //saves a replay, plus another replay given as a parameter
c53e6443 sago007 2012-04-17 11:04 85
	bool loadReplay(string); //laods a replay
6c9b4cd7 sago007 2012-05-01 19:34 86
	bool loadReplay2(string);
6c9b4cd7 sago007 2012-05-01 19:34 87
    void setName(string name);
79d3c1d3 sago007 2012-05-05 15:54 88
    string getName() const;
79d3c1d3 sago007 2012-05-05 15:54 89
    vector<Action> getActions() const; //loads the second part of the replay file, if it exists, returns false otherwise
89c4a3a6 sago007 2008-08-29 14:32 90
};
17916a2e sago007 2010-11-07 11:26 91
17916a2e sago007 2010-11-07 11:26 92
#endif
1970-01-01 00:00 93