Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 137
  • Last Modified:

Help with simple number game

hey i need to make a game where:
the computer pick a random number from 15 to 30
the player starts first, he choses between 1,2,3. then the computer does the same thing.*note it has to substract the 1,2or 3 from the random number the computer picked. le last one to pick the number is a loser.  
0
karatekid182
Asked:
karatekid182
  • 3
  • 3
  • 2
  • +2
1 Solution
 
Lukasz LachCommented:
var
  number, uno, cno: byte;
begin
  Randomize;
  number := Random(30)+1;
  uno := StrToInt(Edit1.Text) mod 3; // user number
  cno := Random(3)+1; // computer number
  if uno <> cno then
  // wrong
  else
  // right...
end;


that is easy :-)
0
 
karatekid182Author Commented:
actually what u said random will equal any number from 1 to 30, i need it to random from 15 to 30
0
 
Lukasz LachCommented:
oh, stupid =)
Random(16)+15;

:-)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ILECommented:
100% working solution :))
all the game in litle code


put two button one memo and one radiogroup on form

and in public put  broj:integer; like

  private
    { Private declarations }
  public
  broj:integer;
    { Public declarations }
  end;


procedure TForm1.FormCreate(Sender: TObject);
begin
 button1.Enabled:=false;
 button1.Caption:='&Pick';
 button2.Caption:='&New';
 with radiogroup1 do
  begin
   items.add('Pick &One');
   items.add('Pick &Rwo');
   items.add('Pick &Three');
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
label kraj;
var cb:integer;
begin
cb:=radiogroup1.itemindex;
if cb>=0 then
begin
  broj:=broj-cb-1;
  memo1.lines.add('you pick'+chr(49+cb)+'  result'+inttostr(broj));
  if broj=0 then begin showmessage('you win'); button1.enabled:=false; goto kraj end else
  if broj mod 4=0 then cb:=1 else cb:=broj mod 4;
   broj:=broj-cb;
   memo1.lines.add('com pick'+chr(48+cb)+'  result'+inttostr(broj));
   if broj=0 then begin showmessage('computer win'); button1.enabled:=false; end;
   kraj:
  end else showmessage('pick a number');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
randomize;
broj:=random(15)+15;
memo1.lines.add('------------');
memo1.Lines.Add('The NUMBER IS:'+inttostr(broj));
button1.Enabled:=true;
end;



work wery good a?

try to defeat computer :))
0
 
karatekid182Author Commented:
two questions it works 2 btw
1) what does broj:integer; mean?
2)what does label kraj; mean
0
 
ILECommented:
just put in the
broj:integer;  
 in the public declaration
that is the global variable i cen accses this wriable from any   procedure of tform1

the

label kraj


i the label declaration
that is for the             goto label   command
when use goto command u must first declare label
label is teh point where program jump when program found
goto command


i hope u anderstand me


i have a wery bad english :))  
0
 
Lukasz LachCommented:
broj:=random(15)+15; -> that gives 0-29
if broj mod 4=0 then cb:=1 else cb:=broj mod 4; -> mod 3 i suppose
kraj: -> :???
and the yhing is there is no "end else showmessage('pick a number');" cause you modify broj var which stores the random number...
0
 
ILECommented:
yep    broj:=ranodm(15)+15      GIVES 15-29    :)))

that
if broj mod 4=0 then cb:=1 else cb:=broj mod 4; -> mod 3 i suppose
kraj: -> :???
is 100% good nothing to change if u put mod 3  computer will lose most of the time    :)))




and the last Pick a nummber  is if a user dont chose any number in the start

so everythin is 100% corectly

opppps the number shoud be between 15 and 30


so broj:=broj:=ranodm(15)+16

only small corection :)))





0
 
CleanupPingCommented:
karatekid182:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
snehanshuCommented:
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: ILE

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now