Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 11th, 2007, 11:00 PM   #31
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Okay, I have a question that's getting to me.
How can I get a previous block of code and bring it back in the program somewhere at demand? I've tried void() but it won't work for me.
EDIT: actually I found the wonderful goto command
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.

Last edited by Arnack; Aug 11th, 2007 at 11:10 PM.
Arnack is offline   Reply With Quote
Old Aug 11th, 2007, 11:18 PM   #32
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
Quote:
Originally Posted by Arnack View Post
EDIT: actually I found the wonderful goto command
Oh my gosh, don't use goto. It's not wonderful.

It can cause random jumps in your code if you implement it incorrectly.

Use functions() to logically sort your code, and go from function to function.
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Aug 11th, 2007, 11:35 PM   #33
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Hmm, I'll take a look, thanks, once again.
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Old Aug 13th, 2007, 1:50 PM   #34
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Okay, after a couple of days I have gotten far in my new program.
But I have a simple problem which I probably am over-looking...
When I get to the fighting code on the .exe, all it does (each time I load the .exe again) is say that I have attacked for 11 damage (I don't see how that's possible. I attack from 5-10) and the enemy attacks me with 10 damage. That's all it says.
Source:
#include <stdio.h>
#include <stdlib.h>
#include <time.h> 
#include <iostream>
#include <cctype>
//"Mage Wars" copyright Crimson Games 2007. All rights reserved.
//Created by Arnack, distributing this source is permited, as long
//as ownership is shown.

using namespace std;

      int gold = 10;
      int level = 1;
      int health = 10;
      int ex = 1;
      int check = 1;
      int outside0;
      int fightorun;
      int en1dmg;
      int dmg = rand() % 5 + 10;    
      
void welcome()
{
     cout << "|------------------------------|\n";
     cout << "|   Welcome to Mage Wars!      |\n";
     cout << "|       Made by Arnack         |\n";
     cout << "| Distributed by Crimson Games |\n";
     cout << "|------------------------------|\n";
     cout << "  You are level " << level << "! \n";
     cout << "  You have " << gold << " gold!  \n\n";
}




void start()
{
     system("CLS");
     welcome();
   cout << "\nHello, stranger. You have came just in time.";
   cout << "In the land known as Barisk, an ancient team of evil mages have taken control\n";
   cout << "They have corrupted the land with their evil. YOU, yes, you, must stop them!\n";
   cout << "Good luck, stranger.\n\n";
   system("PAUSE");
     check = 0;
}


void mainstart()
{
     int inn;
     system("CLS");
     welcome();
     cout << "You are currently in the town of Bask.\n You sit in a local inn, surrounded by nice-looking individuals.\n\n";
     cout << "What would you like to do?\n\n";
     cout << "1.) Talk to the poeple in the inn.\n2.) Walk Outside\n\n";
     cout << "> ";
     cin >> inn;
   

     if (inn == 1)
{
        system("CLS");
        welcome();
     cout << "You walk up to a group of drunkards.\n You can barely understand them, but you catch these words:\n";
     cout << "Egh, *hiccup* these mages are *hiccup* euck.. really SCREWING us over! *hiccup* HAHA!\n\n";
     system("PAUSE");
     mainstart();
}

     if (inn == 2)
{
     system("CLS");
     welcome();
   cout << "\n You are now outside. ";
   cout << "What would you like to do? \n\n";
   cout << "(1) Travel to the city of Basurn \n(2) Travel to the nearby fields. \n(3) Go back inside the inn.\n\n>";
   cin >> outside0;
   
   
   
   if (outside0 == 1)
   {
     system("CLS");
     welcome();
  cout << "You are now in the city of Basurn";
  system("PAUSE");
   }
}  

        
    if (outside0 == 2)
   {
     system("CLS");
     welcome();
   cout << "\nYou walk through the fields of Bask, but all of a sudden a large crow (level 1) attacks you!\n";
   cout << "What shall you do? \n (1)fight \n (2)run\n";
   cin >> fightorun;
{
   if (fightorun == 1)
   {
int enhealth1 = 10;
   while ((health > 0) && (enhealth1 > 0))
{
   system("CLS");
   welcome();
   en1dmg = rand() % 1 + 10;
   srand ( time(NULL) );
   health = 10; 
      
  cout << "Enemy attacks you with  " << en1dmg << "  damage! You attack back: \n" ;
  health = health - en1dmg;
  cout << "You deal  " << dmg << "   damage! \n";
  enhealth1 = enhealth1 - dmg;
  cout << "Your health is " << health << ". The enemy's health is " << enhealth1 << ". \n"; 
}   
if (enhealth1 <= 0) 
         {
         cout << "You have slain the vile enemy! You now gain 10 gold!\n\n";
         
	     gold = gold + 10;
	     enhealth1=10;
	     health=10;
         }
               else if (health <= 0)
{

cout << "You have died in the mists of battle! I am sorry! The enemy steals 10 gold! \n\n";
	gold = gold - 10;
	health=10;
	enhealth1=10;

}   
}   
}

   
  system("PAUSE");
}

  if (fightorun == 2)
 { 
  
   
     system("CLS");
     welcome();
     if (outside0 == 3)
   {
  mainstart();
   }   
   
  
  
   
} 
}




int main()
{
    while (ex == 1)
    {
    system("CLS");
    welcome();
    if (check == 1)
    {
    start();
    }
    else
{
mainstart();
}
}
}
I really hope someone can help me, because I am clueless.
Im guessing it's because it's in a loop.
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.

Last edited by Arnack; Aug 13th, 2007 at 2:33 PM.
Arnack is offline   Reply With Quote
Old Aug 13th, 2007, 5:25 PM   #35
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You are writing your program as if the statements will perform as you wish them to work, rather than how they actually work. Until you get beyond that point, the help you receive here will be of little value. Sure, you can copy and paste code, and maybe fix that particular problem with no understanding of why. Copying and pasting that code into a different area with different requirements will simply yield a failure, no better or worse than what you can generate with your own uninformed key-pounding.

You will either need to actually learn the language, or pay for code-monkeys who have already done so.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 13th, 2007, 5:36 PM   #36
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
DaWie, you see, I have gotten 1/4 of my C++ tutorial done. With what I have learned, I would be able to create a text RPG using Ifs, elses, and loops. I learn the code I copy paste, sometimes implement it into my own taste.
All I need now is how to bring random numbers into loops.
All I am asking.
EDIT:
I fixed it. Thanks for the great help.
But then I again I guess C++ is about trial and error.
People won't be around always to help me. I have to figure this stuff out for myself.
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.

Last edited by Arnack; Aug 13th, 2007 at 5:55 PM.
Arnack is offline   Reply With Quote
Old Aug 13th, 2007, 8:45 PM   #37
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Alright, really simple question.
dmg = rand() % 12 + 7;
This randomizes a number 7-12. (which I use as your damage during a fight)
I need a way to be able to add each number (12, and 7) by 3. (so it would be:
dmg = rand() % 15 + 10

Does anyone know?
Arnack
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Old Aug 13th, 2007, 9:00 PM   #38
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,054
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by Arnack
DaWie, you see, I have gotten 1/4 of my C++ tutorial done. With what I have learned, I would be able to create a text RPG using Ifs, elses, and loops.
Well, you're having trouble, so evidently you're not able to create your text RPG with what you've learned. I'm not insulting you here. Rather, I'm hinting that maybe you should complete the other 75% of the tutorial before trying to write some nontrivial program.
Quote:
Originally Posted by Arnack
All I need now is how to bring random numbers into loops.
All I am asking.
Just put the call to rand() (or whatever PRNG you're using) inside the loop. Don't seed it in the loop, however. Typically, you seed the generator(s) once, at the start of the program, and never seed them again. I say 'typically' because there are exceptions.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Aug 13th, 2007, 9:06 PM   #39
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Learning C++, unlike some things, is not about trial and error. You might write the following statements:

int i = 5;
cout << i << i++ << --i << endl;

You try that and you will observe that some numbers appear on the output. You might study them and conclude that the pattern is the "right" pattern and that said statements will always produce that particular output. You would be wrong.

You learn C++ by studying. You do (hopefully) learn from your errors, but you need to study WHY they are errors. You can't always draw a reasonable inference from the results of an experiment.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 14th, 2007, 2:03 PM   #40
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Updated version of my program. No problems. Just thought I should show you all.
Yes, it is sloppy, but I am a bit proud of myself (we were all newbies once) of how far I have gotten, and that it actually works.
Sadly I did have to use a couple gotos, simply because functions() gave me some problems at times.
#include <stdio.h>
#include <stdlib.h>
#include <time.h> 
#include <iostream>
//"Mage Wars" copyright Crimson Games 2007. All rights reserved.
//Created by Arnack, distributing this source is permited, as long
//as ownership is shown.

using namespace std;

      int gold = 100;
      int level = 1;
      int health = 10;
      int ex = 1;
      int check = 1;
      int outside0;
      int fightorun;
      int en1dmg; 
      int levelup = 100;
      int levelingup = 0 ;
      int fightrun0;
      int maxhealth;
      int dmg = rand() % 10 + 5;
      int basurnarmory;
void welcome()
{
     cout << "|------------------------------|\n";
     cout << "|   Welcome to Mage Wars!      |\n";
     cout << "|       Made by Arnack         |\n";
     cout << "| Distributed by Crimson Games |\n";
     cout << "|------------------------------|\n";
     cout << "  You are level " << level << "! \n";
     cout << "  You have " << levelingup << "/" << levelup << " until level up!   \n";
     cout << "  You have " << gold << " gold!  \n";
     cout << "  You have " << health << "/" << maxhealth << " health!   \n\n";
}




void start()
{
     system("CLS");
     welcome();
   cout << "Hello, stranger. You have came just in time.";
   cout << "In the land known as Barisk, an ancient team of evil mages have taken control\n";
   cout << "They have corrupted the land with their evil. YOU, yes, you, must stop them!\n";
   cout << "Good luck, stranger.\n\n";
   system("PAUSE");
     check = 0;
}


void mainstart()
{
     int inn;
     system("CLS");
     welcome();
     cout << "You are currently in the town of Bask.\n You sit in a local inn, surrounded by nice-looking individuals.\n\n";
     cout << "What would you like to do?\n\n";
     cout << "1.) Talk to the poeple in the inn.\n2.) Walk Outside\n\n";
     cout << "> ";
     cin >> inn;

     if (inn == 1)
{
        system("CLS");
        welcome();
     cout << "You walk up to a group of drunkards.\n You can barely understand them, but you catch these words:\n";
     cout << "Egh, *hiccup* these mages are *hiccup* euck.. really SCREWING us over! *hiccup* HAHA!\n\n";
     system("PAUSE");
     mainstart();
}

{
     if (inn == 2)
{
{
     outsidebask:
     system("CLS");
     welcome();
   cout << "You are now outside. ";
   cout << "What would you like to do? \n\n";
   cout << "\n(1) Travel to the nearby fields. \n(2) Travel to the city of Basurn  \n(3) Go back inside the inn.\n\n>";
   cin >> outside0;
}   
}   
   
   
       if (outside0 == 1)
   {
     system("CLS");
     welcome();
   cout << "You walk through the fields of Bask, but all of a sudden a large crow (level 1) attacks you!\n";
   cout << "What shall you do? \n (1)Fight \n (2)Run\n>";
   cin >> fightorun;
{
     //BATTLESYSTEM
   if (fightorun == 1)  
      srand ( time(0) );
   {
int enhealth1 = 10;
  
{
    fight0:
   system("CLS");
   welcome();
   srand ( time(NULL) );
   en1dmg = rand() % 5 + 0;
   

if ((health > 0 && enhealth1 > 0))
{
{   
      
  cout << "Enemy attacks you with  " << en1dmg << "  damage! You attack back: \n" ;
  health = health - en1dmg;
  cout << "You deal  " << dmg << "   damage! \n";
  enhealth1 = enhealth1 - dmg;
  cout << "Your health is " << health << ". The enemy's health is " << enhealth1 << ". \n\n"; 
  cout << "Would you like to \n(1)Fight \n(2)Run?\n>";
  cin >> fightrun0;
  if (fightrun0 == 1)
  {
  goto fight0;
  }
}   
}
//win
if (enhealth1 <= 0) 
         {
         cout << "You have slain the vile enemy! You now gain 3 gold and 5 experience points!\n\n";
         
	     gold = gold + 3;
	     enhealth1=10;
	     health=10;
	     levelingup = levelingup + 5;
	     if (levelingup >= levelup)
	     {
          maxhealth = maxhealth + 5;
          health = health + 5;
          levelingup = 0;
          dmg = rand() % 12 + 7;
          cout << "\nYou have leveled up! Your health has increased by 5! \n";
	     system ("pause");
	     goto outsidebask; 
         }
          else 
          {
	     system ("pause");
	     goto outsidebask;
      }
         }
               else if (health <= 0)
{
//lose
cout << "You have died in the mists of battle! I am sorry! The enemy steals 10 gold! \n\n";
	gold = gold - 10;
	health=10;
	enhealth1=10;
    system ("pause");
    goto outsidebask;     
} 
                 else if ((health <= 0 && enhealth1 <= 0))
                 {
	  cout << "You both have died!";
	  	health=10;
	enhealth1=10;
    system ("pause");
    goto outsidebask; 
}	  
}   
}
}
}
}

   if (outside0 == 2)
   {
   basurncity:
     system("CLS");
     welcome();
     int basurnoption;
  cout << "You are now in the city of Basurn. It is filled with a gloom of terror.\n";
  cout << "The Evil Mages have taken this city with the force of their magic. \n Mage Gaurds plated in enchanted armor ";
  cout << "walk the streets with a trail of darkness. They watch everything. \nWhat would you like to do?";
  cout << "\n(1)Go to the local Armory\n(2)Go to a local Store\n(3)Go outside the Gates\n>";
  cin >> basurnoption;
  if (basurnoption = 1)
  {
  armoryb:
  
       system("CLS");
     welcome();
  cout << "You are now in a dark, flame lit armory. You walk up to the blacksmith. he says:\n";
  cout << "\"Welcome, lad. My armory is the best in Basurn... What would you like?\"\n";
  cout << "(1)Buy Plate Armor -10 gold- Increase your health by 3.\n";
  cout << "(2)Buy Medium Cuirass - 25 gold- Increases your health by 5.\n";
  cout << "(3)Buy Hauberk Armor - 50 gold- Increases your health by 10. \n";
  cout << "(4)Leave the Armory \n";
  cin >> basurnarmory;
  
  	if(basurnarmory == 1)
		{
			if(gold < 10)
			{
				cout << "\nSorry Not Enough Gold!"<<endl;
				system("pause");
				goto basurncity;
			}
			else
			{
			gold = gold - 10;
			maxhealth = maxhealth + 2;
            health = maxhealth;
			cout <<"\n You have bought the Plate Armor. +2 Health" <<endl;
			system("pause");
			goto basurncity;
			}
		}
   

   else if (basurnarmory == 2)
  {
  
  if (gold < 25)
  {
  cout << "Not enough money!\n";
  system ("pause"); 
  goto basurncity;
  }
  	else
			{
  cout << "You have bought the Medium Cuirass. +5 Health.\n";
  gold = gold -25;
  maxhealth = maxhealth + 5;
  health = maxhealth;
  system ("pause");
  }
  }
  
   else if (basurnarmory == 3)
  {
  if (gold < 50)
  {
  cout << "Not enough money!\n";
  system ("pause");
  goto armoryb;
  }
  
  cout << "You have bought the Hauberk Armor. +10 Health.\n";
  gold = gold -50;
  maxhealth = maxhealth + 10;
  health = maxhealth;
  system ("pause");
  }

   else if (basurnarmory == 4)
{
   goto basurncity;
        }


  if (fightorun == 2)
 { 
  
   
     system("CLS");
     welcome();
     if (outside0 == 3)
   {
  mainstart();
   }   
   
}
}
}
}





int main()
{
    health = 10;
    maxhealth = 10;
    while (ex == 1)
    {
    system("CLS");
    welcome();
    if (check == 1)
    {
    start();
    }
    else
{
mainstart();
}
}
}
-Arnack
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A simple programming question punter C# 8 Jan 5th, 2006 4:04 PM
A simple question Master C++ 9 Dec 24th, 2005 2:20 PM
Question about multidimensional arrays of strings aznluvsmc C 8 Oct 15th, 2005 10:20 PM
Simple c# question nez C# 8 Jul 1st, 2005 6:29 PM
Simple (stupid cause I don't know it) basic question massive-war C++ 17 Apr 11th, 2005 11:03 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:24 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC