Changeset 10168 for code/branches/minigame4DHS14/src/modules
- Timestamp:
- Dec 10, 2014, 4:15:08 PM (10 years ago)
- Location:
- code/branches/minigame4DHS14/src/modules/mini4Dgame
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc
r10156 r10168 54 54 55 55 SetConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut(); 56 SetConsoleCommand("Mini4Dgame", "undoStone", &Mini4Dgame::undoStone).addShortcut(); 56 57 57 58 RegisterUnloadableClass(Mini4Dgame); … … 66 67 67 68 this->board_ = 0; 68 //ConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut().setAsInputCommand();69 69 70 70 // Set the type of Bots for this particular Gametype. … … 88 88 void Mini4Dgame::cleanup() 89 89 { 90 90 if(this->board_ != NULL)// Destroy the board, if present. 91 { 92 //this->board_->destroy(); 93 this->board_ = 0; 94 } 91 95 } 92 96 … … 177 181 } 178 182 183 void Mini4Dgame::undoStone()//Vector4 move, const int playerColor) 184 { 185 ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>::begin(); 186 it->undoMove(); 187 } 188 179 189 //void Mini4Dgame::setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board) 180 190 void Mini4Dgame::setStone(int x,int y,int z,int w)//Vector4 move, const int playerColor) … … 182 192 Vector4 move = Vector4(x,y,z,w); 183 193 ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>::begin(); 184 it->makeMove(move,1);//playerColor);194 it->makeMove(move); 185 195 } 186 196 -
code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h
r10156 r10168 76 76 { return this->board_; } 77 77 78 static void undoStone(); 79 78 80 //static void setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board); 79 81 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 64 64 for(int l=0;l<4;l++){ 65 65 this->board[i][j][k][l]=mini4DgamePlayerColor::none; 66 this->blinkingBillboards[i][j][k][l] = 0; 66 67 } 67 68 } 68 69 } 69 70 } 70 71 this->player_toggle_ = false; 71 72 this->checkGametype(); 72 73 } 73 74 74 /**75 @brief76 Destructor.77 */78 Mini4DgameBoard::~Mini4DgameBoard()79 {80 if (this->isInitialized())81 {82 83 }84 }85 75 86 76 //xml port for loading sounds … … 89 79 SUPER(Mini4DgameBoard, XMLPort, xmlelement, mode); 90 80 } 91 92 /**93 @brief94 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 */107 81 108 82 /** … … 112 86 bool Mini4DgameBoard::isValidMove(const Vector4 move) 113 87 { 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); 115 91 } 116 92 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 } 118 106 119 107 /** … … 121 109 @param the position where to put the stone plus the player who makes the move 122 110 */ 123 void Mini4DgameBoard::makeMove(const Vector4 move , const int playerColor)111 void Mini4DgameBoard::makeMove(const Vector4 move) 124 112 { 125 113 if(this->isValidMove(move)) 126 114 { 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 127 135 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); 133 139 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 } 137 165 138 166 this->attach(bb); 167 this->blinkingBillboards[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = bb; 139 168 140 169 … … 143 172 { 144 173 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 } 146 190 } 191 }else{ 192 orxout(internal_error) << "Mini4Dgame: not a valid move"<< endl; 147 193 } 148 194 } -
code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.h
r10156 r10168 63 63 public: 64 64 Mini4DgameBoard(Context* context); 65 virtual ~Mini4DgameBoard();65 //virtual ~Mini4DgameBoard(); 66 66 67 67 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 68 68 69 69 bool isValidMove(const Vector4 move); 70 void makeMove(const Vector4 move, const int playerColor); 70 void undoMove(); 71 void makeMove(const Vector4 move); 71 72 Mini4DgameWinner getWinner(); 72 73 … … 76 77 private: 77 78 //void registerVariables(); 79 std::vector<Vector4> moves; 80 bool player_toggle_; 81 BlinkingBillboard* blinkingBillboards[4][4][4][4]; 78 82 int board[4][4][4][4]; //!< The logical board where the game takes place. board[row][column][height][number] 79 83 };
Note: See TracChangeset
for help on using the changeset viewer.