Thread: fighting system

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    465

    fighting system

    Code:
    	case 'f':
    	while(monster<1 || monster>4){
    	cout<<"1-man\n";
    	cout<<"2-goblin\n";
    	cin>>monster;
    	if(monster=='1'){	
    	finalcom=20;
    	cout<<"You encounter a man";
    	}
    	}
    	while(finalcom>0){              //fight
    	fight=rand()%6;
    	cin>>combat;
    	if(combat=='a'){                //attack
    	fcom=(((strength*3)+agility)/fight);
    	finalcom=mhp1-fcom;
    	mhp1=finalcom;
    	}
    	if(finalcom>0){
    	cout<<finalcom<<"\n";
    	}
    	}
    	cout<<"\nHe is dead\n";
    I have tried putting finalcom=20 and the cout right next to in different places, and I never seem to get the result that I want. Sometimes it will make finalcom=40 or something instead of 20 and it won't display You ecounter a man. How do I fix this stuff?? Someone told me to put the finalcom=20 at the end,but then what if the person pushed 2 for goblin instead of one?
    My computer is awesome.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    First off, lets get some proper indentation so we can actually read this, shall we? Oh, and we'll add color commentary...
    Code:
    case 'f':
            while(monster<1 || monster>4){
                    cout<<"1-man\n";
                   	cout<<"2-goblin\n";
                    // What happened to 3 and 4?
            	cin>>monster;
    
                    if(monster=='1'){
                            // Is 'monster' a char or an int?
                            finalcom=20;
                            cout<<"You encounter a man";
                    }
                    // So you don't do anything if they pick 2?
                    // Let's assume you left that out to do later.
            }
    
    	while(finalcom>0){              //fight
                    fight=rand()%6;
    
                    // Shouldn't you prompt for input here,
                    // rather than just assume they know how?
                    cin>>combat;
    
                    if(combat=='a'){                //attack
                            fcom=(((strength*3)+agility)/fight);
                            // Want to watch your program crash?
                            // Wait until 'fight' equals 0.
    
                            finalcom=mhp1-fcom;
                            mhp1=finalcom;
                    }
    
                    if(finalcom>0){
                            cout<<finalcom<<"\n";
                    }
            }
            cout<<"\nHe is dead\n";
    [/code]
    See how much nice indentation helps? As to what happens if they push another number, well, you don't handle any of that.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Ya these things are just in the works

    // Shouldn't you prompt for input here,
    // rather than just assume they know how?

    // Want to watch your program crash?
    // Wait until 'fight' equals 0.
    ^
    What do you mean by that?

    monster is an int.
    Why did you highlight the single quotes ' '?
    If I didn't put them in my first post I added them soon after.
    How do I format the code? like this:

    Code:
    if
       code
       code
    while
       code
       code
          if
             code
             code
    and so on? it goes out further the deeper in you get?
    Last edited by cerin; 04-06-2005 at 03:58 PM.
    My computer is awesome.

  4. #4
    Let's do some coding! Welshy's Avatar
    Join Date
    Mar 2005
    Location
    Staffordshire University, UK
    Posts
    168
    Quote Originally Posted by cerin
    How do I format the code? like this:

    Code:
    if
       code
       code
    while
       code
       code
          if
             code
             code
    and so on? it goes out further the deeper in you get?
    You must be kidding right? use either tab, or in extreme cases space bar, but spaces just mess it up most of the time.

  5. #5
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    most compilers will indent it for you..

    if yours doesnt.. then get a new compiler, indentation is what makes the world go round
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  6. #6
    High Flyer stumpster123's Avatar
    Join Date
    Mar 2005
    Posts
    26
    // Want to watch your program crash?
    // Wait until 'fight' equals 0.
    ^
    What do you mean by that?
    He means if you divide by 0 your program will crash. Try going from 1 to 7 or something by incrementing fight after it is generated.

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    I have something in srand that prevents it from generating 0.
    My computer is awesome.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No you don't. You're telling me that you rewrote the standard srand function so it doesn't generate zero any more? Really? I'd like to see that.

    As a matter of fact, I'd really like to see that, because srand doesn't generate random numbers. rand does. srand seeds the random number generator. It doesn't generate anything. It definately doesn't prevent the number 0 from being generated.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 01:04 PM
  2. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 07:56 PM
  3. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  4. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM