CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2006
    Posts
    25

    One more question about IF statement...

    Sorry for the repost, wasnt sure if anyone would notice on that last one!

    One more question on this and I promise I'll leave you alone! lol

    here is my full battle code

    Code:
    int MBattle()
    {
    
    cout<<"Current mpowerLevel is "<<mpowerLevel<<endl;
    cout<<"Current powerlevel is "<<powerLevel<<endl;
    
    if (mpowerLevel > powerLevel)
    {
    	if (mpowerLevel > (10 * powerLevel))
    	{
    		mhit = ((rand() %  500) + 1);
    	}
    
    	else if (mpowerLevel > (9 * powerLevel))
    	{
    		mhit = ((rand() % 550) + 1);
    	}
    
    	else if (mpowerLevel > (8 * powerLevel))
    	{
    		mhit = ((rand() % 400) + 1);
    	}
    
    	else if (mpowerLevel > (7 * powerLevel))
    	{
    		mhit = ((rand() % 350) + 1);
    	}
    
    	else if (mpowerLevel > (6 * powerLevel))
    	{
    		mhit = ((rand() % 300) + 1);
    	}
    
    	else if (mpowerLevel > (5 * powerLevel))
    	{
    		mhit = ((rand() % 250) + 1);
    	}
    
    	else if (mpowerLevel > (4 * powerLevel))
    	{
    		mhit = ((rand() % 200) + 1);
    	}
    
    	else if (mpowerLevel > (3 * powerLevel))
    	{
    		mhit = ((rand() % 150) + 1);
    	}
    
    	else if (mpowerLevel > (2 * powerLevel))
    	{
    		mhit = ((rand() % 100) + 1);
    	}
    
    	else if (mpowerLevel > (1.9 * powerLevel))
    	{
    		mhit = ((rand() % 90) + 1);
    	}
    
    	else if (mpowerLevel > (1.8 * powerLevel))
    	{
    		mhit = ((rand() % 80) + 1);
    	}
    
    	else if (mpowerLevel > (1.7 * powerLevel))
    	{
    		mhit = ((rand() % 70) + 1);
    	}
    
    	else if (mpowerLevel > (1.6 * powerLevel))
    	{
    		mhit = ((rand() % 60) + 1);
    	}
    
    	else if (mpowerLevel > (1.5 * powerLevel))
    	{
    		mhit = ((rand() % 50) + 1);
    	}
    
    	else if (mpowerLevel > (1.4 * powerLevel))
    	{
    		mhit = ((rand() % 40) + 1);
    	}
    		
    	else if (mpowerLevel > (1.3 * powerLevel))
    	{
    		mhit = ((rand() % 35) + 1);
    	}
    
    	else if (mpowerLevel > (1.2 + powerLevel))
    	{
    		mhit = ((rand() % 30) + 1);
    	}
    
    	else if (mpowerLevel > (1.1 * powerLevel))
    	{
    		mhit = ((rand() % 25) + 1);
    	}
    
    	else if (mpowerLevel > powerLevel)
    	{
    		mhit = ((rand() % 20) + 1);
    	}
    	
    	else if (mpowerLevel == powerLevel)
    	{
    		mhit = ((rand() % 20) + 1);
    	}
    }
    
    
    if (mpowerLevel > powerLevel)
    {
    	if (powerLevel > (10 * mpowerLevel))
    	{
    		mhit = 0;
    	}
    
    	else if (powerLevel > (9 * mpowerLevel))
    	{
    		mhit = 0;
    	}
    
    	else if (powerLevel > (8 * mpowerLevel))
    	{
    		mhit = ((rand() % 1) + 1);
    	}
    
    	else if (powerLevel > (7 * mpowerLevel))
    	{
    		mhit = ((rand() % 2) + 1);
    	}
    
    	else if (powerLevel > (6 * mpowerLevel))
    	{
    		mhit = ((rand() % 3) + 1);
    	}
    
    	else if (powerLevel > (5 * mpowerLevel))
    	{
    		mhit = ((rand() % 4) + 1);
    	}
    
    	else if (powerLevel > (4 * mpowerLevel))
    	{
    		mhit = ((rand() % 5) + 1);
    	}
    
    	else if (powerLevel > (3 * mpowerLevel))
    	{
    		mhit = ((rand() % 6) + 1);
    	}
    
    	else if (powerLevel > (2 * mpowerLevel))
    	{
    		mhit = ((rand() % 10) + 1);
    	}
    
    	else if (powerLevel > (1.9 * mpowerLevel))
    	{
    		mhit = ((rand() % 11) + 1);
    	}
    
    	else if (powerLevel > (1.8 * mpowerLevel))
    	{
    		mhit = ((rand() % 12) + 1);
    	}
    
    	else if (powerLevel > (1.7 * mpowerLevel))
    	{
    		mhit = ((rand() % 13) + 1);
    	}
    
    	else if (powerLevel > (1.6 * mpowerLevel))
    	{
    		mhit = ((rand() % 14) + 1);
    	}
    
    	else if (powerLevel > (1.5 * mpowerLevel))
    	{
    		mhit = ((rand() % 15) + 1);
    	}
    
    	else if (powerLevel > (1.4 * mpowerLevel))
    	{
    		mhit = ((rand() % 16) + 1);
    	}
    		
    	else if (powerLevel > (1.3 * mpowerLevel))
    	{
    		mhit = ((rand() % 17) + 1);
    	}
    
    	else if (powerLevel > (1.2 + mpowerLevel))
    	{
    		mhit = ((rand() % 18) + 1);
    	}
    
    	else if (powerLevel > (1.1 * mpowerLevel))
    	{
    		mhit = ((rand() % 19) + 1);
    	}
    }
    
    return 0;
    
    }



    Thats the function MBattle, which determines was mhit is. In another function mhit is subtracted from health.

    There is a problem, if the player has a higher powerlevel than the mob it does NO damage at all. 0. Also, if the player and mob are the exact same powerlevel, they do no damage at all. (NOTE- I have tested it the other ways around. If the mob is stronger than the player, it hits for the proper amount. This is just a one way thing: if the player is stronger).

    I put in breakpoints and checked, it is sending the proper values for mpowerLevel and powerLevel. Any ideas?

  2. #2
    Join Date
    May 2005
    Posts
    399

    Re: One more question about IF statement...


  3. #3
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: One more question about IF statement...

    Quote Originally Posted by Campuschris
    Sorry for the repost, wasnt sure if anyone would notice on that last one!

    One more question on this and I promise I'll leave you alone! lol

    here is my full battle code

    Code:
    int MBattle()
    {
    
    cout<<"Current mpowerLevel is "<<mpowerLevel<<endl;
    cout<<"Current powerlevel is "<<powerLevel<<endl;
    
     if (mpowerLevel > powerLevel)
    {
    }
    if (mpowerLevel > powerLevel)
    {
    }
      
    return 0;
    
    }

    have a look on the above Bold lines .And let us Know Why you are using same condition twice.anyway your second if Will take place at last.and will Print The value.So remove any of One according to your Logic. and then Proceed.

    thanx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured