Sound and arrow key problem.

This is a discussion on Sound and arrow key problem. within the Game Programming forums, part of the General Programming Boards category; Okay.. i got the map boundries plus an item. But on line 111: parse error before 'if' line 26: confused ...

  1. #16
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    Okay.. i got the map boundries plus an item.
    But on
    line 111: parse error before 'if'
    line 26: confused by earlier errors, bailing out

    Code:
    /********************************************************************
    *Zachs first CPP game. Kind of a RPG. Text based.
    ********************************************************************/
    #include <iostream.h>
    #include <stdlib.h>
    #include <conio.h>        //allows getch()
    using namespace std;      //allows cout instead of std::cout
    int player_location_Y = 0; /* Player*/
    int player_location_X = 0;  /*  Start*/
    int health = 100;          //player health
    int health_potion = 10;     //gives ten health
    int end_game = 100;         // timer: if zero, game ends
    int points = 0;             //score
    int bread = 0;              //food
    char input;
    
    int main()
    {
        char name[20];
        cout << "Please enter your name: ";
        cin >> name;
        cout << "\nHello " << name << "Welcome to my quest!\n";
        cout << "You must venture throught this maze avoiding traps\n";
        getch();
    
        do   //start
        {
         if (player_location_Y == 25)
         {
         cout << "That way is blocked!\n";
         player_location_Y--;
         getch();
         }
         else if (player_location_Y == -25)
         {
         cout << "That way is blocked!\n";
         player_location_Y++;
         getch();
         }
         else if (player_location_X == 25)
         {
         cout << "That way is blocked!\n";
         player_location_Y--;
         getch();
         }
         else if (player_location_X == -25)
         {
         cout << "That way is blocked!\n";
         player_location_Y++;
         getch();
         }
    
         end_game--;
         if (end_game == 0)
         {
         system("cls");
         cout << "GAME OVER\n";
         system("pause");
         return 0;
         }
    
         system("cls");
    
    	cout <<"North (1)\nSouth (2)\nEast (3)\nWest (4)\n\n";
    	cin >>input; 
    	cout <<"\n";
    
     	if (input == 'Q' || input == 'q')
    	{
    		system("cls");
    		return 0;
    	}
    
     	if (input == 'I' || input == 'i')
    	{
    		cout <<"North (1)\nSouth (2)\nEast(3)\nWest (4)\nQuit (Q)\nUse Heal (H)\n";
            cout <<"Life (L)\nPoints (P)\n";
      	}
    
     	if (input == 'L' || input == 'l')
    	{
    		cout <<"Health is "<<health<<"\n\n";
    	}
    
     	if (input == 'P' || input == 'p')
    	{
    		cout <<"Points are "<<points<<"\n\n";
    	}
    
     	if (input == '1')
    	{
    		player_location_Y = player_location_Y++;
    	}
    
    	if (input == '2')
    	{
    		player_location_Y = player_location_Y--;
    	}
    
    	if (input == '3')
    	{
    		player_location_X = player_location_X++;
    	}
    
    	if (input == '4')
    	{
    		player_location_X = player_location_X--;
    	}
       }
    
    if (player_location_y == 7 || player_location_x == 3)  //location of bread
    {
       if (bread == 0)
                {
                cout << "You have found a loaf of bread! +20 time!\n"
                end_game = end_game + 20;
                }
       else if (bread == 1)
                {
                cout << "There are bread crumbs here.";
                }
      }
    }
    This war, like the next war, is a war to end war.

  2. #17
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Hmm, not sure what the error is. Would you mind re-formatting the code, to make it easier to read? (i.e. make the brackets line up, point out what line the error is on instead of just showing the line number, etc.) It would make life a lot easier Oh, and just in case, not sure if it matters but at the beginning your comment starts with "/ *" instead of "/*".
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #18
    Registered User Bieh's Avatar
    Join Date
    Sep 2002
    Posts
    83
    Try this instead:

    Code:
    /**************************************************
    ******************
    *Zachs first CPP game. Kind of a RPG. Text based.
     **************************************************
    ******************/
    #include <iostream.h>
    #include <stdlib.h>
    #include <conio.h>        //allows getch()
    
    
    using namespace std;      //allows cout instead of std::cout
    int player_location_Y = 0; /* Player*/
    int player_location_X = 0;  /*  Start*/
    int health = 100;          //player health
    int health_potion = 10;     //gives ten health
    int end_game = 100;         // timer: if zero, game ends
    int points = 0;             //score
    int bread = 0;              //food
    char input;
    
    int main()
    {
        char name[20];
        cout << "Please enter your name: ";
        cin >> name;
        cout << "\nHello " << name << "Welcome to my quest!\n";
        cout << "You must venture throught this maze avoiding traps\n";
        getch();
    
        while(1)  //start
        {
         if (player_location_Y == 25)
         {
         cout << "That way is blocked!\n";
         player_location_Y--;
         getch();
         }
         else if (player_location_Y == -25)
         {
         cout << "That way is blocked!\n";
         player_location_Y++;
         getch();
         }
         else if (player_location_X == 25)
         {
         cout << "That way is blocked!\n";
         player_location_Y--;
         getch();
         }
         else if (player_location_X == -25)
         {
         cout << "That way is blocked!\n";
         player_location_Y++;
         getch();
         }
    
         end_game--;
         if (end_game == 0)
         {
         system("cls");
         cout << "GAME OVER\n";
         system("pause");
         return 0;
         }
    
         system("cls");
    
    	cout <<"North (1)\nSouth (2)\nEast (3)\nWest (4)\n\n";
    	cin >>input; 
    	cout <<"\n";
    
     	if (input == 'Q' || input == 'q')
    	{
    		system("cls");
    		return 0;
    	}
    
     	if (input == 'I' || input == 'i')
    	{
    		cout <<"North (1)\nSouth (2)\nEast(3)\nWest (4)\nQuit (Q)\nUse Heal (H)\n";
            cout <<"Life (L)\nPoints (P)\n";
      	}
    
     	if (input == 'L' || input == 'l')
    	{
    		cout <<"Health is "<<health<<"\n\n";
    	}
    
     	if (input == 'P' || input == 'p')
    	{
    		cout <<"Points are "<<points<<"\n\n";
    	}
    
     	if (input == '1')
    	{
    		player_location_Y = player_location_Y++;
    	}
    
    	if (input == '2')
    	{
    		player_location_Y = player_location_Y--;
    	}
    
    	if (input == '3')
    	{
    		player_location_X = player_location_X++;
    	}
    
    	if (input == '4')
    	{
    		player_location_X = player_location_X--;
    	}
       
    
    	if(player_location_Y == 7 || player_location_X == 3)  //location of bread
    	{
    	   if (bread == 0)
    				{
    				cout << "You have found a loaf of bread! +20 time!\n";
    				end_game = end_game + 20;
    				}
    	   else if (bread == 1)
    				{
    				cout << "There are bread crumbs here.";
    				}
    	  }
    
    	}
    }

    Does this still do what it's supposed to do?
    Last edited by Bieh; 12-02-2002 at 05:08 PM.
    "It always takes longer than you think, even when you take Hofstadter's Law into account."
    -Hofstadter's Law

    Bored? Try my game SpaceWars , made in Allegro and VC++
    or see my new game Redoubt , made in OpenGL and VC++

  4. #19
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    Ookay.. it's working.... I can't get the objects to work, though.....

    Code:
    /********************************************************************
    *Zachs first CPP game. Kind of a RPG. Text based.
    *Started Dec. 1; Put in movement
    *Modified Dec. 2; put in some traps, items, more commands.
    *Modified Dec. 3; Defined enemies. Fixed health/end_game loop.
    *Defined Weaponry, bombs, and sword.
    *Still can't get item manipultion to work.
    *******************************************************************/
    #include <iostream>
    #include <cstdlib>
    #include <conio.h>             //allows getch()
    using namespace std;          //allows cout instead of std::cout
    /*Edit the following for your own custom game*/
    int player_location_Y = 0;    /* Player*/
    int player_location_X = 0;    /*  Start*/
    int health = 100;             //player health
    int health_potion = 10;       //gives ten health
    int end_game = 100;           // timer: if zero, game ends
    int points = 0;               //score
    int bread = 0;                //food
    int trap1 = 0;                //trap
    int trap2 = 0;                //trap
    int trap3 = 0;                //another trap
    int trap4 = 0;                //yet another trap
    int trap5 = 0;                //the last trap
    int wolf = 10;                //wolf enemy
    int ghost = 50;               //ghost enemie
    int dragon = 100;             //dragon enemie
    int impossible = 10000;       //impossible to defeat enemie
    int ledge = 0;                //ledge
    int bomb = 10;                //ticking time bomb
    int sword = 0;                //weapon
    char input;
    
    int Wait ( int Seconds );
    
    int main ( void )
    {
        char name[20];
        cout << "Please enter your name: ";
        cin >> name;
        cout << "\nHello " << name << " Welcome to my quest!\n";
        cout << "You must venture throught this maze avoiding traps\n";
        getch();
        {
         while (end_game > 0 || health > 0)
         {
         if (player_location_Y == 25)
         {
         cout << "That way is blocked!\n";
         player_location_Y--;
         getch();
         }
         else if (player_location_Y == -25)
         {
         cout << "That way is blocked!\n";
         player_location_Y++;
         getch();
         }
         else if (player_location_X == 25)
         {
         cout << "That way is blocked!\n";
         player_location_Y--;
         getch();
         }
         else if (player_location_X == -25)
         {
         cout << "That way is blocked!\n";
         player_location_Y++;
         getch();
         }
         system("cls");
        end_game--;
        {
        if (end_game <= 0)
           {
           cout << "Time Out!\n";
           Wait(4);
           return 0;
           }
        }
        {
        if (health <= 0)
        	{
        	cout << "Out of health!\n";
        	Wait(4);
        	system("cls");
        	cout << "GAME OVER\n";
        	Wait(3);
        	return 0;
    	}
       }
    	cout <<"North (1)\nSouth (2)\nEast (3)\nWest (4)\nHelp (I)\n\n";
    	cin >> input;
    	cout <<"\n";
    
     	if (input == 'Q' || input == 'q')
    	{
    		system("cls");
    		return 0;
    	}
    
     	if (input == 'I' || input == 'i')
    	{
    		cout <<"North (1)\nSouth (2)\nEast(3)\nWest (4)\nQuit (Q)\n";
            cout <<"Life (L)\nPoints (P)\nHelp (I)\nTime (T)\n\n";
            getch();
      	}
    
     	if (input == 'L' || input == 'l')
    	{
    		cout << "Health is "<<health<<"\n\n";
            getch();
    	}
    
     	if (input == 'P' || input == 'p')
    	{
    		cout << "Points are "<<points<<"\n\n";
            getch();
    	}
    
        if (input == 'T' || input == 't')
    	{
    		cout << "Time left is "<<end_game<<" moves left.\n\n";
            getch();
    	}
    
        if (input == 'M' || input == 'm')
    	{
    		cout << "Position is\nY: " << player_location_Y << "\nX: ";
            cout << player_location_X <<"\n\n";
            getch();
    	}
    
     	if (input == '1')
    	{
        cout << "You venture north";
    	   player_location_Y = player_location_Y++;
        getch();
    	}
    
    	if (input == '2')
    	{
        cout << "You venture south";
    		player_location_Y = player_location_Y--;
    	}
    
    	if (input == '3')
    	{
        cout << "You venture east";
    		player_location_X = player_location_X++;
        getch();
    	}
    
    	if (input == '4')
    	{
        cout << "You venture west";
    		player_location_X = player_location_X--;
        getch();
    	}
       }
    
    if (player_location_X == 0 && player_location_Y == 5)  //location of fountain
    {
                {
                cout << "There is a fountian of trickling water. +5 health\n";
                health = health + 5;
                getch();
                }
       }
    
    if (player_location_Y == 1 && player_location_X == 0)  //location of bread
    {
       if (bread == 0)
                {
                cout << "You have found a loaf of bread! +20 time!\n";
                end_game = end_game + 20;
                bread = bread + 1;
                getch();
                }
       else if (bread == 1)
                {
                cout << "There are bread crumbs here.";
                getch();
                }
      }
    
     if (player_location_Y == -1 && player_location_X == 0)  //trap1
    {
       if (trap1 == 0)
                {
                cout << "Fire pit! - 10 health!\n";
                health = health - 10;
                trap1 = trap1 + 1;
                getch();
    
                }
       else if (trap1 == 1)
                {
                cout << "You carefully cross the fire pit\n";
                getch();
       }
    }
    
     if (player_location_Y == -1 && player_location_X == 1)  //trap2
     {
       if (trap2 == 0)
                {
                cout << "YIKES! SPIKES! - 20 health!\n";
                health = health - 20;
                trap2 = trap2 + 1;
                getch();
                }
       else if (trap2 == 1)
                {
                cout << "You carefully cross the spike pit\n";
                getch();
                }
    }
    }
    }
    int Wait ( int Seconds )
    {
        clock_t endtime = clock() + Seconds * CLOCKS_PER_SEC;
        while ( ( clock() < endtime ) );
        return 0;
    }
    Why don't the items work?
    Are they in the wrong loop?
    And i never heard hjow to play sounds. I have a midi i want to play on it, and i can convert that to wave if i need to.
    This war, like the next war, is a war to end war.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21