This commit is contained in:
2026-04-20 23:09:26 +04:30
commit 5168562271
16 changed files with 2183 additions and 0 deletions
BIN
View File
Binary file not shown.
Binary file not shown.
+1563
View File
File diff suppressed because it is too large Load Diff
+32
View File
@@ -0,0 +1,32 @@
#ifndef GAME_HPP
#define GAME_HPP
#include "menu.hpp"
extern player Player;
extern int score;
extern int life;
extern int pauseOption;
extern player history[100];
extern int historyCount;
void render();
void renderPanel();
bool game();
bool game(int);
void HideCursor(bool visible);
void setColor(int color);
void playBeep(int F, int T);
//History
void saveHistory();
int sort();
void loadHistory();
extern int Hoption;
void loadScoresAndPrint(char name[]);
bool printHistory(int historyCount);
//Load Game
void saveGame(player &p);
void setAndMarkAsActive(int index);
void loadPlayer();
bool printLoadGame();
extern int loadOption;
#endif
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

+270
View File
@@ -0,0 +1,270 @@
#include "menu.hpp"
#include "game.hpp"
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <Windows.h>
#include <conio.h>
#include <iomanip>
using namespace std;
bool GameOver();
bool run = false;
void signalHandler(int signum)
{
if (run && Player.name != 0)
{
strcat(Player.name, "(auto save)");
saveGame(Player);
}
exit(signum);
}
int main()
{
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
#ifdef _WIN32
signal(SIGBREAK, signalHandler);
#endif
system("cls");
while (true)
{
menu();
switch (option)
{
case 1:
{
newGame();
run = true;
bool playAgain = false;
int playCount = 1;
do
{
if (playCount > 1)
{
char temp[10]; // یک آرایه موقت برای نگه داشتن عدد
// تبدیل عدد به رشته و ریختن در temp
sprintf(temp, "%d", playCount);
// حالا چسباندن به آرایه اصلی
strcat(Player.name, temp);
}
while (!game())
;
if (pauseOption == 3)
{
saveGame(Player);
run = false;
playAgain = false;
}
else if (pauseOption <= 2)
{
saveHistory();
playAgain = GameOver();
if (playAgain)
{
run = true;
playCount++;
}
}
} while (playAgain);
break;
}
case 2:
{
// printLoadGame();
while (true)
{
loadPlayer();
if (printLoadGame())
{
run = true;
setAndMarkAsActive(loadOption);
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
system("cls");
SetConsoleCursorPosition(h, {0, 5});
render();
renderPanel();
_getch();
Beep(440, 200);
Sleep(50);
Beep(660, 200);
Sleep(50);
Beep(880, 400);
bool playAgain = false;
int playCount = 1;
do
{
if (playCount > 1)
{
char temp[10]; // یک آرایه موقت برای نگه داشتن عدد
// تبدیل عدد به رشته و ریختن در temp
sprintf(temp, "%d", playCount);
// حالا چسباندن به آرایه اصلی
strcat(Player.name, temp);
}
while (!game(2))
;
if (pauseOption == 3)
{
saveGame(Player);
run = false;
playAgain = false;
}
else if (pauseOption <= 2)
{
saveHistory();
playAgain = GameOver();
if (playAgain)
{
run = true;
playCount++;
}
}
} while (playAgain);
}
else
{
break;
}
}
break;
}
case 3:
{
loadHistory();
sort();
while (true)
{
if (printHistory(historyCount))
{
loadScoresAndPrint(history[Hoption - 1].name);
_getch();
}
else
{
break;
}
}
break;
}
case 4:
{
help();
break;
}
case 5:
{
return 0;
}
}
}
}
bool GameOver()
{
HideCursor(false);
setColor(11);
system("cls");
loadHistory();
int High = sort();
string newGame[35][80];
for (int H = 0; H < 35; H++)
{
for (int S = 0; S < 80; S++)
{
newGame[H][S] = " ";
}
}
newGame[0][0] = "";
newGame[0][78] = "";
newGame[34][0] = "";
newGame[34][78] = "";
for (int i = 1; i < 34; i++)
{
newGame[i][0] = "";
newGame[i][78] = "";
}
for (int i = 1; i < 78; i++)
{
newGame[0][i] = "";
newGame[34][i] = "";
}
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(h, {0, 3});
for (int i = 0; i < 17; i++)
{
cout << setw(45) << "";
for (int j = 0; j < 79; j++)
{
cout << newGame[i][j];
}
cout << endl;
}
SetConsoleCursorPosition(h, {45, 20});
cout << "╚═════════════════════════════════════════════════════════════════════════════╝";
SetConsoleCursorPosition(h, {79, 4});
cout << "Game Over";
SetConsoleCursorPosition(h, {46, 5});
cout << "═════════════════════════════════════════════════════════════════════════════";
SetConsoleCursorPosition(h, {48, 8});
cout << "╔═══════════════════╗";
SetConsoleCursorPosition(h, {48, 9});
cout << "║ Score: " << setw(5) << score;
SetConsoleCursorPosition(h, {68, 9});
cout << "";
SetConsoleCursorPosition(h, {48, 10});
cout << "╚═══════════════════╝";
SetConsoleCursorPosition(h, {48, 12});
cout << "╔═══════════════════╗";
SetConsoleCursorPosition(h, {48, 13});
cout << "║ High: " << setw(6) << High;
SetConsoleCursorPosition(h, {68, 13});
cout << "";
SetConsoleCursorPosition(h, {48, 14});
cout << "╚═══════════════════╝";
SetConsoleCursorPosition(h, {90, 7});
cout << "╔══════════════════════════════╗";
SetConsoleCursorPosition(h, {90, 8});
cout << "║ Top Players ║";
SetConsoleCursorPosition(h, {90, 9});
cout << "║══════════════════════════════║";
SetConsoleCursorPosition(h, {90, 10});
cout << "" << left << setw(18) << history[0].name << right << setw(10) << history[0].score;
SetConsoleCursorPosition(h, {121, 10});
cout << "";
SetConsoleCursorPosition(h, {90, 11});
cout << "║══════════════════════════════║";
SetConsoleCursorPosition(h, {90, 12});
cout << "" << left << setw(18) << history[1].name;
history[1].score > 0 ? cout << right << setw(10) << history[1].score : cout << "";
SetConsoleCursorPosition(h, {121, 12});
cout << "";
SetConsoleCursorPosition(h, {90, 13});
cout << "║══════════════════════════════║";
SetConsoleCursorPosition(h, {90, 14});
cout << "" << left << setw(18) << history[2].name;
history[2].score > 0 ? cout << right << setw(10) << history[2].score : cout << "";
SetConsoleCursorPosition(h, {121, 14});
cout << "";
SetConsoleCursorPosition(h, {90, 15});
cout << "╚══════════════════════════════╝";
SetConsoleCursorPosition(h, {76, 17});
cout << "╔═══════════════╗";
SetConsoleCursorPosition(h, {76, 18});
cout << "║ ║";
SetConsoleCursorPosition(h, {78, 18});
setColor(15);
cout << "X: Play Again";
setColor(11);
SetConsoleCursorPosition(h, {76, 19});
cout << "╚═══════════════╝";
setColor(7);
char input = _getch();
if (input == 'X' || input == 'x')
{
return true;
}
return false;
}
+301
View File
@@ -0,0 +1,301 @@
#include "menu.hpp"
#include "game.hpp"
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <windows.h>
#include <string>
using namespace std;
void options(string menu[][80], string option, int optionLength, int i);
int option = 1;
void menu()
{
setColor(7);
HideCursor(false);
string menu[30][80];
for (int H = 0; H < 30; H++)
{
for (int S = 0; S < 80; S++)
{
menu[H][S] = " ";
}
}
menu[0][0] = "";
menu[0][79] = "";
menu[29][0] = "";
menu[29][79] = "";
for (int i = 1; i < 29; i++)
{
menu[i][0] = "";
menu[i][79] = "";
}
for (int i = 1; i < 79; i++)
{
menu[0][i] = "";
menu[29][i] = "";
}
options(menu, "New Game", 8, 3);
options(menu, "Load Game", 9, 8);
options(menu, "Game History", 12, 13);
options(menu, "Help", 4, 18);
// options(menu, "Settings", 8, 23);
options(menu, "Exit", 4, 23);
system("cls");
while (true)
{
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
COORD cursorPosition = {0, 5};
SetConsoleCursorPosition(h, cursorPosition);
for (int i = 0; i < 30; i++)
{
cout << setw(45) << "";
for (int j = 0; j < 80; j++)
{
if (option == 1)
{
if (i > 2 && i < 6 && j > 31 && j < 48)
{
SetConsoleTextAttribute(h, 1);
cout << menu[i][j];
SetConsoleTextAttribute(h, 7);
continue;
}
}
else if (option == 2)
{
if (i > 7 && i < 11 && j > 31 && j < 48)
{
SetConsoleTextAttribute(h, 1);
cout << menu[i][j];
SetConsoleTextAttribute(h, 7);
continue;
}
}
else if (option == 3)
{
if (i > 12 && i < 16 && j > 31 && j < 48)
{
SetConsoleTextAttribute(h, 1);
cout << menu[i][j];
SetConsoleTextAttribute(h, 7);
continue;
}
}
else if (option == 4)
{
if (i > 17 && i < 21 && j > 31 && j < 48)
{
SetConsoleTextAttribute(h, 1);
cout << menu[i][j];
SetConsoleTextAttribute(h, 7);
continue;
}
}
else if (option == 5)
{
if (i > 22 && i < 26 && j > 31 && j < 48)
{
SetConsoleTextAttribute(h, 1);
cout << menu[i][j];
SetConsoleTextAttribute(h, 7);
continue;
}
}
// else
// {
// if (i > 27 && i < 31 && j > 31 && j < 48)
// {
// SetConsoleTextAttribute(h, 1);
// cout << menu[i][j];
// SetConsoleTextAttribute(h, 7);
// continue;
// }
// }
cout << menu[i][j];
}
cout << endl;
}
while (true)
{
if (_kbhit())
{
char userInput = _getch();
if ((userInput == 'w' || userInput == 'W') && option > 1)
{
option -= 1;
break;
}
else if ((userInput == 's' || userInput == 'S') && option < 5)
{
option += 1;
break;
}
if (userInput == 13)
{
return;
}
}
}
Sleep(10);
}
}
void options(string menu[][80], string option, int optionLength, int i)
{
int sapce = (15 - optionLength) / 2;
menu[i][32] = "";
menu[i][47] = "";
menu[i + 1][32] = "";
menu[i + 1][47] = "";
menu[i + 2][32] = "";
menu[i + 2][47] = "";
for (int width = 33; width < 47; width++)
{
menu[i][width] = "";
menu[i + 2][width] = "";
}
for (int T = 0; T < optionLength; T++)
{
menu[i + 1][33 + sapce + T] = option.at(T);
}
}
bool repeat(char name[])
{
loadHistory();
for (int i = 0; i < historyCount; i++)
{
if (strcmp(name, history[i].name) == 0)
{
return true;
}
}
return false;
}
void newGame()
{
Player = {};
HideCursor(true);
system("cls");
string newGame[35][80];
for (int H = 0; H < 35; H++)
{
for (int S = 0; S < 80; S++)
{
newGame[H][S] = " ";
}
}
newGame[0][0] = "";
newGame[0][79] = "";
newGame[34][0] = "";
newGame[34][79] = "";
for (int i = 1; i < 34; i++)
{
newGame[i][0] = "";
newGame[i][79] = "";
}
for (int i = 1; i < 79; i++)
{
newGame[0][i] = "";
newGame[34][i] = "";
}
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(h, {0, 5});
for (int i = 0; i < 17; i++)
{
cout << setw(45) << "";
for (int j = 0; j < 80; j++)
{
cout << newGame[i][j];
}
cout << endl;
}
SetConsoleCursorPosition(h, {45, 21});
cout << "╚══════════════════════════════════════════════════════════════════════════════╝";
SetConsoleTextAttribute(h, 10);
SetConsoleCursorPosition(h, {81, 5});
cout << "Breakout";
while (Player.name[0] == 0 || repeat(Player.name))
{
if(repeat(Player.name))
{
SetConsoleCursorPosition(h, {64, 8});
setColor(4);
cout << "This name is alrady used!";
_getch();
SetConsoleCursorPosition(h, {64, 8});
cout << " ";
}
SetConsoleTextAttribute(h, 7);
SetConsoleCursorPosition(h, {47, 7});
cout << "Enter your name: ";
SetConsoleCursorPosition(h, {64, 7});
cout << " ";
SetConsoleCursorPosition(h, {64, 7});
cin.getline(Player.name, 200);
}
// ══════════════════════════════════Breakout════════════════════════════════════
}
void help()
{
setColor(7);
HideCursor(false);
string menu[30][80];
for (int H = 0; H < 30; H++)
{
for (int S = 0; S < 80; S++)
{
menu[H][S] = " ";
}
}
menu[0][0] = "";
menu[0][79] = "";
menu[29][0] = "";
menu[29][79] = "";
for (int i = 1; i < 29; i++)
{
menu[i][0] = "";
menu[i][79] = "";
}
for (int i = 1; i < 79; i++)
{
menu[0][i] = "";
menu[29][i] = "";
}
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(h, {0, 5});
for (int i = 0; i < 30; i++)
{
cout << setw(45) << "";
for (int j = 0; j < 80; j++)
{
cout << menu[i][j];
}
cout << endl;
}
SetConsoleCursorPosition(h, {47, 7});
cout << "\033[38;5;215m" << "1.Use " << "\033[38;5;11m" << "W/S" << "\033[38;5;215m" << " to move between options.";
SetConsoleCursorPosition(h, {47, 9});
cout << "\033[38;5;215m" << "1.Use " << "\033[38;5;11m" << "A/D" << "\033[38;5;215m" << " to move the Paddle.";
SetConsoleCursorPosition(h, {47, 11});
cout << "\033[38;5;215m" << "2.Press " << "\033[38;5;141m" << "Backspace" << "\033[38;5;215m" << " to back from loadGame menu.";
SetConsoleCursorPosition(h, {47, 14});
cout << "\033[38;5;33mB\033[38;5;82mR\033[38;5;51mI\033[38;5;196mI\033[38;5;201mK\033[38;5;226ms\033[38;5;215m:";
SetConsoleCursorPosition(h, {47, 16});
cout << "\033[38;5;33m1.Hard Brick: These bricks take two hits to break.";
SetConsoleCursorPosition(h, {47, 18});
cout << "\033[38;5;196m2.TNT Brick: explode and destroy nearby bricks";
SetConsoleCursorPosition(h, {47, 20});
cout << "\033[38;5;226m3.Golden brick: grant extra points when destroyed";
SetConsoleCursorPosition(h, {47, 22});
cout << "\033[38;5;215m4.Other colors are just for your eyes:)";
cout << "\033[0m";
_getch();
}
+17
View File
@@ -0,0 +1,17 @@
#ifndef MENU_HPP
#define MENU_HPP
#include <iostream>
struct player
{
char name[200];
char date[80];
char time[80];
int life;
int score;
bool isActive;
};
extern int option;
void menu();
void newGame();
void help();
#endif
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB