play this! Code (Text): { Flip the Coin Game v.1 by Ron Instructions: 1. Run the script. 2. Select heads or tails. 3. Place a bet. 4. and... FLIP! If you like the script, please go to www.goons.co.nr and click on an ad. I make money at my job but not enough for my new car! Ty! :D Also thank you to Janilabo for testing my script! =) } program FlipTheCoinGame; const ron = 100000000; var frmDesign : TForm; Label2,Label4,Label5,Label7,Label9,Label11 : TLabel; Button1,Button2,Button3,Button4,Button5 : TButton; Edit1 : TEdit; RadioButton1,RadioButton2 : TRadioButton; W,L,z : Integer; b : string; function Replace(TheString, Replacee, Replacer: string): string; var a: LongInt; begin a := Pos(Replacee, TheString); if (a > 0) then begin Delete(TheString, a, Length(Replacee)); Insert(Replacer, TheString, a); Result := TheString; end; end; // The ReplaceAll() function will replace all strings with another string. // Made by Ron. :) function ReplaceAll(TheString, Replacee, Replacer : String) : String; var Str, Str2, Str3, Str4 : String; begin Str := TheString; if(pos(Replacee, Str) > 0)then begin repeat Str2 := Replace(copy(Str, 0, pos(Replacee, Str)+Length(Replacee)), Replacee, Replacer); delete(Str, 1, pos(Replacee, Str)+Length(Replacee)); Str4 := Str4 + Str2; Str3 := Str4 + Str; until(pos(Replacee, Str) = 0) Str := Str3; end; Result := Str; end; // Converts an extended number to a string. // Made by Ron and Ron's Dad. function NumCom(Number: Extended): string; var Num, b: string; i, c, d: Integer; begin Num := FloatToStr(Number); if (Number < 0) then begin delete(Num, 1, 1); d := 1; end; c := (Length(Num) / 3) - 1; if (Length(Num) > 15) then begin c := c - 1; end; b := Num; if (Length(Num) > 3) then begin if (Length(b) mod 3 = 0) then c := c - 1; for i := 0 to c do begin if (i = 0) then begin insert(',', b, Length(b) - 2); end else begin insert(',', b, Length(b) - (2 * (2 * i + 1))); end; end; end; if (d = 1) then begin insert('-', b, 1); end; Result := b; end; // Procedure to determine heads/tails and if you win or not. procedure FlipCoin(sender : TObject); var a : integer; begin // remove commas from total cash. Label4.Caption := ReplaceAll(Label4.Caption, ',', ''); // if the random function equals 0 then heads, otherwise tails. if(Random(2)=0)then begin Label2.Caption := 'Heads!'; Label2.Left := 107; a := 1; end else begin Label2.Caption := 'Tails!'; Label2.Left := 116; a := 2; end; if((RadioButton1.CHECKED)and(a = 1))or((RadioButton2.CHECKED)and(a = 2))then begin Label5.Left := 102; Label5.Caption := 'You Win!'; W := W + 1; Label4.Caption := NumCom(StrToInt(Edit1.Text) + StrToInt(Label4.Caption)); end else if((RadioButton1.Checked)and(a = 2))or((RadioButton2.Checked)and(a = 1))then begin Label5.Left := 97; Label5.Caption := 'You Lose!'; L := L + 1; if(StrToInt(Label4.Caption) = 0)then begin Edit1.Text := '0'; z := GetApplication.Messagebox('Would you like to play again?','Game Over',1); if(z = 1)then begin Label4.Caption := NumCom(ron); W := 0; L := 0; b := '0'; a := 0; end else begin frmDesign.ModalResult := 1; end; z := 0; end else if(StrToInt(Label4.Caption) < StrToInt(Edit1.Text))then begin z := Round(abs(StrToInt(Label4.Caption)-StrToInt(Edit1.Text))); Label4.Caption := '0'; Edit1.Text := IntToStr(StrToInt(Edit1.Text)-z); end else begin Label4.Caption := NumCom(StrToInt(Label4.Caption)-StrToInt(Edit1.Text)); end; end; Label7.CAPTION := IntToStr(W); Label11.Caption := IntToStr(L); if(W > 0)or(L > 0)then b := IntToStr(Round((W/(W+L))*100)); Label9.Caption := b; end; // when you add to your bet this procedure is called. procedure AddBet(sender : TObject); var Bet,Bet2,TotalMoney : Integer; begin Label4.Caption := ReplaceAll(Label4.Caption, ',', ''); Bet := StrToInt(Edit1.Text); // case sender of each of the # Bet buttons will do the following. case sender of Button5 : begin Bet := 0; z := 0; end; Button2 : Bet2 := 1000000; Button3 : Bet2 := 2500000; Button4 : Bet2 := 5000000; end; // Bet equals button value plus existing bet #. Bet := Bet + Bet2; // if Bet equals 0 then set total cash back to what is was before. if(Bet = 0)then begin Label4.Caption := NumCom(StrToInt(Edit1.Text)+StrToInt(Label4.Caption)); end else if(Bet > 100000000)and(z = 0)then begin Bet := 100000000; Edit1.Text := IntToStr(Bet); if(not(isfkeydown(12)))then Label4.Caption := IntToStr(StrToInt(Label4.Caption) - Bet2 + 1); z := 1; end; TotalMoney := StrToInt(ReplaceAll(Label4.Caption, ',', '')); if(TotalMoney > 0)and(z = 0)then begin if(TotalMoney < Bet2)then begin TotalMoney := 0; Bet := StrToInt(Edit1.Text)+StrToInt(Label4.Caption); GetApplication.Messagebox('','',0); end else if(not(IsFKeyDown(12)))then begin TotalMoney := TotalMoney-Bet2; end; Edit1.Text := IntToStr(Bet); end; Label4.Caption := NumCom(TotalMoney); end; procedure InitForm; var Label1,Label3,Label6,Label8,Label10 : TLabel; begin frmDesign := CreateForm; frmDesign.Left := 390; frmDesign.Top := 170; frmDesign.BorderStyle := bsSingle; frmDesign.Caption := 'Flip the Coin Game by Ron'; frmDesign.ClientHeight := 250; frmDesign.ClientWidth := 280; frmDesign.Color := clLime; frmDesign.BorderIcons := [biSystemMenu, biMinimize]; frmDesign.Position := poScreenCenter; Label1 := TLabel.Create(frmDesign); Label1.Parent := frmDesign; Label1.Left := 50; Label1.Top := 15; Label1.Width := 181; Label1.Caption := 'Flip the Coin Game'; Label1.Font.Height := -20; Label1.Font.Style := [fsBold]; Label2 := TLabel.Create(frmDesign); Label2.Parent := frmDesign; Label2.Top := 70; Label2.Width := 56; Label2.Font.Height := -18; Label3 := TLabel.Create(frmDesign); Label3.Parent := frmDesign; Label3.Left := 35; Label3.Top := 227; Label3.Width := 80; Label3.Height := 16; Label3.Caption := 'Total Cash: $'; Label3.Font.Height := -14; Label3.Font.Style := [fsBold]; Label4 := TLabel.Create(frmDesign); Label4.Parent := frmDesign; Label4.Left := 200; Label4.Top := 227; Label4.Width := 41; Label4.Height := 16; Label4.Alignment := taRightJustify; Label4.Caption := NumCom(ron); Label4.Font.Height := -14; Label5 := TLabel.Create(frmDesign); Label5.Parent := frmDesign; Label5.Left := 100; Label5.Top := 100; Label5.Width := 56; Label5.Font.Height := -16; Label5.Font.Style := [fsBold]; Label6 := TLabel.Create(frmDesign); Label6.Parent := frmDesign; Label6.Left := 5; Label6.Top := 132; Label6.Font.Height := -14; Label6.Font.Style := [fsBold]; Label6.Caption := 'Wins:'; Label7 := TLabel.Create(frmDesign); Label7.Parent := frmDesign; Label7.Left := 80; Label7.Top := 130; Label7.Font.Height := -16; Label7.Alignment := taRightJustify; Label7.Caption := '0'; Label8 := TLabel.Create(frmDesign); Label8.Parent := frmDesign; Label8.Left := 5; Label8.Top := 162; Label8.Font.Height := -14; Label8.Font.Style := [fsBold]; Label8.Caption := 'Win %:'; Label9 := TLabel.Create(frmDesign); Label9.Parent := frmDesign; Label9.Left := 80; Label9.Top := 160; Label9.Font.Height := -16; Label9.Alignment := taRightJustify; Label9.Caption := '0'; Label10 := TLabel.Create(frmDesign); Label10.Parent := frmDesign; Label10.Left := 5; Label10.Top := 147; Label10.Font.Height := -14; Label10.Font.Style := [fsBold]; Label10.Caption := 'Loses:'; Label11 := TLabel.Create(frmDesign); Label11.Parent := frmDesign; Label11.Left := 80; Label11.Top := 145; Label11.Font.Height := -16; Label11.Alignment := taRightJustify; Label11.Caption := '0'; Button1 := TButton.Create(frmDesign); Button1.Parent := frmDesign; Button1.Left := 100; Button1.Top := 158; Button1.Width := 75; Button1.Height := 25; Button1.Caption := 'Flip Coin'; Button1.TabOrder := 1; Button1.ONCLICK := @FlipCoin; RadioButton1 := TRadioButton.Create(frmDesign); RadioButton1.Parent := frmDesign; RadioButton1.Left := 5; RadioButton1.Top := 188; RadioButton1.Width := 60; RadioButton1.Height := 17; RadioButton1.Caption := 'Heads'; RadioButton1.TabOrder := 2; RadioButton1.Checked := True; RadioButton1.FONT.Height := -14; RadioButton2 := TRadioButton.Create(frmDesign); RadioButton2.Parent := frmDesign; RadioButton2.Left := 5; RadioButton2.Top := 208; RadioButton2.Width := 47; RadioButton2.Height := 17; RadioButton2.Caption := 'Tails'; RadioButton2.TabOrder := 3; RadioButton2.FONT.Height := -14; Button5 := TButton.Create(frmDesign); Button5.Parent := frmDesign; Button5.Left := 67; Button5.Top := 195; Button5.Width := 40; Button5.Height := 25; Button5.Caption := '0'; Button5.TabOrder := 4; Button5.OnClick := @AddBet; Button2 := TButton.Create(frmDesign); Button2.Parent := frmDesign; Button2.Left := 110; Button2.Top := 195; Button2.Width := 40; Button2.Height := 25; Button2.Caption := '10m'; Button2.TabOrder := 5; Button2.OnClick := @AddBet; Button3 := TButton.Create(frmDesign); Button3.Parent := frmDesign; Button3.Left := Button2.Left+43; Button3.Top := 195; Button3.Width := 40; Button3.Height := 25; Button3.Caption := '25m'; Button3.TabOrder := 6; Button3.OnClick := @AddBet; Button4 := TButton.Create(frmDesign); Button4.Parent := frmDesign; Button4.Left := Button2.Left+86; Button4.Top := 195; Button4.Width := 40; Button4.Height := 25; Button4.Caption := '50m'; Button4.TabOrder := 7; Button4.OnClick := @AddBet; Edit1 := TEdit.Create(frmDesign); Edit1.Parent := frmDesign; Edit1.Left := Button2.Left+131; Edit1.Top := 197; Edit1.Width := 30; Edit1.Height := 21; Edit1.ReadOnly := True; Edit1.TabOrder := 8; Edit1.Text := '0'; end; procedure SafeInitForm; var V: TVariantArray; begin SetArrayLength(V, 0); ThreadSafeCall('InitForm', V); end; procedure ShowFormModal; begin frmDesign.ShowModal; end; procedure SafeShowFormModal; var V: TVariantArray; begin SetArrayLength(V, 0); ThreadSafeCall('ShowFormModal', V); end; procedure SetSelfWindowState(state: TWindowState); begin GetSelf.WindowState := state; end; procedure SafeSetSelfWindowState(state: TWindowState); var V: TVariantArray; begin SetArrayLength(V, 1); V[0] := state; ThreadSafeCall('SetSelfWindowState', V); end; begin ClearDebug; SafeSetSelfWindowState(wsMinimized); SafeInitForm; SafeShowFormModal; SafeSetSelfWindowState(wsNormal); FreeForm(frmDesign); WriteLn('--- Flip The Coin Stats ---'); WriteLn(' Wins: '+IntToStr(W)); WriteLn(' Loses: '+IntToStr(L)); WriteLn(' Total: '+IntToStr(W+L)); if(b = '')then b := '0'; WriteLn(' Win %: '+b); WriteLn('--------------------------'); end.