Thread: Fighting game help

  1. #1
    Registered User aaron11193's Avatar
    Join Date
    Oct 2006
    Posts
    13

    Fighting game help

    hey im making an ascii fighting game and i cant understand why this gives errors
    Code:
    attack( int hp, int att, int def, int spd, int power, int cash, int wins, int loses, int awake, int battle_num, int enemyatt, int enemydef, int enemyspd, int enemyhp ){
    	int blowtype;
    	char blow[10];
    	int attacker;
    	char aattacker[10];
    	int attacked;
    	char aattacked[10];
    	int place;
    	char pplace[10];
    	int hit = att - ( rand() % 30 );
    	int hhit = enemyatt - ( rand() % 30 );
    	srand( time( NULL ) );
    	attacker = rand() % 2;
    	blowtype = 1 + ( rand() % 3 );
    	place = 1 + ( rand() % 3 );
    	switch( blowtype ){
    		case 1: blow = 'punch';
    		break;
    		case 2: blow = 'kick';
    		break;
    		case 3: blow = 'slap';
    		break;
    	}
    	switch( place ){
    		case 1: pplace = 'head';
    		break;
    		case 2: pplace = 'stomach';
    		break;
    		case 3: pplace = 'balls';
    	}
    	if( attacker == 0 ){
    		attacked = 1;
    		aattacked = 'Laymow';
    		aattacker = 'You';
    	}else{
    		attacked = 0;
    		aattacked = 'You';
    		aattacker = 'Laymow';
    	}
    	printf("\n%s %s %s in the %s for %d hp...", aattacker, blow, aattacked, pplace, hit );
    }
    thx

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    1. no include files
    2. no return type for function attack
    3. 'balls' - string constans should be placed in "" not ' '
    4. string constant cannot be used in case
    ...

    Do you read the compiler errors at all?

    Start learning structs instead of transferring hundreds of annoying variables
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User aaron11193's Avatar
    Join Date
    Oct 2006
    Posts
    13
    that is just a function in a bigger program btw
    the error messages make no sense
    Code:
    streetfighting.c:207:18: warning: character constant too long for its type
    streetfighting.c: In function ‘attack’:
    streetfighting.c:207: error: incompatible types in assignment
    streetfighting.c:209:18: warning: multi-character character constant
    streetfighting.c:209: error: incompatible types in assignment
    streetfighting.c:211:18: warning: multi-character character constant
    streetfighting.c:211: error: incompatible types in assignment
    streetfighting.c:215:20: warning: multi-character character constant
    streetfighting.c:215: error: incompatible types in assignment
    streetfighting.c:217:20: warning: character constant too long for its type
    streetfighting.c:217: error: incompatible types in assignment
    streetfighting.c:219:20: warning: character constant too long for its type
    streetfighting.c:219: error: incompatible types in assignment
    streetfighting.c:223:15: warning: character constant too long for its type
    streetfighting.c:223: error: incompatible types in assignment
    streetfighting.c:224:15: warning: multi-character character constant
    streetfighting.c:224: error: incompatible types in assignment
    streetfighting.c:227:15: warning: multi-character character constant
    streetfighting.c:227: error: incompatible types in assignment
    streetfighting.c:228:15: warning: character constant too long for its type
    streetfighting.c:228: error: incompatible types in assignment

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Your program is dealing with char arrays, like char blow[10], as though they were a string.

    They are INDIVIDUAL CHAR'S and they can't be made = to a 'punch', 'slap', etc.

    I admire your energy in coding this up, but you gotta know it's going to need a re-write the second that you're done, right?

    You're going to learn just WHY we have structs, etc., the hard way. Which is quite alright.

    For now, why not make the punch just be represented by the char 'p', the kick by 'k', the slap by 's', etc. ? Then it's easy to just add something like:

    Code:
    if (blow == 'k')  /* blow is now just a char itself */
       printf("\n You kicked me!!");
    It's a tedious fix to your game, but until you learn to work with strings, it's the best I can think of.

    That will get rid of a huge number of your errors that you posted.

    Adak

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > case 1: blow = 'punch';
    You need something like
    strcpy( blow, "punch" );

    It's also a good idea to compile often (and get just a few errors), rather than compile once at the end (and get huge numbers).

    Then you wouldn't copy/paste the same mistake in many places.
    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.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You're only supposed to call srand() once during the execution of a program. It might be a good idea to call it in main() or in an initialization function of some kind.

    For now, why not make the punch just be represented by the char 'p', the kick by 'k', the slap by 's', etc. ?
    Another idea would be to use an enum:
    Code:
    enum food_t {
        FOOD_BANANA,
        FOOD_EGGSANDWICH
    };
    
    enum food_t food = FOOD_BANANA;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  2. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 09:26 AM
  3. C# - Building a SCUMM-like game.. questions
    By Iyouboushi in forum Game Programming
    Replies: 0
    Last Post: 05-24-2008, 10:54 PM
  4. my upcoming UNO card game :)
    By Hussain Hani in forum Game Programming
    Replies: 5
    Last Post: 01-24-2008, 01:19 AM
  5. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM