Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ - RPG

Name: Anonymous 2010-10-29 15:44

Lets program a roleplaying game together. Each post must contain either a new function or an edited version of an old function in psudocode. I will start:

int dealDamage(int hp, int damage){
    return hp - damage;
}

Name: Anonymous 2010-10-29 16:44


//    Command format:
//    Commands:
//        SAY    {argument}
//        MOVE {argument} -- Direction north, northeast, ettc
//        WAIT {time_in_hours}
//        ATTACK    {enemy_id},{weapon},{target_location_on_enemy}
//Said command functions will return an int 0 = succeed; 1 = error
//////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int parse(char *x){
    int size = strcspn(x," ")-1;
    char *command;
    char *arg;
    char **argv;
    int i,j;
    if(size<=0)
        return 1;
   
    command = malloc(sizeof(char) *(size));
    for(i=0;i<size;i++)
        command[i]=x[i];
    arg = malloc(sizeof(char) *(sizeof(x)-size));
    for(i=size;i<sizeof(x);i++){
        arg[i-size]=x[i];
    }
   
    if(strncmp(command,"SAY",sizeof(command))){
        free(command);
        return say_function(arg);
    }
    else if(strncmp(command,"MOVE",sizeof(command))){
        free(command);
        return move_function(arg);
    }
    else if(strncmp(command,"WAIT",sizeof(command))){
        free(command);
        return wait_function(arg);
    }
    else if(strncmp(command,"ATTACK",sizeof(command))){
        argv = malloc(sizeof(char *) *3);
        for(i=0;i<3;i++){
            size = strcspn(arg,",")-1;
            argv[i] = malloc(sizeof(char) *size);
            for(j=0;i<size;i++)
                argv[i][j] = arg[j];
            //
            free(command);
            command = malloc(sizeof(char)*(sizeof(arg)-size));
            for(i=size;i<sizeof(arg);i++)
                command[i-size]=arg[i];
            free(arg);
            arg = malloc(sizeof(char)*sizeof(command));
            for(i=0;i<sizeof(command);i++)
                arg[i]=command[i];
        }
        free(command);
        free(arg);
        return attack_function(argv);
    }
       
       
    free(command);
    free(arg);
    return -1;
}


you guys can optimize it,add to it and define the other functions in it

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List