diff --git a/source/code/ReadKeyboard.cpp b/source/code/ReadKeyboard.cpp index cc6d3e8..4a9e6fb 100644 --- a/source/code/ReadKeyboard.cpp +++ b/source/code/ReadKeyboard.cpp @@ -23,6 +23,9 @@ http://blockattack.sf.net #include "ReadKeyboard.h" + +using namespace std; + ReadKeyboard::ReadKeyboard(void) { length = 0; diff --git a/source/code/ReadKeyboard.h b/source/code/ReadKeyboard.h index 8e973fc..b4be478 100644 --- a/source/code/ReadKeyboard.h +++ b/source/code/ReadKeyboard.h @@ -28,8 +28,6 @@ Added to project 5/11-2004 #include #include "SDL.h" -using namespace std; - class ReadKeyboard { private: diff --git a/source/code/editor/BoardHolder.cpp b/source/code/editor/BoardHolder.cpp deleted file mode 100644 index e1c70fb..0000000 --- a/source/code/editor/BoardHolder.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2012 Poul Sander - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see http://www.gnu.org/licenses/ - -Source information and contacts persons can be found at -http://blockattack.sf.net -=========================================================================== -*/ - -#include "BoardHolder.hpp" - -BoardHolder::BoardHolder(string filename) -{ - fstream inFile(filename.c_str(),ios::in); - if(inFile) - { - int nrOfBoards; - inFile >> nrOfBoards; - for(int i=0; i> temp; - ourBoard.setNumberOfMoves(temp); - for(int j=0; j<12; j++) - { - for(int k=0; k<6; k++) - { - inFile >> temp; - ourBoard.setBrick(k,j,temp); - } - } - theBoards[i] = ourBoard; - } - isNull = false; - } -} - -BoardHolder::BoardHolder() -{ - isNull = false; -} - -bool BoardHolder::saveBoards(string filename) -{ - fstream outFile(filename.c_str(),ios::out); - if(outFile) - { - outFile << getNumberOfBoards() << endl; - for(int i=0; i49)||(nr<0)) - return false; - theBoards[nr] = model; - return true; -} - -int BoardHolder::getNumberOfBoards() -{ - return theBoards.size(); -} - -bool BoardHolder::addBoard() -{ - if(!(theBoards.size()<49)) - return false; - TheBoard tb; - theBoards[theBoards.size()] = tb; - return true; -} - -bool BoardHolder::removeBoard(int nr) -{ - vector::iterator itr; - itr = theBoards.begin(); - itr+=nr; - theBoards.erase(itr); -} - -bool BoardHolder::moveBoardBack(int nr) -{ - if(nr<1) //We can't move back - return false; - if(nr>getNumberOfBoards()) - return false; - TheBoard temp = theBoards[nr]; - theBoards[nr] = theBoards[nr-1]; - theBoards[nr-1] = temp; - return true; -} - -bool BoardHolder::moveBoardForward(int nr) -{ - if(nr>getNumberOfBoards()-2) //We can't move forward - return false; - if(nr<0) - return false; - TheBoard temp = theBoards[nr]; - theBoards[nr] = theBoards[nr+1]; - theBoards[nr+1] = temp; - return true; -} diff --git a/source/code/editor/BoardHolder.hpp b/source/code/editor/BoardHolder.hpp deleted file mode 100644 index db32c5e..0000000 --- a/source/code/editor/BoardHolder.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2012 Poul Sander - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see http://www.gnu.org/licenses/ - -Source information and contacts persons can be found at -http://blockattack.sf.net -=========================================================================== -*/ - -#include "TheBoard.hpp" -#include -#include -#include -#include - -#ifndef BOARDHOLDERDEFINED -#define BOARDHOLDERDEFINED -class BoardHolder -{ - -private: - vector theBoards; - -public: - bool isNull; - BoardHolder(); - BoardHolder(string filename); - bool saveBoards(string filename); - TheBoard getModel(int); - bool setModel(int nr,TheBoard model); - int getNumberOfBoards(); - bool addBoard(); - bool removeBoard(int); - bool moveBoardBack(int); - bool moveBoardForward(int); -}; -#endif diff --git a/source/code/editor/EditorInterface.cpp b/source/code/editor/EditorInterface.cpp deleted file mode 100644 index 8f26878..0000000 --- a/source/code/editor/EditorInterface.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2012 Poul Sander - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see http://www.gnu.org/licenses/ - -Source information and contacts persons can be found at -http://blockattack.sf.net -=========================================================================== -*/ - -/* -TODO: The way we test for - -*/ - -#include "EditorInterface.hpp" - -EditorInterface::EditorInterface() -{ - boardActive = -1; - saved = true; - fileSaved = true; - bh.isNull = true; -} - -void EditorInterface::getModel(int nr) -{ - tb = bh.getModel(nr); - saved = true; - boardActive = nr; -} - -bool EditorInterface::exists() -{ - if(bh.isNull) - return false; - else - return true; -} - -void EditorInterface::selectColor(int color) -{ - colorSelected = color; -} - -int EditorInterface::getSelectedColor() -{ - return colorSelected; -} - -void EditorInterface::drawOnModel(int x, int y) -{ - if(boardActive!=-1) - { - if(colorSelected<7) //Ordinary thing - tb.setBrick(x,y,colorSelected); - if(colorSelected==7) - tb.moveUp(x,y); - if(colorSelected==8) - tb.moveDown(x,y); - saved = false; - } -} - -void EditorInterface::moveLeft() -{ - if(boardActive!=-1) - tb.moveLeft(); - saved = false; -} - -void EditorInterface::moveRight() -{ - if(boardActive!=-1) - tb.moveRight(); - saved = false; -} - -void EditorInterface::deleteBoard() -{ - if(boardActive!=-1) - { - bh.removeBoard(boardActive); - boardActive = -1; - saved = true; - fileSaved = false; - } -} - -void EditorInterface::moveBoardBack() -{ - if(boardActive!=-1) - { - if(bh.moveBoardBack(boardActive)) - boardActive--; - } -} - -void EditorInterface::moveBoardForward() -{ - if(boardActive!=-1) - { - if(bh.moveBoardForward(boardActive)) - boardActive++; - } -} - -void EditorInterface::saveBoard() -{ - if(boardActive!=-1) - { - bh.setModel(boardActive,tb); - saved = true; - fileSaved = false; - } -} - -bool EditorInterface::saveFile(string filename) -{ - if((!bh.isNull)&&(filename!="")) - { - fileName = filename; - bh.saveBoards(filename); - fileSaved = true; - return true; - } - return false; -} - -bool EditorInterface::saveFile() -{ - if((!bh.isNull)&&(fileName!="")) - { - bh.saveBoards(fileName); - fileSaved = true; - return true; - } - return false; -} - -void EditorInterface::openFile(string filename) -{ - fileName = filename; - BoardHolder bh2(fileName); - bh = bh2; - saved = true; - fileSaved = true; -} - -void EditorInterface::newFile() -{ - fileName = ""; - bh = BoardHolder(); - TheBoard tb2; - tb.isNull = true; // = null; What here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - boardActive = -1; - saved = true; - fileSaved = false; -} - -int EditorInterface::getColor(int x, int y) -{ - if(boardActive==-1) - return -1; - return tb.getBrick(x,y); -} - -int EditorInterface::getActiveBoardNr() -{ - return boardActive; -} - -int EditorInterface::getNumberOfMoves() -{ - if(!tb.isNull) - { - return tb.getNumberOfMoves(); - } - return 0; -} - -bool EditorInterface::newBoard() -{ - if(!bh.isNull) - { - fileSaved = false; - return bh.addBoard(); - } - else - return false; -} - -int EditorInterface::getNumberOfBoards() -{ - if(!bh.isNull) - return bh.getNumberOfBoards(); - else - return 0; -} - -void EditorInterface::setNumberOfMoves(int moves) -{ - if(!tb.isNull) - { - saved = false; - tb.setNumberOfMoves(moves); - } -} - -bool EditorInterface::isSaved() -{ - return saved; -} - -bool EditorInterface::fileIsSaved() -{ - return fileSaved; -} diff --git a/source/code/editor/EditorInterface.hpp b/source/code/editor/EditorInterface.hpp deleted file mode 100644 index 39b4c5a..0000000 --- a/source/code/editor/EditorInterface.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2012 Poul Sander - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see http://www.gnu.org/licenses/ - -Source information and contacts persons can be found at -http://blockattack.sf.net -=========================================================================== -*/ - -#include "BoardHolder.hpp" - -#ifndef EDITORINTERFACEDEFINED -#define EDITORINTERFACEDEFINED -class EditorInterface -{ -private: - int colorSelected; //The color the user have selected - int boardActive; //Number of the active board, -1 if not active - TheBoard tb; //The active board - BoardHolder bh; //The Vector that holds the boards - bool saved; //The current board is saved - bool fileSaved; //The whole file is saved - string fileName; //The filename that is open, "" if no filename is given - -public: - EditorInterface(); - void getModel(int); - bool exists(); - void selectColor(int color); - int getSelectedColor(); - void drawOnModel(int x, int y); - void moveLeft(); - void moveRight(); - void deleteBoard(); - void moveBoardBack(); - void moveBoardForward(); - void saveBoard(); - bool saveFile(string); - bool saveFile(); - void openFile(string); - void newFile(); - int getColor(int x, int y); - int getActiveBoardNr(); - int getNumberOfMoves(); - bool newBoard(); - int getNumberOfBoards(); - void setNumberOfMoves(int); - bool isSaved(); - bool fileIsSaved(); -}; -#endif diff --git a/source/code/editor/TheBoard.cpp b/source/code/editor/TheBoard.cpp deleted file mode 100644 index 4f349c6..0000000 --- a/source/code/editor/TheBoard.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2012 Poul Sander - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see http://www.gnu.org/licenses/ - -Source information and contacts persons can be found at -http://blockattack.sf.net -=========================================================================== -*/ - -#include "TheBoard.hpp" - -TheBoard::TheBoard() -{ - numberOfMoves = 0; - for(int i = 0; i < BOARDWIDTH; i++) - for(int j = 0; j < BOARDHEIGHT; j++) - TheBoard::board[i][j] = -1; - isNull = false; -} - -TheBoard::TheBoard(const TheBoard &tb) -{ - TheBoard::numberOfMoves = tb.numberOfMoves; - for(int i = 0; i < BOARDWIDTH; i++) - for(int j = 0; j < BOARDHEIGHT; j++) - TheBoard::board[i][j] = tb.board[i][j]; - isNull = false; -} - -void TheBoard::copyFrom(TheBoard *tb) -{ - TheBoard::numberOfMoves = tb->numberOfMoves; - for(int i = 0; i < BOARDWIDTH; i++) - for(int j = 0; j < BOARDHEIGHT; j++) - TheBoard::board[i][j] = tb->board[i][j]; -} - -bool TheBoard::setBrick(int x, int y, int color) -{ - if((x<0)||(x>=BOARDWIDTH)||(y<0)||(y>=12)) - return false; - board[x][y]=color; - return true; -} - -int TheBoard::getBrick(int x, int y) -{ - if((x<0)||(x>=BOARDWIDTH)||(y<0)||(y>=BOARDHEIGHT)) - return -999; - return board[x][y]; -} - -void TheBoard::setNumberOfMoves(int moves) -{ - TheBoard::numberOfMoves = moves; -} - -int TheBoard::getNumberOfMoves() -{ - return TheBoard::numberOfMoves; -} - -bool TheBoard::moveUp(int x, int y) -{ - if((x<0)||(x>=BOARDWIDTH)||(y<0)||(y>=BOARDHEIGHT)) - return false; - for(int i=1; i<=y; i++) - { - board[x][i-1]=board[x][i]; - } - board[x][y]=-1; - return true; -} //moveUp - -bool TheBoard::moveDown(int x, int y) -{ - if((x<0)||(x>=BOARDWIDTH)||(y<0)||(y>=BOARDHEIGHT)) - return false; - for(int i=y-1; i>=0; i--) - { - board[x][i+1]=board[x][i]; - } - board[x][0]=-1; - return true; -} - -void TheBoard::moveRight() -{ - for(int i=0; i=0; j--) - { - board[j+1][i]=board[j][i]; - } - board[0][i] = -1; - } -} //moveRight - - -//moves all pieces one to the right -void TheBoard::moveLeft() -{ - for(int i=0; i0) - ei.setNumberOfMoves(ei.getNumberOfMoves()-1); - } - } -}; - -theEditor::theEditor() -{ - //This is the constructor - createFileButton cb; - buttons.push_back(cb); - deletePuzzleButton dpb; - buttons.push_back(dpb); -} - -void theEditor::drawButtons() -{ - for(int i = 0; idraw(); - } -} - -void aButton::click(int x, int y) -{ - cout << "Error: aButtons's click command was executed!" << endl; -} - -void aButton::draw() -{ - DrawIMG(label,screen,x,y); -} - -void theEditor::click(int x, int y) -{ - for(int i = 0; iclick(x,y); - } -} - -int main() -{ - theEditor te; - te.drawButtons(); -} \ No newline at end of file diff --git a/source/code/editor/editorMain.hpp b/source/code/editor/editorMain.hpp deleted file mode 100644 index 0bdcfa3..0000000 --- a/source/code/editor/editorMain.hpp +++ /dev/null @@ -1,99 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2012 Poul Sander - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see http://www.gnu.org/licenses/ - -Source information and contacts persons can be found at -http://blockattack.sf.net -=========================================================================== -*/ - -#include "SDL.h" -#include "EditorInterface.hpp" -#include - -//Do to stability reasons we load everything in the main and just refer to it here: -extern SDL_Surface *bCreateFile; -extern SDL_Surface *bDeletePuzzle; -extern SDL_Surface *bLoadFile; -extern SDL_Surface *bMoveBack; -extern SDL_Surface *bMoveDown; -extern SDL_Surface *bMoveForward; -extern SDL_Surface *bMoveLeft; -extern SDL_Surface *bMoveRight; -extern SDL_Surface *bMoveUp; -extern SDL_Surface *bNewPuzzle; -extern SDL_Surface *bSaveFileAs; -extern SDL_Surface *bSavePuzzle; -extern SDL_Surface *bSaveToFile; -extern SDL_Surface *bTestPuzzle; - -//The screen we draw on: -extern SDL_Surface *screen; - -extern EditorInterface ei; - -class aButton -{ -public: - int x,y,width,height; - SDL_Surface *label; - - aButton() - { - } - - aButton(int x,int y,SDL_Surface *ss) - { - this->x = x; - this->y = y; - this->label = ss; - width = this->label->w; - height = this->label->h; - } - - void draw(); - - //Function to check if the button is clicked. - bool clicked(int x, int y) - { - if((x>=this->x)&&(x<=this->x+width)&&(y>=this->y)&&(y<=this->y+height)) - return true; - else - return false; - } - - void click(int x, int y); -}; - -const int numberOfButtons = 14; - -//The editor itself... -class theEditor -{ -private: - vector buttons; - - -public: - - theEditor(); - - virtual void drawButtons(); - - virtual void click(int x, int y); - -}; diff --git a/source/code/highscore.cpp b/source/code/highscore.cpp index f021784..cf72c50 100644 --- a/source/code/highscore.cpp +++ b/source/code/highscore.cpp @@ -23,6 +23,8 @@ http://blockattack.sf.net #include "highscore.h" +using namespace std; + #ifdef WIN32 //Returns path to "my Documents" in windows: