add loader
add schema new loader model using xml separated work and load data validation using schema map data in xml new core model... proecting
This commit is contained in:
57
Makefile
57
Makefile
@@ -1,6 +1,6 @@
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
# Makefile for building: aliendefender
|
# Makefile for building: aliendefender
|
||||||
# Generated by qmake (2.01a) (Qt 4.6.2) on: ?? ???? 30 01:35:39 2010
|
# Generated by qmake (2.01a) (Qt 4.6.2) on: ?? ???. 17 20:37:06 2010
|
||||||
# Project: aliendefender.pro
|
# Project: aliendefender.pro
|
||||||
# Template: app
|
# Template: app
|
||||||
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro
|
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro
|
||||||
@@ -10,13 +10,13 @@
|
|||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CXX = g++
|
CXX = g++
|
||||||
DEFINES = -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
|
DEFINES = -DQT_XMLPATTERNS_LIB -DQT_XML_LIB -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
|
||||||
CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
|
CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
|
||||||
CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
|
CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
|
||||||
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I.
|
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4/QtXml -I/usr/include/qt4/QtXmlPatterns -I/usr/include/qt4 -I/usr/X11R6/include -I.
|
||||||
LINK = g++
|
LINK = g++
|
||||||
LFLAGS =
|
LFLAGS =
|
||||||
LIBS = $(SUBLIBS) -L/usr/lib -lQtGui -lQtCore -lpthread
|
LIBS = $(SUBLIBS) -L/usr/lib -L/usr/X11R6/lib -lQtXmlPatterns -lQtXml -lQtOpenGL -lQtGui -lQtNetwork -lQtCore -lGLU -lGL -lpthread
|
||||||
AR = ar cqs
|
AR = ar cqs
|
||||||
RANLIB =
|
RANLIB =
|
||||||
QMAKE = /usr/bin/qmake-qt4
|
QMAKE = /usr/bin/qmake-qt4
|
||||||
@@ -51,13 +51,15 @@ SOURCES = map.cpp \
|
|||||||
splashes.cpp \
|
splashes.cpp \
|
||||||
adcore.cpp \
|
adcore.cpp \
|
||||||
player.cpp \
|
player.cpp \
|
||||||
settreader.cpp moc_map.cpp \
|
settreader.cpp \
|
||||||
|
loader.cpp moc_map.cpp \
|
||||||
moc_game_data.cpp \
|
moc_game_data.cpp \
|
||||||
moc_aliens.cpp \
|
moc_aliens.cpp \
|
||||||
moc_towers.cpp \
|
moc_towers.cpp \
|
||||||
moc_splashes.cpp \
|
moc_splashes.cpp \
|
||||||
moc_adcore.cpp \
|
moc_adcore.cpp \
|
||||||
moc_player.cpp \
|
moc_player.cpp \
|
||||||
|
moc_loader.cpp \
|
||||||
qrc_images.cpp
|
qrc_images.cpp
|
||||||
OBJECTS = map.o \
|
OBJECTS = map.o \
|
||||||
game_data.o \
|
game_data.o \
|
||||||
@@ -68,6 +70,7 @@ OBJECTS = map.o \
|
|||||||
adcore.o \
|
adcore.o \
|
||||||
player.o \
|
player.o \
|
||||||
settreader.o \
|
settreader.o \
|
||||||
|
loader.o \
|
||||||
moc_map.o \
|
moc_map.o \
|
||||||
moc_game_data.o \
|
moc_game_data.o \
|
||||||
moc_aliens.o \
|
moc_aliens.o \
|
||||||
@@ -75,6 +78,7 @@ OBJECTS = map.o \
|
|||||||
moc_splashes.o \
|
moc_splashes.o \
|
||||||
moc_adcore.o \
|
moc_adcore.o \
|
||||||
moc_player.o \
|
moc_player.o \
|
||||||
|
moc_loader.o \
|
||||||
qrc_images.o
|
qrc_images.o
|
||||||
DIST = /usr/share/qt4/mkspecs/common/g++.conf \
|
DIST = /usr/share/qt4/mkspecs/common/g++.conf \
|
||||||
/usr/share/qt4/mkspecs/common/unix.conf \
|
/usr/share/qt4/mkspecs/common/unix.conf \
|
||||||
@@ -88,6 +92,7 @@ DIST = /usr/share/qt4/mkspecs/common/g++.conf \
|
|||||||
/usr/share/qt4/mkspecs/features/default_post.prf \
|
/usr/share/qt4/mkspecs/features/default_post.prf \
|
||||||
/usr/share/qt4/mkspecs/features/warn_on.prf \
|
/usr/share/qt4/mkspecs/features/warn_on.prf \
|
||||||
/usr/share/qt4/mkspecs/features/qt.prf \
|
/usr/share/qt4/mkspecs/features/qt.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/unix/opengl.prf \
|
||||||
/usr/share/qt4/mkspecs/features/unix/thread.prf \
|
/usr/share/qt4/mkspecs/features/unix/thread.prf \
|
||||||
/usr/share/qt4/mkspecs/features/moc.prf \
|
/usr/share/qt4/mkspecs/features/moc.prf \
|
||||||
/usr/share/qt4/mkspecs/features/resources.prf \
|
/usr/share/qt4/mkspecs/features/resources.prf \
|
||||||
@@ -139,6 +144,7 @@ Makefile: aliendefender.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/sh
|
|||||||
/usr/share/qt4/mkspecs/features/default_post.prf \
|
/usr/share/qt4/mkspecs/features/default_post.prf \
|
||||||
/usr/share/qt4/mkspecs/features/warn_on.prf \
|
/usr/share/qt4/mkspecs/features/warn_on.prf \
|
||||||
/usr/share/qt4/mkspecs/features/qt.prf \
|
/usr/share/qt4/mkspecs/features/qt.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/unix/opengl.prf \
|
||||||
/usr/share/qt4/mkspecs/features/unix/thread.prf \
|
/usr/share/qt4/mkspecs/features/unix/thread.prf \
|
||||||
/usr/share/qt4/mkspecs/features/moc.prf \
|
/usr/share/qt4/mkspecs/features/moc.prf \
|
||||||
/usr/share/qt4/mkspecs/features/resources.prf \
|
/usr/share/qt4/mkspecs/features/resources.prf \
|
||||||
@@ -146,7 +152,11 @@ Makefile: aliendefender.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/sh
|
|||||||
/usr/share/qt4/mkspecs/features/yacc.prf \
|
/usr/share/qt4/mkspecs/features/yacc.prf \
|
||||||
/usr/share/qt4/mkspecs/features/lex.prf \
|
/usr/share/qt4/mkspecs/features/lex.prf \
|
||||||
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
|
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
|
||||||
|
/usr/lib/libQtXmlPatterns.prl \
|
||||||
|
/usr/lib/libQtXml.prl \
|
||||||
|
/usr/lib/libQtOpenGL.prl \
|
||||||
/usr/lib/libQtGui.prl \
|
/usr/lib/libQtGui.prl \
|
||||||
|
/usr/lib/libQtNetwork.prl \
|
||||||
/usr/lib/libQtCore.prl
|
/usr/lib/libQtCore.prl
|
||||||
$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro
|
$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro
|
||||||
/usr/share/qt4/mkspecs/common/g++.conf:
|
/usr/share/qt4/mkspecs/common/g++.conf:
|
||||||
@@ -161,6 +171,7 @@ Makefile: aliendefender.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/sh
|
|||||||
/usr/share/qt4/mkspecs/features/default_post.prf:
|
/usr/share/qt4/mkspecs/features/default_post.prf:
|
||||||
/usr/share/qt4/mkspecs/features/warn_on.prf:
|
/usr/share/qt4/mkspecs/features/warn_on.prf:
|
||||||
/usr/share/qt4/mkspecs/features/qt.prf:
|
/usr/share/qt4/mkspecs/features/qt.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/unix/opengl.prf:
|
||||||
/usr/share/qt4/mkspecs/features/unix/thread.prf:
|
/usr/share/qt4/mkspecs/features/unix/thread.prf:
|
||||||
/usr/share/qt4/mkspecs/features/moc.prf:
|
/usr/share/qt4/mkspecs/features/moc.prf:
|
||||||
/usr/share/qt4/mkspecs/features/resources.prf:
|
/usr/share/qt4/mkspecs/features/resources.prf:
|
||||||
@@ -168,14 +179,18 @@ Makefile: aliendefender.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/sh
|
|||||||
/usr/share/qt4/mkspecs/features/yacc.prf:
|
/usr/share/qt4/mkspecs/features/yacc.prf:
|
||||||
/usr/share/qt4/mkspecs/features/lex.prf:
|
/usr/share/qt4/mkspecs/features/lex.prf:
|
||||||
/usr/share/qt4/mkspecs/features/include_source_dir.prf:
|
/usr/share/qt4/mkspecs/features/include_source_dir.prf:
|
||||||
|
/usr/lib/libQtXmlPatterns.prl:
|
||||||
|
/usr/lib/libQtXml.prl:
|
||||||
|
/usr/lib/libQtOpenGL.prl:
|
||||||
/usr/lib/libQtGui.prl:
|
/usr/lib/libQtGui.prl:
|
||||||
|
/usr/lib/libQtNetwork.prl:
|
||||||
/usr/lib/libQtCore.prl:
|
/usr/lib/libQtCore.prl:
|
||||||
qmake: FORCE
|
qmake: FORCE
|
||||||
@$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro
|
@$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro
|
||||||
|
|
||||||
dist:
|
dist:
|
||||||
@$(CHK_DIR_EXISTS) .tmp/aliendefender1.0.0 || $(MKDIR) .tmp/aliendefender1.0.0
|
@$(CHK_DIR_EXISTS) .tmp/aliendefender1.0.0 || $(MKDIR) .tmp/aliendefender1.0.0
|
||||||
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents base_types.h map.h game_data.h aliens.h towers.h splashes.h adcore.h player.h settreader.h .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents images.qrc .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents map.cpp game_data.cpp aliens.cpp towers.cpp main.cpp splashes.cpp adcore.cpp player.cpp settreader.cpp .tmp/aliendefender1.0.0/ && (cd `dirname .tmp/aliendefender1.0.0` && $(TAR) aliendefender1.0.0.tar aliendefender1.0.0 && $(COMPRESS) aliendefender1.0.0.tar) && $(MOVE) `dirname .tmp/aliendefender1.0.0`/aliendefender1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/aliendefender1.0.0
|
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents base_types.h map.h game_data.h aliens.h towers.h splashes.h adcore.h player.h settreader.h loader.h .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents images.qrc .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents map.cpp game_data.cpp aliens.cpp towers.cpp main.cpp splashes.cpp adcore.cpp player.cpp settreader.cpp loader.cpp .tmp/aliendefender1.0.0/ && (cd `dirname .tmp/aliendefender1.0.0` && $(TAR) aliendefender1.0.0.tar aliendefender1.0.0 && $(COMPRESS) aliendefender1.0.0.tar) && $(MOVE) `dirname .tmp/aliendefender1.0.0`/aliendefender1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/aliendefender1.0.0
|
||||||
|
|
||||||
|
|
||||||
clean:compiler_clean
|
clean:compiler_clean
|
||||||
@@ -194,9 +209,9 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean
|
|||||||
|
|
||||||
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
|
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
|
||||||
|
|
||||||
compiler_moc_header_make_all: moc_map.cpp moc_game_data.cpp moc_aliens.cpp moc_towers.cpp moc_splashes.cpp moc_adcore.cpp moc_player.cpp
|
compiler_moc_header_make_all: moc_map.cpp moc_game_data.cpp moc_aliens.cpp moc_towers.cpp moc_splashes.cpp moc_adcore.cpp moc_player.cpp moc_loader.cpp
|
||||||
compiler_moc_header_clean:
|
compiler_moc_header_clean:
|
||||||
-$(DEL_FILE) moc_map.cpp moc_game_data.cpp moc_aliens.cpp moc_towers.cpp moc_splashes.cpp moc_adcore.cpp moc_player.cpp
|
-$(DEL_FILE) moc_map.cpp moc_game_data.cpp moc_aliens.cpp moc_towers.cpp moc_splashes.cpp moc_adcore.cpp moc_player.cpp moc_loader.cpp
|
||||||
moc_map.cpp: base_types.h \
|
moc_map.cpp: base_types.h \
|
||||||
settreader.h \
|
settreader.h \
|
||||||
map.h
|
map.h
|
||||||
@@ -241,6 +256,7 @@ moc_adcore.cpp: aliens.h \
|
|||||||
settreader.h \
|
settreader.h \
|
||||||
towers.h \
|
towers.h \
|
||||||
splashes.h \
|
splashes.h \
|
||||||
|
loader.h \
|
||||||
adcore.h
|
adcore.h
|
||||||
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) adcore.h -o moc_adcore.cpp
|
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) adcore.h -o moc_adcore.cpp
|
||||||
|
|
||||||
@@ -250,6 +266,14 @@ moc_player.cpp: map.h \
|
|||||||
player.h
|
player.h
|
||||||
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) player.h -o moc_player.cpp
|
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) player.h -o moc_player.cpp
|
||||||
|
|
||||||
|
moc_loader.cpp: game_data.h \
|
||||||
|
player.h \
|
||||||
|
map.h \
|
||||||
|
base_types.h \
|
||||||
|
settreader.h \
|
||||||
|
loader.h
|
||||||
|
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) loader.h -o moc_loader.cpp
|
||||||
|
|
||||||
compiler_rcc_make_all: qrc_images.cpp
|
compiler_rcc_make_all: qrc_images.cpp
|
||||||
compiler_rcc_clean:
|
compiler_rcc_clean:
|
||||||
-$(DEL_FILE) qrc_images.cpp
|
-$(DEL_FILE) qrc_images.cpp
|
||||||
@@ -329,7 +353,8 @@ main.o: main.cpp adcore.h \
|
|||||||
base_types.h \
|
base_types.h \
|
||||||
settreader.h \
|
settreader.h \
|
||||||
towers.h \
|
towers.h \
|
||||||
splashes.h
|
splashes.h \
|
||||||
|
loader.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
|
||||||
|
|
||||||
splashes.o: splashes.cpp splashes.h \
|
splashes.o: splashes.cpp splashes.h \
|
||||||
@@ -348,7 +373,8 @@ adcore.o: adcore.cpp adcore.h \
|
|||||||
base_types.h \
|
base_types.h \
|
||||||
settreader.h \
|
settreader.h \
|
||||||
towers.h \
|
towers.h \
|
||||||
splashes.h
|
splashes.h \
|
||||||
|
loader.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o adcore.o adcore.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o adcore.o adcore.cpp
|
||||||
|
|
||||||
player.o: player.cpp player.h \
|
player.o: player.cpp player.h \
|
||||||
@@ -360,6 +386,14 @@ player.o: player.cpp player.h \
|
|||||||
settreader.o: settreader.cpp settreader.h
|
settreader.o: settreader.cpp settreader.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o settreader.o settreader.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o settreader.o settreader.cpp
|
||||||
|
|
||||||
|
loader.o: loader.cpp loader.h \
|
||||||
|
game_data.h \
|
||||||
|
player.h \
|
||||||
|
map.h \
|
||||||
|
base_types.h \
|
||||||
|
settreader.h
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o loader.o loader.cpp
|
||||||
|
|
||||||
moc_map.o: moc_map.cpp
|
moc_map.o: moc_map.cpp
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_map.o moc_map.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_map.o moc_map.cpp
|
||||||
|
|
||||||
@@ -381,6 +415,9 @@ moc_adcore.o: moc_adcore.cpp
|
|||||||
moc_player.o: moc_player.cpp
|
moc_player.o: moc_player.cpp
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_player.o moc_player.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_player.o moc_player.cpp
|
||||||
|
|
||||||
|
moc_loader.o: moc_loader.cpp
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_loader.o moc_loader.cpp
|
||||||
|
|
||||||
qrc_images.o: qrc_images.cpp
|
qrc_images.o: qrc_images.cpp
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_images.o qrc_images.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_images.o qrc_images.cpp
|
||||||
|
|
||||||
|
|||||||
38
adcore.cpp
38
adcore.cpp
@@ -4,23 +4,27 @@ adCore::adCore(QObject *parent) :
|
|||||||
QThread(parent)
|
QThread(parent)
|
||||||
{
|
{
|
||||||
step = 0;
|
step = 0;
|
||||||
admap = new Map(1);
|
//admap = new Map(1);
|
||||||
addata = new Game_Data(admap);
|
//addata = new Game_Data(admap);
|
||||||
Player * pl1 = new Player(0);
|
adload = new Loader();
|
||||||
Player * pl2 = new Player(0);
|
//admap->load();
|
||||||
addata->players.push_back(pl1);
|
//adload->create();
|
||||||
addata->players.push_back(pl2);
|
//adload->readAliens();
|
||||||
adaliens = new Aliens(addata);
|
// Player * pl1 = new Player(0);
|
||||||
adtowers = new Towers(addata);
|
// Player * pl2 = new Player(0);
|
||||||
adsplashes = new Splashes(addata);
|
// addata->players.push_back(pl1);
|
||||||
connect(admap,SIGNAL(RecreateAlienPath(bool*)),adaliens,SLOT(retrace(bool*)));
|
// addata->players.push_back(pl2);
|
||||||
adaliens->AddAlien(0);
|
// adaliens = new Aliens(addata);
|
||||||
adaliens->AddAlien(0);
|
// adtowers = new Towers(addata);
|
||||||
adaliens->AddAlien(0);
|
// adsplashes = new Splashes(addata);
|
||||||
for (int i=0; i<qMin(admap->mapsize.width(),admap->mapsize.height()); i++)
|
// connect(admap,SIGNAL(RecreateAlienPath(bool*)),adaliens,SLOT(retrace(bool*)));
|
||||||
adtowers->AddTower(0,0,QPoint(i,i));
|
// adaliens->AddAlien(0);
|
||||||
for (int i=0; i<admap->mapsize.height();i++)
|
// adaliens->AddAlien(0);
|
||||||
adtowers->AddTower(1,0,QPoint(admap->mapsize.width()-2,i));
|
// adaliens->AddAlien(0);
|
||||||
|
// for (int i=0; i<qMin(admap->mapsize.width(),admap->mapsize.height()); i++)
|
||||||
|
// adtowers->AddTower(0,0,QPoint(i,i));
|
||||||
|
// for (int i=0; i<admap->mapsize.height();i++)
|
||||||
|
// adtowers->AddTower(1,0,QPoint(admap->mapsize.width()-2,i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
adcore.h
2
adcore.h
@@ -7,6 +7,7 @@
|
|||||||
#include "aliens.h"
|
#include "aliens.h"
|
||||||
#include "towers.h"
|
#include "towers.h"
|
||||||
#include "splashes.h"
|
#include "splashes.h"
|
||||||
|
#include "loader.h"
|
||||||
|
|
||||||
class adCore : public QThread
|
class adCore : public QThread
|
||||||
{
|
{
|
||||||
@@ -19,6 +20,7 @@ public:
|
|||||||
Aliens *adaliens;
|
Aliens *adaliens;
|
||||||
Towers *adtowers;
|
Towers *adtowers;
|
||||||
Splashes *adsplashes;
|
Splashes *adsplashes;
|
||||||
|
Loader * adload;
|
||||||
int step;
|
int step;
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ HEADERS += base_types.h \
|
|||||||
splashes.h \
|
splashes.h \
|
||||||
adcore.h \
|
adcore.h \
|
||||||
player.h \
|
player.h \
|
||||||
settreader.h
|
settreader.h \
|
||||||
|
loader.h
|
||||||
SOURCES += map.cpp \
|
SOURCES += map.cpp \
|
||||||
game_data.cpp \
|
game_data.cpp \
|
||||||
aliens.cpp \
|
aliens.cpp \
|
||||||
@@ -15,8 +16,18 @@ SOURCES += map.cpp \
|
|||||||
splashes.cpp \
|
splashes.cpp \
|
||||||
adcore.cpp \
|
adcore.cpp \
|
||||||
player.cpp \
|
player.cpp \
|
||||||
settreader.cpp
|
settreader.cpp \
|
||||||
|
loader.cpp
|
||||||
RESOURCES += images.qrc
|
RESOURCES += images.qrc
|
||||||
OTHER_FILES += map.conf \
|
OTHER_FILES += map.conf \
|
||||||
example16x16.map \
|
example16x16.map \
|
||||||
example16x12.map
|
example16x12.map \
|
||||||
|
data.xml \
|
||||||
|
schema.xml \
|
||||||
|
example16x16_64.map
|
||||||
|
QT += core \
|
||||||
|
gui \
|
||||||
|
network \
|
||||||
|
opengl \
|
||||||
|
xml \
|
||||||
|
xmlpatterns
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
<value key="QtVersionId" type="int">2</value>
|
<value key="QtVersionId" type="int">2</value>
|
||||||
<value key="ToolChain" type="int">0</value>
|
<value key="ToolChain" type="int">0</value>
|
||||||
|
<value key="addQDumper" type=""></value>
|
||||||
<value key="buildConfiguration" type="int">2</value>
|
<value key="buildConfiguration" type="int">2</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
</data>
|
</data>
|
||||||
@@ -66,7 +67,7 @@
|
|||||||
<valuemap type="QVariantMap">
|
<valuemap type="QVariantMap">
|
||||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
||||||
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-oJVJLhEuxX,guid=dd326939f06256af8e013dce4c50f54e</value>
|
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-5i8Go7nPio,guid=870ffe971971ceac89206f0e4c5facbd</value>
|
||||||
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
|
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
|
||||||
<value type="QString">DESKTOP_SESSION=gnome</value>
|
<value type="QString">DESKTOP_SESSION=gnome</value>
|
||||||
<value type="QString">DISPLAY=:0.0</value>
|
<value type="QString">DISPLAY=:0.0</value>
|
||||||
@@ -74,7 +75,7 @@
|
|||||||
<value type="QString">GDM_KEYBOARD_LAYOUT=us</value>
|
<value type="QString">GDM_KEYBOARD_LAYOUT=us</value>
|
||||||
<value type="QString">GDM_LANG=ru_RU.UTF-8</value>
|
<value type="QString">GDM_LANG=ru_RU.UTF-8</value>
|
||||||
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
|
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
|
||||||
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-UECX54</value>
|
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-7vXnOW</value>
|
||||||
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
|
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
|
||||||
<value type="QString">HOME=/home/andrey</value>
|
<value type="QString">HOME=/home/andrey</value>
|
||||||
<value type="QString">LANG=ru_RU.UTF-8</value>
|
<value type="QString">LANG=ru_RU.UTF-8</value>
|
||||||
@@ -85,17 +86,17 @@
|
|||||||
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
|
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
|
||||||
<value type="QString">PWD=/home/andrey</value>
|
<value type="QString">PWD=/home/andrey</value>
|
||||||
<value type="QString">QTDIR=/usr/share/qt4</value>
|
<value type="QString">QTDIR=/usr/share/qt4</value>
|
||||||
<value type="QString">SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1144,unix/buull-eeePC:/tmp/.ICE-unix/1144</value>
|
<value type="QString">SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1124,unix/buull-eeePC:/tmp/.ICE-unix/1124</value>
|
||||||
<value type="QString">SHELL=/bin/bash</value>
|
<value type="QString">SHELL=/bin/bash</value>
|
||||||
<value type="QString">SPEECHD_PORT=6561</value>
|
<value type="QString">SPEECHD_PORT=6561</value>
|
||||||
<value type="QString">SSH_AGENT_PID=1178</value>
|
<value type="QString">SSH_AGENT_PID=1158</value>
|
||||||
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-UECX54/ssh</value>
|
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-7vXnOW/ssh</value>
|
||||||
<value type="QString">USER=andrey</value>
|
<value type="QString">USER=andrey</value>
|
||||||
<value type="QString">USERNAME=andrey</value>
|
<value type="QString">USERNAME=andrey</value>
|
||||||
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-andrey-SArBRZ/database</value>
|
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-andrey-HWCXAG/database</value>
|
||||||
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
|
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
|
||||||
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
|
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
|
||||||
<value type="QString">XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1280374094.93008-1317282182</value>
|
<value type="QString">XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1281338556.676663-803309736</value>
|
||||||
</valuelist>
|
</valuelist>
|
||||||
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
||||||
<value type="QString">/home/andrey/AD/aliendefender/aliendefender.pro</value>
|
<value type="QString">/home/andrey/AD/aliendefender/aliendefender.pro</value>
|
||||||
@@ -114,7 +115,7 @@
|
|||||||
<valuemap type="QVariantMap">
|
<valuemap type="QVariantMap">
|
||||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
||||||
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-oJVJLhEuxX,guid=dd326939f06256af8e013dce4c50f54e</value>
|
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-5i8Go7nPio,guid=870ffe971971ceac89206f0e4c5facbd</value>
|
||||||
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
|
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
|
||||||
<value type="QString">DESKTOP_SESSION=gnome</value>
|
<value type="QString">DESKTOP_SESSION=gnome</value>
|
||||||
<value type="QString">DISPLAY=:0.0</value>
|
<value type="QString">DISPLAY=:0.0</value>
|
||||||
@@ -122,7 +123,7 @@
|
|||||||
<value type="QString">GDM_KEYBOARD_LAYOUT=us</value>
|
<value type="QString">GDM_KEYBOARD_LAYOUT=us</value>
|
||||||
<value type="QString">GDM_LANG=ru_RU.UTF-8</value>
|
<value type="QString">GDM_LANG=ru_RU.UTF-8</value>
|
||||||
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
|
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
|
||||||
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-UECX54</value>
|
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-7vXnOW</value>
|
||||||
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
|
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
|
||||||
<value type="QString">HOME=/home/andrey</value>
|
<value type="QString">HOME=/home/andrey</value>
|
||||||
<value type="QString">LANG=ru_RU.UTF-8</value>
|
<value type="QString">LANG=ru_RU.UTF-8</value>
|
||||||
@@ -133,17 +134,17 @@
|
|||||||
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
|
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
|
||||||
<value type="QString">PWD=/home/andrey</value>
|
<value type="QString">PWD=/home/andrey</value>
|
||||||
<value type="QString">QTDIR=/usr/share/qt4</value>
|
<value type="QString">QTDIR=/usr/share/qt4</value>
|
||||||
<value type="QString">SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1144,unix/buull-eeePC:/tmp/.ICE-unix/1144</value>
|
<value type="QString">SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1124,unix/buull-eeePC:/tmp/.ICE-unix/1124</value>
|
||||||
<value type="QString">SHELL=/bin/bash</value>
|
<value type="QString">SHELL=/bin/bash</value>
|
||||||
<value type="QString">SPEECHD_PORT=6561</value>
|
<value type="QString">SPEECHD_PORT=6561</value>
|
||||||
<value type="QString">SSH_AGENT_PID=1178</value>
|
<value type="QString">SSH_AGENT_PID=1158</value>
|
||||||
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-UECX54/ssh</value>
|
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-7vXnOW/ssh</value>
|
||||||
<value type="QString">USER=andrey</value>
|
<value type="QString">USER=andrey</value>
|
||||||
<value type="QString">USERNAME=andrey</value>
|
<value type="QString">USERNAME=andrey</value>
|
||||||
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-andrey-SArBRZ/database</value>
|
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-andrey-HWCXAG/database</value>
|
||||||
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
|
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
|
||||||
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
|
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
|
||||||
<value type="QString">XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1280374094.93008-1317282182</value>
|
<value type="QString">XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1281338556.676663-803309736</value>
|
||||||
</valuelist>
|
</valuelist>
|
||||||
<value key="abstractProcess.IgnoreReturnValue" type="bool">false</value>
|
<value key="abstractProcess.IgnoreReturnValue" type="bool">false</value>
|
||||||
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
||||||
|
|||||||
48
aliens.cpp
48
aliens.cpp
@@ -7,17 +7,16 @@ Aliens::Aliens(Game_Data *gd, QObject *parent) :
|
|||||||
{
|
{
|
||||||
gameData = gd;
|
gameData = gd;
|
||||||
nextId = 0;
|
nextId = 0;
|
||||||
Alien al;
|
|
||||||
al.speed = 0.1f;
|
|
||||||
al.health = 10;
|
|
||||||
al.type = 0;
|
|
||||||
gameData->srcAliens.push_back(al);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Aliens::AddAlien(int srcId)
|
void Aliens::AddAlien(int srcId)
|
||||||
{
|
{
|
||||||
if (srcId < 0 || srcId >= gameData->srcAliens.size()) qDebug("ERROR out of aliens range"),exit(-1);
|
if (srcId < 0 || srcId >= gameData->srcAliens.size())
|
||||||
|
{
|
||||||
|
qCritical("ERROR out of aliens range");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Alien al = gameData->srcAliens.at(srcId);
|
Alien al = gameData->srcAliens.at(srcId);
|
||||||
al.Id = nextId;
|
al.Id = nextId;
|
||||||
al.finish = gameData->map->finishs.at(qrand()%gameData->map->finishs.size());
|
al.finish = gameData->map->finishs.at(qrand()%gameData->map->finishs.size());
|
||||||
@@ -25,21 +24,21 @@ void Aliens::AddAlien(int srcId)
|
|||||||
al.pos = QPointF(gameData->map->starts.at(qrand()%gameData->map->starts.size()));
|
al.pos = QPointF(gameData->map->starts.at(qrand()%gameData->map->starts.size()));
|
||||||
al.path = gameData->map->CreatePath(al.pos.toPoint(),al.finish);
|
al.path = gameData->map->CreatePath(al.pos.toPoint(),al.finish);
|
||||||
al.pathIndex = 1;
|
al.pathIndex = 1;
|
||||||
if (al.path.isEmpty()) qDebug("ERROR create path"),exit(-1);
|
if (al.path.isEmpty()) qFatal("ERROR create path");
|
||||||
qDebug() << al.path;
|
qDebug() << al.path;
|
||||||
gameData->map->printMap();
|
//gameData->map->printMap();
|
||||||
|
gameData->curAliens.insert(al.Id,al);
|
||||||
nextId++;
|
nextId++;
|
||||||
gameData->curAliens.push_back(al);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Aliens::retrace(bool *OK)
|
void Aliens::retrace(bool *OK)
|
||||||
{
|
{
|
||||||
qDebug("retarce!");
|
qDebug("re-trace!");
|
||||||
gameData->map->removeAliensPath();
|
gameData->map->removeAliensPath();
|
||||||
for (int i=0; i<gameData->curAliens.size(); i++)
|
for (int i=0; i<gameData->curAliens.size(); i++)
|
||||||
{
|
{
|
||||||
Alien al = gameData->curAliens.at(i);
|
Alien al = gameData->curAliens.take(i);
|
||||||
al.path = gameData->map->CreatePath(al.pos.toPoint(),al.finish);
|
al.path = gameData->map->CreatePath(al.pos.toPoint(),al.finish);
|
||||||
al.pathIndex = 1;
|
al.pathIndex = 1;
|
||||||
if (al.path.isEmpty()) *OK = false;
|
if (al.path.isEmpty()) *OK = false;
|
||||||
@@ -47,33 +46,18 @@ void Aliens::retrace(bool *OK)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Aliens::DelAlien(int index)
|
void Aliens::DelAlien(int Id)
|
||||||
{
|
{
|
||||||
gameData->curAliens.remove(index);
|
gameData->curAliens.remove(Id);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Aliens::DelAlienById(int Id)
|
|
||||||
{
|
|
||||||
DelAlien(AlienIndex(Id));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Aliens::AlienIndex(int alienId)
|
|
||||||
{
|
|
||||||
int i=-1;
|
|
||||||
for (i=0; i<gameData->curAliens.size(); i++)
|
|
||||||
if (gameData->curAliens.at(i).Id==alienId) return i;
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Aliens::update()
|
void Aliens::update()
|
||||||
{
|
{
|
||||||
QVector <int> missIndex;
|
QList <int> missIndex;
|
||||||
for (int i=0; i<gameData->curAliens.size(); i++)
|
for (int i=0; i<gameData->curAliens.size(); i++)
|
||||||
{
|
{
|
||||||
Alien al = gameData->curAliens.at(i);
|
Alien al = gameData->curAliens.values().at(i);
|
||||||
//qDebug() << i;
|
//qDebug() << i;
|
||||||
//if (al.health < 0) emit AlienKill();
|
//if (al.health < 0) emit AlienKill();
|
||||||
float tmpdx,tmpdy,angl,arctg = 0;
|
float tmpdx,tmpdy,angl,arctg = 0;
|
||||||
@@ -117,11 +101,11 @@ void Aliens::update()
|
|||||||
al.pos.setY(al.pos.y()
|
al.pos.setY(al.pos.y()
|
||||||
-al.speed*std::cos(arctg));
|
-al.speed*std::cos(arctg));
|
||||||
//return true;
|
//return true;
|
||||||
gameData->curAliens[i] = al;
|
gameData->curAliens[al.Id] = al;
|
||||||
}
|
}
|
||||||
for (int j=0; j<missIndex.size(); j++)
|
for (int j=0; j<missIndex.size(); j++)
|
||||||
{
|
{
|
||||||
gameData->missingAliens++;
|
gameData->missingAliens++;
|
||||||
DelAlienById(missIndex.at(j));
|
DelAlien(missIndex.at(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
aliens.h
4
aliens.h
@@ -14,13 +14,11 @@ public:
|
|||||||
void AddAlien(int srcId);
|
void AddAlien(int srcId);
|
||||||
void nextWave();
|
void nextWave();
|
||||||
void update();
|
void update();
|
||||||
int AlienIndex(int alienId);
|
|
||||||
int size() const {return gameData->curAliens.size();}
|
int size() const {return gameData->curAliens.size();}
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void DelAlienById(int Id);
|
void DelAlien(int Id);
|
||||||
void DelAlien(int index);
|
|
||||||
void retrace(bool * OK);
|
void retrace(bool * OK);
|
||||||
private:
|
private:
|
||||||
Game_Data * gameData;
|
Game_Data * gameData;
|
||||||
|
|||||||
19
base_types.h
19
base_types.h
@@ -2,11 +2,13 @@
|
|||||||
#define BASE_TYPES_H
|
#define BASE_TYPES_H
|
||||||
|
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
|
#include <QList>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
struct Alien
|
struct Alien
|
||||||
{
|
{
|
||||||
int Id;
|
int Id; // uses for QHash
|
||||||
|
QString name;
|
||||||
int type;
|
int type;
|
||||||
QPointF pos;
|
QPointF pos;
|
||||||
float angle; // -180 .. 180
|
float angle; // -180 .. 180
|
||||||
@@ -15,19 +17,19 @@ struct Alien
|
|||||||
QPoint finish;
|
QPoint finish;
|
||||||
QVector <QPointF> path;
|
QVector <QPointF> path;
|
||||||
int pathIndex;
|
int pathIndex;
|
||||||
unsigned int gold;
|
unsigned int prise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct Tower
|
struct Tower
|
||||||
{
|
{
|
||||||
int Id;
|
QString name;
|
||||||
int type;
|
int type;
|
||||||
int AlienId; // aim alien
|
int AlienId; // aim alien
|
||||||
int PlayerId; // tower's owner
|
int PlayerId; // tower's owner
|
||||||
QPoint pos; // not QPointF because tower fixed on grid
|
QPoint pos; // not QPointF because tower fixed on grid
|
||||||
float angle; // -180 .. 180
|
float angle; // -180 .. 180
|
||||||
float range;
|
float range; // in cells
|
||||||
float reload; // time for reload in ticks
|
float reload; // time for reload in ticks
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,11 +37,12 @@ struct Tower
|
|||||||
struct Splash
|
struct Splash
|
||||||
{
|
{
|
||||||
int Id;
|
int Id;
|
||||||
|
QString name;
|
||||||
int type;
|
int type;
|
||||||
int TowerId; // parent tower
|
QPoint TowerId; // parent tower (-1;-1) for null parent
|
||||||
int AlienId; // aim alien (different from tower.AlienId)
|
int AlienId; // aim alien (different from tower.AlienId)
|
||||||
int lifetime; // in ticks
|
int lifetime; // in ticks
|
||||||
float radius;
|
float radius; // in cells
|
||||||
float angle; // -180 .. 180
|
float angle; // -180 .. 180
|
||||||
QPointF pos;
|
QPointF pos;
|
||||||
};
|
};
|
||||||
@@ -48,8 +51,8 @@ struct Splash
|
|||||||
struct Wave
|
struct Wave
|
||||||
{
|
{
|
||||||
int Id;
|
int Id;
|
||||||
QVector <int> types; // some types of aliens (e.g. 2 fly and 3 grount in one wave)
|
QList <int> types; // some types of aliens (e.g. 2 fly and 3 grount in one wave)
|
||||||
QVector <int> counts; // count aliens of each type
|
QList <int> counts; // count aliens of each type
|
||||||
int wait_time; // time in ticks
|
int wait_time; // time in ticks
|
||||||
unsigned int gold;
|
unsigned int gold;
|
||||||
};
|
};
|
||||||
|
|||||||
27
data.xml
Normal file
27
data.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<!DOCTYPE data>
|
||||||
|
<ADdata>
|
||||||
|
<aliens>
|
||||||
|
<alien speed="0.012" imageType="1" prise="0" id="10" name="my alien" health="100"/>
|
||||||
|
<alien speed="0.0099" imageType="1" prise="1" id="12" name="MONSTR" health="200" armor="1.5" regeneration="3"/>
|
||||||
|
</aliens>
|
||||||
|
<maps>
|
||||||
|
<map imageType="1" id="1" data="AAAERHicY2BgEGAA4v///0hQgmFmAGlGcjCxZuCTHzUDuxkMDOr85JrBwKC0A8kMJlwYagYOeYgZ+NXgNwMtPEbNINIMIsynOO8DAG0r1Q0=" name="Map 16x16" maxPlayers="2"/>
|
||||||
|
</maps>
|
||||||
|
<waves>
|
||||||
|
<wave id="1" timeout="20000" prise="100"/>
|
||||||
|
<wave id="2" timeout="20000" prise="200"/>
|
||||||
|
</waves>
|
||||||
|
<levels>
|
||||||
|
<level id="1" map="1" name="First Level"/>
|
||||||
|
</levels>
|
||||||
|
<waveParts>
|
||||||
|
<wavePart wave="1" alien="10" count="4"/>
|
||||||
|
<wavePart wave="1" alien="12" count="5"/>
|
||||||
|
<wavePart wave="1" alien="10" count="10"/>
|
||||||
|
<wavePart wave="2" alien="10" count="9"/>
|
||||||
|
</waveParts>
|
||||||
|
<wavesOnLevels>
|
||||||
|
<waveOnLevel wave="1" level="1"/>
|
||||||
|
<waveOnLevel level="1" wave="2"/>
|
||||||
|
</wavesOnLevels>
|
||||||
|
</ADdata>
|
||||||
1
example16x16_64.map
Normal file
1
example16x16_64.map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
AAAERHicY2BgEGAA4v///0hQgmFmAGlGcjCxZuCTHzUDuxkMDOr85JrBwKC0A8kMJlwYagYOeYgZ+NXgNwMtPEbNINIMIsynOO8DAG0r1Q0=
|
||||||
14
game_data.h
14
game_data.h
@@ -2,6 +2,7 @@
|
|||||||
#define GAME_DATA_H
|
#define GAME_DATA_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
@@ -10,12 +11,13 @@ class Game_Data : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Game_Data(Map * map, QObject *parent = 0);
|
explicit Game_Data(Map * map, QObject *parent = 0);
|
||||||
QVector <Alien> srcAliens;
|
QList <Alien> srcAliens;
|
||||||
QVector <Alien> curAliens;
|
QList <Tower> srcTowers;
|
||||||
QVector <Tower> curTowers;
|
QHash <int,Alien> curAliens;
|
||||||
QVector <Splash> curSplashes;
|
QHash <QPoint,Tower> curTowers;
|
||||||
QVector <Wave> waves;
|
QHash <int,Splash> curSplashes;
|
||||||
QVector <Player *> players;
|
QList <Wave> waves;
|
||||||
|
QList <Player *> players;
|
||||||
Map * map;
|
Map * map;
|
||||||
int curWave;
|
int curWave;
|
||||||
int missingAliens;
|
int missingAliens;
|
||||||
|
|||||||
401
loader.cpp
Normal file
401
loader.cpp
Normal file
@@ -0,0 +1,401 @@
|
|||||||
|
#include "loader.h"
|
||||||
|
|
||||||
|
Loader::Loader(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
doc = new QDomDocument("data");
|
||||||
|
//create();
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::load()
|
||||||
|
{
|
||||||
|
validate();
|
||||||
|
file = new QFile("data.xml");
|
||||||
|
if (!file->open(QIODevice::ReadOnly))
|
||||||
|
qFatal("No file data.xml found!");
|
||||||
|
if (!doc->setContent(file))
|
||||||
|
{
|
||||||
|
file->close();
|
||||||
|
qFatal("Error parsing data.xml");
|
||||||
|
}
|
||||||
|
readAliens();
|
||||||
|
readMaps();
|
||||||
|
readLevels();
|
||||||
|
//readMorphs();
|
||||||
|
//readSplashes();
|
||||||
|
//readTowers();
|
||||||
|
//readLevTowers();
|
||||||
|
//readTriggers();
|
||||||
|
readWaves();
|
||||||
|
readWaveParts();
|
||||||
|
readLevWaves();
|
||||||
|
|
||||||
|
file->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::create()
|
||||||
|
{
|
||||||
|
QFile cfile("data.xml");
|
||||||
|
if (!cfile.open(QIODevice::WriteOnly))
|
||||||
|
return;
|
||||||
|
cfile.resize(0);
|
||||||
|
// if (!doc.setContent(&file)) {
|
||||||
|
// file.close();
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
QDomElement elem;
|
||||||
|
QDomElement root = doc->createElement("ADdata");
|
||||||
|
doc->appendChild(root);
|
||||||
|
QDomElement child = doc->createElement("aliens");
|
||||||
|
root.appendChild(child);
|
||||||
|
elem = doc->createElement("alien");
|
||||||
|
child.appendChild(elem);
|
||||||
|
elem.setAttribute("name","my alien");
|
||||||
|
elem.setAttribute("speed",0.012);
|
||||||
|
elem.setAttribute("health",100);
|
||||||
|
elem.setAttribute("prise",0);
|
||||||
|
elem.setAttribute("id",10);
|
||||||
|
elem.setAttribute("imageType",1);
|
||||||
|
elem = doc->createElement("alien");
|
||||||
|
child.appendChild(elem);
|
||||||
|
elem.setAttribute("name","MONSTR");
|
||||||
|
elem.setAttribute("speed",0.0099);
|
||||||
|
elem.setAttribute("health",200);
|
||||||
|
elem.setAttribute("prise",1);
|
||||||
|
elem.setAttribute("id",12);
|
||||||
|
elem.setAttribute("imageType",1);
|
||||||
|
child = doc->createElement("towers");
|
||||||
|
root.appendChild(child);
|
||||||
|
elem = doc->createElement("tower");
|
||||||
|
child.appendChild(elem);
|
||||||
|
elem.setAttribute("name","my tower");
|
||||||
|
elem.setAttribute("imageType",1);
|
||||||
|
elem.setAttribute("reload",20);
|
||||||
|
elem.setAttribute("buildTime",100);
|
||||||
|
elem.setAttribute("price",10);
|
||||||
|
elem.setAttribute("radius",1.2);
|
||||||
|
elem.setAttribute("splashType",0);
|
||||||
|
elem.setAttribute("id",0);
|
||||||
|
elem = doc->createElement("tower");
|
||||||
|
child.appendChild(elem);
|
||||||
|
elem.setAttribute("name","Wall");
|
||||||
|
elem.setAttribute("imageType",1);
|
||||||
|
elem.setAttribute("buildTime",300);
|
||||||
|
elem.setAttribute("reload",0);
|
||||||
|
elem.setAttribute("price",9);
|
||||||
|
elem.setAttribute("radius",0);
|
||||||
|
elem.setAttribute("splashType",0);
|
||||||
|
elem.setAttribute("id",1);
|
||||||
|
child = doc->createElement("maps");
|
||||||
|
root.appendChild(child);
|
||||||
|
elem = doc->createElement("map");
|
||||||
|
child.appendChild(elem);
|
||||||
|
elem.setAttribute("name","Map 16x16");
|
||||||
|
elem.setAttribute("maxPlayers","2");
|
||||||
|
elem.setAttribute("id",1);
|
||||||
|
elem.setAttribute("imageType",1);
|
||||||
|
elem.setAttribute("data",CreateMapExample());
|
||||||
|
child = doc->createElement("splashes");
|
||||||
|
root.appendChild(child);
|
||||||
|
elem = doc->createElement("splash");
|
||||||
|
child.appendChild(elem);
|
||||||
|
elem.setAttribute("name","shot");
|
||||||
|
elem.setAttribute("imageType",1);
|
||||||
|
elem.setAttribute("damage",2.5);
|
||||||
|
elem.setAttribute("speed",100);
|
||||||
|
elem.setAttribute("autoControl","true");
|
||||||
|
elem.setAttribute("radius",1.2);
|
||||||
|
elem.setAttribute("id",0);
|
||||||
|
|
||||||
|
cfile.write(doc->toByteArray());
|
||||||
|
cfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString Loader::CreateMapExample()
|
||||||
|
{
|
||||||
|
QVector < QVector < int > > Cells;
|
||||||
|
Cells.resize(16);
|
||||||
|
for (int i=0; i<Cells.size(); i++)
|
||||||
|
{
|
||||||
|
Cells[i].resize(16);
|
||||||
|
Cells[i][0]=Map::Wall;
|
||||||
|
Cells[i][Cells[i].size()-1]=Map::Wall;
|
||||||
|
}
|
||||||
|
for (int i=0; i<Cells.size(); i++)
|
||||||
|
{
|
||||||
|
for (int j=0; j<Cells[i].size(); j++)
|
||||||
|
{
|
||||||
|
Cells[0][j]=Map::Wall;
|
||||||
|
Cells[Cells.size()-1][j]=Map::Wall;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i=1; i<Cells.size()/2; i++)
|
||||||
|
for (int j=1; j<Cells[i].size()-1; j++)
|
||||||
|
Cells[i][j]=Map::Player;
|
||||||
|
for (int i=Cells.size()/2; i<Cells.size()-1; i++)
|
||||||
|
for (int j=1; j<Cells[i].size()-1; j++)
|
||||||
|
Cells[i][j]=Map::Player+1;
|
||||||
|
for (int i=2; i<Cells.size()-2; i++)
|
||||||
|
Cells[i][Cells[i].size()/2] = Map::Wall;
|
||||||
|
Cells[Cells.size()/2][0]=Map::Start;
|
||||||
|
Cells[Cells.size()/2-1][0]=Map::Start;
|
||||||
|
Cells[Cells.size()/2][Cells[Cells.size()/2].size()-1]=Map::Finish;
|
||||||
|
Cells[Cells.size()/2-1][Cells[Cells.size()/2].size()-1]=Map::Finish;
|
||||||
|
QByteArray ba;
|
||||||
|
QDataStream tmps(&ba,QIODevice::ReadWrite);
|
||||||
|
tmps << Cells;
|
||||||
|
ba = qCompress(ba);
|
||||||
|
ba = ba.toBase64();
|
||||||
|
QString str(ba);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::readAliens()
|
||||||
|
{
|
||||||
|
QDomNodeList alelems = doc->elementsByTagName("alien");
|
||||||
|
for (int i=0; i<alelems.size(); i++)
|
||||||
|
{
|
||||||
|
tbAlien al;
|
||||||
|
QDomNamedNodeMap nm = alelems.at(i).attributes();
|
||||||
|
al.id = nm.namedItem("id").nodeValue().toInt();
|
||||||
|
if (aliens.contains(al.id)) qCritical("Same alien ID dedected, replacing...");
|
||||||
|
al.name = nm.namedItem("name").nodeValue();
|
||||||
|
al.speed = nm.namedItem("speed").nodeValue().toFloat();
|
||||||
|
al.health = nm.namedItem("health").nodeValue().toFloat();
|
||||||
|
al.prise = nm.namedItem("prise").nodeValue().toInt();
|
||||||
|
al.armor = nm.namedItem("armor").nodeValue().toFloat();
|
||||||
|
al.imgType = nm.namedItem("imageType").nodeValue().toInt();
|
||||||
|
al.regeneration = nm.namedItem("regeneration").nodeValue().toFloat();
|
||||||
|
aliens.insert(al.id,al);
|
||||||
|
qDebug() << tr("Alien %1 id=%2 health=%3 speed=%4 prise=%5 imgType=%6 armor=%7 regeneration=%8").arg(al.name).arg(al.id).arg(al.health).arg(al.speed).arg(al.prise).arg(al.imgType).arg(al.armor).arg(al.regeneration);
|
||||||
|
}
|
||||||
|
qDebug("================");
|
||||||
|
qDebug() << tr("Found %1 aliens").arg(aliens.size());
|
||||||
|
qDebug("================");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::readWaves()
|
||||||
|
{
|
||||||
|
QDomNodeList welems = doc->elementsByTagName("wave");
|
||||||
|
for (int i=0; i<welems.size(); i++)
|
||||||
|
{
|
||||||
|
tbWave w;
|
||||||
|
QDomNamedNodeMap nm = welems.at(i).attributes();
|
||||||
|
w.id = nm.namedItem("id").nodeValue().toInt();
|
||||||
|
if (waves.contains(w.id)) qCritical("Same wave ID dedected, replacing...");
|
||||||
|
w.prise = nm.namedItem("prise").nodeValue().toInt();
|
||||||
|
w.timeout = nm.namedItem("timeout").nodeValue().toInt();
|
||||||
|
waves.insert(w.id,w);
|
||||||
|
qDebug() << tr("Wave %1 prise=%2 timeout=%3").arg(w.id).arg(w.prise).arg(w.timeout);
|
||||||
|
}
|
||||||
|
qDebug("================");
|
||||||
|
qDebug() << tr("Found %1 waves").arg(waves.size());
|
||||||
|
qDebug("================");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::readWaveParts()
|
||||||
|
{
|
||||||
|
QDomNodeList wpelems = doc->elementsByTagName("wavePart");
|
||||||
|
for (int i=0; i<wpelems.size(); i++)
|
||||||
|
{
|
||||||
|
bool OK = true;
|
||||||
|
tbWavePart wp;
|
||||||
|
QDomNamedNodeMap nm = wpelems.at(i).attributes();
|
||||||
|
wp.waveId = nm.namedItem("wave").nodeValue().toInt();
|
||||||
|
if (!waves.contains(wp.waveId))
|
||||||
|
{
|
||||||
|
qCritical("invalid wave Id");
|
||||||
|
OK = false;
|
||||||
|
}
|
||||||
|
wp.alienId = nm.namedItem("alien").nodeValue().toInt();
|
||||||
|
if (!aliens.contains(wp.alienId))
|
||||||
|
{
|
||||||
|
qCritical("invalid alien Id");
|
||||||
|
OK = false;
|
||||||
|
}
|
||||||
|
wp.count = nm.namedItem("count").nodeValue().toInt();
|
||||||
|
if (OK)
|
||||||
|
{
|
||||||
|
waveParts.insert(wp.waveId,wp);
|
||||||
|
qDebug() << tr("Wave=%1 alien=%2 count=%3").arg(wp.waveId).arg(wp.alienId).arg(wp.count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug("================");
|
||||||
|
qDebug() << tr("Found %1 waveParts").arg(waveParts.size());
|
||||||
|
qDebug("================");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::readLevWaves()
|
||||||
|
{
|
||||||
|
QDomNodeList lwelems = doc->elementsByTagName("waveOnLevel");
|
||||||
|
for (int i=0; i<lwelems.size(); i++)
|
||||||
|
{
|
||||||
|
bool OK = true;
|
||||||
|
tbWaveOnLevel lw;
|
||||||
|
QDomNamedNodeMap nm = lwelems.at(i).attributes();
|
||||||
|
lw.levelId= nm.namedItem("level").nodeValue().toInt();
|
||||||
|
if (!levels.contains(lw.levelId))
|
||||||
|
{
|
||||||
|
qCritical("invalid level Id");
|
||||||
|
OK = false;
|
||||||
|
}
|
||||||
|
lw.waveId = nm.namedItem("wave").nodeValue().toInt();
|
||||||
|
if (!waves.contains(lw.waveId))
|
||||||
|
{
|
||||||
|
qCritical("invalid wave Id");
|
||||||
|
OK = false;
|
||||||
|
}
|
||||||
|
if (OK)
|
||||||
|
{
|
||||||
|
levWaves.insert(lw.levelId,lw);
|
||||||
|
qDebug() << tr("level=%1 wave=%2").arg(lw.levelId).arg(lw.waveId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug("================");
|
||||||
|
qDebug() << tr("Found %1 Waves On Level").arg(levWaves.size());
|
||||||
|
qDebug("================");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::readLevels()
|
||||||
|
{
|
||||||
|
QDomNodeList lelems = doc->elementsByTagName("level");
|
||||||
|
for (int i=0; i<lelems.size(); i++)
|
||||||
|
{
|
||||||
|
bool OK = true;
|
||||||
|
tbLevel l;
|
||||||
|
QDomNamedNodeMap nm = lelems.at(i).attributes();
|
||||||
|
l.id = nm.namedItem("id").nodeValue().toInt();
|
||||||
|
l.name = nm.namedItem("name").nodeValue();
|
||||||
|
if (levels.contains(l.id)) qCritical("Same wave ID dedected, replacing...");
|
||||||
|
l.mapId = nm.namedItem("map").nodeValue().toInt();
|
||||||
|
if (!maps.contains(l.mapId))
|
||||||
|
{
|
||||||
|
qCritical("invalid map Id");
|
||||||
|
OK = false;
|
||||||
|
}
|
||||||
|
if (OK)
|
||||||
|
{
|
||||||
|
levels.insert(l.id,l);
|
||||||
|
qDebug() << tr("Level %1 id=%2 map=%3 ").arg(l.name).arg(l.id).arg(l.mapId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug("================");
|
||||||
|
qDebug() << tr("Found %1 levels").arg(levels.size());
|
||||||
|
qDebug("================");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::readSplashes()
|
||||||
|
{
|
||||||
|
QString str;
|
||||||
|
QDomNodeList selems = doc->elementsByTagName("splash");
|
||||||
|
for (int i=0; i<selems.size(); i++)
|
||||||
|
{
|
||||||
|
tbSplash s;
|
||||||
|
// s.id = selems.at(i).attributes().namedItem("id").nodeValue().toInt();
|
||||||
|
// if (splashes.contains(s.id)) qCritical("Same splash ID dedected, replacing...");
|
||||||
|
// s.name = selems.at(i).attributes().namedItem("name").nodeValue();
|
||||||
|
// s.speed = selems.at(i).attributes().namedItem("speed").nodeValue().toFloat();
|
||||||
|
// s.radius = selems.at(i).attributes().namedItem("radius").nodeValue().toFloat();
|
||||||
|
// s.damage = selems.at(i).attributes().namedItem("damage").nodeValue().toFloat();
|
||||||
|
// s.timer = selems.at(i).attributes().namedItem("timer").nodeValue().toInt();
|
||||||
|
// s.lifetime = selems.at(i).attributes().namedItem("lifetime").nodeValue().toInt();
|
||||||
|
// s.imgType = selems.at(i).attributes().namedItem("imageType").nodeValue().toInt();
|
||||||
|
// str = selems.at(i).attributes().namedItem("autoControl").nodeValue();
|
||||||
|
// s.autoControl = (str == "true");
|
||||||
|
// str = selems.at(i).attributes().namedItem("triggerDeath").nodeValue();
|
||||||
|
// s.isDeadAfterTrigger = (str == "true");
|
||||||
|
// str = selems.at(i).attributes().namedItem("trigger").nodeValue();
|
||||||
|
// s.trigger = tbSplash::noTrigger;
|
||||||
|
// if (str == "onDestination")
|
||||||
|
// s.trigger = tbSplash::onDestination;
|
||||||
|
// if (str == "onTimer")
|
||||||
|
// s.trigger = tbSplash::onTimer;
|
||||||
|
// if (str == "onAlienInRadius")
|
||||||
|
// s.trigger = tbSplash::onAlienInRadius;
|
||||||
|
// splashes.insert(s.id,s);
|
||||||
|
// qDebug() << tr("Splash %1 id=%2 damage=%3 speed=%4 radius=%5 imgType=%6 ").arg(s.name).arg(s.id).arg(s.damage).arg(s.speed).arg(s.radius).arg(s.imgType) << tr("lifetime=%1 timer=%2 trigger=%3 autoControl=%4 triggerDeath=%5").arg(s.lifetime).arg(s.timer).arg(s.trigger).arg(s.autoControl).arg(s.isDeadAfterTrigger);
|
||||||
|
}
|
||||||
|
qDebug("================");
|
||||||
|
qDebug() << tr("Found %1 splashes").arg(splashes.size());
|
||||||
|
qDebug("================");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::readTowers()
|
||||||
|
{
|
||||||
|
QDomNodeList twelems = doc->elementsByTagName("tower");
|
||||||
|
for (int i=0; i<twelems.size(); i++)
|
||||||
|
{
|
||||||
|
tbTower tw;
|
||||||
|
tw.id = twelems.at(i).attributes().namedItem("id").nodeValue().toInt();
|
||||||
|
if (towers.contains(tw.id)) qCritical("Same tower ID dedected, replacing...");
|
||||||
|
tw.name = twelems.at(i).attributes().namedItem("name").nodeValue();
|
||||||
|
towers.insert(tw.id,tw);
|
||||||
|
qDebug() << tr("Tower %1 id=%2").arg(tw.name).arg(tw.id);
|
||||||
|
}
|
||||||
|
qDebug("================");
|
||||||
|
qDebug() << tr("Found %1 towers").arg(towers.size());
|
||||||
|
qDebug("================");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::readMaps()
|
||||||
|
{
|
||||||
|
QDomNodeList melems = doc->elementsByTagName("map");
|
||||||
|
for (int i=0; i<melems.size(); i++)
|
||||||
|
{
|
||||||
|
tbMap m;
|
||||||
|
QDomNamedNodeMap mn = melems.at(i).attributes();
|
||||||
|
m.id = mn.namedItem("id").nodeValue().toInt();
|
||||||
|
if (maps.contains(m.id)) qCritical("Same map ID dedected, replacing...");
|
||||||
|
m.name = mn.namedItem("name").nodeValue();
|
||||||
|
m.imgType = mn.namedItem("imageType").nodeValue().toInt();
|
||||||
|
m.maxPlayers = mn.namedItem("maxPlayers").nodeValue().toInt();
|
||||||
|
QByteArray ba = QByteArray::fromBase64(mn.namedItem("data").nodeValue().toUtf8());
|
||||||
|
ba = qUncompress(ba);
|
||||||
|
QDataStream s(ba);
|
||||||
|
s >> m.cells;
|
||||||
|
maps.insert(m.id,m);
|
||||||
|
qDebug() << tr("Map %1 id=%2 imgType=%3 maxPlayers=%5").arg(m.name).arg(m.id).arg(m.imgType).arg(m.maxPlayers);
|
||||||
|
for (int k=0; k<m.cells.size(); k++) qDebug()<<m.cells.at(k);
|
||||||
|
}
|
||||||
|
qDebug("================");
|
||||||
|
qDebug() << tr("Found %1 maps").arg(maps.size());
|
||||||
|
qDebug("================");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Loader::validate()
|
||||||
|
{
|
||||||
|
QFile sfile("schema.xml");
|
||||||
|
if (!sfile.open(QIODevice::ReadOnly))
|
||||||
|
qFatal("No file schema.xml found!");
|
||||||
|
QXmlSchema schema;
|
||||||
|
if (!schema.load(&sfile))
|
||||||
|
qFatal("Error parsing schema.xml");
|
||||||
|
if (!schema.isValid())
|
||||||
|
qFatal("Invalid XMLSchema in schema.xml");
|
||||||
|
QXmlSchemaValidator sval(schema);
|
||||||
|
QFile dfile("data.xml");
|
||||||
|
if (!dfile.open(QIODevice::ReadOnly))
|
||||||
|
qFatal("No file data.xml found!");
|
||||||
|
if (!sval.validate(&dfile))
|
||||||
|
qFatal("Validation failure!");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sfile.close();
|
||||||
|
dfile.close();
|
||||||
|
qDebug("Validation SUCSESS!!!");
|
||||||
|
qDebug("================");
|
||||||
|
}
|
||||||
|
}
|
||||||
164
loader.h
Normal file
164
loader.h
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
#ifndef LOADER_H
|
||||||
|
#define LOADER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QDomDocument>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QXmlSchema>
|
||||||
|
#include <QXmlSchemaValidator>
|
||||||
|
#include "game_data.h"
|
||||||
|
|
||||||
|
struct tbAlien
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
QString name;
|
||||||
|
float speed;
|
||||||
|
float health;
|
||||||
|
float armor;
|
||||||
|
float regeneration;
|
||||||
|
int imgType;
|
||||||
|
unsigned int prise;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tbSplash
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
QString name;
|
||||||
|
float speed;
|
||||||
|
float radius;
|
||||||
|
unsigned int lifetime;
|
||||||
|
bool autoControl;
|
||||||
|
int imgType;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tbTrigger
|
||||||
|
{
|
||||||
|
enum triggerType
|
||||||
|
{
|
||||||
|
onDestination,
|
||||||
|
onTimer,
|
||||||
|
onAlienInRadius
|
||||||
|
};
|
||||||
|
int id;
|
||||||
|
float damage;
|
||||||
|
triggerType type;
|
||||||
|
unsigned int timer;
|
||||||
|
int count;
|
||||||
|
float randomPosRadius;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tbTower
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
QString name;
|
||||||
|
float radius;
|
||||||
|
unsigned int price;
|
||||||
|
unsigned int reload;
|
||||||
|
unsigned int buildTime;
|
||||||
|
float expByShot;
|
||||||
|
float expByKill;
|
||||||
|
float expByDamage;
|
||||||
|
int splashId;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tbMorph
|
||||||
|
{
|
||||||
|
int fromId;
|
||||||
|
int toId;
|
||||||
|
int cost;
|
||||||
|
float expRequired;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tbWavePart
|
||||||
|
{
|
||||||
|
int waveId;
|
||||||
|
int alienId;
|
||||||
|
unsigned int count;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tbWave
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
unsigned int timeout;
|
||||||
|
unsigned int prise;
|
||||||
|
int type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tbWaveOnLevel
|
||||||
|
{
|
||||||
|
int levelId;
|
||||||
|
int waveId;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tbMap
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
QString name;
|
||||||
|
unsigned int maxPlayers;
|
||||||
|
QVector < QVector <int> > cells;
|
||||||
|
int imgType;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tbTowerOnLevel
|
||||||
|
{
|
||||||
|
int levelId;
|
||||||
|
int towerId;
|
||||||
|
int enableWaveId;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tbLevel
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
QString name;
|
||||||
|
int mapId;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Loader : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Loader(QObject *parent = 0);
|
||||||
|
void create();
|
||||||
|
void reload();
|
||||||
|
void loadlevel(Game_Data * gd);
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
QDomDocument * doc;
|
||||||
|
QFile * file;
|
||||||
|
|
||||||
|
QHash <int,tbAlien> aliens;
|
||||||
|
QHash <int,tbMap> maps;
|
||||||
|
QHash <int,tbLevel> levels;
|
||||||
|
QHash <int,tbMorph> morphs;
|
||||||
|
QHash <int,tbSplash> splashes;
|
||||||
|
QHash <int,tbTower> towers;
|
||||||
|
QHash <int,tbTowerOnLevel> levTowers;
|
||||||
|
QHash <int,tbTrigger> triggers;
|
||||||
|
QHash <int,tbWave> waves;
|
||||||
|
QMultiHash <int,tbWaveOnLevel> levWaves;
|
||||||
|
QMultiHash <int,tbWavePart> waveParts;
|
||||||
|
|
||||||
|
void readAliens();
|
||||||
|
void readMaps();
|
||||||
|
void readLevels();
|
||||||
|
void readMorphs();
|
||||||
|
void readSplashes();
|
||||||
|
void readTowers();
|
||||||
|
void readLevTowers();
|
||||||
|
void readTriggers();
|
||||||
|
void readWaves();
|
||||||
|
void readLevWaves();
|
||||||
|
void readWaveParts();
|
||||||
|
|
||||||
|
void validate();
|
||||||
|
void load();
|
||||||
|
QString CreateMapExample();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOADER_H
|
||||||
8
main.cpp
8
main.cpp
@@ -8,8 +8,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
adCore core;
|
adCore core;
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
QTimer * timer = new QTimer();
|
//QTimer * timer = new QTimer();
|
||||||
QObject::connect(timer,SIGNAL(timeout()),&core,SLOT(next()));
|
//QObject::connect(timer,SIGNAL(timeout()),&core,SLOT(next()));
|
||||||
timer->start(100);
|
//timer->start(100);
|
||||||
return a.exec();
|
//return a.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
28
map.cpp
28
map.cpp
@@ -4,7 +4,12 @@ Map::Map(int Id, QObject *parent) :
|
|||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
mapId=Id;
|
mapId=Id;
|
||||||
ReadSettings();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Map::load()
|
||||||
|
{
|
||||||
|
//ReadSettings();
|
||||||
//CreateMapExample();
|
//CreateMapExample();
|
||||||
for (int i=0; i<Cells.size(); i++)
|
for (int i=0; i<Cells.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -14,7 +19,7 @@ Map::Map(int Id, QObject *parent) :
|
|||||||
if (Cells[i][j]==Finish) finishs.push_back(QPoint(i,j));
|
if (Cells[i][j]==Finish) finishs.push_back(QPoint(i,j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (starts.isEmpty() || finishs.isEmpty()) qDebug("invalid map, not found start/finish"),exit(-1);
|
if (starts.isEmpty() || finishs.isEmpty()) qFatal("invalid map, not found start/finish");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -32,8 +37,8 @@ void Map::ReadSettings()
|
|||||||
{
|
{
|
||||||
mapsize.setWidth(Cells.size());
|
mapsize.setWidth(Cells.size());
|
||||||
mapsize.setHeight(Cells[0].size());
|
mapsize.setHeight(Cells[0].size());
|
||||||
qDebug() << "Map size" << mapsize;
|
//qDebug() << "Map size" << mapsize;
|
||||||
printMap();
|
//printMap();
|
||||||
} else qDebug("invalid size");
|
} else qDebug("invalid size");
|
||||||
delete f;
|
delete f;
|
||||||
delete sreader;
|
delete sreader;
|
||||||
@@ -128,10 +133,19 @@ void Map::CreateMapExample()
|
|||||||
Cells[Cells.size()/2-1][0]=Start;
|
Cells[Cells.size()/2-1][0]=Start;
|
||||||
Cells[Cells.size()/2][Cells[Cells.size()/2].size()-1]=Finish;
|
Cells[Cells.size()/2][Cells[Cells.size()/2].size()-1]=Finish;
|
||||||
Cells[Cells.size()/2-1][Cells[Cells.size()/2].size()-1]=Finish;
|
Cells[Cells.size()/2-1][Cells[Cells.size()/2].size()-1]=Finish;
|
||||||
QFile * f = new QFile("example16x16.map");
|
QFile * f = new QFile("example16x16_64.map");
|
||||||
f->open(QIODevice::ReadWrite);
|
f->open(QIODevice::ReadWrite);
|
||||||
QDataStream s(f);
|
f->resize(0);
|
||||||
s << Cells;
|
QByteArray ba;
|
||||||
|
QDataStream tmps(&ba,QIODevice::ReadWrite);
|
||||||
|
tmps << Cells;
|
||||||
|
ba = qCompress(ba);
|
||||||
|
ba = ba.toBase64();
|
||||||
|
QString str(ba);
|
||||||
|
// QDataStream s(f);
|
||||||
|
// s << ba;
|
||||||
|
f->write(str.toUtf8());
|
||||||
|
f->close();
|
||||||
delete f;
|
delete f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
map.h
15
map.h
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QVector>
|
#include <QList>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@@ -11,6 +11,8 @@
|
|||||||
#include "base_types.h"
|
#include "base_types.h"
|
||||||
#include "settreader.h"
|
#include "settreader.h"
|
||||||
|
|
||||||
|
// Maximum map is 65530 x 65530 because qHash may be repeat and towers has same Id
|
||||||
|
|
||||||
class Map : public QObject
|
class Map : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -37,10 +39,8 @@ public:
|
|||||||
// -1000 - it is wall or some place where you can't build
|
// -1000 - it is wall or some place where you can't build
|
||||||
|
|
||||||
QVector < QVector <int> > Cells;
|
QVector < QVector <int> > Cells;
|
||||||
QVector < QVector <int> > TmpCells;
|
QList <QPoint> starts;
|
||||||
QVector <QPoint> starts;
|
QList <QPoint> finishs;
|
||||||
QVector <QPoint> finishs;
|
|
||||||
QSize mapsize;
|
|
||||||
int maxPlayers;
|
int maxPlayers;
|
||||||
|
|
||||||
explicit Map(int Id, QObject *parent = 0);
|
explicit Map(int Id, QObject *parent = 0);
|
||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
void removeAliensPath();
|
void removeAliensPath();
|
||||||
QVector <QPointF> CreatePath(QPoint start, QPoint finish);
|
QVector <QPointF> CreatePath(QPoint start, QPoint finish);
|
||||||
QSize size() const {return mapsize;}
|
QSize size() const {return mapsize;}
|
||||||
void ReadSettings();
|
void load();
|
||||||
signals:
|
signals:
|
||||||
void RecreateAlienPath(bool * pathOK);
|
void RecreateAlienPath(bool * pathOK);
|
||||||
public slots:
|
public slots:
|
||||||
@@ -58,10 +58,13 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int mapId;
|
int mapId;
|
||||||
|
QSize mapsize;
|
||||||
|
QVector < QVector <int> > TmpCells;
|
||||||
|
|
||||||
QVector<QPoint> InvWaveTrace(QPoint finish, int cnt);
|
QVector<QPoint> InvWaveTrace(QPoint finish, int cnt);
|
||||||
int WaveTrace(QPoint start, QPoint finish);
|
int WaveTrace(QPoint start, QPoint finish);
|
||||||
void CreateMapExample();
|
void CreateMapExample();
|
||||||
|
void ReadSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAP_H
|
#endif // MAP_H
|
||||||
|
|||||||
4
player.h
4
player.h
@@ -12,8 +12,8 @@ public:
|
|||||||
explicit Player(int Id, QObject *parent = 0);
|
explicit Player(int Id, QObject *parent = 0);
|
||||||
unsigned long int adMoney;
|
unsigned long int adMoney;
|
||||||
int selectAlienId;
|
int selectAlienId;
|
||||||
QVector <Tower> srcTowers;
|
QList <Tower> srcTowers;
|
||||||
QVector <Splash> srcSplashes;
|
QList <Splash> srcSplashes;
|
||||||
int playerId;
|
int playerId;
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|||||||
158
schema.xml
Normal file
158
schema.xml
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||||
|
|
||||||
|
<xsd:element name="ADdata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:all>
|
||||||
|
<xsd:element name="aliens">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="alien" type="alienType" maxOccurs="unbounded"/>
|
||||||
|
</xsd:sequence>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="maps">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="map" type="mapType" maxOccurs="unbounded"/>
|
||||||
|
</xsd:sequence>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="waves">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="wave" type="waveType" maxOccurs="unbounded"/>
|
||||||
|
</xsd:sequence>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="waveParts">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="wavePart" type="wavePartType" maxOccurs="unbounded"/>
|
||||||
|
</xsd:sequence>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="wavesOnLevels">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="waveOnLevel" type="waveOnLevelType" maxOccurs="unbounded"/>
|
||||||
|
</xsd:sequence>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="levels">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="level" type="levelType" maxOccurs="unbounded"/>
|
||||||
|
</xsd:sequence>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:all>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
|
||||||
|
<xsd:complexType name="alienType">
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||||
|
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="speed" type="xsd:float" use="required"/>
|
||||||
|
<xsd:attribute name="health" type="xsd:float" use="required"/>
|
||||||
|
<xsd:attribute name="prise" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="imageType" type="xsd:integer" use="required"/>
|
||||||
|
<xsd:attribute name="armor" type="xsd:float" use="optional"/>
|
||||||
|
<xsd:attribute name="regeneration" type="xsd:float" use="optional"/>
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
<xsd:complexType name="splashType">
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||||
|
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="speed" type="xsd:float" use="required"/>
|
||||||
|
<xsd:attribute name="damage" type="xsd:float" use="required"/>
|
||||||
|
<xsd:attribute name="radius" type="xsd:float" use="required"/>
|
||||||
|
<xsd:attribute name="imageType" type="xsd:integer" use="required"/>
|
||||||
|
<xsd:attribute name="triggerDeath" type="xsd:boolean" use="optional"/>
|
||||||
|
<xsd:attribute name="autoControl" type="xsd:boolean" use="optional"/>
|
||||||
|
<xsd:attribute name="timer" type="xsd:positiveInteger" use="optional"/>
|
||||||
|
<xsd:attribute name="lifetime" type="xsd:positiveInteger" use="optional"/>
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
<xsd:complexType name="triggerType">
|
||||||
|
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="parentSplash" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="childSplash" type="xsd:nonNegativeInteger" use="optional"/>
|
||||||
|
<xsd:attribute name="count" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="randomPosRadius" type="xsd:float" use="optional"/>
|
||||||
|
<xsd:attribute name="type" use="optional">
|
||||||
|
<xsd:simpleType>
|
||||||
|
<xsd:restriction base="xsd:string">
|
||||||
|
<xsd:enumeration value="noTrigger"/>
|
||||||
|
<xsd:enumeration value="onDestination"/>
|
||||||
|
<xsd:enumeration value="onTimer"/>
|
||||||
|
<xsd:enumeration value="onAlienInRadius"/>
|
||||||
|
</xsd:restriction>
|
||||||
|
</xsd:simpleType>
|
||||||
|
</xsd:attribute>
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
|
||||||
|
<xsd:complexType name="towerType">
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||||
|
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="imageType" type="xsd:integer" use="required"/>
|
||||||
|
<xsd:attribute name="buildTime" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="price" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="splashType" type="xsd:integer" use="required"/>
|
||||||
|
<xsd:attribute name="reload" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="radius" type="xsd:float" use="required"/>
|
||||||
|
<xsd:attribute name="expByShot" type="xsd:float" use="optional"/>
|
||||||
|
<xsd:attribute name="expByKill" type="xsd:float" use="optional"/>
|
||||||
|
<xsd:attribute name="expByDamage" type="xsd:float" use="optional"/>
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
<xsd:complexType name="mapType">
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||||
|
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="maxPlayers" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="imageType" type="xsd:integer" use="required"/>
|
||||||
|
<xsd:attribute name="data" type="xsd:string" use="required"/>
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
<xsd:complexType name="morphType">
|
||||||
|
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="from" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="to" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="price" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="expRequired" type="xsd:float" use="required"/>
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
<xsd:complexType name="wavePartType">
|
||||||
|
<xsd:attribute name="alien" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="wave" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="count" type="xsd:positiveInteger" use="required"/>
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
<xsd:complexType name="waveType">
|
||||||
|
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="timeout" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="prise" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<!--xsd:attribute name="type" type="xsd:nonNegativeInteger" use="required"/!-->
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
<xsd:complexType name="waveOnLevelType">
|
||||||
|
<xsd:attribute name="level" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="wave" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
<xsd:complexType name="towerOnLevelType">
|
||||||
|
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="level" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="tower" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
<xsd:attribute name="enableWave" type="xsd:nonNegativeInteger" use="optional"/>
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
<xsd:complexType name="levelType">
|
||||||
|
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||||
|
<xsd:attribute name="map" type="xsd:nonNegativeInteger" use="required"/>
|
||||||
|
</xsd:complexType>
|
||||||
|
|
||||||
|
</xsd:schema>
|
||||||
|
|
||||||
37
towers.cpp
37
towers.cpp
@@ -4,7 +4,6 @@ Towers::Towers(Game_Data *gd, QObject *parent) :
|
|||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
gameData = gd;
|
gameData = gd;
|
||||||
nextId = 0;
|
|
||||||
Tower tw;
|
Tower tw;
|
||||||
for (int i=0; i<gameData->players.size(); i++)
|
for (int i=0; i<gameData->players.size(); i++)
|
||||||
gameData->players[i]->srcTowers.push_back(tw);
|
gameData->players[i]->srcTowers.push_back(tw);
|
||||||
@@ -12,42 +11,36 @@ Towers::Towers(Game_Data *gd, QObject *parent) :
|
|||||||
|
|
||||||
bool Towers::AddTower(int playerId, int srcId, QPoint pos)
|
bool Towers::AddTower(int playerId, int srcId, QPoint pos)
|
||||||
{
|
{
|
||||||
if (playerId < 0 || playerId >= gameData->players.size()) qDebug("ERROR out of players range"),exit(-1);
|
//QByteArray ar;
|
||||||
if (srcId < 0 || srcId >= gameData->players.at(playerId)->srcTowers.size()) qDebug("ERROR out of towers range"),exit(-1);
|
//ar << pos;
|
||||||
|
if (playerId < 0 || playerId >= gameData->players.size())
|
||||||
|
{
|
||||||
|
qCritical("ERROR out of players range");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (srcId < 0 || srcId >= gameData->players.at(playerId)->srcTowers.size())
|
||||||
|
{
|
||||||
|
qCritical("ERROR out of towers range");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Tower tw = gameData->players.at(playerId)->srcTowers.at(srcId);
|
Tower tw = gameData->players.at(playerId)->srcTowers.at(srcId);
|
||||||
tw.Id = nextId;
|
|
||||||
if (gameData->map->addTowerOnMap(playerId,pos))
|
if (gameData->map->addTowerOnMap(playerId,pos))
|
||||||
{
|
{
|
||||||
tw.pos = pos;
|
tw.pos = pos;
|
||||||
gameData->map->printMap();
|
gameData->map->printMap();
|
||||||
nextId++;
|
gameData->curTowers.insert(tw.pos,tw);
|
||||||
gameData->curTowers.push_back(tw);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Towers::DelTower(int index)
|
void Towers::DelTower(QPoint pos)
|
||||||
{
|
{
|
||||||
gameData->curTowers.remove(index);
|
gameData->curTowers.remove(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Towers::DelTowerById(int Id)
|
|
||||||
{
|
|
||||||
DelTower(TowerIndex(Id));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Towers::TowerIndex(int towerId)
|
|
||||||
{
|
|
||||||
int i=-1;
|
|
||||||
for (i=0; i<gameData->curTowers.size(); i++)
|
|
||||||
if (gameData->curTowers.at(i).Id==towerId) return i;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Towers::update()
|
void Towers::update()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
12
towers.h
12
towers.h
@@ -11,10 +11,7 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
explicit Towers(Game_Data * gd, QObject *parent = 0);
|
explicit Towers(Game_Data * gd, QObject *parent = 0);
|
||||||
bool AddTower(int playerId, int srcId, QPoint pos);
|
bool AddTower(int playerId, int srcId, QPoint pos);
|
||||||
void DelTowerById(int Id);
|
void DelTower(QPoint pos);
|
||||||
void DelTowerByPos(QPoint pos);
|
|
||||||
void DelTower(int index);
|
|
||||||
int TowerIndex(int towerId);
|
|
||||||
void update();
|
void update();
|
||||||
int size() const {return gameData->curTowers.size();}
|
int size() const {return gameData->curTowers.size();}
|
||||||
signals:
|
signals:
|
||||||
@@ -23,8 +20,11 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Game_Data * gameData;
|
Game_Data * gameData;
|
||||||
|
|
||||||
int nextId;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline uint qHash(const QPoint &pos)
|
||||||
|
{
|
||||||
|
return qHash(pos.x()) + (qHash(pos.y()) << 16);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // TOWERS_H
|
#endif // TOWERS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user