You can add a readln at the end to make the program wait or run it from a Dos prompt.
You can add a readln at the end to make the program wait or run it from a Dos prompt.
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)
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
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)
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)
The (documented) default in Free Pascal is a console app, so there is no need to force this.Originally Posted by cairnswm
Huh, why? There is no need to teach this man floating point yet.Originally Posted by cairnswm
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.Originally Posted by eJay
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.
and round would round the number up to between 0 and 2.Originally Posted by cairnswm
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
Bookmarks