# Roulette

by Ayotunde: Y9 Age ~14

## Introduction

We chose program Roulette for Ayotunde's interesting dialogue and for the range of options provided at each stage. You have £50 money in the bank at the start in addition to £100 to spend immediately. The console program compiles and runs using Lazarus on the Raspberry Pi. See the next page for an Oxygene for Java version.

## The Program

```program Roulette;

{

use this file except in compliance with the License, as described at
}

{\$APPTYPE CONSOLE}

uses
SysUtils,
Math;
var
endgame, number, redblack, bet, wheelroll, decide,
bank, deposit, take, redblackchoose : integer;
total, wager1, wager2, maxbet, minbet: real;

procedure betS;
begin
sleep(500);
writeln('You can bet up to three quarters of your current total.');
sleep(500);
writeln('How much money do you want to bet, in pounds?');
maxbet := total * 0.75;
minbet := 6;
if wager1 >= (maxbet + 1) then
begin
writeln('That is too much. You want to be able to buy food, no?');
end
else if wager1 <= (minbet - 1) then
begin
writeln('That is too little. This is for-profit business, you know.');
end;
end;

procedure betR;
begin
writeln('You can bet up to half of your current total.');
sleep(500);
writeln('How much you want to bet?');
maxbet := total * 0.5;
minbet := 6;
if wager2 >= (maxbet + 1) then
begin
writeln('That is too much. You want to be able to buy food, no?');
end
else if wager2 <= (minbet - 1) then
begin
writeln('That is too little. This is for-profit business, you know.');
end;
end;

begin
wager1 := 999;
bank := 50;
endgame := 5667;
total := 100;
writeln('Velcome. You vant to lose some cash?');
sleep(500);
repeat
randomize;
writeln('You can place bet on either number or a colour, red or black.');
sleep(500);
writeln('You have ' + floattostr(total) + ' pounds. Try not to lose it too fast!');
sleep(500);
writeln('1= Bet on a number.');
writeln('2= Bet on red or black.');
writeln('3= Vithdraw some cash.');

if bet = 1 then
begin
repeat
betS;
until (wager1 < (maxbet + 1)) and (wager1 > (minbet - 1));

if (wager1 < (maxbet + 1)) and (wager1 > (minbet - 1)) then
begin
writeln('Bet on a number. It can be anything from 1 to 37.');
wheelroll := random(37) + 1;
if number = wheelroll then
begin
writeln('Hey, you hit the jackpot! You guessed right!');
total := total + 30 * wager1;
end
else
begin
writeln('Sorry, that is incorrect....hehehe...');
total := total - wager1;
end;
end; //if wager1
end; //bet = 1

if bet = 2 then
begin
repeat
betR;
until (wager2 < (maxbet + 1)) and (wager2 > (minbet - 1));
if (wager2 < (maxbet + 1)) and (wager2 > (minbet - 1)) then
begin
writeln('Bet on 1 (Red) or 2 (Black).');
redblack := random(2) + 1;          //Redblack can either be 2 or 1.
if (redblack = 1) and (redblackchoose = 1) then
begin
writeln('It came out red. You got lucky this time.');
total := total + wager2;
end
else if (redblack = 2) and (redblackchoose = 2) then
begin
writeln('It seems to be black. Fortune has smiled on you.');
total := total + wager2;
end
else
begin
writeln('Unlucky, you were wrong.');
total := total - wager2;
end;
end;
end  //bet = 2
else if bet = 3 then
begin
repeat
writeln('Your current balance is ', bank, ' pounds.');
sleep(100);
writeln('How much you want to vithdraw?');
if take > bank then
writeln('Hehehe, nice try, kiddo.');
until take <= bank;
bank := bank - take;
total := total + take;
writeln('Your balance is now ', bank, ' pounds.');
end; //bet = 3

writeln('Come on, play Roulette.');
writeln('1= Play the game.');
writeln('2= Quit the game.');
writeln('3= Continue and bank some cash.');
if decide = 2 then
begin
writeln('........');
endgame := 1789;
end
else if decide = 3 then
begin
writeln('How much cash you vant to bank?');
total := total - deposit;
bank := bank + deposit;
writeln('Your current balance is ', bank, ' pounds.');
sleep(100);
end;
if decide = 1 then
begin
sleep(100);
end;
until (total < minbet * 2) or (total > 3000) or (endgame = 1789);

if total < minbet * 2 then
begin
writeln('You have ', floattostr(total), ' pounds remaining.');
writeln('You have not got enough money to keep playing. Get out!');
sleep(2000);
end;
if endgame = 1789  then
begin
writeln('You have ', floattostr(total), ' pounds remaining.');
if (total + bank) < 150 then
begin
writeln('Thank you for vasting money. Please show yourself out.');
end;
sleep(2000);
end;
end.

```
Programming - a skill for life!

Student programs to inspire you!