void play (int *board, int *newboard, int N) { /* (copied this from some web page, hence the English spellings...) 1.STASIS : If, for a given cell, the number of on neighbours is exactly two, the cell maintains its status quo into the next generation. If the cell is on, it stays on, if it is off, it stays off. 2.GROWTH : If the number of on neighbours is exactly three, the cell will be on in the next generation. This is regardless of the cell's current state. 3.DEATH : If the number of on neighbours is 0, 1, 4-8, the cell will be off in the next generation. */ int i, j, a; /* for each cell, apply the rules of Life */ for (i=0; i<N; i++) for (j=0; j<N; j++) { a = adjacent_to (board, i, j, N); if (a == 2) NewBoard(i,j) = Board(i,j); if (a == 3) NewBoard(i,j) = 1; if (a < 2) NewBoard(i,j) = 0; if (a > 3) NewBoard(i,j) = 0; } /* copy the new board back into the old board */ for (i=0; i<N; i++) for (j=0; j<N; j++) { Board(i,j) = NewBoard(i,j); } }
cDSRoomLevel1::cDSRoomLevel1(const char* bgTexture, const int puzzleInUse, const int rows, const int columns) : cDSRoom(bgTexture) , mPuzzleDefaultInitialized(false) , mPuzzleUserInitialized(false) , mPuzzleInUse(puzzleInUse) , mRows(rows) , mColumns(columns) , mpBitmapFull(NULL) , mpBoard(NULL) , mpButtonBack(NULL)//Switch NULL for nullptr when using visual studio 2010 or newer , mpButtonScramble(NULL)//Switch NULL for nullptr when using visual studio 2010 or newer { //Create Objects //Tools mpBitmapFull = new cBitmap24bit; //Buttons mpButtonBack = new cDSMenuButton((cDSApp::msScreenWidth * 0.9) - (168 / 2), (cDSApp::msScreenHeight * 0.9) - (64 / 2), 168, 64, "./Resources/Textures/Buttons/back_up.png", "./Resources/Textures/Buttons/back_hover.png", "./Resources/Textures/Buttons/back_down.png", "./Resources/Textures/Buttons/back_click.png", false, cDSApp::msDepthButton); NewBoard(); if(!mpBoard->mPiecesInitialPosSet) { int bottomLeftX = -1; int bottomLeftY = -1; mpBoard->mkWidth = mpBitmapFull->GetWidth(); mpBoard->mkHeight = mpBitmapFull->GetHeight(); const int tileWidth = (mpBoard->mkWidth / mpBoard->mkTilesX); const int tileHeight = (mpBoard->mkHeight / mpBoard->mkTilesY); for(int j = 0; j < mpBoard->mkTilesY; ++j) { for(int i = 0; i < mpBoard->mkTilesX; ++i) { bottomLeftX = i * tileWidth; bottomLeftY = j * tileHeight; //if not at the bottom right corner where the empty space will be if(i != (mpBoard->mkTilesX - 1) || j != (mpBoard->mkTilesY - 1)) { mpBoard->mpTiles[(j * mpBoard->mkTilesX) + i]->SetOrigin(mpBoard->mkPosX + bottomLeftX, mpBoard->mkPosY + bottomLeftY); } else if(i == (mpBoard->mkTilesX - 1) || j == (mpBoard->mkTilesY - 1)) { //place mpEmptyTile mpBoard->mpEmptyTile->SetOrigin(mpBoard->mkPosX + bottomLeftX, mpBoard->mkPosY + bottomLeftY); mpBoard->mpEmptyTile->SetSize(mpBoard->mpTiles[0]->GetSize()); } } } mpBoard->mPiecesInitialPosSet = true; } //Create Objects - con't //if the puzzle pieces have not yet been scrambled if(!mpBoard->mPiecesPosScrambled) { //if the scramble button does NOT exist if(!mpButtonScramble) { mpButtonScramble = new cDSMenuButton(mpBoard->mkPosX + (mpBoard->mkWidth / 2) - (168 / 2), mpBoard->mkPosY + mpBoard->mkHeight + (64 / 2), 168, 64, "./Resources/Textures/Buttons/scramble_up.png", "./Resources/Textures/Buttons/scramble_hover.png", "./Resources/Textures/Buttons/scramble_down.png", "./Resources/Textures/Buttons/scramble_click.png", false, cDSApp::msDepthButton); } } //Graphics //Congratulations mCongratulationsTexture.Load("./Resources/Textures/Graphics/roomScoreScreenCongratulations_v3.png"); mCongratulationsSprite.AddTexture(&mCongratulationsTexture); mCongratulationsSprite.SetDepth(cDSApp::msDepthButton); //Fonts mFontStats.Create(FontType::IMPACT, 64); mFontStats.SetColor(142, 255, 117); //Initialize Positions //Congratulations mCongratulationsSprite.SetPosition((cDSApp::msScreenWidth - 700) / 2, mpBoard->mkPosY - 150); }