?
Solved

Help with simple number game

Posted on 2003-03-03
11
Medium Priority
?
135 Views
Last Modified: 2010-04-04
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
Comment
Question by:karatekid182
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8057952
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
 

Author Comment

by:karatekid182
ID: 8059741
actually what u said random will equal any number from 1 to 30, i need it to random from 15 to 30
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8059774
oh, stupid =)
Random(16)+15;

:-)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Accepted Solution

by:
ILE earned 160 total points
ID: 8060705
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
 

Author Comment

by:karatekid182
ID: 8060955
two questions it works 2 btw
1) what does broj:integer; mean?
2)what does label kraj; mean
0
 
LVL 3

Expert Comment

by:ILE
ID: 8061044
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
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8062549
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
 
LVL 3

Expert Comment

by:ILE
ID: 8062921
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
 

Expert Comment

by:CleanupPing
ID: 9316963
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
 
LVL 5

Expert Comment

by:snehanshu
ID: 10033378
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question