Solved

# Help with simple number game

Posted on 2003-03-03
Medium Priority
135 Views
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
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
• 3
• 3
• 2
• +2

LVL 5

Expert Comment

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

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

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

:-)
0

LVL 3

Accepted Solution

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';
begin
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
label kraj;
var cb:integer;
begin
if cb>=0 then
begin
broj:=broj-cb-1;
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;
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;
button1.Enabled:=true;
end;

work wery good a?

try to defeat computer :))
0

Author Comment

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

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

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

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

ID: 9316963
karatekid182:
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

LVL 5

Expert Comment

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:

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.

...Snehanshu
EE Cleanup Volunteer
0

## Featured Post

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