diff --git a/README.md b/README.md index 5cbaf75..75780e7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # StackAttack -Учебный проект по практикуму на ЭВМ,игра для Arduino "Шар в лабиринте" +Учебный проект по практикуму на ЭВМ,игра для Arduino "Stack attack" Игрок,нажимая на кнопки движения,перемещает персонажа в стороны,передвигает блоки так,чтобы они образовывали цельную прямую и уничтожались -На данном этапе реализована тестовая консольная версия,в которой персонаж может передвигаться и двигать блоки.Управление осуществляется с помощью клавиш WSAD +На данном этапе реализована финальная версия игры со всем функционалом перенесённым из оригинала. Управление осуществляется как на джостик так и на кнопки joystickshield. + diff --git a/StackAttack/.vs/StackAttack/v16/.suo b/StackAttack/.vs/StackAttack/v16/.suo deleted file mode 100755 index 739e7a1..0000000 Binary files a/StackAttack/.vs/StackAttack/v16/.suo and /dev/null differ diff --git a/StackAttack/.vs/StackAttack/v16/Browse.VC.db b/StackAttack/.vs/StackAttack/v16/Browse.VC.db deleted file mode 100755 index a56c056..0000000 Binary files a/StackAttack/.vs/StackAttack/v16/Browse.VC.db and /dev/null differ diff --git a/StackAttack/.vs/StackAttack/v16/TestStore/0/000-0000.testlog b/StackAttack/.vs/StackAttack/v16/TestStore/0/000-0000.testlog deleted file mode 100755 index 842f369..0000000 Binary files a/StackAttack/.vs/StackAttack/v16/TestStore/0/000-0000.testlog and /dev/null differ diff --git a/StackAttack/.vs/StackAttack/v16/TestStore/0/testlog.manifest b/StackAttack/.vs/StackAttack/v16/TestStore/0/testlog.manifest deleted file mode 100755 index b6ec9cf..0000000 Binary files a/StackAttack/.vs/StackAttack/v16/TestStore/0/testlog.manifest and /dev/null differ diff --git a/StackAttack/.vs/StackAttack/v16/ipch/AutoPCH/418b1029a935854d/MAIN.ipch b/StackAttack/.vs/StackAttack/v16/ipch/AutoPCH/418b1029a935854d/MAIN.ipch deleted file mode 100755 index 360393e..0000000 Binary files a/StackAttack/.vs/StackAttack/v16/ipch/AutoPCH/418b1029a935854d/MAIN.ipch and /dev/null differ diff --git a/StackAttack/Debug/StackAttack.exe b/StackAttack/Debug/StackAttack.exe deleted file mode 100755 index b2bcbd0..0000000 Binary files a/StackAttack/Debug/StackAttack.exe and /dev/null differ diff --git a/StackAttack/Debug/StackAttack.ilk b/StackAttack/Debug/StackAttack.ilk deleted file mode 100755 index 0da892b..0000000 Binary files a/StackAttack/Debug/StackAttack.ilk and /dev/null differ diff --git a/StackAttack/Debug/StackAttack.pdb b/StackAttack/Debug/StackAttack.pdb deleted file mode 100755 index 9824117..0000000 Binary files a/StackAttack/Debug/StackAttack.pdb and /dev/null differ diff --git a/StackAttack/StackAttack.sln b/StackAttack/StackAttack.sln deleted file mode 100755 index 64bde10..0000000 --- a/StackAttack/StackAttack.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29306.81 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StackAttack", "StackAttack\StackAttack.vcxproj", "{704DC626-5CE3-4A9B-9A7B-612E5EF657D1}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {704DC626-5CE3-4A9B-9A7B-612E5EF657D1}.Debug|x64.ActiveCfg = Debug|x64 - {704DC626-5CE3-4A9B-9A7B-612E5EF657D1}.Debug|x64.Build.0 = Debug|x64 - {704DC626-5CE3-4A9B-9A7B-612E5EF657D1}.Debug|x86.ActiveCfg = Debug|Win32 - {704DC626-5CE3-4A9B-9A7B-612E5EF657D1}.Debug|x86.Build.0 = Debug|Win32 - {704DC626-5CE3-4A9B-9A7B-612E5EF657D1}.Release|x64.ActiveCfg = Release|x64 - {704DC626-5CE3-4A9B-9A7B-612E5EF657D1}.Release|x64.Build.0 = Release|x64 - {704DC626-5CE3-4A9B-9A7B-612E5EF657D1}.Release|x86.ActiveCfg = Release|Win32 - {704DC626-5CE3-4A9B-9A7B-612E5EF657D1}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {83FAA760-AA2F-4979-8E4F-BDB86DFC585F} - EndGlobalSection -EndGlobal diff --git a/StackAttack/StackAttack/Debug/Game.obj b/StackAttack/StackAttack/Debug/Game.obj deleted file mode 100755 index ea57390..0000000 Binary files a/StackAttack/StackAttack/Debug/Game.obj and /dev/null differ diff --git a/StackAttack/StackAttack/Debug/Main.obj b/StackAttack/StackAttack/Debug/Main.obj deleted file mode 100755 index d456cdd..0000000 Binary files a/StackAttack/StackAttack/Debug/Main.obj and /dev/null differ diff --git a/StackAttack/StackAttack/Debug/StackAttack.log b/StackAttack/StackAttack/Debug/StackAttack.log deleted file mode 100755 index 9d64eda..0000000 --- a/StackAttack/StackAttack/Debug/StackAttack.log +++ /dev/null @@ -1,9 +0,0 @@ - Main.cpp -C:\Users\Пользователь\source\repos\StackAttack\StackAttack\Main.cpp(1,9): warning C4067: непредвиденные лексемы за директивой препроцессора, требуется newline -C:\Users\Пользователь\source\repos\StackAttack\StackAttack\Main.cpp(2,10): warning C4067: непредвиденные лексемы за директивой препроцессора, требуется newline -C:\Users\Пользователь\source\repos\StackAttack\StackAttack\Main.cpp(3,9): warning C4067: непредвиденные лексемы за директивой препроцессора, требуется newline -C:\Users\Пользователь\source\repos\StackAttack\StackAttack\Main.cpp(4,10): warning C4067: непредвиденные лексемы за директивой препроцессора, требуется newline -C:\Users\Пользователь\source\repos\StackAttack\StackAttack\Main.cpp(70,1): warning C4804: >: небезопасное использование типа "bool" в операции -C:\Users\Пользователь\source\repos\StackAttack\StackAttack\Main.cpp(148,13): warning C4244: аргумент: преобразование "time_t" в "unsigned int", возможна потеря данных -C:\Users\Пользователь\source\repos\StackAttack\StackAttack\Main.cpp(214,7): warning C4101: input: неиспользованная локальная переменная - StackAttack.vcxproj -> C:\Users\Пользователь\source\repos\StackAttack\Debug\StackAttack.exe diff --git a/StackAttack/StackAttack/Debug/StackAttack.tlog/CL.command.1.tlog b/StackAttack/StackAttack/Debug/StackAttack.tlog/CL.command.1.tlog deleted file mode 100755 index 7d22c38..0000000 Binary files a/StackAttack/StackAttack/Debug/StackAttack.tlog/CL.command.1.tlog and /dev/null differ diff --git a/StackAttack/StackAttack/Debug/StackAttack.tlog/CL.read.1.tlog b/StackAttack/StackAttack/Debug/StackAttack.tlog/CL.read.1.tlog deleted file mode 100755 index bd3e064..0000000 Binary files a/StackAttack/StackAttack/Debug/StackAttack.tlog/CL.read.1.tlog and /dev/null differ diff --git a/StackAttack/StackAttack/Debug/StackAttack.tlog/CL.write.1.tlog b/StackAttack/StackAttack/Debug/StackAttack.tlog/CL.write.1.tlog deleted file mode 100755 index f628f8e..0000000 Binary files a/StackAttack/StackAttack/Debug/StackAttack.tlog/CL.write.1.tlog and /dev/null differ diff --git a/StackAttack/StackAttack/Debug/StackAttack.tlog/StackAttack.lastbuildstate b/StackAttack/StackAttack/Debug/StackAttack.tlog/StackAttack.lastbuildstate deleted file mode 100755 index 1693658..0000000 --- a/StackAttack/StackAttack/Debug/StackAttack.tlog/StackAttack.lastbuildstate +++ /dev/null @@ -1,2 +0,0 @@ -#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0 -Debug|Win32|C:\Users\Пользователь\source\repos\StackAttack\| diff --git a/StackAttack/StackAttack/Debug/StackAttack.tlog/link.command.1.tlog b/StackAttack/StackAttack/Debug/StackAttack.tlog/link.command.1.tlog deleted file mode 100755 index 6b668b8..0000000 Binary files a/StackAttack/StackAttack/Debug/StackAttack.tlog/link.command.1.tlog and /dev/null differ diff --git a/StackAttack/StackAttack/Debug/StackAttack.tlog/link.read.1.tlog b/StackAttack/StackAttack/Debug/StackAttack.tlog/link.read.1.tlog deleted file mode 100755 index 79e1887..0000000 Binary files a/StackAttack/StackAttack/Debug/StackAttack.tlog/link.read.1.tlog and /dev/null differ diff --git a/StackAttack/StackAttack/Debug/StackAttack.tlog/link.write.1.tlog b/StackAttack/StackAttack/Debug/StackAttack.tlog/link.write.1.tlog deleted file mode 100755 index 9ac6b33..0000000 Binary files a/StackAttack/StackAttack/Debug/StackAttack.tlog/link.write.1.tlog and /dev/null differ diff --git a/StackAttack/StackAttack/Debug/vc142.idb b/StackAttack/StackAttack/Debug/vc142.idb deleted file mode 100755 index 169ca7c..0000000 Binary files a/StackAttack/StackAttack/Debug/vc142.idb and /dev/null differ diff --git a/StackAttack/StackAttack/Debug/vc142.pdb b/StackAttack/StackAttack/Debug/vc142.pdb deleted file mode 100755 index 649b818..0000000 Binary files a/StackAttack/StackAttack/Debug/vc142.pdb and /dev/null differ diff --git a/StackAttack/StackAttack/Game.cpp b/StackAttack/StackAttack/Game.cpp deleted file mode 100755 index 5b7ae53..0000000 --- a/StackAttack/StackAttack/Game.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "Game.h" -#include -#include -#include -void Game::Move(char button)//moving player -{ - - - switch (button) - { - case 'w': - if (mas[body.y - 1][body.x] != 1 && body.y-1>=0 && body.y+1 !=0) - body.y++; - break; - case 'a': - if (mas[body.y][body.x - 1] != 1 && body.x - 1 >= 0) - body.x--; - else if (mas[body.y][body.x - 1] == 1 && body.x - 1 >= 0) - { - if (mas[body.y][body.x - 2] == 0 && body.x - 2 >= 0) - { - mas[body.y][body.x - 1] = 1; - body.x--; - } - //else if(mas[body.y][body.x - 2] != 0 && body.x - 2 >= 0) - - } - break; - case 'd': - if (mas[body.y][body.x + 1] != 1 && body.x + 1 <29) - body.x++; - else if (mas[body.y][body.x + 1] == 1 && body.x + 1 <29) - { - if (mas[body.y][body.x + 2] == 0 && body.x + 2 <29) - { - mas[body.y][body.x + 1] = 1; - body.x++; - } - //else if(mas[body.y][body.x + 2] != 0 && body.x +2 <29) - - } - break; - - - - } - -} - - -void Game::Drop() -{ - body.x=this->Random(); - - int blocks = 1; - for(int i=0;i - -struct Point -{ -public: - int x; - int y; -}; - -/* -0- -1- -2- -*/ - -class Game -{ -private: - static const int cols = 30; - static const int rows = 39; - Point body; - unsigned char mas[rows][cols]; - Point block; - -public: - - Game() : mas{0} - { - for (int i = 0; i < 30; ++i) - mas[38][i] = 1; - body.x = 14; - body.y = 12; - } - - - void Move(char); - void Drop(); - int Random(); - void Show(); -}; - diff --git a/StackAttack/StackAttack/Main.cpp b/StackAttack/StackAttack/Main.cpp deleted file mode 100755 index 7e240e0..0000000 --- a/StackAttack/StackAttack/Main.cpp +++ /dev/null @@ -1,231 +0,0 @@ -#include; -#include "Game.h"; -#include; -#include ; -// constants stand for settings & iterating over scene grid - - - -class StackAttack -{ -private: - static const int rows = 7; - static const int cols = 12; - - char sceneGrid[rows][cols]; - Point player; - - bool UpdatePlayer(const int& input) - { - char playerSideBottom; - char playerSideUp; - char playerUp; - switch (input) - { - case 'w': - // player jumps - // check for blocks & destroy if there is one - if((sceneGrid[player.x+1][player.y]!=' ' && player.x+1 0) - return true; - - playerSideBottom = sceneGrid[player.x][player.y - 1]; - playerSideUp = sceneGrid[player.x - 1][player.y - 1]; - - if (playerSideBottom == ' ') - { - if (playerSideUp == ' ') - player.y -= 1; - else return true; - - } - else - { - if (sceneGrid[player.x][player.y - 2] == ' ') - { - sceneGrid[player.x][player.y - 2] = '#'; - sceneGrid[player.x][player.y - 1] = ' '; - player.y -= 1; - } - } - return true; - default: - return false; - } - } - -public: - StackAttack() - { - // initilize scene grid with empty space - for (int i = 0; i < rows; ++i) - for (int j = 0; j < cols; ++j) - sceneGrid[i][j] = ' '; - - // spawn play & align it vertically & horizontally (imperfect as grid width is not even) - player = { 6, 6 }; - - // draw player renders - // sceneGrid[6][6] = '%'; - // sceneGrid[5][6] = '%'; - } - - void Render() - { - for (int i = 0; i < rows; ++i) - { - for (int j = 0; j < cols; ++j) - { - if (sceneGrid[player.x + 1][j] != ' ' && (player.x+1)!=rows-1) - { - if ((player.x == i && player.y == j) || - (player.x - 1 == i && player.y == j)) - std::cout << "% "; - else std::cout << sceneGrid[i][j]; - } - else - { - // - if ((player.x+1 == i && player.y == j) || - (player.x == i && player.y == j)) - std::cout << "% "; - else std::cout << sceneGrid[i][j]; - } - } - - std::cout << std::endl; - } - } - - - void block_rand() - { - srand(time(NULL)); - int y = rand() % rows; - sceneGrid[0][y] = '#'; - } - - - - bool Update(const char& input) - { - if (UpdatePlayer(input)) - { - // sceneGrid[player] - for (int i = 0; i < rows; i++) - { - for(int j = 0; j < cols;j++) - { - if (player.x-1 == 0 || player.x-1 == 1) - return false; - else - if (sceneGrid[i][j] == '#' && i != rows-1) - { - if (player.x - 1 == i && player.y == j) - { - return false; - } - else - { - // - sceneGrid[i][j] = ' '; - sceneGrid[i + 1][j] = '#'; - } - } - } - } - - - } - return true; - } -}; - -/* - Game: - public: - Update(input) : takes player input handled in main & runs update for all gameobjects in the scene - Handle input (send data to Player Game Object) - If input is correct than run update for block game objects (block logic) - Update render buffer - Game() : constructor that initializes empty scene & spawns player -*/ - -int main() -{ - // Game a; - // - // do - // { - // a.Show(); - // a.Move(_getch()); - // a.Drop(); - // - // - // system("cls"); - // } while (true); - - StackAttack game; - - char input; - int counter = 0; - do - { - if (counter % 5 == 0) - { - game.block_rand(); - } - system("cls"); - game.Render(); - - - //std::cin >> input; - - counter++; - } while (game.Update(_getch())); - - std::cout << std::endl << "You lost" << std::endl; - - return 0; -} \ No newline at end of file diff --git a/StackAttack/StackAttack/StackAttack.vcxproj b/StackAttack/StackAttack/StackAttack.vcxproj deleted file mode 100755 index 2b72957..0000000 --- a/StackAttack/StackAttack/StackAttack.vcxproj +++ /dev/null @@ -1,135 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - {704DC626-5CE3-4A9B-9A7B-612E5EF657D1} - StackAttack - 10.0 - - - - Application - true - v142 - MultiByte - - - Application - false - v142 - true - MultiByte - - - Application - true - v142 - MultiByte - - - Application - false - v142 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - - - Level3 - Disabled - true - true - - - Console - - - - - Level3 - Disabled - true - true - - - Console - - - - - Level3 - MaxSpeed - true - true - true - true - - - Console - true - true - - - - - Level3 - MaxSpeed - true - true - true - true - - - Console - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/StackAttack/StackAttack/StackAttack.vcxproj.filters b/StackAttack/StackAttack/StackAttack.vcxproj.filters deleted file mode 100755 index 22a073c..0000000 --- a/StackAttack/StackAttack/StackAttack.vcxproj.filters +++ /dev/null @@ -1,30 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы - - - Исходные файлы - - - - - Файлы заголовков - - - \ No newline at end of file diff --git a/StackAttack/StackAttack/StackAttack.vcxproj.user b/StackAttack/StackAttack/StackAttack.vcxproj.user deleted file mode 100755 index 88a5509..0000000 --- a/StackAttack/StackAttack/StackAttack.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/StackAttack/Stack_Attack/Stack_Attack/Stack_Attack.ino b/StackAttack/Stack_Attack/Stack_Attack/Stack_Attack.ino new file mode 100644 index 0000000..640dade --- /dev/null +++ b/StackAttack/Stack_Attack/Stack_Attack/Stack_Attack.ino @@ -0,0 +1,878 @@ +#include +#include +LCD5110 LCD(9,10,11,12,13); +extern unsigned char SmallFont[]; +#define ANALOG_X_pin 0 +#define ANALOG_Y_pin 1 +#define RIGHT_pin 3 +#define LEFT_pin 5 +#define UP_pin 2 +#define DOWN_pin 4 +#define BUTTON_E 6 +#define BUTTON_F 7 +#define BUTTON_G 8 + +struct Point +{ +public: + int x; + int y; +}; + +class StackAttack +{ +private: + static const uint8_t rows = 9; + static const uint8_t cols = 14; + bool gameover = false; + uint8_t _isPlaying = 0; + //settings + uint8_t size = 2; + uint8_t contrast = 70; + uint8_t difficulty = 0; + int gameSpeed = 1000; + + //chosen params + uint8_t _chosenOption = 0; + uint8_t _section = 0; + //record table + String Top1 = "ZZZ"; + int Top1score = 0; + + String Top2 = "ZZZ"; + int Top2score = 0; + + String Top3 = "ZZZ"; + int Top3score = 0; + + char sceneGrid[rows][cols]; + Point player; + + bool UpdatePlayer() + { + char playerSideBottom; + char playerSideUp; + char playerUp; + + if (digitalRead(UP_pin)==LOW||(analogRead(ANALOG_Y_pin)> 553)) + { + // player jumps + // check for blocks & destroy if there is one + if(sceneGrid[player.x+1][player.y] == '#' || (player.x) == rows - 1) + { + if (sceneGrid[player.x - 1][player.y] == '#') // destroy block in top of player + { + for(int i = player.x; i > 1; i--) + sceneGrid[i][player.y] = '*'; + + return true; + } + else // just stay in air + { + player.x -= 1; + return true; + } + } + else if (sceneGrid[player.x + 1][player.y] == '*') // drop if there is empty in the bottom + { + player.x += 1; + return true; + } + else + return false; + } + + if (digitalRead(RIGHT_pin)==LOW||(analogRead(ANALOG_X_pin)> 553)) + { + // player moves right + // check for blocks & try to move block & move player + if (!(player.y < cols - 1)) + return true; + + playerSideBottom = sceneGrid[player.x][player.y + 1]; // right place + playerSideUp = sceneGrid[player.x - 1][player.y + 1]; // right and top place + + if (playerSideBottom == '*' ) + { + if (playerSideUp == '*') + { + if (sceneGrid[player.x + 1][player.y + 1] == '*') + { + player.y += 1; + player.x += 1; + return true; + } + else + { + player.y += 1; + return true; + } + + } + else + { + if (sceneGrid[player.x - 1][player.y + 2] == '*' && player.y + 1 != 0) + { + sceneGrid[player.x - 1][player.y + 2] = '#'; + sceneGrid[player.x - 1][player.y + 1] = '*'; + player.y += 1; + return true; + } + } + + } + else + { + if (sceneGrid[player.x - 1][player.y + 1] == '*') + { + if (sceneGrid[player.x][player.y + 2] == '*' && player.y != 10) + { + sceneGrid[player.x][player.y + 2] = '#'; + sceneGrid[player.x][player.y + 1] = '*'; + player.y += 1; + return true; + } + else + { + return true; + } + } + else + return true; + + + } + } + + + if (digitalRead(LEFT_pin)==LOW||(analogRead(ANALOG_X_pin)< 320)) + { + // player moves left + // check for blocks & try to move block & move player + if (!player.y > 0) + return true; + + playerSideBottom = sceneGrid[player.x][player.y - 1]; + playerSideUp = sceneGrid[player.x - 1][player.y - 1]; + + if (playerSideBottom == '*') // empty near + { + if (playerSideUp == '*') // enty in top + { + if (sceneGrid[player.x + 1][player.y - 1] == '*') + { + player.x += 1; + player.y -= 1; + return true; + } + else + { + player.y -= 1; + return true; + } + } + else + if (sceneGrid[player.x - 1][player.y - 2] == '*' && player.y - 1 != 0) + { + sceneGrid[player.x-1][player.y - 2] = '#'; + sceneGrid[player.x-1][player.y - 1] = '*'; + player.y -= 1; + return true; + } + return true; + + } + else + { + if (sceneGrid[player.x - 1][player.y - 1] == '*') + { + if (sceneGrid[player.x][player.y - 2] == '*' && player.y != 1) + { + sceneGrid[player.x][player.y - 2] = '#'; + sceneGrid[player.x][player.y - 1] = '*'; + player.y -= 1; + return true; + } + else + { + return true; + } + } + else + return true; + + + } + return true; + } + } + + + +public: + uint8_t score = 0; + + void GameOver() + { + //write info and score + LCD.clrScr(); + LCD.print("Game Over",0,0); + + LCD.print("Score:",0,16); + LCD.printNumI(score,40,16); + score = 0; + LCD.print("Press Any Key",0,24); + LCD.print("To Continue",0,32); + LCD.update(); + //unlimited cikle + while (true) + if (digitalRead(UP_pin)==LOW||digitalRead(DOWN_pin)==LOW||digitalRead(LEFT_pin)==LOW||digitalRead(RIGHT_pin)==LOW||digitalRead(BUTTON_E)==LOW||digitalRead(BUTTON_F)==LOW||digitalRead(BUTTON_G)==LOW) + { + String _name = "AAA"; + uint8_t _chosenChar = 0; + while (true) + { + //write name of player + if(digitalRead(LEFT_pin)==LOW) + if(_chosenChar == 0) + _chosenChar = 2; + else _chosenChar -= 1; + + if(digitalRead(RIGHT_pin)==LOW) + if(_chosenChar == 2) + _chosenChar = 0; + else _chosenChar += 1; + + if(digitalRead(DOWN_pin)==LOW) + if(_name[_chosenChar] == 'A') + _name[_chosenChar] = 'Z'; + else _name[_chosenChar] -= 1; + + if(digitalRead(UP_pin)==LOW) + if(_name[_chosenChar] == 'Z') + _name[_chosenChar] = 'A'; + else _name[_chosenChar] += 1; + + LCD.clrScr(); + LCD.print("Enter Name:",0,0); + LCD.print(_name,64,0); + LCD.drawRect(64 + _chosenChar*6,8,70 + _chosenChar*6,10); + + LCD.print("Press G",0,12); + LCD.print("To Try Again",0,20); + LCD.print("Press E,F",0,28); + LCD.print("To Menu",0,36); + + + + LCD.update(); + delay(200); + //check if we should change score place for G + //In case of E and F go to menu + + if (digitalRead(BUTTON_G)==LOW) + { + + delay(1000); + CalcRecords(_name, score); + + gameover = false; + LCD.clrScr(); + LoopGame(); + } + if (digitalRead(BUTTON_E)==LOW||digitalRead(BUTTON_F)==LOW) + { + LCD.clrScr(); + CalcRecords(_name, score); + _isPlaying = 0; + gameover = false; + //return; + LCD.update(); + delay(1000); + ShowMenu(); + + + } + } + } + } + + + + + void CalcRecords(String _name, int _score) + { + + if (_score >= Top1score) + { + if (_score == Top1score) + { + if (_name.compareTo(Top1) < 0) + { + for (int i = 0; i<3;++i) + Top3[i] = Top2[i]; + Top3score = Top2score; + + + for (int i = 0; i<3;++i) + Top2[i] = Top1[i]; + Top2score = Top1score; + + + for (int i = 0; i<3;++i) + Top1[i] = _name[i]; + Top1score = _score; + + } + else if(_name.compareTo(Top1) > 0) + { + for (int i = 0; i<3;++i) + Top3[i] = Top2[i]; + Top3score = Top2score; + + + for (int i = 0; i<3;++i) + Top2[i] = _name[i]; + Top2score = _score; + + } + else if (_name.compareTo(Top1) == 0) + { + for (int i = 0; i<3;++i) + Top1[i] = _name[i]; + Top1score = _score; + + } + } + else + { + for (int i = 0; i<3;++i) + Top3[i] = Top2[i]; + Top3score = Top2score; + + + for (int i = 0; i<3;++i) + Top2[i] = Top1[i]; + Top2score = Top1score; + + + for (int i = 0; i<3;++i) + Top1[i] = _name[i]; + Top1score = _score; + + } + } + else if (_score >= Top2score) + { + if (_score == Top2score) + { + if(_name.compareTo(Top2) < 0) + { + for (int i = 0; i<3;++i) + Top3[i] = Top2[i]; + Top3score = Top2score; + + + for (int i = 0; i<3;++i) + Top2[i] = _name[i]; + Top2score = _score; + + } + else if(_name.compareTo(Top2) > 0) + { + for (int i = 0; i<3;++i) + Top3[i] = _name[i]; + Top3score = _score; + + } + else if(_name.compareTo(Top2) == 0) + { + for (int i = 0; i<3;++i) + Top2[i] = _name[i]; + Top2score = _score; + + } + } + else + { + for (int i = 0; i<3;++i) + Top3[i] = Top2[i]; + Top3score = Top2score; + + + for (int i = 0; i<3;++i) + Top2[i] = _name[i]; + Top2score = _score; + + } + } + else if (_score >= Top3score) + { + for (int i = 0; i<3;++i) + Top3[i] = _name[i]; + Top3score = _score; + + } + + //save top 3 in memory + for (int i = 0; i < 3; ++i) + EEPROM.write(237 + i*9, Top1[i]); + for (int i = 0; i < 3; ++i) + EEPROM.write(362 + i*9, Top2[i]); + for (int i = 0; i < 3; ++i) + EEPROM.write(487 + i*9, Top3[i]); + + EEPROM.put(111, Top1score); + EEPROM.put(128, Top2score); + EEPROM.put(145, Top3score); + + } + + void LoopGame() + { + /* + int counter = 0; + do + { + if (counter % 5 == 0) + { + block_rand(); + } + LCD.clrScr(); + Render(); + LCD.update(); + + //std::cin >> input; + + counter++; + } while (Update()); + LCD.clrScr(); + + GameOver();*/ + int gameSpeed = 1000; + gameSpeed -= difficulty * 200; + int counter = 0; + Refrash(); + do + { + if (counter % 3 == 0) + { + Falling(); + } + + if (counter % 7 == 0) + { + block_rand(); + } + LCD.clrScr(); + Render(); + LCD.update(); + + //std::cin >> input; + counter++; + delay(gameSpeed); + } while (Update()); + LCD.clrScr(); + GameOver(); + + + } + //call menu + int ShowMenu() + { + while(true) + { + //change option buy up or down buttons + if(digitalRead(UP_pin)==LOW) + if(_chosenOption == 0) + _chosenOption = 3; + else _chosenOption -= 1; + + if(digitalRead(DOWN_pin)==LOW) + if(_chosenOption == 3) + _chosenOption = 0; + else _chosenOption += 1; + LCD.clrScr(); + LCD.drawRect(0,5 + _chosenOption*8, 6,11 + _chosenOption*8); + + //writing of default menu + if(_section == 0) + { + LCD.print("START",27,5); + LCD.print("RECORDS",20,13); + LCD.print("SETTINGS",18,21); + LCD.print("EXIT",30,29); + LCD.update(); + if(digitalRead(BUTTON_E)==LOW||digitalRead(BUTTON_G)==LOW) + //Actions for button START + if(_chosenOption == 0) + { + //Begin game + LCD.clrScr(); + _isPlaying = 1; + LoopGame(); + } + //For button RECORDS + else if(_chosenOption == 1) + { + //Way to record table + LCD.clrScr(); + _section = 2; + _chosenOption = 0; + delay(100); + } + //For button SETTINGS + else if(_chosenOption == 2) + { + //Way to settings + LCD.clrScr(); + _section = 1; + _chosenOption = 0; + delay(100); + } + //For button EXIT + else if(_chosenOption == 3) + { + //Writing buy message + LCD.clrScr(); + LCD.print("Goodbye!",0,0); + LCD.update(); + delay(1000); + LCD.clrScr(); + LCD.update(); + LCD.enableSleep(); + _isPlaying = 5; + } + } + //Show settings menu + else if(_section == 1) + { + + LCD.print("BACK",8,5); + LCD.print("SIZE",8,13); + LCD.printNumI(size,76,13); + LCD.print("DIFFICULTY",8,21); + LCD.printNumI(difficulty,76,21); + LCD.print("CONTRAST",8,29); + LCD.printNumI(contrast,70,29); + LCD.update(); + if(digitalRead(BUTTON_E)==LOW||digitalRead(BUTTON_G)==LOW) + if(_chosenOption == 0) + { + //Return to the default menu + LCD.clrScr(); + _section = 0; + _chosenOption = 0; + delay(300); + } + if(_chosenOption == 1) + { + //change size from 1 to 3 + if(digitalRead(RIGHT_pin)==LOW) + if(size == 5) + size = 3; + else size++; + else if(digitalRead(LEFT_pin)==LOW) + if(size == 3) + size = 5; + else size--; + EEPROM.put(0, size); + } + else if(_chosenOption == 2) + { + //Change difficult (0-3) + if(digitalRead(RIGHT_pin)==LOW) + if(difficulty == 3) + difficulty = 0; + else difficulty++; + else if(digitalRead(LEFT_pin)==LOW) + if(difficulty == 0) + difficulty = 3; + else difficulty--; + EEPROM.put(9, difficulty); + } + else if(_chosenOption == 3) + { + //change kontrast + if(digitalRead(RIGHT_pin)==LOW) + if(contrast == 70) + contrast = 50; + else contrast += 2; + else if(digitalRead(LEFT_pin)==LOW) + if(contrast == 50) + contrast = 70; + else contrast -= 2; + LCD.setContrast(contrast); + + EEPROM.put(18, contrast); + } + } + //out of records table + else if (_section == 2) + { + LCD.print("BACK",8,5); + LCD.print("1]",8,13); + LCD.print(Top1,20,13); + + LCD.printNumI(Top1score,47,13); + + LCD.print("2]",8,21); + LCD.print(Top2,20,21); + + LCD.printNumI(Top2score,47,21); + + LCD.print("3]",8,29); + LCD.print(Top3,20,29); + + LCD.printNumI(Top3score,47,29); + + LCD.update(); + if(digitalRead(BUTTON_E)==LOW||digitalRead(BUTTON_F)==LOW||digitalRead(BUTTON_G)==LOW) + if(_chosenOption == 0) + { + LCD.clrScr(); + _section = 0; + _chosenOption = 0; + delay(300); + } + } + delay(100); + } + } + +void Falling(){ + for (int i = 0; i < rows; ++i) + for (int j = 0; j < cols; ++j) + if(sceneGrid[player.x + 1][player.y] == '*') + player.x += 1; + +} + + void Refrash() + { + // initilize scene grid with empty space + for (int i = 0; i < rows; ++i) + for (int j = 0; j < cols; ++j) + if (i == 0 || i == rows - 1 || j == 0 || j == cols - 1) + { + sceneGrid[i][j] = '#'; + } + else + { + sceneGrid[i][j] = '*'; + } + + // spawn play & align it vertically & horizontally (imperfect as grid width is not even) + player = { 7, 6 }; + + // draw player renders + // sceneGrid[6][6] = '%'; + // sceneGrid[5][6] = '%'; + } + + void Print(uint8_t i, uint8_t j) + { + + for (uint8_t _i = 0; _i < size; ++_i) + for (uint8_t _j = 0; _j < size; ++_j) + LCD.setPixel(size*j+_j,size*i+_i); + + } + //rendering only player + void Render() + { + LCD.printNumI(score,72,0); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < cols; j++) + { + + if (sceneGrid[i][j] != '*') + { + if((i==0) ||(i== rows-1) || (j==0) || (j==cols-1)) + { + for (uint8_t _i = 0; _i < size; ++_i) + for (uint8_t _j = 0; _j < size; ++_j) + if((_i==0) ||(_i== size-1) || (_j==0) || (_j==size-1) ||(_i == _j)) + LCD.setPixel(size*j+_j,size*i+_i); + } + else + Print(i,j); + } + else if((player.x - 1 == i && player.y == j) || + (player.x == i && player.y == j)) + { + //Print(i,j); + for (uint8_t _i = 0; _i < size; ++_i) + for (uint8_t _j = 0; _j < size; ++_j) + if((_i==0) ||(_i== size-1) || (_j==0) || (_j==size-1)) + LCD.setPixel(size*j+_j,size*i+_i); + } + //else + // std::cout << sceneGrid[i][j]; + + + } + //std::cout << std::endl; + } + } + + //randomaiser + void block_rand() + { + + int y = rand() % cols - 2; + sceneGrid[1][y + 1] = '#'; + } + + + //logic of dropping blocks and kiiling player by them + bool Update() + { + if (UpdatePlayer()) + { + // scenegrid[player] + + + if (player.x - 1 == 0 || player.x - 1 == 1) // if player on top 2 lines he dies + return false; + + for (int i = rows - 2; i > 0; --i) + { + for (int j = cols - 1; j > -1; --j) + { + if (sceneGrid[i][j] == '#') + { + if (sceneGrid[i + 1][j] == '*')//dropping blocks + { + sceneGrid[i][j] = '*'; + sceneGrid[i + 1][j] = '#'; + } + if(sceneGrid[i+1][j] == sceneGrid[player.x-1][player.y])//killing player + { + return false; + } + } + } + } + ProcessBottomLine(); + } + return true; + } + + //checking and clear bottom line + void ProcessBottomLine() + { + bool canDelete = true; + for (int i = 0; i < cols; ++i) + { + if (sceneGrid[rows - 2][i] != '#') + { + canDelete = false; + break; + } + } + + if (canDelete) { + for (int i = 1; i < cols - 1; ++i) + sceneGrid[rows - 2][i] = '*'; + score++; + } + } + + void SetVals() + { + size = 2; + contrast = 70; + + Top1 = "ZZZ"; + + Top1score = 0; + + Top2 = "ZZZ"; + + Top2score = 0; + + Top3 = "ZZZ"; + + Top3score = 0; + + if (EEPROM.read(0) >= 1 && EEPROM.read(0) <= 3) + EEPROM.get(0,size); + if (EEPROM.read(9) >= 0 && EEPROM.read(9) <= 3) + EEPROM.get(9,difficulty); + if (EEPROM.read(18) >= 50 && EEPROM.read(18) <= 70 && EEPROM.read(18) % 2 == 0) + EEPROM.get(18,contrast); + + int flag = 0; + for (int i = 0; i < 3; ++i) + if(EEPROM.read(237 + i*9) >= 'A' && EEPROM.read(237 + i*9) <= 'Z') + flag++; + + for (int i = 0; i < 3; ++i) + if(flag == 3) + EEPROM.get(237 + i*9, Top1[i]); + + flag = 0; + for (int i = 0; i < 3; ++i) + if(EEPROM.read(362 + i*9) >= 'A' && EEPROM.read(362 + i*9) <= 'Z') + flag++; + + for (int i = 0; i < 3; ++i) + if(flag == 3) + EEPROM.get(362 + i*9, Top2[i]); + + flag = 0; + for (int i = 0; i < 3; ++i) + if(EEPROM.read(487 + i*9) >= 'A' && EEPROM.read(487 + i*9) <= 'Z') + flag++; + + for (int i = 0; i < 3; ++i) + if(flag == 3) + EEPROM.get(487 + i*9, Top3[i]); + + if(EEPROM.read(111) >= 0 && EEPROM.read(111) <= 32000) + EEPROM.get(111, Top1score); + if(EEPROM.read(128) >= 0 && EEPROM.read(128) <= 32000) + EEPROM.get(128, Top2score); + if(EEPROM.read(145) >= 0 && EEPROM.read(145) <= 32000) + EEPROM.get(145, Top3score); + + } + +}; + +/* + Game: + public: + Update(input) : takes player input handled in main & runs update for all gameobjects in the scene + Handle input (send data to Player Game Object) + If input is correct than run update for block game objects (block logic) + Update render buffer + Game() : constructor that initializes empty scene & spawns player +*/ +StackAttack game; + +void setup() { + pinMode(UP_pin, INPUT_PULLUP); + pinMode(DOWN_pin, INPUT_PULLUP); + pinMode(RIGHT_pin, INPUT_PULLUP); + pinMode(LEFT_pin, INPUT_PULLUP); + pinMode(BUTTON_E, INPUT_PULLUP); + pinMode(BUTTON_F, INPUT_PULLUP); + pinMode(BUTTON_G, INPUT_PULLUP); + //pinMode(7, OUTPUT); + //digitalWrite(7, LOW); + srand(analogRead(0)); + + LCD.InitLCD(); + LCD.setFont(SmallFont); + game.SetVals(); + game.ShowMenu(); + +} + +void loop() { + game.ShowMenu(); + +} diff --git a/StackAttack/.vs/StackAttack/v16/ipch/AutoPCH/cd2c4e266b4a6230/GAME.ipch b/StackAttack/Stackatack.pptx old mode 100755 new mode 100644 similarity index 60% rename from StackAttack/.vs/StackAttack/v16/ipch/AutoPCH/cd2c4e266b4a6230/GAME.ipch rename to StackAttack/Stackatack.pptx index 0997dc6..e2e31be Binary files a/StackAttack/.vs/StackAttack/v16/ipch/AutoPCH/cd2c4e266b4a6230/GAME.ipch and b/StackAttack/Stackatack.pptx differ diff --git a/StackAttack/UML/UML class.png b/StackAttack/UML/UML class.png new file mode 100644 index 0000000..6d2cd2a Binary files /dev/null and b/StackAttack/UML/UML class.png differ diff --git "a/StackAttack/UML/\320\220\320\275\320\275\320\276\321\202\320\260\321\206\320\270\321\217 2019-12-17 020435.png" "b/StackAttack/UML/\320\220\320\275\320\275\320\276\321\202\320\260\321\206\320\270\321\217 2019-12-17 020435.png" new file mode 100644 index 0000000..e003975 Binary files /dev/null and "b/StackAttack/UML/\320\220\320\275\320\275\320\276\321\202\320\260\321\206\320\270\321\217 2019-12-17 020435.png" differ