Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc @ 10131

Last change on this file since 10131 was 10131, checked in by richtero, 9 years ago

new structure: Board in separate class

File size: 5.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      ...
24 *   Co-authors:
25 *      Johannes Ritz
26 *
27 *
28 *
29 *
30 *TASK c) end the game in a nicer way
31 *TASK d) save the highscore
32 *TASK e) eye candy
33 */
34
35/**
36    @file Tetris.cc
37    @brief Implementation of the Mini4Dgame class.
38*/
39
40#include "Mini4Dgame.h"
41
42#include "core/CoreIncludes.h"
43#include "core/EventIncludes.h"
44#include "core/command/Executor.h"
45#include "core/config/ConfigValueIncludes.h"
46#include "infos/PlayerInfo.h"
47#include "core/command/ConsoleCommand.h"
48
49#include "gamestates/GSLevel.h"
50#include "chat/ChatManager.h"
51
52#include "Mini4DgameCenterpoint.h"
53
54namespace orxonox
55{
56
57        SetConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut();
58
59    RegisterUnloadableClass(Mini4Dgame);
60
61    /**
62    @brief
63        Constructor. Registers and initializes the object.
64    */
65    Mini4Dgame::Mini4Dgame(Context* context) : Deathmatch(context)
66    {
67        RegisterObject(Mini4Dgame);
68
69        this->center_ = 0;
70        this->board_ = 0;
71
72        // Set the type of Bots for this particular Gametype.
73        //this->botclass_ = Class(Mini4DgameBot);
74    }
75
76    /**
77    @brief
78        Destructor. Cleans up, if initialized.
79    */
80    Mini4Dgame::~Mini4Dgame()
81    {
82        if (this->isInitialized())
83            this->cleanup();
84    }
85
86    /**
87    @brief
88        Cleans up the Gametype.
89    */
90    void Mini4Dgame::cleanup()
91    {
92
93    }
94
95    /**
96    @brief
97        Starts the mini4Dgame.
98    */
99    void Mini4Dgame::start()
100    {
101        if (this->center_ != NULL) // There needs to be a Mini4DgameCenterpoint, i.e. the area the game takes place.
102        {
103                if (this->board_ == NULL)
104                {
105                        this->board_ = new Mini4DgameBoard(this->center_->getContext());
106                        // Apply the template for the ball specified by the centerpoint.
107                        this->board_->addTemplate(this->center_->getBoardtemplate());
108                }
109
110                // Attach the board to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
111                this->center_->attach(this->board_);
112                this->board_->setPosition(0, 0, 0);
113
114        }
115        else // If no centerpoint was specified, an error is thrown and the level is exited.
116        {
117            orxout(internal_error) << "Mini4Dgame: No Centerpoint specified." << endl;
118            GSLevel::startMainMenu();
119            return;
120        }
121
122        // Set variable to temporarily force the player to spawn.
123        bool temp = this->bForceSpawn_;
124        this->bForceSpawn_ = true;
125
126        // Call start for the parent class.
127        Deathmatch::start();
128
129        // Reset the variable.
130        this->bForceSpawn_ = temp;
131    }
132
133    /**
134    @brief
135        Ends the Mini4Dgame minigame.
136    */
137    void Mini4Dgame::end()
138    {
139        this->cleanup();
140
141        // Call end for the parent class.
142        Deathmatch::end();
143    }
144
145
146    /**
147    @brief
148        Spawns player.
149    */
150    void Mini4Dgame::spawnPlayersIfRequested()
151    {
152        // first spawn human players to assign always the left bat to the player in singleplayer
153        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
154            if (it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))
155                this->spawnPlayer(it->first);
156        // now spawn bots
157        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
158            if (!it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))
159                this->spawnPlayer(it->first);
160    }
161
162    /**
163    @brief
164        Spawns the input player.
165    @param player
166        The player to be spawned.
167    */
168    void Mini4Dgame::spawnPlayer(PlayerInfo* player)
169    {
170        assert(player);
171
172        if(false)//this->player_ == NULL)
173        {
174            //this->player_ = player;
175            this->players_[player].state_ = PlayerState::Alive;
176        }
177    }
178
179    static void Mini4Dgame::setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board)
180    {
181        board->makeMove(move,playerColor);
182    }
183
184    void Mini4Dgame::win(Mini4DgameWinner winner)
185    {
186
187    }
188}
Note: See TracBrowser for help on using the repository browser.