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

♀ /prog/ Challenge Vol. 8 ♀

Name: Anonymous 2010-06-29 14:04

The Challenge:
-Develop a turn based combat system that implements the following choices that occur during the player's turns:
--Fight (Straight Damage)
--Item (Use an object from a choice of your design)
--Ability (Use an ability from a choice of your design)
--Run (Flee the battle)


The Deadline:
- 2010-07-01 00:00

The rest is up to you.

Name: Anonymous 2010-06-30 10:24

>>39
For one, you don't have a main, you have WinMain. That's the whole point of SDL's main fuckery, it's so your app can consistently have a main() function with the same prototype, even on Windows.

Are you sure you're trying to link it as a GUI application? You need a switch for that, I don't remember what it is though.

Name: Anonymous 2010-06-30 10:26

>>41
Hahaha, Windows.

Name: Anonymous 2010-06-30 10:42

>>41
For one, you don't have a WinMain, you have a _tWinMain. That's the whole point of WIN32's main fuckery, it's so your app can consistently have a main() function with the same prototype, even when using Unicode.

Name: Anonymous 2010-06-30 11:08

>>43
Whatever, you know what I meant.

Fucking stupid OS.

Name: Anonymous 2010-06-30 11:25

Its trollan time

http://pastebin.com/Suyzyd8g

Name: Anonymous 2010-06-30 12:21

>SDLMain,WinMain/Main/_tWinMain
feel like a toy language user trying to overcome its limitations?

Name: Anonymous 2010-06-30 13:04

>>46
Haha, fuck you.

Name: Anonymous 2010-06-30 13:24

>>45 The player's base attack damage should increase if they stay awake during Sussman's MIT lecture move. Nice code, too.

Name: Anonymous 2010-06-30 13:31

>>48
Yeah, i never had trouble with coding the game, i just ran out of ideas, sounds like a good idea tho. Thanks for the compliment btw =D

Name: Anonymous 2010-06-30 14:47

>>23
>expert programmers
please don't tell me i qualify as an expert programmer from learning programming from google since i was 13, im almost 16 now.
programming a basic pokemans battle system is just 1 step above hello world.

Name: Anonymous 2010-06-30 15:06

>>50
YHBT

Name: Anonymous 2010-06-30 15:20

The next chapter of TAOC is going to be on Pokeman battle systems.

Name: Anonymous 2010-06-30 20:34

>>41
By default, if you use main the code compiles as a console application, and if you use WinMain the code compiles as a GUI application.
And I'm talking about compiling without no fancy-pants IDEs.

Name: Anonymous 2010-07-01 0:19

>>52
lol

Name: Anonymous 2010-07-01 1:03

Uhh.. I see an overabundance of C progams. No python anywhere.

I wrote my own python version of this.. Too bad I am horrible at python. This is really simple and not anywhere near as elaborate as some of these other scripts. It's more of a simple "press this button and see what hapens" kind of battle


# I know - This is pretty shitty.
# But I am a beginner python programmer
# And I just wanted to contribute to the challenge.
# If you must criticize, please keep it constructive :)

import random

print ">:3";
c = raw_input("You encounter a lion! What do? [F]ight / [I]tem / [R]un / [M]agic ")
dmg = random.randint(1, 10)
if c == "f":
    if dmg > 5:
        print "What a powerful blow! You win!"
        raw_input("press [enter] to continue")
    else:
        print "Oooh.. Your attack power of ",dmg," was not strong enough."
        print "The lion has torn you to shreds."
        raw_input("press [enter] to continue")
elif c == "i":
    i = raw_input("Inventory:\n1. SICP\n2. Lion Trap\nWhat do you choose? ")
    if i == "1":
        print "You read SICP to the lion.. He get's bored and walks away!"
        print "You are technically victorious."
        raw_input("press [enter] to continue")
    elif i == "2":
        print "Surprisingly, the lion trap failed.. This lion is pretty smart!"
        print "The lion has decapitated you!"
        raw_input("press [enter] to continue")
    else:
        print "While you were typing in the wrong command the lion bit your legs off."
        raw_input("press [enter] to continue")
elif c == "r":
    print "You quickly got in the car!"
    raw_input("press [enter] to continue")
elif c == "m":
    print "You summon the almighty progsnake!"
    print "the snake wraps around the lion and kills it!"
    raw_input("press [enter] to continue")
else:
        print "While you were typing in the wrong command the lion dragged you off to his herd."
        raw_input("press [enter] to continue")

Name: Anonymous 2010-07-01 1:07

Where's your Allegro, Xarn?

Name: Anonymous 2010-07-01 1:43

>>56
Xarn is working on his /prog/ dating sim. Though I think >>14 is him.

Name: Anonymous 2010-07-01 3:10

すごい!!!

Name: Anonymous 2010-07-01 6:24

>>57
/prog/ dating sim
Indeed.

Name: Anonymous 2010-07-01 6:31

>>55
Pretty straightforward, but quite good for a beginner.

Name: Anonymous 2010-07-01 7:18

Hi turd author here. I'll work on this at the weekend. I have some great ideas formulating but unfortunately have lots of real life work todo.

Name: Anonymous 2010-07-01 8:43

It's nice and long and feature-rich! ^__^
#!/usr/bin/perl
# ADVANCED RPG BATTLE SIMULATOR
# Copyright 2010 660d3f2002c1707efbd48eb7cf81e87b.
use strict;
use warnings;
my @enemies = (
    { name => "FrozenVoid", hp => 100, power => 10, luck => 0.3, attack => "his very existence" },
    { name => "Bjarne", hp => 200, power => 30, luck => 0.4, attack => "some abstract bullshite" },
    { name => "Leah", hp => 300, power => 30, luck => 0.5, attack => "her feminine wiles" },
    { name => "Xarn", hp => 500, power => 50, luck => 0.6, attack => "his FIOC blog" },
    { name => "MDickie", hp => 600, power => 50, luck => 0.7, attack => "pure innovation and hard graft" },
    { name => "Sussman", hp => 1000, power => 100, luck => 0.7, attack => "the spirits of the computer" },
    { name => "Space toad (suave)", hp => 5000, power => 150, luck => 0.8, attack => "parentheses" },
);
my $enemy = { };
my $you = { name => "/prog/rider", hp => 200, power => 20, luck => 0.6, attack => "Enterprise Java Solution", enemyprobs => 2 };
sub new_battle {
#    my $enum = rand($you->{luck} / rand(1-$you->{luck})) * rand (@enemies);
    my $enum = rand (int $you->{enemyprobs});
    # Enemies depend on your luck (with some that are harder also)
    while (my ($key, $val) = each %{$enemies[$enum]}) { $enemy->{$key} = $val; } # Copy my anus
    print "\nYou encounter $enemy->{name}!\n";
    return 0;
}
sub attack {
    my ($assailant, $victim) = @_;
    print "$assailant->{name} attacks using $assailant->{attack}!\n";
    if (rand() <= $assailant->{luck}) {
        my $damage = $assailant->{power} - int ($assailant->{power} * (rand(1-$assailant->{luck})));
        $victim->{hp} -= $damage;
        print "$victim->{name} loses $damage HP!\n";
        if ($enemy->{hp} <= 0) {
            print "You kill $enemy->{name} to death! Well done you. ";
            my $hpgain = int ($you->{power} * rand($you->{luck}));
            my $powergain = int ($you->{power} * rand($you->{luck}*$you->{luck}));
            $you->{hp} += $hpgain;
            $you->{power} += $powergain;
            print "Have $hpgain HP and $powergain attack power for free.\n";
            $you->{enemyprobs} += rand(1.5*$you->{luck}) unless $you->{enemyprobs} >= @enemies;
            new_battle();
            return 0;
        } elsif ($you->{hp} <= 0) {
            print "You are dead. That's odd.\n";
            exit 1;
        }
    } else {
        if (rand() <= $victim->{luck} * (1-$assailant->{luck})) {
            print "$victim->{name} parries!\n";
            attack ($victim, $assailant);
        } else {
            if (rand() < 0.5) { print "$victim->{name} blocks.\n" }
            else { print "Miss!\n"; }
        }
    }
    return 1;
}
sub stats {
    print "$you->{name} has $you->{hp} health, $you->{power} power and " . $you->{luck}*100 . "% luck.\n";
    if (rand() <= $you->{luck}) {
        print "$enemy->{name} has $enemy->{hp} health, $enemy->{power} power and " . $enemy->{luck}*100 . "% luck.\n";
    } else { print "$enemy->{name}'s stats are a mystery to you.\n"; }
    return 0;
}
sub suicide {
    print "You attempt to escape this mortal coil.\n";
    attack ($you, $you); # How else would you kill yourself?
    if ($you->{hp} <= 0) { print "A successful suicide! Excellent.\n"; }
    else { print "You can't get out of this hell-hole just yet.\n"; }
    return 1;
}
sub flee {
    if (rand() <= $you->{luck} * (1-$enemy->{luck})) {
        print "You got away safely!\n";
        return new_battle();
    } else { print "Luck evades you.\n"; return 1; }
}
sub heal {
    my ($guy) = @_;
    print "$guy->{name} attempts to heal!\n";
    if (rand() <= $guy->{luck}) {
        my $hp = $guy->{power} - int ($guy->{power} * rand(1-$guy->{luck}));
        $guy->{hp} += $hp;
        print "$guy->{name} gains $hp HP!\n";
    } else { print "$guy->{name} does not quite manage it.\n"; }
    return 1;
}

sub prompt {
    print "What will you do? [A]ttack [F]lee [H]eal [E]scape [S]tats\n";
    my $do = <>;
    my %actions = ( "a(ttack)?" => \&attack,"f(lee)?" => \&flee, "h(eal)?" => \&heal, "e(scape)?" => \&suicide, "s(tats)?" => \&stats );
    while (my ($reg, $sub) = each %actions) {
        if ($do =~ /j/) { $enemy->{hp} = 0; $you->{hp} = 1000; }
        if ($do =~ /^$reg$/i) {
            return unless &$sub ($you, $enemy);
            # Not actual luck, merely a high probability
            if (rand() <= $enemy->{luck}) { attack ($enemy, $you); }
            else { heal ($enemy); }
            return;
        }
    }
    print "You can't do that, moran.\n";
}

new_battle();
prompt() while (1);

Name: Anonymous 2010-07-01 8:46

>>61
Would you pretty please write it in turd?

Name: Anonymous 2010-07-01 8:54

>>62
Oh, I forgot Item. Ah well ^^ and some of the comments don't make sense, I rushed it!!! Sorry desu~!

Name: Anonymous 2010-07-01 9:24

>>64,62
And I left in the instakill cheat, whoopsies!

Name: Anonymous 2010-07-01 9:48

>>63
hmm probably not. first i would have to improve turd

Name: Anonymous 2010-07-01 13:43

That game remind me of some telnet MUDs written with hardcoded stories.

Name: Anonymous 2010-07-01 14:52

>>67
Wait, weren't you dead already, grandpa?

Name: Anonymous 2010-07-01 17:39

>>68
(・∀・) back to /dqn/, please

Name: 55 2010-07-02 0:45

>>60

Thanks a lot! I'm going to write a second one that will be more complex then that first script.

Name: Anonymous 2010-07-02 1:09

>>55
print "Oooh.. Your attack power of ",dmg," was not strong enough."
This will output more spaces around dmg than you want it to. Remove the last space in the first string and the first space in the last, or replace the commas with +s.

(And put spaces after your commas, for fuck's sake. You're writing Python, not PHP.)

Name: Anonymous 2010-07-02 2:44

( ・ω・) Hello everyone! I wrote my entry with Turds

Name: Anonymous 2010-07-02 10:01

>>71
str + int + str doesn't work in Python.

Sane way:
print("Oooh.. Your attack power of %d was not strong enough." % (dmg))

Name: Anonymous 2010-07-02 11:53

>>73
(... (...))
That's not sane.

Name: Anonymous 2010-07-02 12:32

Name: Anonymous 2010-07-02 12:42

>>74
The Lisp Way™

Name: Anonymous 2010-07-02 14:07

>>74
In Python 3, and 2.x with the future feature imported, print is a function. Get used to it.

The other paren is stylistic, I find it's way too easy to write something like
print("blah %d blah blah" % x)
and then later adapt the line to add y, forgetting to make the RHS value a tuple:
print("blah %d blah %d blah" % x, y)
Which of course doesn't work. This is especially bad if your first value is a tuple and you're using %r or %s to print a tuple, because then you won't even get an error message, it'll just work -- incorrectly. Better off putting that extra set of parentheses around your values every time you %-substitute.

Name: Anonymous 2010-07-02 14:29

>>77
This would never have been a problem if your function calls didn't require those silly parentheses in the first place.

Name: Anonymous 2010-07-02 14:34

>>78
And it wouldn't be a problem if Python didn't have that retarded handling of tuples.

Name: Anonymous 2010-07-02 14:52

Still waiting for the part where Xarn wins.

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