Page 1 of 2

my text life bar(WIP)

Posted: Mon Nov 10, 2008 9:01 pm
by Jokeboxproductions
I made a text life bar still need work because I'm still learning C++.
I just made this when i was tried of reading.

Have to find away to implement a continue feature instead of putting in one number and the program ending.
Have Any pointer shoot for it.

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    int x;
    x = 100;

    double y =  0.0;
    double i = 0.0;
    int Dead;
    Dead = 0;

    cin >> y;
    cin >> i;
     if (y - x)
        cout << "Hit \n";

      if ( x == Dead)
           cout << "Game over";

    system ("pause");
    return 0;
}

Life bar (WIP)

Posted: Mon Nov 10, 2008 9:23 pm
by Jokeboxproductions
I wasn't paying attention when I was posting.

I made a text life bar still need work because I'm still learning C++.
I just made this when i was tried of reading.

Have to find away to implement a continue feature instead of putting in one number and the program ending.
Have Any pointer shoot for it.

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    int x;
    x = 100;

    double y =  0.0;
    double i = 0.0;
    int Dead;
    Dead = 0;

    cin >> y;
    cin >> i;
     if (y - x)
        cout << "Hit \n";

      if ( x == Dead)
           cout << "Game over";

    system ("pause");
    return 0;
}
(Merged topics) This is the other topic's OP, not sure if code is different. --Mar

Re: Life bar (WIP)

Posted: Mon Nov 10, 2008 9:41 pm
by Trask
Well you could have a variable called 'Lives' and set that to a set amount and deduct 1 from lives every time you die, then terminate the program after lives = 0.

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    int x;
    x = 100;

    double y =  0.0;
    double i = 0.0;
    int Dead;
    Dead = 0;
`int lives = 3;

    cin >> y;
    cin >> i;
     if (y - x)
        cout << "Hit \n";

      if ( x == Dead)
         lives--;

     if(lives == 0)
       cout << "Game over";

    system ("pause");
    return 0;
}

Re: Life bar (WIP)

Posted: Mon Nov 10, 2008 10:00 pm
by Jokeboxproductions
Here it before I add your functions
Some reason even when it post to equal 0 and say "game over" it says heal up.

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    int x;
    x = 100;

    double y =  0.0;
    double i = 0.0;
    int Dead;
    Dead = 0;

    cin >> y;


     if (y - x)
        cout << "Hit \n";
    cin >> i;

    if (i - x)
          cout << "Hit again watch it! \n";

              if ( x == Dead)
                 cout << "Game over \n";
               else
                    cout << "Heal up \n";
    system ("pause");
    return 0;
}

Re: my text life bar(WIP)

Posted: Mon Nov 10, 2008 10:40 pm
by dandymcgee
Just thought I'd point out:

Code: Select all

if (y - x)
This code will always be true, it's not really a condition.

Code: Select all

if ( x == Dead)
This code will always be false, x is 100 and Dead is 0 and neither of those are changed regardless of input.

Here's something that's maybe similar to what you were trying to do?

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    int life = 100;
    double damage =  0.0;

    do
    {
        cin >> damage;
        life -= damage;
        cout << "You took " << damage << " damage. Current life: " << life << endl;
    }while ( life > 0 );

    cout << "Game over";

    cin.get();
    return 0;
}
Yeah.. I was bored.

Re: Life bar (WIP)

Posted: Mon Nov 10, 2008 10:54 pm
by dandymcgee
I posted in the other topic:

http://elysianshadows.com/phpBB3/viewto ... 685#p26685

// Topics merged -- Mar

Re: my text life bar(WIP)

Posted: Mon Nov 10, 2008 11:07 pm
by MarauderIIC
Actually, does (y - x) test the value of (y - x), or whether the operation was successful?

Re: my text life bar(WIP)

Posted: Mon Nov 10, 2008 11:32 pm
by Jokeboxproductions
I kind of thought I put this in the wrong place so I put it in the other forum.

Re: my text life bar(WIP)

Posted: Tue Nov 11, 2008 8:36 am
by dandymcgee
MarauderIIC wrote:Actually, does (y - x) test the value of (y - x), or whether the operation was successful?
Is that a serious question, if so I don't have a clue either.
Jokeboxproductions wrote:I kind of thought I put this in the wrong place so I put it in the other forum.
It's probably better if you had just left it here and requested the mods just move it. Having two topics is worse than having one in the wrong place. Oh well.

EDIT: Actually I think you can delete your own topics in phpBB3 using the little "X" button right next to edit in top right corner of your post.

Re: my text life bar(WIP)

Posted: Tue Nov 11, 2008 2:13 pm
by MarauderIIC
Seriously. I haven't gotten around to trying it yet. I'd assume it'd return the value, as

if ( (x = new Class(initializers) ) is a way to assign while testing whether or not the assignment was successful, IIRC. But that's an assignment, not an expression.

Also yeah, don't cross-post. Just leave it and post a move request. I merged the topics. Feel free to delete any of your own posts that are total duplicates.

Re: my text life bar(WIP)

Posted: Tue Nov 11, 2008 5:02 pm
by Jokeboxproductions
dandymcgee wrote:Just thought I'd point out:

Code: Select all

if (y - x)
This code will always be true, it's not really a condition.

Code: Select all

if ( x == Dead)
This code will always be false, x is 100 and Dead is 0 and neither of those are changed regardless of input.

Here's something that's maybe similar to what you were trying to do?

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    int life = 100;
    double damage =  0.0;

    do
    {
        cin >> damage;
        life -= damage;
        cout << "You took " << damage << " damage. Current life: " << life << endl;
    }while ( life > 0 );

    cout << "Game over";

    cin.get();
    return 0;
}
Yeah.. I was bored.
I use your code and like 5billion Gameovers Came flying on the screen.

Re: my text life bar(WIP)

Posted: Tue Nov 11, 2008 5:04 pm
by davidthefat
Jokeboxproductions wrote:
dandymcgee wrote:Just thought I'd point out:

Code: Select all

if (y - x)
This code will always be true, it's not really a condition.

Code: Select all

if ( x == Dead)
This code will always be false, x is 100 and Dead is 0 and neither of those are changed regardless of input.

Here's something that's maybe similar to what you were trying to do?

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    int life = 100;
    double damage =  0.0;

    do
    {
        cin >> damage;
        life -= damage;
        cout << "You took " << damage << " damage. Current life: " << life << endl;
    }while ( life > 0 );

    cout << "Game over";

    cin.get();
    return 0;
}
Yeah.. I was bored.
I use your code and like 5billion Gameovers Came flying on the screen.
because of

while ( life > 0 ); //that means that if life is bigger... which it always will be until it gets to 0... and it will repeat.. If i were you, i would use if

cout << "Game over";

cin.get();
return 0;
}

Re: my text life bar(WIP)

Posted: Tue Nov 11, 2008 5:27 pm
by dandymcgee
Jokeboxproductions wrote: I use your code and like 5billion Gameovers Came flying on the screen.
Lol what? I compiled it and it worked correctly. Did you edit it?
davidthefat wrote: because of

while ( life > 0 ); //that means that if life is bigger... which it always will be until it gets to 0... and it will repeat.. If i were you, i would use if

cout << "Game over";

cin.get();
return 0;
}
It shouldn't give you game over but only once after which it exits. There's no need for an if statement unless you only want to take damage once?

Re: Life bar (WIP)

Posted: Tue Nov 11, 2008 11:42 pm
by MarauderIIC
There is no way for his code to output game over more than once. Game over & exit are in the same basic block. Copy and paste it, perhaps. The only thing I'd say is that since

Code: Select all

while (life > 0) { ... }
would work fine, use it (easier to read)

Re: Life bar (WIP)

Posted: Wed Nov 12, 2008 6:01 pm
by Jokeboxproductions
I mostly edit your code to fit around mine.
I got ride of my dead variable and replaced it with your live variable.

I got rid of your functions but here it is before i did.

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    int x;
    x = 100;

    double y =  0.0;
    double i = 0.0;

    int Dead;
    Dead = 0;

    int lives = 0;

    cin >> y;
    cin >> i;

   if (y - x)
        cout << "Hit \n";

      if ( x == Dead)
         lives--;

     if(lives == 0)
       cout << "Game over";
;
    system ("pause");
    return 0;
}