Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8900


Ignore:
Timestamp:
Oct 19, 2011, 11:02:56 PM (13 years ago)
Author:
jo
Message:

Finished Polishing Pong. (gametype ends properly now, points necessary to win are configurable)

Location:
code/branches/gamecontent/src/modules/pong
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamecontent/src/modules/pong/Pong.cc

    r8895 r8900  
    3737#include "core/EventIncludes.h"
    3838#include "core/command/Executor.h"
     39#include "core/ConfigValueIncludes.h"
    3940
    4041#include "gamestates/GSLevel.h"
     
    7576        // Set the type of Bots for this particular Gametype.
    7677        this->botclass_ = Class(PongBot);
    77         this->scoreLimit_ = 3; //TODO: 21
     78        this->scoreLimit_ = 10;
     79        this->setConfigValues();
    7880    }
    7981
     
    291293            std::string message(name1 + " has won!");
    292294            ChatManager::message(message);
     295this->tick(0);
    293296            this->end();
    294297        }
     
    298301             std::string message2(name2 + " has won!");
    299302             ChatManager::message(message2);
     303this->tick(0);
    300304             this->end();
    301305        }
     
    342346            return 0;
    343347    }
     348
     349    /**
     350     @brief
     351         Make scoreLimit_ configurable e.g. in the menu.
     352     */
     353    void Pong::setConfigValues()
     354    {
     355        SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins.");
     356    }
    344357}
  • code/branches/gamecontent/src/modules/pong/Pong.h

    r8895 r8900  
    8181            void setCenterpoint(PongCenterpoint* center)
    8282                { this->center_ = center; }
    83 
    84             PlayerInfo* getLeftPlayer() const; //!< Get the left player.
     83            void setConfigValues(); //!< Makes scoreLimit configurable.
     84           
     85            PlayerInfo* getLeftPlayer() const; //!< Get the left player.
    8586            PlayerInfo* getRightPlayer() const; //!< Get the right player.
    8687
  • code/branches/gamecontent/src/modules/pong/PongScore.cc

    r8108 r8900  
    6060        this->bShowLeftPlayer_ = false;
    6161        this->bShowRightPlayer_ = false;
     62        this->player1_ = NULL;
     63        this->player2_ = NULL;
    6264    }
    6365
     
    98100        if (this->owner_ != NULL)
    99101        {
    100             // Get the two players.
    101             PlayerInfo* player1 = this->owner_->getLeftPlayer();
    102             PlayerInfo* player2 = this->owner_->getRightPlayer();
    103 
    104             std::string name1;
    105             std::string name2;
    106 
    107             std::string score1("0");
    108             std::string score2("0");
    109 
    110             // Save the name and score of each player as a string.
    111             if (player1 != NULL)
     102            if(!this->owner_->hasEnded())
    112103            {
    113                 name1 = player1->getName();
    114                 score1 = multi_cast<std::string>(this->owner_->getScore(player1));
    115             }
    116             if (player2 != NULL)
    117             {
    118                 name2 = player2->getName();
    119                 score2 = multi_cast<std::string>(this->owner_->getScore(player2));
     104                //get the two players
     105                player1_ = this->owner_->getLeftPlayer();
     106                player2_ = this->owner_->getRightPlayer();
    120107            }
    121108
    122             // Assemble the strings, depending on what should all be displayed.
    123             std::string output1;
    124             if (this->bShowLeftPlayer_)
     109            if(this->owner_->hasStarted())
    125110            {
    126                 if (this->bShowName_ && this->bShowScore_ && player1 != NULL)
    127                     output1 = name1 + " - " + score1;
    128                 else if (this->bShowScore_)
    129                     output1 = score1;
    130                 else if (this->bShowName_)
    131                     output1 = name1;
    132             }
     111                // Get the two players.
    133112
    134             std::string output2;
    135             if (this->bShowRightPlayer_)
    136             {
    137                 if (this->bShowName_ && this->bShowScore_ && player2 != NULL)
     113                std::string name1;
     114                std::string name2;
     115
     116                std::string score1("0");
     117                std::string score2("0");
     118
     119                // Save the name and score of each player as a string.
     120                if (player1_ != NULL)
     121                {
     122                    name1 = player1_->getName();
     123                    score1 = multi_cast<std::string>(this->owner_->getScore(player1_));
     124                }
     125                if (player2_ != NULL)
     126                {
     127                    name2 = player2_->getName();
     128                    score2 = multi_cast<std::string>(this->owner_->getScore(player2_));
     129                }
     130
     131                // Assemble the strings, depending on what should all be displayed.
     132                std::string output1;
     133                if (this->bShowLeftPlayer_)
     134                {
     135                    if (this->bShowName_ && this->bShowScore_ && player1_ != NULL)
     136                         output1 = name1 + " - " + score1;
     137                    else if (this->bShowScore_)
     138                         output1 = score1;
     139                    else if (this->bShowName_)
     140                         output1 = name1;
     141                }
     142
     143                std::string output2;
     144                if (this->bShowRightPlayer_)
     145                {
     146                if (this->bShowName_ && this->bShowScore_ && player2_ != NULL)
    138147                    output2 = score2 + " - " + name2;
    139148                else if (this->bShowScore_)
     
    143152            }
    144153
    145             std::string output("PONG");
    146             if (this->bShowName_ || this->bShowScore_)
    147             {
    148                 if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)
    149                     output = output1 + ':' + output2;
    150                 else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)
    151                     output = output1 + output2;
     154                std::string output("PONG");
     155                if (this->bShowName_ || this->bShowScore_)
     156                {
     157                    if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)
     158                        output = output1 + ':' + output2;
     159                    else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)
     160                        output = output1 + output2;
     161                }
     162                this->setCaption(output);
    152163            }
    153 
    154             this->setCaption(output);
    155164        }
    156165    }
  • code/branches/gamecontent/src/modules/pong/PongScore.h

    r8108 r8900  
    122122            bool bShowLeftPlayer_; //!< Whether the left player is shown.
    123123            bool bShowRightPlayer_; //!< Whether the right player is shown.
     124            PlayerInfo* player1_; //!< Store information about left player permanently.
     125            PlayerInfo* player2_; //!< Same for the right player. To end the game properly.
    124126    };
    125127}
Note: See TracChangeset for help on using the changeset viewer.