Jump to content
Column

C++ Console Game For Beginner

Recommended Posts

Atem_Knight_pnh.png

#include <iostream>
#include <windows.h>
using namespace std;
int y, x;
char Map[100][100] = { "----ATEM KNIGHT----- ",
"#################### *-------Legenda-------*",
"# # % # | |",
"# # # # # ######### | #-> Wall |",
"# # # # # ### %## | @-> Character |",
"# # # # ## ### #### | !-> Finish Line |",
"#@#% %# !# * *### | %-> Enemies |",
"#################### | Copyright->'Column' |",
" | or Copyright->'Atem'|",
" *---------------------*" };
int GameSpeed = 90;
int level = 1;
int stopgame = false;
int HP = 100;
int Score = 0;
int main()
{
while(stopgame == false && level == 1)
{
system("cls");
for(int y=0; y<20;y++)
{
cout<<Map[y]<<endl;
}
cout<<"Level: "<<level<<endl;
cout<<"Score: "<<Score<<endl;
cout<<"HP: "<<HP<<endl;
for(y=0;y<20;y++)
{
for(x=0;x<20;x++)
{
switch(Map[y][x])
{
case '@':
{
if(GetAsyncKeyState(VK_UP) != 0)
{
int y2 = (y-1);
switch(Map[y2][x])
{
case ' ':
{
Map[y][x] = ' ';
y -= 1;
Map[y2][x] = '@';
}break;
case '!':
{
level = 2;
}
case '%':
{
HP -= 20;
Map[y][x] = ' ';
y += 1;
Map[y2][x] = '@';
}
case '*':
{
HP +=5;
Map[y][x] = ' ';
y += 1;
Map[y2][x] = '@';
Score += 4;
}
}
}
if(GetAsyncKeyState(VK_DOWN) != 0)
{
int y2 = (y+1);
switch(Map[y2][x])
{
case ' ':
{
Map[y][x] = ' ';
y += 1;
Map[y2][x] = '@';
}break;
case '!':
{
level = 2;
}
case '%':
{
HP -= 20;
Map[y][x] = ' ';
y += 1;
Map[y2][x] = '@';
}
case '*':
{
HP += 5;
Map[y][x] = ' ';
y += 1;
Score += 4;
Map[y2][x] = '@';
}
}
}
if(GetAsyncKeyState(VK_RIGHT) != 0)
{
int x2 = (x+1);
switch(Map[y][x2])
{
case ' ':
{
Map[y][x] = ' ';
x += 1;
Map[y][x2] = '@';
}break;
case '!':
{
level = 2;
}
case '%':
{
HP -= 20;
Map[y][x] = ' ';
x += 1;
Map[y][x2] = '@';
}
case '*':
{
HP += 5;
Map[y][x] = ' ';
x += 1;
Score += 4;
Map[y][x2] = '@';
}
}
}
if(GetAsyncKeyState(VK_LEFT) != 0)
{
int x2 = (x-1);
switch(Map[y][x2])
{
case ' ':
{
Map[y][x] = ' ';
x -= 1;
Map[y][x2] = '@';
}break;
case '!':
{
level = 2;
}
case '%':
{
HP -= 20;
Map[y][x] = ' ';
x -= 1;
Map[y][x2] = '@';
}
case '*':
{
HP += 5;
Map[y][x] = ' ';
x-=1;
Score += 4;
Map[y][x2] = '@';
}
}
}
}break;
}
}
}
Sleep(GameSpeed);
}
while(stopgame == false && level == 2)
{
system("cls");
cout<<"Felicitari! Ai obtinut Level: "<<level<<", scor"<<endl;
system("pause");
}
return 0;}

PS: "Am realizat acest joc pentru programatorii incepatori si de asemenea ii incurajez sa invete inca din clasele 9-12 librariile

<windows.h>
<ctype.h>
<ctime.h>

chiar si altele ce se fac prin facultate! Succes programatorilor!"

Link to comment
Share on other sites

Atem_Knight_pnh.png

#include <iostream>
#include <windows.h>
using namespace std;
int y, x;
char Map[100][100] = { "----ATEM KNIGHT----- ",
"#################### *-------Legenda-------*",
"# # % # | |",
"# # # # # ######### | #-> Wall |",
"# # # # # ### %## | @-> Character |",
"# # # # ## ### #### | !-> Finish Line |",
"#@#% %# !# * *### | %-> Enemies |",
"#################### | Copyright->'Column' |",
" | or Copyright->'Atem'|",
" *---------------------*" };
int GameSpeed = 90;
int level = 1;
int stopgame = false;
int HP = 100;
int Score = 0;
int main()
{
while(stopgame == false && level == 1)
{
system("cls");
for(int y=0; y<20;y++)
{
cout<<Map[y]<<endl;
}
cout<<"Level: "<<level<<endl;
cout<<"Score: "<<Score<<endl;
cout<<"HP: "<<HP<<endl;
for(y=0;y<20;y++)
{
for(x=0;x<20;x++)
{
switch(Map[y][x])
{
case '@':
{
if(GetAsyncKeyState(VK_UP) != 0)
{
int y2 = (y-1);
switch(Map[y2][x])
{
case ' ':
{
Map[y][x] = ' ';
y -= 1;
Map[y2][x] = '@';
}break;
case '!':
{
level = 2;
}
case '%':
{
HP -= 20;
Map[y][x] = ' ';
y += 1;
Map[y2][x] = '@';
}
case '*':
{
HP +=5;
Map[y][x] = ' ';
y += 1;
Map[y2][x] = '@';
Score += 4;
}
}
}
if(GetAsyncKeyState(VK_DOWN) != 0)
{
int y2 = (y+1);
switch(Map[y2][x])
{
case ' ':
{
Map[y][x] = ' ';
y += 1;
Map[y2][x] = '@';
}break;
case '!':
{
level = 2;
}
case '%':
{
HP -= 20;
Map[y][x] = ' ';
y += 1;
Map[y2][x] = '@';
}
case '*':
{
HP += 5;
Map[y][x] = ' ';
y += 1;
Score += 4;
Map[y2][x] = '@';
}
}
}
if(GetAsyncKeyState(VK_RIGHT) != 0)
{
int x2 = (x+1);
switch(Map[y][x2])
{
case ' ':
{
Map[y][x] = ' ';
x += 1;
Map[y][x2] = '@';
}break;
case '!':
{
level = 2;
}
case '%':
{
HP -= 20;
Map[y][x] = ' ';
x += 1;
Map[y][x2] = '@';
}
case '*':
{
HP += 5;
Map[y][x] = ' ';
x += 1;
Score += 4;
Map[y][x2] = '@';
}
}
}
if(GetAsyncKeyState(VK_LEFT) != 0)
{
int x2 = (x-1);
switch(Map[y][x2])
{
case ' ':
{
Map[y][x] = ' ';
x -= 1;
Map[y][x2] = '@';
}break;
case '!':
{
level = 2;
}
case '%':
{
HP -= 20;
Map[y][x] = ' ';
x -= 1;
Map[y][x2] = '@';
}
case '*':
{
HP += 5;
Map[y][x] = ' ';
x-=1;
Score += 4;
Map[y][x2] = '@';
}
}
}
}break;
}
}
}
Sleep(GameSpeed);
}
while(stopgame == false && level == 2)
{
system("cls");
cout<<"Felicitari! Ai obtinut Level: "<<level<<", scor"<<endl;
system("pause");
}
return 0;}

PS: "Am realizat acest joc pentru programatorii incepatori si de asemenea ii incurajez sa invete inca din clasele 9-12 librariile

<windows.h>
<ctype.h>
<ctime.h>

chiar si altele ce se fac prin facultate! Succes programatorilor!"

Foloseste termenul de biblioteci. Librariile inseamna cu totul altceva. library != librarie, library = biblioteca.

Link to comment
Share on other sites

PS: "Am realizat acest joc pentru programatorii incepatori si de asemenea ii incurajez sa invete inca din clasele 9-12 librariile

<windows.h>
<ctype.h>
<ctime.h>

chiar si altele ce se fac prin facultate! Succes programatorilor!"

M-ar ajuta mai mult niste linkuri/tutoriale/sfaturi de unde pot sa le invat, daca se poate. Mul?umesc anticipat :D Am rulat codul si l-am inteles, iar primul gand mi s-a dus la Pacman [..]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...