Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Project 3

Here are some projects of actual programs you can practice making.

Postby antiRTFM on Sun Aug 17, 2008 4:04 pm

Doctor Salt wrote:What would be the best way to equip armor to specific slots? I want there to be different armor slots, for the most customization, meaning helmet, chest piece, gloves, belt, thigh armor, boots, etc. When coding, i want to be able to call on a class function and tell me the armor value of the specific piece, and name.

But how? would i have to create a boolean value for every single armor thing in the game for every single place where armor can be put on?

Ah i remember when dealing with these things for the first time...

There are so many different ways of going about this. And in each specific way, there are many sub-paths to choose.

Here are a few hints of one particular approach;

Code: Select all
class Item
{
   string name;
   int typeCode;
   int placeHolder1;   // for a potion this would be amount, for a weapon this would be strength
   int placeHolder2;   // for a potion this would be unused, for a weapon this would be speed
   ...
};


class Character
{
   ...
   DiscardItem(string itemName);
   TakeItem(Item & theItem);
   ...
   
   private:
   Item handEquipment[2];
   Item bodyEquipment[3];
   Item inventory[10];
   ...
};
Last edited by antiRTFM on Sun Aug 17, 2008 5:04 pm, edited 1 time in total.
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Postby Marss++ on Sun Aug 17, 2008 4:32 pm

ha ha.


That will take some time. If you think of how long and how many people and how much willpower it actually took to create those games. It would be quite a challenge to perform that on your own. With one computer. One mind and all that stuff.

Good luck with that. Not saying you can't do it. Maybe I'm misunderstanding you and the size of the program that you create.

If you need any help with anything. We'll be here.

Good luck though :)
I'm a 15 year old kid who has his heart set on Programming.

Came here hoping to help so if you have any questions just ask!
Marss++
 
Posts: 149
Joined: Fri Jul 18, 2008 3:20 pm

Postby antiRTFM on Sun Aug 17, 2008 4:58 pm

Depends on how complicated you wanna make it. And even really complex stuff is - though very rare and non-recommended - possible to make solo; check out this GTA-like game made completely by one guy.
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Postby Doctor Salt on Sun Aug 17, 2008 6:38 pm

well, keep in mind, that the program i want to create is only going to be text-based not 3D! The great thing about my 'program to be' is that i can easily make it as complicated as i want, its not like easy and nonuseful to freaking mind crushing difficult.

So what i hope to include is......

1) Turn based combat, where you choose either melee weapons, ranged, magic, or items, then the enemy chooses, based off a variable of how far they are from you :P I'm coming up with ways to have multiperson fights at the moment.....

2)A fairly advanced equipment section, where you can buy and equip stuff for every part of your body, where each section of armor effects not only the armor rating, but speed and dexterity.

3) Hopefully a sort of item creation thing, so if i have say 10 units of wood, i can change it to 10 units of arrows instead, or maybe if i have a pint of achohol, change it to a giant flaming molotov of death :]

4)Hopefully, i'll have a sort of "scripted" scenes, where you choose the best path (think of that field command game) but instead of just dying if you choose incorrectly, you are put into regular combat.

EDIT:
5) I've been coming up with an interesting sort of leveling system, which ties in with my combat system, and my armor system. So what i plan to have is that for each time you level up, you have a choice whether to focus on improving your strength more, or your dexterity. So what i mean, is that bludgening, heavy weapons are going to use formulas involving your strength to deal damage, and faster, swift weapons are going to use dexterity formulas instead. Also, i'm planning to have armor to effect it too. So armor i declare as bulky will drastically decrease dexterity, but giving you more armor, and leather armors, etc, will increase dexterity but won't give as much protection.


I'm going into high school very soon, as a freshman, and i will be taking a c++ course (i'm very excited for it). I'm thinking about making my program once i took a bit of a real course, and ask the teacher lots of questions about it, cause i can't have you guys solve all my questions, can I?




P.S-I looked at the urban empire link thing... and WOW. So apparently he built everything by scratch, pretty much.. even the engine too, i'm impressed. I guess at least when/if it comes out, he wouldn't owe ANYONE money :P
Doctor Salt
 
Posts: 147
Joined: Wed Jul 30, 2008 3:32 pm

Re: Project 3

Postby Levistus on Tue Oct 14, 2008 7:49 am

Sup guys! I need some help. Can you tell me if I'm going through the right path on my program? Should the functions be where they are?
I will make functions or whatever I need for the ones with parenthesis in the program when you run it(Monster, X, Item). Please tell me what I should do to improve my code. This is not complete yet. I used getch here btw but I think I'll change it later cause if the choice is pressed a couple of times or held for a time it will be counted.

Code: Select all
#include <iostream>
#include <string>
#include "conio.h"

using namespace std;

void welcome();
void game();
void action();

class Player
{
     

public:
        Player(string playername, int startHitpoints, int startStrength, int startToughness):
        name(playername),
        hitpoints(startHitpoints),
        strength(startStrength),
        toughness(startToughness)
        {         
        }
       
        void attack()
        {
             _sleep(2000);
             cout << name << " attacks for (X) dmg!" << endl;
             _sleep(2000);
             cout << "(Monster) dies!";
             _sleep(2000);
             encounter();
        }
        void defend()
        {
             _sleep(2000);
             cout << name << " defends!" << endl << endl;
             _sleep(2000);
             cout << "(Monster) hits you for (X) dmg!" << endl << endl;
             _sleep(2000);
             chooseAction();
        }
        void useMagic()
        {
             _sleep(2000);
             cout << name << " uses Lightning Strike on (Monster) and hits (X) dmg!" << endl;
             _sleep(2000);
             cout << "(Monster) dies!" << endl;
             _sleep(2000);
             encounter();
        }
        void useSkill()
        {
              _sleep(2000);
              cout << name << " uses Power Strike on (Monster) and hits (X) dmg!" << endl;
              _sleep(2000);
              cout << "(Monster) dies!" << endl;
              _sleep(2000);
              encounter();
             
        }
        void useItem()
        {
             _sleep(2000);
             cout << name << " uses (Item)" << endl;
             _sleep(2000);
             encounter();
        }
        void runAway()
        {
             _sleep(2000);
             cout << "You try to run away. " << endl;
             _sleep(2000);
             cout << "While running away, the (Monster) throws cheese at you" << endl;
             _sleep(2000);
             cout << "and hit you for (X) dmg!" << endl;
             _sleep(2000);
             cout << "You get away.";
             _sleep(2000);
             encounter();
        }
        void start()
        {
             cout << "(STORY HERE)" << endl << endl << endl;
             cout << name << ", these are your starting stats." << endl << endl;
            // _sleep(500);
             cout << "Hitpoints: " << hitpoints << endl;
            // _sleep(500);
             cout << "Strength: " << strength << endl;
            // _sleep(500);
             cout << "Toughness: " << toughness << endl;
            // _sleep(500);
             encounter();
        }
        void encounter()
        {
             cout << endl << endl;
             cout << "A (Monster) appears!" << endl;
             _sleep(2000);
             chooseAction();
        }
        void chooseAction()
        {     
             cout << endl;
             cout << "What will you do?" << endl;
             cout << "(A)ttack  "; 
             cout << "(S)kill  ";
             cout << "(U)se Item  " << endl;
             cout << "(D)efend  "; 
             cout << "(M)agic  ";
             cout << "(R)un Away  " << endl << endl << endl << endl;
             
             char choice;
             
             do choice = getch();
             while (toupper(choice) != 'A' && toupper(choice) != 'S' && toupper(choice) != 'U'
             && toupper(choice) != 'D' && toupper(choice) != 'M' && toupper(choice) != 'R');
             
             if (toupper(choice) == 'A')
             {
                  attack();
             }
             else if (toupper(choice) == 'S')
             {
                  useSkill();
             }   
             else if (toupper(choice) == 'U')
             {
                  useItem();
             }
             else if (toupper(choice) == 'D')
             {
                  defend();
             }
             else if (toupper(choice) == 'M')
             {
                  useMagic();
             }
             else if (toupper(choice) == 'R')
             {
                  runAway();
             }
             else
             {
                 cout << "Wrong key!" << endl;
                 chooseAction();
             }
        }
private:
             
      string name;
      int hitpoints;
      int strength;
      int toughness;
      string weapon;
      string armor;
      string inventory[20];
     
};

int main()
{
    system("CLS");
    welcome();
    game();   
    cout << endl << endl;
    system("PAUSE");
    return 0;
}



void welcome()
{
     cout << "                                   " << endl;
     cout << "                                   " << endl;
     cout << "      L E V I S T U S   R P G      " << endl;
     cout << "                                   " << endl;
     cout << "           a.Start Game            " << endl;
     cout << "           b.Exit  Game            " << endl;
     cout << "                                   " << endl;
}

void game()
{
     char choice;
   
     do choice = getch();
     
     while (toupper(choice) != 'A' && toupper(choice) != 'B');
     
     if (toupper(choice) == 'A')
     {
           system("CLS");
           cout << "Welcome Adventurer! What is your name and title?" << endl << endl;
           string name;
           getline(cin, name);
           Player Hero(name, 100, 15, 12);
           cout << endl << "Nice to meet you, " << name << "! Let us begin." << endl;
           _sleep(2000);
           system("CLS");
           Hero.start();
     }
     else if (toupper(choice) == 'B')
     {
          system("CLS");
          cout << "Thank you for playing. Goodbye brave adventurer!" << endl << endl;   
          return;
     }
     
}
Levistus
 
Posts: 7
Joined: Mon Oct 06, 2008 8:10 am

Re: Project 3

Postby antiRTFM on Wed Oct 15, 2008 9:33 pm

Hey Levistus, it's good to see you trying things out and practicing. That's the most important thing.

1: _sleep() is a Win32 API function and thus is not standard C++, just so you know.

2: in (wrap 6 @ video 40) i explain about program execution calling a function which calls another function which calls another function etc without ever returning. Your functions seem to be doing this.

3: In order to make dynamic combat situations where you can battle against many different mosnters (not just one and only monster called "monster") try creating a monster class and passing around pointers to different instances of it into the attack/defend/etc functions
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Re: Project 3

Postby Levistus on Thu Oct 16, 2008 11:01 am

antiRTFM wrote:Hey Levistus, it's good to see you trying things out and practicing. That's the most important thing.

1: _sleep() is a Win32 API function and thus is not standard C++, just so you know.

2: in (wrap 6 @ video 40) i explain about program execution calling a function which calls another function which calls another function etc without ever returning. Your functions seem to be doing this.

3: In order to make dynamic combat situations where you can battle against many different mosnters (not just one and only monster called "monster") try creating a monster class and passing around pointers to different instances of it into the attack/defend/etc functions


Is there any good alternative to _sleep() to just pause for a sec which is C++ Standard? I just don't want every action written in 1 go.
Levistus
 
Posts: 7
Joined: Mon Oct 06, 2008 8:10 am

Re: Project 3

Postby antiRTFM on Sun Oct 19, 2008 11:33 pm

Sometimes there is no choice but to use platform specific stuff. There is no Standard C++ way of sleeping the program so i guess this is one of those times.

Note that that's what i meant when i said "...just so you know" :)
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Re: Project 3

Postby Laynk on Fri Apr 24, 2009 10:14 pm

I have a question. What video should I be on before I attempt project 3? Should I watch them all first?
Laynk
 
Posts: 2
Joined: Wed Apr 08, 2009 6:18 am

Re: Project 3

Postby antiRTFM on Sat Apr 25, 2009 9:18 pm

hm tough question... i guess watch vids until you feel you have all the techniques you need to do the project
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Re: Project 3

Postby InfiniteLoop on Fri May 01, 2009 2:09 pm

Hey antiRTFM, working on mine as we speak.

And I wanted to use the sleep function for the combat system, so that it wouldn't all appear at the same time(as you said), but it just says

'Sleep' identifier not found

or something like that. Then I thought I probably need to include <ctime>, but still no luck. What am I doing wrong?

And one other thing, you said you can use that the random thing to have a value in a specific range, but how do I change the range of the value? (Edit: Found out you just type them into the parentheses when you call the function, am I correct?)

Thanks!
InfiniteLoop
 
Posts: 11
Joined: Sun Apr 26, 2009 1:03 pm

Re: Project 3

Postby antiRTFM on Fri May 01, 2009 2:21 pm

#include <windows.h> to use Sleep()

yup, just pass a minimum and maximum as parameters into the function
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Re: Project 3

Postby InfiniteLoop on Fri May 01, 2009 6:00 pm

Wow. This is turning out quite nicely.

One thing....In the beginning I have like a sort of menu thing that you can choose to fight, shop, or use items. That's like the base. You start from there. Then after you, for example, fight, it is over and it needs to go back to the menu.

Is the best way to do that to make a function for the menu, and at the end of the fighting, call the menu function? Or can you not call a function inside itself?

To be clearer, can I do this:

Code: Select all
// note this is a function and would appear before the main function,
//but I did not list out the whole code, this is just an example

menu()
{
cout << "Welcome to the menu";
menu();
}


Also, I'm sorta stuck on the leveling system. I could make it so you can gain xp and level up, but what would be a way to make your character stronger, have more health, etc if s/he is a higher level?

Should I just make something like an int called level, and then when I put the attack dmg, do something like this?

Code: Select all
if(level == 1)
{
damage = GetRand(0, 20)
}

if(level == 2)
{
damage = GetRand(10, 30)
}


So basically, is having an 'if' for each level the best way to do this?


Sorry for my so many and so confusing questions. Hope you understand them, and if not, just ask.

Thanks!
InfiniteLoop
 
Posts: 11
Joined: Sun Apr 26, 2009 1:03 pm

Re: Project 3

Postby antiRTFM on Fri May 01, 2009 7:02 pm

wrap 6 @ video 40 talks about functions calling itself. use 'loops' instead

in your particular case, maybe it would be easier to have a mathematical calculation that sets the random number range based on your desired figures. something like replacing all those if statements with

Code: Select all
damage = GetRand((level * 10) - 10, (level * 10) + 10);


this way, level 1 will have a range of 0-20, level 2 will have 10-30, level 3 will have 20-40 and so forth

or any other calculations you see fit (exponential curve ftw?)
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Re: Project 3

Postby InfiniteLoop on Fri May 01, 2009 7:29 pm

Not sure what an exponential curve is.

Lol.

Anyways, I'm at video 37..or more tutorial 37, its actually video 41 since you had a couple wrap ups, so I hadn't really gotten there yet.

But for the random number, sounds like a good idea. Not really sure how it works that much, just used the code that you gave me, so I didn't really think to do that or even know I could.

Your great antiRTFM. Thanks!

Edit: Haha so I tried the loop, and while trying to exit the program, I forgot that I couldn't just type something anymore, and when I did, it sent me into an infinite loop for some reason(what a coincidence with my name). Just kept repeating my menu.
InfiniteLoop
 
Posts: 11
Joined: Sun Apr 26, 2009 1:03 pm

PreviousNext

Return to Projects

Who is online

Users browsing this forum: No registered users and 0 guests

cron