Sign in to follow this  
Followers 0
Vlad Muresan

Help me please!

24 posts in this topic

Hello guys,

I am a little bit scared for making this topic because i think i cant find help or you will start to laught [img]http://public.gamedev.net//public/style_emoticons/default/dry.png[/img].
I am 14 years old and i dont make Informatic at school cuz i`am in 8-a and i started to studi C++ like 3 weeaks ago and i am really excited in programing and I try to improve my language so I am asking you to teache me or give a good link for learning how to program(i want to start making a game like snake then go to 2D simple game.)
Also i have a tacher who learn me c++ but i want to know more and more if u want to help me please leave a comment.
My skipe is vladmihail(sorry for bed eng i am ok when i speak [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img])
[img]http://public.gamedev.net//public/style_emoticons/default/cool.png[/img]
[img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img]

[mod edit: please reserve custom text colours for emphasis only -- rip-off]
0

Share this post


Link to post
Share on other sites
Don't be scared. I started when I was just two years younger than you, except I started with Quick Basic. I am very impressed that you trying C++ at such a young age. Some pretty basic tutorials are available at: [url="http://www.cprogramming.com/tutorial/c++-tutorial.html"]http://www.cprogramming.com/tutorial/c++-tutorial.html[/url] and [url="http://www.cplusplus.com/doc/tutorial/"]http://www.cplusplus.com/doc/tutorial/[/url]. The important thing with programming is not just learning the syntax (language) but also getting into a logical mindset and developing your ability to think through a problem. I strongly recommend trying some of the problems from [url="http://projecteuler.net/"]http://projecteuler.net/[/url] to build up your ability to think through problems as you start to understand the language. Depending on where you are in Math (Algebra or Pre-Algebra?) you should be able to do some of the easier problems without too much difficulty. Feel free to PM me (or just post) any questions, and I will try to answer them. At one point I started writing an Intro to C++ book aimed directly at your age group; however, life has taken over, and to be I honest I enjoy programming more than writing about it.
0

Share this post


Link to post
Share on other sites
[left]Thanks very much Zael for replay i aleardy done the [url="http://www.cplusplus.com/doc/tutorial/"]http://www.cplusplus.com/doc/tutorial/[/url][font=helvetica, arial, verdana, tahoma, sans-serif][size=2][color=#282828] and it was awesome.[/color][/size][/font][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=2]P.S:I am traying to make a maze[/size][/font][/color][/left]
0

Share this post


Link to post
Share on other sites
Hey guys i want to ask you something very important for all the beginers:
1-How many hours we shold stay to learn C++,the point is to make simple games like maze,snake etc.
2-How many lessons should i learn?(i am currently at Arrays)
3-How many years/months it will take to become an intermediar?
4-Do you love porgraming?
5-Are the proggramers search on marketing?
Thx for reading,please try to respond as many questions is possible!
0

Share this post


Link to post
Share on other sites
I can't comment on your first three questions. It's really hard to quantify the time involved because it's highly dependent upon your own comprehension and devotion to learning the language well. It's also based upon whether you have prior experience with other languages too.

As for myself, I do love programming. I was fortunate at a very young age to have been exposed to programming. My father introduced me to Basic at age 7 and sometime between then and age 10, I was programming in Pascal and by early teens, I made the leap to C/C++. Programming has always been a passion of mine. I've been in the industry professionally for almost 15 years and that passion continues to burn today as strong as it did at 7.
1

Share this post


Link to post
Share on other sites
Like crancran said, 1 and 3 will vary based on previous experience and just how quickly you learn things. I think 2 is a little bit more definable, but I think it is more about making sure you know the content of said lessons than the actual number of lessons you go through.

I personally think you should feel comfortable with the everything up to and including Object Oriented Programming before starting a 2D game (from the tutorial series at [url="http://www.cplusplus.com/doc/tutorial/"]http://www.cplusplus.com/doc/tutorial/[/url]). I would start trying a simple text based adventure game (kind of like the you-choose-the-ending type books) by the time you get through Control Structures. Depending on the simplicity of the game and the 2D library you choose to work with, you could conceivable start writing a 2D game at that time as well, but I wouldn't recommend it yet. Also, even though they are not really called out in that tutorial series I would strongly recommend looking at and learning how to use std::vector and std::string as soon as possible. While it is good to know about raw arrays and character sequences they can lead to a lot of bugs that are easily avoided by using the string and vector classes.

As for 4, I started my first full-time job as a software developer last year at about this time. I still love programming, and still spend a lot of my evenings working on personal programming projects (most of them game related). I still hope to break into the game industry someday (probably as an indie), but I have to pay off my student loans first. For me programming has always been a creative outlet. I can literally create worlds with whatever rules I set for them, and then see them on my computer screen. Nothing else I know has ever let me do anything like it.

5) I don't quite understand question 5 to be honest.

P.S. SDL requires the use of pointers. I have never used SFML, but if it doesn't require the use of Pointers then you could probably create a simple Snake clone by the time you have finished Control Structures. I would still recommend getting classes and inheritance down. They make your code much more managable.
0

Share this post


Link to post
Share on other sites
Thanks you for comment.I aleardy made a text-base game and it was really simple [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]. Now i am trying to learn char(i know this is a very important lesson).
I can learn like 1-1.30 hour per moring(i preffer to learn when i am fresh) and i think is ok,right?
Also i know how to use strings [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img].But i dont know wath is a vector :( :(*
When i will learn enought i will try to learn SDL because i saw its very powefull and popular [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img].
1)When i will finish [url="http://www.cplusplus.com/doc/tutorial/"]http://www.cplusplus.com/doc/tutorial/[/url] can i say : -I know somethink about programming? more important ,if i finish
that tutu can i start learning SDL?(basics)

2)And the i have a problem with DEV programs,i am using DEV-C++ also i have Microsoft Visual Studio C++ Express 2010 and the problem is i dont know who is better and wath i need to choose to make a game and here is wath i mean : Windows Application , Console Application , Static Librari , DLL , Empty Project . And I dont know wath this mean and wath i need to choose to make a game [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] Please help [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

3)Also i dont see the difference between : String,int,char,using name space( <= here i may wrong)
And an ex is : char[color=#000000][size=3] question[] = [/size][/color]"Please, enter your first name: "[color=#000000][size=3] ; [/size][/color]char[color=#000000][size=3] greeting[] = [/size][/color]"Hello,. I can use STring [color=#600030][size=3]or int,so why i need to put char??(My lord)[/size][/color]

Thanks you very much for comments and for the help and please keep helping me [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Have a nice day!
0

Share this post


Link to post
Share on other sites
[quote]

When i will finish http://www.cplusplus.com/doc/tutorial/ can i say : -I know somethink about programming?
[/quote]
Yes, you can certainly say you know something about programming when you finish those tutorials. You probably know some stuff about programming already. But there is more to learn. Take it from me, there will always be more to learn. I think this is a good thing.

[quote]

more important ,if i finish that tutu can i start learning SDL?(basics)
[/quote]
I understand the attraction, but I'd advise you to get comfortable with with the C++ language by building "big" text based projects first before you start using something like SDL. The issue here is that building any game is a non-trivial project. There are skills you will need to build such a project. Trying to learn them, while simultaneously trying to learn how to do graphics and learning a third party library all at the same time will be challenging.

You can make games in the console, by using characters as graphics. But stick to simpler projects first while you're building your skills in program flow, data structures and writing algorithms.

[quote]
And the i have a problem with DEV programs,i am using DEV-C++ also i have Microsoft Visual Studio C++ Express 2010 and the problem is i dont know who is better
[/quote]
Use Visual C++, it is the best C++ IDE on Windows.

[quote]
... and wath i need to choose to make a game and here is wath i mean : Windows Application , Console Application , Static Librari , DLL , Empty Project . And I dont know wath this mean and wath i need to choose to make a game
[/quote]
You want to make Console Applications for the moment.

[quote]
Also i dont see the difference between : String,int,char...
[/quote]
Give it some time, the differences between the data types will become clearer. It might help to understand the terminology:
[list]
[*] "int" is short for "integer", which bascially means whole numbers (e.g. 0, -13, 42, etc)
[*] "char" is short for "character", which are individual text representations of letters, numbers and symbols.
[*] "string" is a computer science name for a sequence of characters. Any bit of text can be considered a string - a word, a sentence, a line or paragraph made of multiple sentences, up to a book or even a compilation of books could be stored in a single string. You can even have strings with just a single character, or even an empty string which has no characters.

[quote]
... using name space( <= here i may wrong)
[/quote]
The "using namespace" directive is different from the other types. It is merely a short cut. If you didn't have it, you'd have to write code like this:
[code]
#include <string>
#include <iostream>

int main()
{
std::string message = "Hello, World";
std::cout << message << std::endl;
}
[/code]
This is because the contents of <string> and <iostream> are in the standard namespace, called "std". Namespaces are good when you have very large projects that use lots of libraries. Each library might have it's own namespace, and this means that library A's types and functions can be differentiated from library B's, even if the library developers happened to use the same name.

Namespaces are an advanced concept, don't worry about them for the moment.

[quote]
And an ex is : char question[] = "Please, enter your first name: " ; char greeting[] = "Hello,. I can use STring or int,so why i need to put char??(My lord)
[/quote]
C++ is a [i]strongly, explicitly typed[/i] programming language. This means that the language insists you mention the expected types of variables, function parameters and return values, etc.

Here, you are creating arrays of characters, initialised with the contents of a string literal. I would suggest you do not use arrays of characters to represent text, they are error prone. Stick to string question = "Please, enter your first name: " in your own code for the time being, unless you are completing a tutorial.
1

Share this post


Link to post
Share on other sites
Thanks you very much for such a good explication!
I aleardy know wath u explicate there about Namespace std; but i wanted to ask somethink else but is not important.
And when u mean Text Games is that kind of games where it ask you for name , choose a race and choose a number 1,2,3 ,no?
0

Share this post


Link to post
Share on other sites
Because if u want me to do a Text game i think i will need just : char,int,array,cin.cout,if,else,while,do while? not too much [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img].I was thinking at making a maze but i am too stupid to make an object to move around [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img](I CANT find any tutus on net)
I thought if i make something like this will work but i am pretty sure it wont work [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] : so if we have a char ,,&,, and a room:
1 2 3 (<== room)
4 & 6
7 8 9
and he is siting on 5 i can make him to move using an algoritm like : 8-5 = 2 if he want to go to 2 but i cant imagin how to move an object around using MATH (i am not so bad at match but this is very hard) whitout that ideea from up i cant imagin something else...
I was thinking at this cuz when i made the tic-tac toe it was like this, but i want to make him to move perfect not in many screens if u understand.
And i was thinking to add:

(i cant make it to work on the forum but u can try it for yourself)
* * * * * * * * * * * *
* *
* Hello, Vlad! *
* *
********************

so i made this program:

[code]
// [i]ask for a person's name, and generate a greeting[/i]
#include <iostream>
#include <string>

int main()
{
std::cout << "Please enter your first name: ";
std::string name;
std::cin >> name;

// [i]build the message that we intend to write[/i]
const std::string greeting = "Hello, " + name + "!";

// [i]build the second and fourth lines of the output[/i]
const std::string spaces(greeting.size(), ' ');
const std::string second = "* " + spaces + " *";

// [i]build the first and fifth lines of the output[/i]
const std::string first(second.size(), '*');

// [i]write it all[/i]
std::cout << std::endl;
std::cout << first << std::endl;
std::cout << second << std::endl;
std::cout << "* " << greeting << " *" << std::endl;
std::cout << second << std::endl;
std::cout << first << std::endl;

return 0;
}
[/code]
(i dont know if this is a rule but when i want to use the string amd i use << xxx << instend of + xxx + is not working)
If someone know a better way to show the ,,*,, please post it,thanks for reading,please comment [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
and a way to put the ,*, as the walls(it dosent matter if they are solid -for text game dosent mater, but if u know how to make it solid leave anathor post [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img].
Finally i want to thanks to everyone for such a good COMUNITY! Have a nice day !

[mod edit: added code tags -- rip-off]
0

Share this post


Link to post
Share on other sites
[quote name='vladmihail' timestamp='1334923865' post='4933158']
Because if u want me to do a Text game i think i will need just : char,int,array,cin.cout,if,else,while,do while? not too much [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img].I was thinking at making a maze but i am too stupid to make an object to move around [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img](I CANT find any tutus on net)
I thought if i make something like this will work but i am pretty sure it wont work [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] : so if we have a char ,,&,, and a room:
1 2 3 (<== room)
4 & 6
7 8 9
and he is siting on 5 i can make him to move using an algoritm like : 8-5 = 2 if he want to go to 2 but i cant imagin how to move an object around using MATH (i am not so bad at match but this is very hard) whitout that ideea from up i cant imagin something else...
I was thinking at this cuz when i made the tic-tac toe it was like this, but i want to make him to move perfect not in many screens if u understand.
And i was thinking to add:

(i cant make it to work on the forum but u can try it for yourself)
* * * * * * * * * * * *
* *
* Hello, Vlad! *
* *
********************

so i made this program:


// [i]ask for a person's name, and generate a greeting[/i]
#include <iostream>
#include <string>

int main()
{
std::cout << "Please enter your first name: ";
std::string name;
std::cin >> name;

// [i]build the message that we intend to write[/i]
const std::string greeting = "Hello, " + name + "!";

// [i]build the second and fourth lines of the output[/i]
const std::string spaces(greeting.size(), ' ');
const std::string second = "* " + spaces + " *";

// [i]build the first and fifth lines of the output[/i]
const std::string first(second.size(), '*');

// [i]write it all[/i]
std::cout << std::endl;
std::cout << first << std::endl;
std::cout << second << std::endl;
std::cout << "* " << greeting << " *" << std::endl;
std::cout << second << std::endl;
std::cout << first << std::endl;

return 0;
}
(i dont know if this is a rule but when i want to use the string amd i use << xxx << instend of + xxx + is not working)
If someone know a better way to show the ,,*,, please post it,thanks for reading,please comment [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
and a way to put the ,*, as the walls(it dosent matter if they are solid -for text game dosent mater, but if u know how to make it solid leave anathor post [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img].
Finally i want to thanks to everyone for such a good COMUNITY! Have a nice day !
[/quote]

Use code tags please (there's a button in the text editor shaped like "<>".

write
[CODE]
using namespace std;
[/CODE]
at the top of your code (below #include <iostream>)

That way you don't have to write out 'std::' all the time
0

Share this post


Link to post
Share on other sites
Guys i have a very important question for you!! please respond as quickly is possible!!!
1) How can i make a main menu where the player will see start game,save game,load,credits,exit.Then i want to start the main game in a different screen,like the pages from the book,damn eng.
2)And can i color the numbers or the letters?
Thanks for helping me out! Have a nice day!


P.S:If u teach me how to make the main menu please take your time and teach me how to make a script for saving and loading the game,TY!
0

Share this post


Link to post
Share on other sites
[quote]
How can i make a main menu where the player will see start game,save game,load,credits,exit.Then i want to start the main game in a different screen,like the pages from the book,damn eng.
[/quote]
What specific parts of making a main menu are you having trouble with? What have you got working so far?

[quote]
And can i color the numbers or the letters?
[/quote]
Standard c++ does not provide you with a way to do this. You can use platform specific APIs to do this.

For example, on Windows you can call a function [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms686047(v=vs.85).aspx"]SetConsoleTextAttribute[/url] to do this:
[code]
#include <string>
#include <iostream>
#include <Windows.h>

int main()
{
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
WORD colours[] = { FOREGROUND_RED, FOREGROUND_GREEN, FOREGROUND_BLUE };
for(int i = 0 ; i < 3 ; ++i)
{
SetConsoleTextAttribute(console, colours[i]);
std::cout << "Dark!" << std::endl;
SetConsoleTextAttribute(console, colours[i] | FOREGROUND_INTENSITY);
std::cout << "Bright!" << std::endl;
std::string s;
std::getline(std::cin, s);
}

const WORD Yellow = FOREGROUND_RED | FOREGROUND_GREEN;
SetConsoleTextAttribute(console, Yellow);
std::cout << "Dark Yellow!" << std::endl;
SetConsoleTextAttribute(console, Yellow | FOREGROUND_INTENSITY);
std::cout << "Bright Yellow!" << std::endl;

std::string s;
std::getline(std::cin, s);
}
[/code]
There are similar [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682088(v=vs.85).aspx#_win32_character_attributes"]BACKGROUND colour constants[/url]. As illustrated, you can get other colours by combining the colours using the [b]bitwise OR[/b] operator. The colours you can make are [url="http://en.wikipedia.org/wiki/File:AdditiveColor.svg"]illustrated like so[/url], and as demonstrated you can use the FOREGROUND_INTENSITY to make a brighter colour.

[quote]
P.S:If u teach me how to make the main menu please take your time and teach me how to make a script for saving and loading the game,TY!
[/quote]
Take things one step at a time. Get a simple menu to work first - don't include "save" or "load" for the moment.
1

Share this post


Link to post
Share on other sites
Rip-off u are one of the best guy from here [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] and i want to thanks you very much for helping a noob how to fix out the problems.
I want to make Main menu where u can see the start game and exit(u said no save/load [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img])
And i was looking for a
[b] [size=5][background=transparent]CONSOLE RPG GAME tutorial but i cant find one (i want to have it for the future)[/background][/size][/b]
0

Share this post


Link to post
Share on other sites
[quote]
I want to make Main menu where u can see the start game and exit(u said no save/load )
[/quote]
I understand. Still, what specific parts of making a main menu are you having trouble with? What have you got working so far?
0

Share this post


Link to post
Share on other sites
I have problem have problem with all the main menu [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] but i made an @ to move around in a room [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] and now i am trying to add a new room(i only need to make a room then to add & no? i mean to connect them eachother)
0

Share this post


Link to post
Share on other sites
Typically in a text based game a menu will be simple output with different input option.


Example "Menu":
[CODE]
int choice = 0;
while(choice != 2)
{
std::cout << "What would you like to do?\n";
std::cout << "1) Start a new game\n";
std::cout << "2) Quit\n";
cin >> choice;
switch (choice)
{
case 1:
startGame();
break;
case 2:
return;
break:
}
}
[/CODE]

Does that make sense or are you asking something else?
1

Share this post


Link to post
Share on other sites
Man...thx for helping but i am not stupid,i am making a Dos Rpg game [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] not a text game cuz that is too simple [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
-2

Share this post


Link to post
Share on other sites
Didn't mean to insult you. You would be surprised at some of the simple things people will ask how to do. In a cmd window I am not aware of any mouse functions (could be wrong), so you may still need to do a simple menu like that when the user makes choices. Of course maybe you are more creative than I. Ideally you would use a system library that reads each key as it is pressed (instead of waiting for the user to hit the enter key). Most text based games I have played use a method like that with certain keys toggling a menu.
0

Share this post


Link to post
Share on other sites
Thx Zael [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] 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 [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
I am using the 219 wall graph and its cool [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img].
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 [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img].
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! [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]


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...
-1

Share this post


Link to post
Share on other sites
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;
}

}
}
0

Share this post


Link to post
Share on other sites
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.

[CODE]
#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;
}

[/CODE]

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.

[CODE]
#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;
}
[/CODE]

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".


[CODE]
#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;
}
[/CODE]

"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.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0