Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Need Urgent Help!

  1. #11

    Need Urgent Help!

    You can add a readln at the end to make the program wait or run it from a Dos prompt.

  2. #12
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Need Urgent Help!

    Should this not be a console app?

    {$CONSOLE}

    I think needs to be added before the Vars statement - I'm not sure this is correct though so please check in the help first.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  3. #13

    Need Urgent Help!

    thanks for all the help so far, it has been valuable.
    i've applied the readln statement, and played around with the code.

    one problem i have though is that when the user presses 1 (head) they win, if they press 2 (tail) they lose. How can i make so that the user doesn't always win with head and lose with tail

  4. #14
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Need Urgent Help!

    From Delphi Help:
    function Random [ ( Range: Integer) ];

    Description

    In Delphi code, Random returns a random number within the range 0 <= X < Range. If Range is not specified, the result is a real-type random number within the range

    0 <= X < 1.

    To initialize the random number generator, add a single call Randomize or assign a value to the RandSeed variable before making any calls to Random.

    So the random number returned from Random(1) is always 0.

    Change to
    [pascal]
    RandomNumber := Trunc(Random * 2)+1;
    [/pascal]

    To get a 1 or 2 result.

    Random * 2 - will return a number between 0 and 1.999999.

    Trunc drops the digits after the '.' - So a number betwenn 0 and 1


    [size=7px]Does anyone ealse feel we are doing someones homework....[/size]
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  5. #15

    Need Urgent Help!

    to make your program not quit straight away and keep playing, start off with something simple like this:

    [pascal]
    program youprog;
    var
    quit : boolean;
    quitStr: string;
    begin
    quit := false;
    repeat



    //your code here



    writeln('Whould you like to play again? y/n');
    ReadLn(quitStr);

    if LowerCase(quitStr) = 'y' then //still quit if they have CAPs on
    quit := true;

    until quit = true;
    writeLn('Good bye!')
    end.
    [/pascal]

    ---

    I think {$CONSOLE} is a Delphi only thing. (I been caught out by this in Delphi a few times though, lol)

  6. #16

    Need Urgent Help!

    Quote Originally Posted by cairnswm
    Should this not be a console app?
    {$CONSOLE}
    I think needs to be added before the Vars statement - I'm not sure this is correct though so please check in the help first.
    The (documented) default in Free Pascal is a console app, so there is no need to force this.

    Quote Originally Posted by cairnswm
    Change to
    [pascal]
    RandomNumber := Trunc(Random * 2)+1;
    [/pascal]
    Huh, why? There is no need to teach this man floating point yet.


    Quote Originally Posted by eJay
    one problem i have though is that when the user presses 1 (head) they win, if they press 2 (tail) they lose. How can i make so that the user doesn't always win with head and lose with tail
    This is because you haven't randomized the random generator yet. Computers are highly predictable devices, each time you run your program, the random number it starts with is the same.

    To counter this, call "randomize" at the begin of your program, i.e.:

    [pascal]
    begin
    randomize;
    [/pascal]

    A call to randomize will put the random generator in a ruly random state, so each time you run your program the result will be different.

  7. #17

    Need Urgent Help!

    Quote Originally Posted by cairnswm
    Random * 2 - will return a number between 0 and 1.999999.

    Trunc drops the digits after the '.' - So a number betwenn 0 and 1
    and round would round the number up to between 0 and 2.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  8. #18
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Need Urgent Help!

    Quote Originally Posted by K4Z
    I think {$CONSOLE} is a Delphi only thing. (I been caught out by this in Delphi a few times though, lol)
    [pascal]{$APPTYPE CONSOLE} // for Delphi[/pascal]
    [pascal]{$APPTYPE GUI} // for FreePascal/Lazarus[/pascal]

    Don't ask my why it's 'GUI', but it is.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  9. #19
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Need Urgent Help!

    Here is a quick little guide for using Random.


    For Integer values: Random(X);

    Result: 0 <= Random < X


    For Real values: ie. Random

    Result: 0 <= Random < 1
    Jason McMillen
    Pascal Game Development
    Co-Founder





Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •