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 15:48

>>1
Now rewrite that function to return 0 if its negative without using an if statement!

Name: Anonymous 2010-10-29 15:50

Easy.

int dealDamage(int hp, int damage){
    hp -= damage;
    while(hp > 0)
        return hp;
    return 0;
}

Name: Anonymous 2010-10-29 16:07

return ((hp-damage) + (abs(hp-damage)) / 2)

Name: Anonymous 2010-10-29 16:09

float randomize(float x, float m = 0.9){
    float n = random(m, 1/m);
    return x*n;
}

Name: Anonymous 2010-10-29 16:10


int dealDamage(int hp, int damage) {
    return (damage > hp) ? 0 : (hp - damage);
}

Name: Anonymous 2010-10-29 16:10

I propose we increase the grit and realism in this game.

int dealDamage(int hp, int damage) {
    return damage?0:hp;}

Name: Anonymous 2010-10-29 16:13

>>6
>>7
?,: is just a shortened version of the if-else statement

Name: Anonymous 2010-10-29 16:15

dealDamage :: (Integral a) => a -> a -> a
dealDamage hp damage = max 0 (hp - damage)

Name: Anonymous 2010-10-29 16:19

void die() {
 tell ("You are dead. Is funny to me.");
 main_menu();
}
void newGame() {
 die();
}

Name: Anonymous 2010-10-29 16:22

>>8
>>7 wasn't solving your stupid problem.

Name: Anonymous 2010-10-29 16:26


int fuck(struct anus *thing, bool condom) {
  if(condom)
    thing->an_sore++;
   else
    thing->an_sore += 2;
  sperm_c = 0;
  return thing_an_sore;
}

Name: Anonymous 2010-10-29 16:27

>>12
return thing->an_sore;

Name: Anonymous 2010-10-29 16:36

>>10
define tell(char*)
define main_menu(void)

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

Name: Anonymous 2010-10-29 17:32

Here's some ENTERPRISE Common Lisp RPG skeleton I wrote in the last 15 minutes:

(defclass damageable-mixin ()
  ((damage-accumulated :accessor total-damage :initform 0)))

(defgeneric damage (object &key)
  (:documentation "Inflict damage upon an object in some way"))

(defmethod damage ((object damageable-mixin) &key amount)
  (with-accessors ((total total-damage)) object
    (incf total amount)))

(defgeneric consume-damage (object &key)
  (:documentation "Remove damage from an object"))

(defmethod consume-damage ((object damageable-mixin) &key amount)
  (with-accessors ((total total-damage)) object
    (let ((consumed-amount (if amount total 0)))
      (decf total consumed-amount))))

(defclass game-character (damageable-mixin)
  ((hitpoints :accessor hitpoints :initarg :hitpoints)))

(defmethod deal-accumulated-damage ((char game-character))
  (with-accessors ((hp hitpoints) (dmg total-damage)) char   
    (decf hp dmg)
    (consume-damage char :amount dmg)))

(defmethod damage ((char game-character) &key)
  (call-next-method)
  (deal-accumulated-damage char))

(defgeneric heal (character amount)
  (:documentation "Heal a character by some amount"))

(defmethod heal ((char game-character) amount)
  (deal-accumulated-damage char)
  (with-accessors ((hp hitpoints)) char
    (incf hp amount)))


(defclass player-character (game-character) ())
(defclass non-playable-character (game-character) ())
(defclass monster (non-playable-character) ())

;; item may not have hp, but it can still accumulate damage,
;; it may break eventually depending on item's implementation
(defclass item (damageable-mixin) ())

(defmethod damage :before ((player player-character) &key amount)
  (format t "You received ~A damage.~&" amount))

(defmethod heal :before ((player player-character) amount)
  (format t "You were healed by ~A hitpoints.~&" amount))

(defmethod show-hitpoints ((player player-character))
  (format t "You now have ~A hitpoints.~&" (hitpoints player)))

(defmethod damage :after ((player player-character) &key)
  (show-hitpoints player))
(defmethod heal :after ((player player-character) amount)
  (show-hitpoints player))

(let ((player (make-instance 'player-character :hitpoints 100)))
  (damage player :amount 10)
  (heal player 9.99))

;; Outputs:
;You received 10 damage.
;You now have 90 hitpoints.
;You were healed by 9.99 hitpoints.
;You now have 99.99 hitpoints.


It's overengineered, however it is imagined to allow one to define all kinds of things that can be damaged, and thigns that have HPs, each with more general and more specific behaviours as the game designer wishes. Items are meant to be able to receive damage, but they don't have to have a set HP, instead how damage is handled is left to the developer. Playable and non-playable characters do have HP and the damage is reflected by changing the HP, however such behaviour can be easily overridden by defining more specific methods on the characters.

Name: Anonymous 2010-10-29 18:03

>>14-16
This is meant to be pseudocode, you brain-damaged idiots; code written for the entertainment of the readers, nothing more.
>>2-6 and others are also missing the point entirely.

Name: Anonymous 2010-10-29 18:11

>>17
deal with it

Name: Anonymous 2010-10-29 18:25

>>17
Who cares, I never write psuedocode most of the time, unless the language is braindead, I can just express myself in it without the need of an extra translation step.

Name: Anonymous 2010-10-29 18:29

struct item
{
  String item;
  int quantity;
};

void inventory_initialize (int slots)
{
  inventory = allocate(slots);
}

void inventory_add_item(String item, int quantity);
Item inventory_remove_item (String item, int quantity);
void inventory_reset();

Name: Anonymous 2010-10-29 18:31

>>19
But then there are retards like >>14 writing function definitions.
>>15-16 are nice and all but we were going to write it together and end up having humorous game logic or something not totally boring.
And >>2-6 just spewed their Asperger's all over the place.

Name: Anonymous 2010-10-29 18:34

>>17
is C to deep for you to understand

Name: Anonymous 2010-10-29 18:35

>>15
sizeof(command)
WHBT

Name: Anonymous 2010-10-29 18:41

>>8
?,: is just a shortened version of the if-else statement
?: is an expression, whereas if-else is a statement, YOU FUCKING IDIOT!!!

Name: Anonymous 2010-10-29 18:44

>>24
Your homosexuality is a statement.

Name: Anonymous 2010-10-29 18:44

>>24
Bunch of Code Golf bullshit is that ternary operator.
Considered Harmful, etc..

Name: Anonymous 2010-10-29 19:11

>>26
?:>if

Name: Anonymous 2010-10-29 19:11

>>26
What are you on about? Expressions are always better than statements. Its syntax in C may suck, but it's still superior to the normal statements semantically, at least when it comes to usefulness.

Name: Anonymous 2010-10-29 19:24

use v6;

sub MAIN() {
    my @resp = <Ok. Cool. Rad. Neato. Hella. Spankin'.>;
    my $input = prompt "What's happening?";
    while $input !~~ "The End." {
        $input = prompt "{@resp.pick} What happens next?";
    }
}

Name: Anonymous 2010-10-29 19:28

>>29
this is a good game

Name: Anonymous 2010-10-29 20:54

>>26
Clueless about programming.

It's the statement what's shit.

P.S. You can indent ?: properly.

Name: Anonymous 2010-10-29 21:04

what's the real difference between ternary and a regular if-else statement? any performance gain? or is it just a matter of writing less?

Name: Anonymous 2010-10-29 21:08

>>32
?: is a full-fledged expression that can be used anywhere and combined anyhow. if-else is a statement, which is a FORTRAN-derived wart.

any performance gain?

A programming gain. Don't be so worried about performance (OMG OPTIMIZED!!!!!!! -funroll-loops -malign-pointers lolol)

it just a matter of writing less

Not at all.

Name: Anonymous 2010-10-29 21:10

char *get_name(void)
{
    static char name[64];
    printf("What is your name?\n");
    if (scanf("%63[^\n]%*[^\n]", name) < 1)
        strcpy(name, "Anus");
    return name;
}

Name: Anonymous 2010-10-29 21:34

>>32
A FREAKING RETURN VALUE

Name: Anonymous 2010-10-29 23:21

void postLogin()
{
    if(userName == "doridian"){
          überAdminモード = true;
    }
}

Name: Anonymous 2010-10-29 23:26

>>32
truth?then:else;
works like:
(if truth then else)

if(truth){then}else{else}
works like:
PIG DISGUSTING!!

Name: Anonymous 2010-10-30 0:25

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

If we're lucky, we'll never call this function when hp is zero.

Name: Anonymous 2010-10-30 0:37

>>38
Ignore me.
int dealDamage(int hp, int damage){
    return hp - damage + (int)floor(damage/hp - 0.5);
}

Name: Anonymous 2010-10-30 0:51

    return hp - damage + (int)floor(damage/(hp - 0.5));
ftfy

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