[Orxonox-commit 5505] r10168 - code/branches/minigame4DHS14/src/modules/mini4Dgame

richtero at orxonox.net richtero at orxonox.net
Wed Dec 10 16:15:08 CET 2014


Author: richtero
Date: 2014-12-10 16:15:08 +0100 (Wed, 10 Dec 2014)
New Revision: 10168

Modified:
   code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc
   code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h
   code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.cc
   code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.h
Log:
working game

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc	2014-12-10 14:51:52 UTC (rev 10167)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc	2014-12-10 15:15:08 UTC (rev 10168)
@@ -53,6 +53,7 @@
 {
 
 	SetConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut();
+	SetConsoleCommand("Mini4Dgame", "undoStone", &Mini4Dgame::undoStone).addShortcut();
 
     RegisterUnloadableClass(Mini4Dgame);
 
@@ -65,7 +66,6 @@
         RegisterObject(Mini4Dgame);
 
         this->board_ = 0;
-        //ConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut().setAsInputCommand();
 
         // Set the type of Bots for this particular Gametype.
         //this->botclass_ = Class(Mini4DgameBot);
@@ -87,7 +87,11 @@
     */
     void Mini4Dgame::cleanup()
     {
-
+    	if(this->board_ != NULL)// Destroy the board, if present.
+    	{
+    		//this->board_->destroy();
+    		this->board_ = 0;
+    	}
     }
 
     /**
@@ -176,12 +180,18 @@
         }
     }
 
+    void Mini4Dgame::undoStone()//Vector4 move, const int playerColor)
+    {
+    	ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>::begin();
+        it->undoMove();
+    }
+
     //void Mini4Dgame::setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board)
     void Mini4Dgame::setStone(int x,int y,int z,int w)//Vector4 move, const int playerColor)
     {
     	Vector4 move = Vector4(x,y,z,w);
         ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>::begin();
-    	it->makeMove(move,1);//playerColor);
+        it->makeMove(move);
     }
 
     void Mini4Dgame::win(Mini4DgameWinner winner)

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h	2014-12-10 14:51:52 UTC (rev 10167)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h	2014-12-10 15:15:08 UTC (rev 10168)
@@ -75,6 +75,8 @@
             Mini4DgameBoard* getBoard(void)
             	{ return this->board_; }
 
+            static void undoStone();
+
             //static void setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board);
             static void setStone(int x,int y, int z, int w);//Vector4 move, const int playerColor);
 

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.cc
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.cc	2014-12-10 14:51:52 UTC (rev 10167)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.cc	2014-12-10 15:15:08 UTC (rev 10168)
@@ -63,87 +63,133 @@
         		for(int k=0;k<4;k++){
         			for(int l=0;l<4;l++){
         				this->board[i][j][k][l]=mini4DgamePlayerColor::none;
+        				this->blinkingBillboards[i][j][k][l] = 0;
         			}
         		}
         	}
         }
-
+        this->player_toggle_ = false;
         this->checkGametype();
     }
 
-    /**
-    @brief
-        Destructor.
-    */
-    Mini4DgameBoard::~Mini4DgameBoard()
-    {
-        if (this->isInitialized())
-        {
 
-        }
-    }
-
     //xml port for loading sounds
     void Mini4DgameBoard::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(Mini4DgameBoard, XMLPort, xmlelement, mode);
     }
 
-    /**
-    @brief
-        Register variables to synchronize over the network.
-
-    void Mini4DgameBoard::registerVariables()
-    {
-        registerVariable( this->fieldWidth_ );
-        registerVariable( this->fieldHeight_ );
-        registerVariable( this->batlength_ );
-        registerVariable( this->speed_ );
-        registerVariable( this->relMercyOffset_ );
-        registerVariable( this->batID_[0] );
-        registerVariable( this->batID_[1], VariableDirection::ToClient, new NetworkCallback<PongBall>( this, &PongBall::applyBats) );
-    }
-     */
-
 	/**
         @brief checks if the move is valid
         @param the position where to put the stone plus the player who makes the move
     */
     bool Mini4DgameBoard::isValidMove(const Vector4 move)
     {
-    	return (this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] == mini4DgamePlayerColor::none);
+    	return (move.x<4 && move.y<4 && move.z<4 && move.w<4
+    			&& move.x>=0 && move.y>=0 && move.z>=0 && move.w>=0
+    			&& this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] == mini4DgamePlayerColor::none);
     }
 
+	void Mini4DgameBoard::undoMove()
+	{
+		Vector4 move = moves.back();
+		moves.pop_back();
+    	this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = mini4DgamePlayerColor::none;
+    	this->blinkingBillboards[(int)move.x][(int)move.y][(int)move.z][(int)move.w]->destroy();
+    	this->blinkingBillboards[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = 0;
+    	if(player_toggle_){
+    		this->player_toggle_ = false;
+    	}else{
+    		this->player_toggle_ = true;
+    	}
+	}
 
-
     /**
     @brief makes a move on the logic playboard
     @param the position where to put the stone plus the player who makes the move
     */
-    void Mini4DgameBoard::makeMove(const Vector4 move, const int playerColor)
+    void Mini4DgameBoard::makeMove(const Vector4 move)
     {
     	if(this->isValidMove(move))
     	{
+    		if(!moves.empty())
+    		{
+    			//stop blinking of last move
+    			Vector4 lastMove = moves.back();
+    			this->blinkingBillboards[(int)lastMove.x][(int)lastMove.y][(int)lastMove.z][(int)lastMove.w]
+    					->setActive(false);
+    			this->blinkingBillboards[(int)lastMove.x][(int)lastMove.y][(int)lastMove.z][(int)lastMove.w]
+    					->setScale(0.1);
+    		}
+
+    		moves.push_back(move);
+    		mini4DgamePlayerColor::color playerColor = mini4DgamePlayerColor::none;
+    		if(player_toggle_){
+    			playerColor = mini4DgamePlayerColor::blue;
+    			this->player_toggle_ = false;
+    		}else{
+    			playerColor = mini4DgamePlayerColor::green;
+    			this->player_toggle_ = true;
+    		}
+
     		this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = (mini4DgamePlayerColor::color) playerColor;
-			BlinkingBillboard* bb = new BlinkingBillboard(this->getContext());
-			orxout(user_status) << "Mini4Dgame: move.x " << move.x << endl;
 
-			bb->setPosition(60*(int)move.x-90,60*(int)move.y-90,60*(int)move.z-90);
-			bb->setFrequency(0.6);
+    		BlinkingBillboard* bb = new BlinkingBillboard(this->getContext());
+			bb->setFrequency(0.3);
 			bb->setAmplitude(0.1);
-			//bb->setMaterial("Flares/lensflare");
-			bb->setMaterial("Numbers/One");
-			bb->setColour(ColourValue(0,1,0));
 
+			switch((int)move.w){
+			case 0:	bb->setMaterial("Numbers/One");
+					bb->setPosition(60*(int)move.x-95,60*(int)move.y-95,60*(int)move.z-95);
+					break;
+			case 1:	bb->setMaterial("Numbers/Two");
+					bb->setPosition(60*(int)move.x-85,60*(int)move.y-85,60*(int)move.z-95);
+					break;
+			case 2:	bb->setMaterial("Numbers/Three");
+					bb->setPosition(60*(int)move.x-85,60*(int)move.y-95,60*(int)move.z-85);
+					break;
+			case 3:	bb->setMaterial("Numbers/Four");
+					bb->setPosition(60*(int)move.x-85,60*(int)move.y-85,60*(int)move.z-85);
+					break;
+			}
+
+			switch(playerColor){
+			case mini4DgamePlayerColor::red:
+				bb->setColour(ColourValue(1,0,0)); break;
+			case mini4DgamePlayerColor::green:
+				bb->setColour(ColourValue(0,1,0)); break;
+			case mini4DgamePlayerColor::blue:
+				bb->setColour(ColourValue(0,0,1)); break;
+			default:	break;
+			}
+
 			this->attach(bb);
+			this->blinkingBillboards[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = bb;
 
 
     		Mini4DgameWinner winner = this->getWinner();
     		if(winner.color_ != mini4DgamePlayerColor::none)
     		{
     			orxout(user_status) << "Mini4Dgame: win!!!!!!!" << endl;
-    			//win(winner);
+    			for(int i=0;i<4;i++){
+    				BlinkingBillboard* redFlare = new BlinkingBillboard(this->getContext());
+					redFlare->setFrequency(0.5);
+					redFlare->setAmplitude(3);
+					redFlare->setPosition(60*(int)winner.winningRow[i]-90,
+									60*(int)winner.winningColumn[i]-90,
+									60*(int)winner.winningHeight[i]-90);
+					redFlare->setMaterial("Flares/lensflare");
+					redFlare->setColour(ColourValue(1,0,0));
+					this->attach(redFlare);
+					BlinkingBillboard* bb = this->blinkingBillboards[winner.winningRow[i]]
+																	[winner.winningColumn[i]]
+																	[winner.winningHeight[i]]
+																	[winner.winningNumber[i]];
+					bb->setActive(true);//start blinking
+				}
     		}
+    	}else{
+			orxout(internal_error) << "Mini4Dgame: not a valid move"<< endl;
     	}
     }
 

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.h
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.h	2014-12-10 14:51:52 UTC (rev 10167)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameBoard.h	2014-12-10 15:15:08 UTC (rev 10168)
@@ -62,12 +62,13 @@
     {
         public:
     		Mini4DgameBoard(Context* context);
-            virtual ~Mini4DgameBoard();
+            //virtual ~Mini4DgameBoard();
 
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
 
             bool isValidMove(const Vector4 move);
-            void makeMove(const Vector4 move, const int playerColor);
+            void undoMove();
+            void makeMove(const Vector4 move);
             Mini4DgameWinner getWinner();
 
             void changedGametype();
@@ -75,6 +76,9 @@
 
         private:
             //void registerVariables();
+            std::vector<Vector4> moves;
+            bool player_toggle_;
+            BlinkingBillboard* blinkingBillboards[4][4][4][4];
             int board[4][4][4][4]; //!< The logical board where the game takes place. board[row][column][height][number]
     };
 }




More information about the Orxonox-commit mailing list