Commit 806e2402 authored by alistert's avatar alistert

Created LocalGame class from parts of the Game class.

parent 4da24843
......@@ -2,7 +2,7 @@
objects = src/bonus/bonus.o \
src/game/clientgame.o src/game/game.o src/game/gamemode.o \
src/game/servergame.o \
src/game/localgame.o src/game/servergame.o \
src/io/gfx/anim.o src/io/gfx/font.o src/io/gfx/paletteeffects.o \
src/io/gfx/sprite.o src/io/gfx/video.o \
src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \
......
......@@ -45,7 +45,7 @@ endif
OBJS = src/bonus/bonus.o \
src/game/clientgame.o src/game/game.o src/game/gamemode.o \
src/game/servergame.o \
src/game/localgame.o src/game/servergame.o \
src/io/gfx/anim.o src/io/gfx/font.o src/io/gfx/paletteeffects.o \
src/io/gfx/sprite.o src/io/gfx/video.o \
src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \
......
......@@ -2,7 +2,7 @@
objects = src/bonus/bonus.o \
src/game/clientgame.o src/game/game.o src/game/gamemode.o \
src/game/servergame.o \
src/game/localgame.o src/game/servergame.o \
src/io/gfx/anim.o src/io/gfx/font.o src/io/gfx/paletteeffects.o \
src/io/gfx/sprite.o src/io/gfx/video.o \
src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \
......
......@@ -6,7 +6,7 @@ INCLUDE=/opt/mipsel-linux-uclibc/usr/include
objects = src/bonus/bonus.o \
src/game/clientgame.o src/game/game.o src/game/gamemode.o \
src/game/servergame.o \
src/game/localgame.o src/game/servergame.o \
src/io/gfx/anim.o src/io/gfx/font.o src/io/gfx/paletteeffects.o \
src/io/gfx/sprite.o src/io/gfx/video.o \
src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \
......
......@@ -10,6 +10,7 @@
* 3rd June 2009: Created network.cpp from parts of game.cpp
* 18th July 2009: Created servergame.cpp from parts of game.cpp
* 18th July 2009: Created clientgame.cpp from parts of game.cpp
* 3rd October 2010: Created localgame.cpp from parts of game.cpp
*
* @section Licence
* Copyright (c) 2005-2010 Alister Thomson
......@@ -28,14 +29,11 @@
#include "gamemode.h"
#include "bonus/bonus.h"
#include "io/controls.h"
#include "io/gfx/font.h"
#include "io/gfx/video.h"
#include "io/sound.h"
#include "jj2level/jj2level.h"
#include "level/level.h"
#include "planet/planet.h"
#include "player/bonusplayer.h"
#include "player/levelplayer.h"
#include "util.h"
......@@ -56,30 +54,6 @@ Game::Game () {
}
/**
* Create a new game
*
* @param firstLevel File name of the first level to play
* @param gameDifficulty Difficulty setting
*/
Game::Game (char *firstLevel, int gameDifficulty) {
levelFile = createString(firstLevel);
difficulty = gameDifficulty;
mode = new SingleGameMode();
// Create the player
nPlayers = 1;
localPlayer = players = new Player[1];
localPlayer->init(characterName, NULL, 0);
return;
}
/**
* Destroy game
*/
......@@ -145,25 +119,6 @@ GameMode* Game::getMode () {
}
/**
* Set the next level
*
* @param fileName The file name of the next level
*
* @return Error code
*/
int Game::setLevel (char *fileName) {
if (levelFile) delete[] levelFile;
if (fileName) levelFile = createString(fileName);
else levelFile = NULL;
return E_NONE;
}
/**
* Play the game
*
......@@ -171,9 +126,6 @@ int Game::setLevel (char *fileName) {
*/
int Game::play () {
Planet* planet;
Bonus* bonus;
char* fileName;
bool multiplayer;
bool checkpoint;
int ret;
......@@ -195,6 +147,8 @@ int Game::play () {
if (!strncasecmp(levelFile, F_BONUSMAP, 8)) {
Bonus* bonus;
try {
baseLevel = bonus = new Bonus(levelFile, difficulty, multiplayer);
......@@ -218,6 +172,8 @@ int Game::play () {
} else if (ret == WON) {
char *fileName;
// Go to next level
fileName = createFileName(F_BONUSMAP, (levelFile[10] * 10) + levelFile[11] - 527);
setLevel(fileName);
......@@ -287,7 +243,9 @@ int Game::play () {
if (!multiplayer) {
planet = NULL;
Planet *planet;
char *fileName;
fileName = createFileName(F_PLANET, level->getWorld());
try {
......@@ -296,7 +254,7 @@ int Game::play () {
} catch (int e) {
// Do nothing
planet = NULL;
}
......@@ -381,66 +339,6 @@ void Game::view (int change) {
}
/**
* No data is sent in single-player mode
*
* @param buffer Data that will not be sent. First byte indicates length.
*/
void Game::send (unsigned char *buffer) {
// Do nothing
return;
}
/**
* Game iteration
*
* @param ticks Current time
*
* @return Error code
*/
int Game::step (unsigned int ticks) {
// Do nothing
return E_NONE;
}
/**
* Assign point to team
*
* @param team Team to receive point
*/
void Game::score (unsigned char team) {
// Do nothing
return;
}
/**
* Set the checkpoint
*
* @param gridX X-coordinate (in tiles) of the checkpoint
* @param gridY Y-coordinate (in tiles) of the checkpoint
*/
void Game::setCheckpoint (unsigned char gridX, unsigned char gridY) {
checkX = gridX;
checkY = gridY;
return;
}
/**
* Make a player restart the level from the beginning/last checkpoint
*
......
......@@ -84,7 +84,7 @@
class Anim;
class File;
/// Handling for single-player games and base class for multiplayer game handling classes
/// Base class for game handling classes
class Game {
protected:
......@@ -101,23 +101,38 @@ class Game {
GameMode* createMode (GameModeType modeType);
public:
Game (char *firstLevel, int gameDifficulty);
virtual ~Game ();
GameMode* getMode ();
virtual int setLevel (char *fileName);
virtual int setLevel (char *fileName) = 0;
int play ();
void view (int change);
virtual void send (unsigned char *buffer);
virtual int step (unsigned int ticks);
virtual void score (unsigned char team);
virtual void setCheckpoint (unsigned char gridX, unsigned char gridY);
virtual void send (unsigned char *buffer) = 0;
virtual int step (unsigned int ticks) = 0;
virtual void score (unsigned char team) = 0;
virtual void setCheckpoint (unsigned char gridX, unsigned char gridY) = 0;
void resetPlayer (Player *player);
void resetPlayer (Player *player, LevelType levelType, Anim** anims);
};
/// Game handling for single-player local play
class LocalGame : public Game {
public:
LocalGame (char *firstLevel, int gameDifficulty);
~LocalGame ();
int setLevel (char *fileName);
void send (unsigned char *buffer);
int step (unsigned int ticks);
void score (unsigned char team);
void setCheckpoint (unsigned char gridX, unsigned char gridY);
};
/// Game handling for multiplayer servers
class ServerGame : public Game {
......
/**
*
* @file localgame.cpp
*
* Part of the OpenJazz project
*
* @section History
* 3rd October 2010: Created localgame.cpp from parts of game.cpp
*
* @section Licence
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "game.h"
#include "gamemode.h"
#include "player/player.h"
#include "util.h"
/**
* Create a single-player local game
*
* @param firstLevel File name of the first level to play
* @param gameDifficulty Difficulty setting
*/
LocalGame::LocalGame (char *firstLevel, int gameDifficulty) {
levelFile = createString(firstLevel);
difficulty = gameDifficulty;
mode = new SingleGameMode();
// Create the player
nPlayers = 1;
localPlayer = players = new Player[1];
localPlayer->init(characterName, NULL, 0);
return;
}
/**
* Destroy local game
*/
LocalGame::~LocalGame () {
delete mode;
return;
}
/**
* Set the next level
*
* @param fileName The file name of the next level
*
* @return Error code
*/
int LocalGame::setLevel (char *fileName) {
if (levelFile) delete[] levelFile;
if (fileName) levelFile = createString(fileName);
else levelFile = NULL;
return E_NONE;
}
/**
* No data is sent in local games
*
* @param buffer Data that will not be sent. First byte indicates length.
*/
void LocalGame::send (unsigned char *buffer) {
// Do nothing
return;
}
/**
* Game iteration - nothing to be done in local games
*
* @param ticks Current time
*
* @return Error code
*/
int LocalGame::step (unsigned int ticks) {
// Do nothing
return E_NONE;
}
/**
* No points are assigned to teams in local games
*
* @param team Team to receive point
*/
void LocalGame::score (unsigned char team) {
// Do nothing
return;
}
/**
* Set the checkpoint
*
* @param gridX X-coordinate (in tiles) of the checkpoint
* @param gridY Y-coordinate (in tiles) of the checkpoint
*/
void LocalGame::setCheckpoint (unsigned char gridX, unsigned char gridY) {
checkX = gridX;
checkY = gridY;
return;
}
......@@ -156,7 +156,7 @@ int GameMenu::newGameDifficulty (GameModeType mode, char* firstLevel) {
try {
game = new Game(firstLevel, difficulty);
game = new LocalGame(firstLevel, difficulty);
} catch (int e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment