Life bar (WIP)

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
Jokeboxproductions
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 16
Joined: Mon Nov 03, 2008 6:46 am

my text life bar(WIP)

Post 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;
}
User avatar
Jokeboxproductions
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 16
Joined: Mon Nov 03, 2008 6:46 am

Life bar (WIP)

Post 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
User avatar
Trask
ES Beta Backer
ES Beta Backer
Posts: 738
Joined: Wed Oct 29, 2008 8:17 pm
Current Project: Building a 2D Engine
Favorite Gaming Platforms: Sega Genesis and Xbox 360
Programming Language of Choice: C/C++
Location: Pittsburgh, PA
Contact:

Re: Life bar (WIP)

Post 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;
}
MarauderIIC wrote:You know those people that are like "CHECK IT OUT I just made Linux run on this piece of celery [or other random object]!!"? Yeah, that's Falco, but with ES.
Dear god, they actually ported ES to a piece of celery!
Martin Golding wrote: "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
User avatar
Jokeboxproductions
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 16
Joined: Mon Nov 03, 2008 6:46 am

Re: Life bar (WIP)

Post 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;
}
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: my text life bar(WIP)

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Life bar (WIP)

Post by dandymcgee »

I posted in the other topic:

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

// Topics merged -- Mar
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: my text life bar(WIP)

Post by MarauderIIC »

Actually, does (y - x) test the value of (y - x), or whether the operation was successful?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Jokeboxproductions
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 16
Joined: Mon Nov 03, 2008 6:46 am

Re: my text life bar(WIP)

Post by Jokeboxproductions »

I kind of thought I put this in the wrong place so I put it in the other forum.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: my text life bar(WIP)

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: my text life bar(WIP)

Post 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.
Last edited by MarauderIIC on Tue Nov 11, 2008 2:21 pm, edited 2 times in total.
Reason: see sig
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Jokeboxproductions
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 16
Joined: Mon Nov 03, 2008 6:46 am

Re: my text life bar(WIP)

Post 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.
User avatar
davidthefat
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 529
Joined: Mon Nov 10, 2008 3:51 pm
Current Project: Fully Autonomous Robot
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: California
Contact:

Re: my text life bar(WIP)

Post 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;
}
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: my text life bar(WIP)

Post 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?
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Life bar (WIP)

Post 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)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Jokeboxproductions
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 16
Joined: Mon Nov 03, 2008 6:46 am

Re: Life bar (WIP)

Post 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;
}
 
Post Reply