Thread: Help with my fighter game

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    46

    Help with my fighter game

    OK so here is a fighter game I made..except my fighters power won't decrease and I can't get my fighters names to show up....*sigh*... any idea.. My functions could be wrong.. but I always thought it went above int main()..


    Code:
    #include<iostream>
    using namespace std;
    int fighterOne (char fighter1Attack){
    string fighter1Name;
    // char fighter1Attack; 
    int fighter2Power=1000;
    string fighter2Name;
    cout << fighter1Name << " please choose an attack (P) = Punch, (K) = Kick => ";
    cin >> fighter1Attack;
    if (fighter1Attack == 'P' || fighter1Attack == 'p') {
    fighter2Power -= 50;
    cout << fighter2Name << "'s health reduced to " << fighter2Power << endl;
    }
    else if (fighter1Attack == 'K' || fighter1Attack == 'k') {
    fighter2Power -= 100;
    cout << fighter2Name << "'s health reduced to " << fighter2Power << endl;
    }
    else {
    cout << "Invalid attack, you lose a turn!" << endl;
    }
    }
    int fighterTwo (char fighter2Attack) {
    string fighter2Name;
    //char fighter2Attack; 
    int fighter1Power=1000;
    string fighter1Name;
    cout << fighter2Name << " please choose an attack (P) = Punch, (K) = Kick => ";
    cin >> fighter2Attack;
    if (fighter2Attack == 'P' || fighter2Attack == 'p') {
    fighter1Power -= 50;
    }
    else if (fighter2Attack == 'K' || fighter2Attack == 'k') {
    fighter1Power -= 100;
    cout << fighter1Name << "'s health reduced to " << fighter1Power << endl;
    }
    else {
    cout << "Invalid attack, you lose a turn!" << endl;
    }
    }
    int main() {
    string fighter1Name = "Greg"; 
    string fighter2Name = "Casey"; 
    int fighter1Power = 1000; 
    int fighter2Power = 1000; 
    char fighter1Attack;
    char fighter2Attack;
     
    do {
    fighterOne (fighter1Attack);
    fighterTwo (fighter2Attack);
    }while((fighter1Power > 0) && (fighter2Power > 0));
    if (fighter1Power > fighter2Power) {
    cout << "Fighter 1 is the winner!" << endl;
    }
    else if (fighter2Power > fighter1Power) {
    cout << "Fighter 2 is the winner!" << endl;
    }
    else {
    cout << "The game ended in a draw!" << endl;
    }
    return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I've got a new game for you to play, it's called "indent your code".

    > My functions could be wrong.. but I always thought it went above int main()
    Above, below, in another file - it doesn't matter.
    What matters is that before you attempt to USE a function, there must be a prototype for that function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    using namespace std;
    Unless you have a good reason for doing this I'd advise against bringing all of the std namespace into scope.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM