#include <windows.h>
#include <conio.h>
#include <string.h>
#include <iostream>
using namespace std;
struct Objetos
{
int x, y;
bool hit;
};
struct Scores
{
int num;
char name[3];
};
void gotoxy(int x, int y) {
HANDLE hcon;
hcon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwPos;
dwPos.X = x;
dwPos.Y = y;
SetConsoleCursorPosition(hcon, dwPos);
}
void Marco()
{
char a = 186, b = 205, c[4]{ 201,187,188,200 };
for (int i = 1; i <= 100; i++)
{
if (i < 30)
{
gotoxy(100, i);
cout << a;
gotoxy(0, i);
cout << a;
}
gotoxy(i, 0);
cout << b;
gotoxy(i, 30);
cout << b;
}
gotoxy(0, 0);
cout << c[0];
gotoxy(100, 0);
cout << c[1];
gotoxy(0, 30);
cout << c[3];
gotoxy(100, 30);
cout << c[2];
}
void Menu(int &opc)
{
char tecla;
gotoxy(40, 10);
cout << "BREAKOUT";
gotoxy(40, 12);
cout << " PLAY";
gotoxy(40, 13);
cout << " HIGH SCORES";
gotoxy(40, 14);
cout << " EXIT";
do
{
gotoxy(39, opc);
cout << ">";
gotoxy(39, opc);
tecla = _getch();
gotoxy(39, opc);
cout << " ";
if (tecla == 72 && opc > 12) opc--;
if (tecla == 80 && opc < 14) opc++;
} while (tecla != 13);
}
void gameover()
{
system("cls");
Marco();
gotoxy(45, 15);
cout << "GAME OVER";
getchar();
}
char name(int ar)
{
char move, letter = 65;
do
{
gotoxy(45 + ar, 17);
cout << letter;
move = _getch();
if (move == -32)
{
move = _getch();
if (move == 72 && letter != 65) letter--;
if (move == 80 && letter != 90) letter++;
}
} while (move != 13);
return letter;
}
class Bloque;
class Barra;
class Bola;
class Bola
{
friend void Rebote(Bola &bol, Bloque &blo, int &sup);
friend void Rebote(Bola &bol, Barra &barr);
public:
Objetos boot;
void Mostrar(Objetos ball)
{
gotoxy(abs(ball.x), abs(ball.y));
cout << "*";
}
void Borrar(Objetos ball)
{
gotoxy(abs(ball.x), abs(ball.y));
cout << " ";
}
void Rebote()
{
if (abs(boot.x) == 1 || abs(boot.x) == 99) boot.x = boot.x*-1;
if (abs(boot.y) == 1) boot.y = boot.y*-1;
}
};
class Bloque
{
friend void Rebote(Bola &bol, Bloque &blo, int &sup);
public:
Objetos boot[116];
void Mostrar(Objetos blocks[116])
{
char a = 223;
for (int x = 0; x < 116; x++)
{
gotoxy(blocks[x].x, blocks[x].y);
cout << a;
cout << a;
cout << a;
cout << a;
}
}
void Hit(int qeuw)
{
gotoxy(boot[qeuw].x, boot[qeuw].y);
cout << " ";
}
};
class Barra
{
friend void Rebote(Bola &bol, Barra &barr);
public:
Objetos boot;
void Mostrar()
{
char a = 238;
gotoxy(boot.x, 25);
for (int weu = 0; weu < 8; weu++)
{
cout << a;
}
}
void Borrar()
{
gotoxy(boot.x, 25);
cout << " ";
}
void Mover(char cTecla)
{
if (cTecla == 77 && boot.x < 90) boot.x += 3;
if (cTecla == 75 && boot.x > 3) boot.x -= 3;
}
};
void Rebote(Bola &bol, Bloque &blo, int &sup)
{
for (int ay = 0; ay < 116; ay++)
{
for (int ya = 0; ya < 5; ya++)
{
if (abs(bol.boot.x) == blo.boot[ay].x + ya && abs(bol.boot.y) == blo.boot[ay].y && blo.boot[ay].hit == false)
{
bol.boot.y = bol.boot.y*-1;
blo.boot[ay].hit = true;
blo.Hit(ay);
sup++;
gotoxy(90, 31);
cout << "SCORE: " << sup;
break;
}
}
}
}
void Rebote(Bola &bol, Barra &barr)
{
if (abs(bol.boot.y) == barr.boot.y)
{
for (int a = 0; a < 8; a++)
{
if (abs(bol.boot.x) == barr.boot.x + a)
{
bol.boot.y = bol.boot.y*-1;
if (a > -1 && a < 4 && bol.boot.x > 0)
{
bol.boot.x = bol.boot.x*-1;
}
else
{
if (a > 3 && a < 8 && bol.boot.x < 0)
{
bol.boot.x = bol.boot.x*-1;
}
}
}
}
}
}
int main()
{
int opc = 12, nana, score, wer, gallo;
char tecla;
Scores a[5];
Bloque Cblock;
Barra Cbar;
Bola Cball;
for (int marvel = 0; marvel < 5; marvel++)
{
for (int dc = 0; dc < 3; dc++)
{
a[marvel].name[dc] = 'A';
}
a[marvel].num = 0;
}
do
{
system("cls");
Marco();
Menu(opc);
switch (opc)
{
case 12:
system("cls"); score = 0;
nana = 0;
wer = 9;
for (int qwe = 9; qwe <= 15; qwe++)
{
for (wer; wer <= 90; wer += 5)
{
Cblock.boot[nana].hit = false;
Cblock.boot[nana].x = wer;
Cblock.boot[nana].y = qwe;
nana++;
}
if (qwe % 2 != 0)
{
wer = 11;
}
else
{
wer = 9;
}
}
Cball.boot.hit = false;
Cball.boot.x = 50;
Cball.boot.y = 24;
Cbar.boot.y = 25;
Cbar.boot.x = 46;
Marco();
Cblock.Mostrar(Cblock.boot);
Cbar.Mostrar();
gotoxy(90, 31);
cout << "SCORE: " << score;
do
{
do
{
Cball.Mostrar(Cball.boot);
Sleep(100);
Cball.Borrar(Cball.boot);
Cball.Rebote();
Rebote(Cball, Cbar);
Rebote(Cball, Cblock, score);
if (abs(Cball.boot.y) == 29)
{
Cball.boot.hit = true;
break;
}
Cball.boot.y--;
Cball.boot.x++;
} while (!_kbhit());
if (Cball.boot.hit != true)
{
tecla = _getch();
Cbar.Borrar();
Cbar.Mover(tecla);
Cbar.Mostrar();
}
} while (Cball.boot.hit == false);
gameover();
for (int derp = 0; derp < 5; derp++)
{
if (a[derp].num < score)
{
switch (derp)
{
case 0:
a[4].num = a[3].num;
a[3].num = a[2].num;
a[2].num = a[1].num;
a[1].num = a[0].num;
a[0].num = score;
for (gallo = 0; gallo < 3; gallo++)
{
a[4].name[gallo] = a[3].name[gallo];
a[3].name[gallo] = a[2].name[gallo];
a[2].name[gallo] = a[1].name[gallo];
a[1].name[gallo] = a[0].name[gallo];
}
break;
case 1:
a[4].num = a[3].num;
a[3].num = a[2].num;
a[2].num = a[1].num;
a[1].num = score;
for (gallo = 0; gallo < 3; gallo++)
{
a[4].name[gallo] = a[3].name[gallo];
a[3].name[gallo] = a[2].name[gallo];
a[2].name[gallo] = a[1].name[gallo];
}
break;
case 2:
a[4].num = a[3].num;
a[3].num = a[2].num;
a[2].num = score;
for (gallo = 0; gallo < 3; gallo++)
{
a[4].name[gallo] = a[3].name[gallo];
a[3].name[gallo] = a[2].name[gallo];
}
break;
case 3:
a[4].num = a[3].num;
a[3].num = score;
for (gallo = 0; gallo < 3; gallo++)
{
a[4].name[gallo] = a[3].name[gallo];
}
break;
case 4:
a[4].num = score;
break;
}
for (int baia = 0; baia < 3; baia++)
{
a[derp].name[baia] = name(baia);
}
break;
}
}
break;
case 13:
system("cls");
Marco();
gotoxy(40, 10);
cout << "HIGH SCORES:";
for (int Ronan = 0; Ronan < 5; Ronan++)
{
gotoxy(40, 12 + Ronan);
cout << Ronan + 1;
cout << ".- ";
for (int vertigo = 0; vertigo < 3; vertigo++)
{
gotoxy(45 + vertigo, 12 + Ronan);
cout << a[Ronan].name[vertigo];
}
gotoxy(49, 12 + Ronan);
if (a[Ronan].num == 0)
{
cout << "000";
}
else
{
if (a[Ronan].num < 10)
{
cout << "00";
}
else
{
if (a[Ronan].num < 100)
{
cout << "0";
}
}
cout << a[Ronan].num;
}
}
getchar();
break;
}
} while (opc != 14);
}
An almost complete breakout, the Atari game. The only thing that I need to add is files to save all the scores!
UPDATE: I made some changes but it works the same!
UPDATE: I made some changes but it works the same!
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.