problems with first game

This is a discussion on problems with first game within the Game Programming forums, part of the General Programming Boards category; I'm writing my first game.the game is in c++, its a text based fighting game like "Rpg" in the game ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    2

    problems with first game

    I'm writing my first game.the game is in c++, its a text based fighting game like "Rpg" in the game section of the source code page of this site. at first the enemy was attacking himself but now he is not attacking at all and when he starts the program is not executing properly. the whole code can be found at C++ code by eltonbang - 114 lines - codepad but i will of course post the area i believe to be the problem area. any help would be greatly appreciated. thanks

    Code:
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int Lvl1();
    int Lvl2();
    int Lvl3();
    int Lvl4();
    int Lvl5();
    int Lvl6();
    int Lvl7();
    int Lvl8();
    int Lvl9();
    int lvl10();
    int main();
    int choice;
    int ENhp,PLhp,ENagi,PLagi,I,PLdef,ENdef,ENatk,PLatk,init,PLdamage,ENdamage; // EN = Enemy,PL = player
    ////////////////////////////////main/////////////////////////////////////////////////////////////
    int main(){
    {srand((unsigned)time(0));}
         cout <<"Back Ally Brawls by John Billingsley\n";
    do {Lvl1();} while (ENhp>0||PLhp>0);
    return 0;}
    ///////////////////LVL_1/////////////////////////////////////////////////////////
    int Lvl1(){
     PLatk = 20 + rand() % 10;/////////////////////////////////////////////////////////////////
     PLdef = 20 + rand() % 10;
     PLagi = 20 + rand() % 10;
     PLhp  = 200;                          // player values before attack bonus
     init  =      rand() % 2+1;
     ENatk = 15 + rand() % 10;
     ENdef = 15 + rand() % 10;
     ENagi = 15 + rand() % 10;
     ENhp  = 150;
     srand((unsigned)time(0));
     ////////////////////////////////////////////////////////////////////////////////////
     if (init==1){ cout << "You start.\n";
     cout << "you'r first fight will be against a deranged crack head\n";
     while (ENhp > 0 && PLhp > 0) {
        cout << "What do you want to do?\n1 - punch\n2 - kick\n3 - Block\n";
     do{cin>>choice;}while(choice>3 || choice<1);
     switch (choice){case 1:
          PLatk == 20+rand()% 6;
    	  PLdef == 20 ;
    	  PLagi == 20+rand()% 11;
    	break;
         case 2:                                              ///attacks and attack bonuses           
          PLatk == 20+rand()% 11;
    	  PLdef == 20;
    	  PLagi == 20+rand()% 6;
        break;
         case 3:
          PLatk == 0 ;
    	  PLdef == 20+rand()% 11;
    	  PLagi == 20+rand()% 16;
    	break;
        }
     ///////////////////////////////////////////////////////////////////////////
    ENdamage=(PLatk+PLagi)-(ENdef+ENagi);
      if (ENdamage<1) {ENdamage=0;}                                        ////dealing damage, this may be a problem area
     ENhp=(ENhp-ENdamage);                                   
     cout<<"The enemy has:"<<ENhp<<" health remaining\n";
     cin.get();
     if (ENhp<1){cout<<"One crackhead down, 9 fierce fighters to go!\n";
    return 0;}
    
    PLdamage=(ENatk+ENagi)-(PLdef+PLagi);
      if(PLdamage<1){PLdamage=0;}
     PLhp=(PLhp-PLdamage);
     cout<<"You have:"<<PLhp<<" health remaining\n";
     cin.get();
     if (PLhp<1){cout<<"YOU GOT KNOCKED THE ........ OUT\n";
    return 0;}}}
       /////////////////////////////////////////////////////////////////////////////
     else {
        cout<<"your first fight will be against a deranged crack head.\n";
        cout<<"Crack Head will start.\n";           
        while (PLhp > 0 && ENhp > 0){
            choice = rand()% 3;                   /////the enemy was attacking himself
        switch (choice) {
         case 1:                                  //// now he is not attacking    
          ENatk == 15+rand()% 6;
    	  ENdef == 15 ;
    	  ENagi == 15+rand()% 6;
    	break;
         case 2:
          ENatk == 15+rand()% 11;
    	  ENdef == 15;
    	  ENagi == 15+rand()% 6;
        break;
         case 3:
         ENatk == 0;
         ENdef == 15+rand()% 11;
         ENagi == 15+rand()% 6;
    	break;
    	}}}
    
    ENdamage=(PLatk+PLagi)-(ENdef+ENagi);
      if (ENdamage<1) {ENdamage=0;}
     ENhp=(ENhp-ENdamage);
     cout<<"The enemy has:"<<ENhp<<" health remaining\n";
     cin.get();
     if (ENhp<1){cout<<"One crackhead down, 9 fierce fighters to go!\n";
    return 0;}
    
    PLdamage=(ENatk+ENagi)-(PLdef+PLagi);
      if(PLdamage<1){PLdamage=0;}
     PLhp=(PLhp-PLdamage);
     cout<<"You have:"<<PLhp<<" health remaining\n";
     cin.get();
     if (PLhp<1){cout<<"YOU GOT KNOCKED THE ........ OUT\n";
    return 0;}
    }
    Last edited by Salem; 06-24-2012 at 02:37 PM. Reason: inserted all the code

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    For starters, every time you're doing
    Code:
    ENdef == 15 ;
    it's not an assignment. You should be using =, not ==.

    Also, you should learn to not use globals by passing around values from function to function (and if there is too many, use a struct).

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    2
    thanks my code is cleaned up a bit now. however do you know how i can get my enemy to fight back?

  4. #4
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    200
    He doesn't. You have to figure out how you want your enemy to attack. It's your game, not ours. Design an intelligence to meet the standards of the enemy you're trying to create.
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game of Life Problems
    By emj83 in forum C Programming
    Replies: 7
    Last Post: 02-25-2009, 02:27 PM
  2. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  3. Game problems!
    By Tynnhammar in forum Tech Board
    Replies: 14
    Last Post: 01-12-2005, 07:49 AM
  4. Game Problems
    By Spectrum48k in forum Tech Board
    Replies: 4
    Last Post: 06-02-2004, 08:08 PM
  5. problems with my tic tac toe game
    By Leeman_s in forum C++ Programming
    Replies: 4
    Last Post: 04-12-2002, 09:59 PM

Tags for this Thread


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