Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Seeking Feed Back on a Game (long)

by CharlesClarkson (Curate)
on Nov 21, 2001 at 22:32 UTC ( [id://126819]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    print "What Goal In Cash Do You Want To Set? :";
    chomp ($goal=<STDIN>);
    
  2. or download this
    sub query_user {
        print @_ if @_;
        chomp (my $answer = <STDIN> );
        return $answer;
    }
    
  3. or download this
    sub notify_user {
        return print @_;
    }
    
  4. or download this
    sub query_user {
        notify_user(@_) if @_;
        chomp (my $answer = <STDIN> );
        return $answer;
    }
    
  5. or download this
    my (%ticker, %portfolio);
    my @stock_names = ('Derpco', 'Tetrabytz', 'Mojo Inc', 'Freke', 'Mega')
    +;
    @portfolio{@stock_names} = (0) x @stock_names;
    @ticker{@stock_names} =
            map {   price       => generate_random(10, 100),
                    volitility  => int(rand(7)) * 5 + 5 }, @stock_names;
    
  6. or download this
    @stocks = (0,0,0,0,0);
    $derpco=genRand(10,100);
    $tetrabytz=genRand(10,100);
    ...
    $freke=genRand(10,100);
    $mega=genRand(10,100);
    $cash=genRand(500,1000);
    
  7. or download this
    #!/usr/bin/perl -w
    use strict;
    
    ...
    $freke=genRand(10,100);
    $mega=genRand(10,100);
    $cash=genRand(500,1000);
    
  8. or download this
    #!/usr/bin/perl
    use strict;
    use diagnostics;
    ...
        return print @_;
    }
    
  9. or download this
    unless ( defined $end ) {
        $end = $start;
        $start = 0 - $end;
    }
    
  10. or download this
    sub generate_random {
        my ($start, $end) = @_;
        $end = 0 - ($start = 0 - $start) unless defined $end;
        return int( $start + rand($end - $start + 1) );
    }
    
  11. or download this
    $manip=genRand(0,50);
    $derpco=$derpco+genRand(-10,10);
    $tetrabytz=$tetrabytz+genRand(-40,40);
    ...
    if ($mojoinc < 1){$mojoinc = 0; $stocks[2]=0;};
    if ($freke < 1){$freke = 0; $stocks[3]=0;};
    if ($mega < 1){$mega = 0; $stocks[4]=0;};
    
  12. or download this
        # update prices
        foreach my $stock ( @ticker{@stock_names} ) {
            $$stock{price} += generate_random($$stock{volitility});
    ...
        foreach my $stock ( @stock_names ) {
            $portfolio{$stock} = 0 if $ticker{$stock}{price} == 0
        }
    
  13. or download this
        notify_user (
            qq|\n\nYour Stock Report for January $date\n\n|,
    ...
            portfolio_value( \%portfolio, \%ticker, ),
            qq| in stocks.\n|,
            qq|Would you like to (B)uy or (S)ell or are you (D)one? | );
    
  14. or download this
    sub portfolio_value {
        my ($portfolio, $ticker) = @_;
    ...
                for keys %$portfolio;
        return $total_value;
    }
    
  15. or download this
    until ( $cash > $goal or $date == 31 ) {
    
        # update prices
    ...
            }
        }
    }
    
  16. or download this
    sub sell {
        my ($portfolio, $ticker) = @_;
    ...
        }
        return $cash;
    }
    
  17. or download this
    buy<CODE> sub routine fixes a bug in the original game which allowed t
    +he player to purchase a few million shares when the price reached zer
    +o.</P>
    <CODE>
    sub buy {
    ...
        }
        return $cash;
    }
    
  18. or download this
    if ( $cash > $goal ) {
        my $dif = $cash - $goal;
    ...
        my $dif = $goal - $cash;
        notify_user( qq|Boo! you lost, you missed your goal by \$$dif\n| )
    +;
    }
    
  19. or download this
    #!/usr/bin/perl
    #require v5.6.1;
    ...
        return print @_;
    }
    __END__
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://126819]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found