Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10168


Ignore:
Timestamp:
Dec 10, 2014, 4:15:08 PM (9 years ago)
Author:
richtero
Message:

working game

Location:
code/branches/minigame4DHS14/src/modules/mini4Dgame
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc

    r10156 r10168  
    5454
    5555        SetConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut();
     56        SetConsoleCommand("Mini4Dgame", "undoStone", &Mini4Dgame::undoStone).addShortcut();
    5657
    5758    RegisterUnloadableClass(Mini4Dgame);
     
    6667
    6768        this->board_ = 0;
    68         //ConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut().setAsInputCommand();
    6969
    7070        // Set the type of Bots for this particular Gametype.
     
    8888    void Mini4Dgame::cleanup()
    8989    {
    90 
     90        if(this->board_ != NULL)// Destroy the board, if present.
     91        {
     92                //this->board_->destroy();
     93                this->board_ = 0;
     94        }
    9195    }
    9296
     
    177181    }
    178182
     183    void Mini4Dgame::undoStone()//Vector4 move, const int playerColor)
     184    {
     185        ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>::begin();
     186        it->undoMove();
     187    }
     188
    179189    //void Mini4Dgame::setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board)
    180190    void Mini4Dgame::setStone(int x,int y,int z,int w)//Vector4 move, const int playerColor)
     
    182192        Vector4 move = Vector4(x,y,z,w);
    183193        ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>::begin();
    184         it->makeMove(move,1);//playerColor);
     194        it->makeMove(move);
    185195    }
    186196
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h

    r10156 r10168  
    7676                { return this->board_; }
    7777
     78            static void undoStone();
     79
    7880            //static void setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board);
    7981            static void setStone(int x,int y, int z, int w);//Vector4 move, const int playerColor);
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.cc

    r10156 r10168  
    6464                                for(int l=0;l<4;l++){
    6565                                        this->board[i][j][k][l]=mini4DgamePlayerColor::none;
     66                                        this->blinkingBillboards[i][j][k][l] = 0;
    6667                                }
    6768                        }
    6869                }
    6970        }
    70 
     71        this->player_toggle_ = false;
    7172        this->checkGametype();
    7273    }
    7374
    74     /**
    75     @brief
    76         Destructor.
    77     */
    78     Mini4DgameBoard::~Mini4DgameBoard()
    79     {
    80         if (this->isInitialized())
    81         {
    82 
    83         }
    84     }
    8575
    8676    //xml port for loading sounds
     
    8979        SUPER(Mini4DgameBoard, XMLPort, xmlelement, mode);
    9080    }
    91 
    92     /**
    93     @brief
    94         Register variables to synchronize over the network.
    95 
    96     void Mini4DgameBoard::registerVariables()
    97     {
    98         registerVariable( this->fieldWidth_ );
    99         registerVariable( this->fieldHeight_ );
    100         registerVariable( this->batlength_ );
    101         registerVariable( this->speed_ );
    102         registerVariable( this->relMercyOffset_ );
    103         registerVariable( this->batID_[0] );
    104         registerVariable( this->batID_[1], VariableDirection::ToClient, new NetworkCallback<PongBall>( this, &PongBall::applyBats) );
    105     }
    106      */
    10781
    10882        /**
     
    11286    bool Mini4DgameBoard::isValidMove(const Vector4 move)
    11387    {
    114         return (this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] == mini4DgamePlayerColor::none);
     88        return (move.x<4 && move.y<4 && move.z<4 && move.w<4
     89                        && move.x>=0 && move.y>=0 && move.z>=0 && move.w>=0
     90                        && this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] == mini4DgamePlayerColor::none);
    11591    }
    11692
    117 
     93        void Mini4DgameBoard::undoMove()
     94        {
     95                Vector4 move = moves.back();
     96                moves.pop_back();
     97        this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = mini4DgamePlayerColor::none;
     98        this->blinkingBillboards[(int)move.x][(int)move.y][(int)move.z][(int)move.w]->destroy();
     99        this->blinkingBillboards[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = 0;
     100        if(player_toggle_){
     101                this->player_toggle_ = false;
     102        }else{
     103                this->player_toggle_ = true;
     104        }
     105        }
    118106
    119107    /**
     
    121109    @param the position where to put the stone plus the player who makes the move
    122110    */
    123     void Mini4DgameBoard::makeMove(const Vector4 move, const int playerColor)
     111    void Mini4DgameBoard::makeMove(const Vector4 move)
    124112    {
    125113        if(this->isValidMove(move))
    126114        {
     115                if(!moves.empty())
     116                {
     117                        //stop blinking of last move
     118                        Vector4 lastMove = moves.back();
     119                        this->blinkingBillboards[(int)lastMove.x][(int)lastMove.y][(int)lastMove.z][(int)lastMove.w]
     120                                        ->setActive(false);
     121                        this->blinkingBillboards[(int)lastMove.x][(int)lastMove.y][(int)lastMove.z][(int)lastMove.w]
     122                                        ->setScale(0.1);
     123                }
     124
     125                moves.push_back(move);
     126                mini4DgamePlayerColor::color playerColor = mini4DgamePlayerColor::none;
     127                if(player_toggle_){
     128                        playerColor = mini4DgamePlayerColor::blue;
     129                        this->player_toggle_ = false;
     130                }else{
     131                        playerColor = mini4DgamePlayerColor::green;
     132                        this->player_toggle_ = true;
     133                }
     134
    127135                this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = (mini4DgamePlayerColor::color) playerColor;
    128                         BlinkingBillboard* bb = new BlinkingBillboard(this->getContext());
    129                         orxout(user_status) << "Mini4Dgame: move.x " << move.x << endl;
    130 
    131                         bb->setPosition(60*(int)move.x-90,60*(int)move.y-90,60*(int)move.z-90);
    132                         bb->setFrequency(0.6);
     136
     137                BlinkingBillboard* bb = new BlinkingBillboard(this->getContext());
     138                        bb->setFrequency(0.3);
    133139                        bb->setAmplitude(0.1);
    134                         //bb->setMaterial("Flares/lensflare");
    135                         bb->setMaterial("Numbers/One");
    136                         bb->setColour(ColourValue(0,1,0));
     140
     141                        switch((int)move.w){
     142                        case 0: bb->setMaterial("Numbers/One");
     143                                        bb->setPosition(60*(int)move.x-95,60*(int)move.y-95,60*(int)move.z-95);
     144                                        break;
     145                        case 1: bb->setMaterial("Numbers/Two");
     146                                        bb->setPosition(60*(int)move.x-85,60*(int)move.y-85,60*(int)move.z-95);
     147                                        break;
     148                        case 2: bb->setMaterial("Numbers/Three");
     149                                        bb->setPosition(60*(int)move.x-85,60*(int)move.y-95,60*(int)move.z-85);
     150                                        break;
     151                        case 3: bb->setMaterial("Numbers/Four");
     152                                        bb->setPosition(60*(int)move.x-85,60*(int)move.y-85,60*(int)move.z-85);
     153                                        break;
     154                        }
     155
     156                        switch(playerColor){
     157                        case mini4DgamePlayerColor::red:
     158                                bb->setColour(ColourValue(1,0,0)); break;
     159                        case mini4DgamePlayerColor::green:
     160                                bb->setColour(ColourValue(0,1,0)); break;
     161                        case mini4DgamePlayerColor::blue:
     162                                bb->setColour(ColourValue(0,0,1)); break;
     163                        default:        break;
     164                        }
    137165
    138166                        this->attach(bb);
     167                        this->blinkingBillboards[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = bb;
    139168
    140169
     
    143172                {
    144173                        orxout(user_status) << "Mini4Dgame: win!!!!!!!" << endl;
    145                         //win(winner);
     174                        for(int i=0;i<4;i++){
     175                                BlinkingBillboard* redFlare = new BlinkingBillboard(this->getContext());
     176                                        redFlare->setFrequency(0.5);
     177                                        redFlare->setAmplitude(3);
     178                                        redFlare->setPosition(60*(int)winner.winningRow[i]-90,
     179                                                                        60*(int)winner.winningColumn[i]-90,
     180                                                                        60*(int)winner.winningHeight[i]-90);
     181                                        redFlare->setMaterial("Flares/lensflare");
     182                                        redFlare->setColour(ColourValue(1,0,0));
     183                                        this->attach(redFlare);
     184                                        BlinkingBillboard* bb = this->blinkingBillboards[winner.winningRow[i]]
     185                                                                                                                                        [winner.winningColumn[i]]
     186                                                                                                                                        [winner.winningHeight[i]]
     187                                                                                                                                        [winner.winningNumber[i]];
     188                                        bb->setActive(true);//start blinking
     189                                }
    146190                }
     191        }else{
     192                        orxout(internal_error) << "Mini4Dgame: not a valid move"<< endl;
    147193        }
    148194    }
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.h

    r10156 r10168  
    6363        public:
    6464                Mini4DgameBoard(Context* context);
    65             virtual ~Mini4DgameBoard();
     65            //virtual ~Mini4DgameBoard();
    6666
    6767            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    6868
    6969            bool isValidMove(const Vector4 move);
    70             void makeMove(const Vector4 move, const int playerColor);
     70            void undoMove();
     71            void makeMove(const Vector4 move);
    7172            Mini4DgameWinner getWinner();
    7273
     
    7677        private:
    7778            //void registerVariables();
     79            std::vector<Vector4> moves;
     80            bool player_toggle_;
     81            BlinkingBillboard* blinkingBillboards[4][4][4][4];
    7882            int board[4][4][4][4]; //!< The logical board where the game takes place. board[row][column][height][number]
    7983    };
Note: See TracChangeset for help on using the changeset viewer.