Help me please!

Started by
23 comments, last by Zael 11 years, 11 months ago
Thx Zael biggrin.png u are really nice!
So my game name is Dungeon Runner and its a Rpg Console game,i made the lvl 1 + Character Movment + Health Packs + Traps + Doors to get pass to next lvl biggrin.png
I am using the 219 wall graph and its cool biggrin.png.
If someoane have any ideea for making the game better i will put you in Credits(u need to say more than 8 staffs)and not toooooo hard to make:D.Now i am trying to add Zombie as Z and he will need to move around and attack the player dealing 5-10 dmg biggrin.png.
If someoane knows how to make a zombie and add him please leave a comment and the 8 will be reduced to 4 ALSO if u have skype and if u know how to proggramm and u think u can help a begginer guy <<<< ME <<< please say i will add you on skipe! biggrin.png


P.S: I know most of the guys from here are pro and i am pointing at Zael but i will not making you to make for me staffs (bigger staffs),i mean i will need to the easy staffs like like how to make the character to change the clour(lets say the zombie infected you:D) etc...
Advertisement
Also please if someone would look at my code and try to make it to cool nicer or maybe correct some staffs(for the moment the movment is not working and i really dont know why cuz i am trying to add the trapps,this might bE?)

#include <cstdlib>
#include <iostream>
#include <windows.h>
// trebuie sa rez ,,+,, problema => corectata
//trebuie sa add traps ,,*,,=>lucrez
//trebuie sa add un fel de apa
// trebuie sa add atac + Z(zombie)
//introducere
using namespace std;
//cum arata mapa
char Map[10][10] = { // Map is 10 lines down and 10 characters across
"#########",
"# # !#",
"# # + #",
"# ### #",
"# # *#",
"# # #",
"# # #",
"# ## #",
"# # @ #",
"#########", };
int Hp = 100;
int MaxHp = 100;
int Gamespeed = 80;
int Level = 1;
bool stopgame = false;
int main()
{
system("cls");
while(stopgame == false && Level == 1)
{
system("cls");
for (int y = 0; y < 10; y++)
{
cout << Map[y] << endl;
}
if ( Hp > MaxHp)
cout << "Viata ta este plina"<< endl;
cout << "Hp: "<< Hp << "/" << MaxHp << endl;
for (int y = 0; y<10; y++)
{
for (int x = 0; x<10; x++)
{
switch(Map[y][x])
{
case '#':
{ // pt culoarea peretilor
Map[y][x] = 219;
}
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;
}break;
case '+':
{
for(Hp += MaxHp; Hp= MaxHp - Hp;)




Hp += 10; // an pus ,,+,, in loc de ,,-,, pt a face viata
Map[y][x] = ' ';
y -= 1;
Map [y2][x] = '@';
}break;

}
}
if(GetAsyncKeyState(VK_DOWN) !=0) // miscare
{
int y2 = (y + 1);

switch(Map[y2][x])
{
case ' ':
{
Map[y][x] = ' ';
y += 1;
Map[y2][x] = '@';
}break;
case '!':
{
Level = 2;
}break;
case '+':
{
for(Hp +=MaxHp; Hp= MaxHp - Hp;);
Hp += 10; Hp += 10;
Map[y][x] = ' ';
y += 1;
Map [y2][x] = '@';
}break;
case '*':
{

Hp -= 15; Hp += 10;
Map[y][x] = ' ';
y += 1;
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;
}break;
case '+':
{
Hp += 10;
Map[y][x] = ' ';
x += 1;
Map [y][x2] = '@';
}break;
}
}

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;
}break;
case '+':

for(Hp +=MaxHp; Hp= MaxHp - Hp;)
{
Hp += 10;
Map[y][x] = ' ';
x -= 1;
Map [y][x2] = '@';
}break;


}
}
}break;
}
}
}
Sleep(Gamespeed);
}
while (stopgame == false && Level == 2)
{
system("cls");
cout << "LEvel 2 script goes here: " << endl;
system("pause");
return EXIT_SUCCESS;
}

}
}
Sorry i dont know how to atach it :(
I Screwd all :*(
I will see if I can take a moment to look at it more in-depth over the next few evening, but right off the bat, you can make it a lot cleaner if you look at using functions. Functions help you abstract different procedures and not only easily re-use code, but also make the code itself more readable. In case you haven't encountered them before I have included a small example.


#include <iostream>

using namespace std;

int sumOfRange(int a, int b);

int main()
{
int a, b;
cout << "Provide first number: ";
cin >> a;
cout << "Provide second number: ";
cin >> b;
cout << "The sum of all numbers between " << a << " and " << b << " is: " << sumOfRange(a, b) << endl;
int c,d;
cout << "Provide first number: ";
cin >> c;
cout << "Provide second number: ";
cin >> d;
cout << "The sum of all numbers between " << c << " and " << d << " is: " << sumOfRange(c, d) << endl;
}

int sumOfRange(int a, int b)
{
int total = 0;
for(int i = a; i <= b; i++)
{
total+=i;
}
return total;
}



The first thing I do is declare the function on line 5. All functions must be declared before using. A function is comprised of really three parts. The first is the return type. In this case the function returns an int. The second is the name of the function. This is how the function is called. The last thing is a list of parameters. I believe there is an upper limit on the number of parameters a function can have, but I have never hit that limit (it is pretty high). Each parameter is essentially a variable that is declared just like you would inside a function except that it is a copy of the whatever value was passed to the function.

The next thing I do is define and declare my main function. Inside my main function I use the the function I declared on line 5. Finally after my main function I define my function. The function definition is essentially the code that is executed when the code is used.

A minor, but essential thing to understand is that because parameters are copies, if you change the value of a parameter in a function the variable used when calling the function is unchanged.


#include <iostream>

using namespace std;

void functionThatDoesNothing(int a)
{

a = 10;
}

int main()
{
int a = 5;
cout << "The variable 'a' is: "<< a << endl;
functionThatDoesNothing(a);
cout << "The variable 'a' is still "<< a << endl;
return 0;
}


You can see from this example that the function does not change a. I have also shown that you can define the function at the same time you declare it. It is usually best to define and declare the function separately if you have more than one file (declarations go in the .h or .hpp file and definitions go in the .cpp file).

If you want to have the parameter directly affect the variable that was used when calling the function you can use what is called "pass by reference". Whether a function parameter is "pass by value" or "pass by reference" depends on the way it is declared in the function declaration. To make a variable "pass by reference" you simply place an '&' character before the variable name. Below I will demonstrate the same code as above, except with "pass by reference".



#include <iostream>

using namespace std;

void functionThatDoesSomething(int & a)
{

a = 10;
}

int main()
{
int a = 5;
cout << "The variable 'a' is: "<< a << endl;
functionThatDoesSomething(a);
cout << "The variable 'a' is now "<< a << endl;
return 0;
}


"Pass by reference" can get a little bit dangerous (your code will crash) if you use it in certain ways (like for the return type of a function), but for the way I have demonstrated above it should be safe in most if not all situations.

P.S. Classes and Structs can also make code a lot cleaner and more readable, but I think learning to write your own functions first is a nice step in the right direction.

This topic is closed to new replies.

Advertisement