Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 8th, 2005, 7:32 AM   #1
SquareGamerGuy
Newbie
 
Join Date: Apr 2005
Posts: 4
Rep Power: 0 SquareGamerGuy is on a distinguished road
Craps in Pascal

I need some help with this program. I am a beginning pascal programmer and I am a bit lost in this program for the game craps.

program ch52;
uses wincrt;
var die1,die2 : real;
var x,a,b,p,a2,b2 : integer;
var die1a,die2a : string;
procedure header;
begin
writeln('The game of Craps');
writeln('How to play:');
writeln('Roll the dice.  If the sum of the dice is 7 or 11 then the player wins.');
writeln('If the roll is not a 7 or 11 then the player continues to roll until ');
writeln('they roll a number equal to their first roll.  If the player rolls a ');
writeln('7 or 11 on any other roll except for the first.  You lose. Get it, good.');
writeln('So when you are ready.  Hit enter to begin.');
end;
procedure craps;
begin
randomize;
die1:=random(6) + 1;
randomize;
die2:=random(6) + 1;
if die1=1 then
begin
die1a:='1';
end
else if die1=2 then
begin
die1a:='2';
end
else if die1=3 then
begin
die1a:='3';
end
else if die1=4 then
begin
die1a:='4';
end
else if die1=5 then
begin
die1a:='5';
end
else if die1=6 then
begin
die1a:='6';
end
else if die2=1 then
begin
die2a:='1';
end
else if die2=2 then
begin
die2a:='2';
end
else if die2=3 then
begin
die2a:='3';
end
else if die2=4 then
begin
die2a:='4';
end
else if die2=5 then
begin
die2a:='4';
end
else if die2=5 then
begin
die2a:='5';
end
else if die2=6 then
begin
 die2a:='6';
end
else if (die1a='1') and (die2a='1') then
begin
writeln('Snake eyes!');
x := x + 1;
end
else if (die1a='8') and (die2a='8') then
begin
writeln('Box Cars!');
x := x + 1;
end
else if   (die1a='1') and (die2a='6')
or (die1a='2') and (die2a='5')
or (die1a='3') and (die2a='4')
or (die1a='6') and (die2a='1')
or (die1a='5') and (die2a='2')
or (die1a='4') and (die2a='3')
or (die1a='6') and (die2a='5')
or (die1a='5') and (die2a='6')
and (x <= 1) then
begin
writeln('You win!');
end
else if   (die1a='1') and (die2a='6')
or (die1a='2') and (die2a='5')
or (die1a='3') and (die2a='4')
or (die1a='6') and (die2a='1')
or (die1a='5') and (die2a='2')
or (die1a='4') and (die2a='3')
or (die1a='6') and (die2a='5')
or (die1a='5') and (die2a='6')
and (x >= 2) then
begin
writeln('You Lose!');
end;
if(die1a<>'1') or (die1a<>'8')
and (die2a<>'1') or (die2a<>'8')
and (x > 1) then
begin
writeln('Roll again.');
x := x + 1;
end;
end;
procedure output;
begin
write(die1a:1);
write(die2a:1);
readln;
repeat
writeln(die1a:1);
writeln(die2a:1);
readln;
until (x = 9);
end;
begin
x := 1;
header;
readln;
clrscr;
craps;
output;
readln;
donewincrt;
end.

this is going to make me cry.
SquareGamerGuy is offline   Reply With Quote
Old Apr 8th, 2005, 7:29 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Learn how to tab, and I'll take a look.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 9th, 2005, 8:02 AM   #3
SquareGamerGuy
Newbie
 
Join Date: Apr 2005
Posts: 4
Rep Power: 0 SquareGamerGuy is on a distinguished road
Actually it was formatted but it read the FAQ and it said somehting about removing spaces. So I thought I was just follow the forum rules.
SquareGamerGuy is offline   Reply With Quote
Old Apr 9th, 2005, 8:09 AM   #4
SquareGamerGuy
Newbie
 
Join Date: Apr 2005
Posts: 4
Rep Power: 0 SquareGamerGuy is on a distinguished road
here.

program ch52;
uses wincrt;
var die1,die2 : real;
var x,a,b,p,a2,b2 : integer;
var die1a,die2a : string;

procedure header;
begin
   writeln('The game of Craps');
   writeln('How to play:');
   writeln('Roll the dice.  If the sum of the dice is 7 or 11 then the player wins.');
   writeln('If the roll is not a 7 or 11 then the player continues to roll until ');
   writeln('they roll a number equal to their first roll.  If the player rolls a ');
   writeln('7 or 11 on any other roll except for the first.  You lose. Get it, good.');
   writeln('So when you are ready.  Hit enter to begin.');
end;

procedure craps;
begin
  randomize;
  die1:=random(6) + 1;
  randomize;
  die2:=random(6) + 1;

if die1=1 then
begin
  die1a:='1';
end

else if die1=2 then
begin
  die1a:='2';
end

else if die1=3 then
begin
  die1a:='3';
end

else if die1=4 then
begin
  die1a:='4';
end

else if die1=5 then
begin
  die1a:='5';
end

else if die1=6 then
begin
  die1a:='6';
end

else if die2=1 then
begin
  die2a:='1';
end

else if die2=2 then
begin
  die2a:='2';
end

else if die2=3 then
begin
  die2a:='3';
end

else if die2=4 then
begin
  die2a:='4';
end

else if die2=5 then
begin
  die2a:='4';
end

else if die2=5 then
begin
  die2a:='5';
end

else if die2=6 then
begin
  die2a:='6';
end

else if (die1a='1') and (die2a='1') then
begin
  writeln('Snake eyes!');
      x := x + 1;
end

else if (die1a='8') and (die2a='8') then
begin
  writeln('Box Cars!');
      x := x + 1;
end

else if  (die1a='1') and (die2a='6')
      or (die1a='2') and (die2a='5')
      or (die1a='3') and (die2a='4')
      or (die1a='6') and (die2a='1')
      or (die1a='5') and (die2a='2')
      or (die1a='4') and (die2a='3')
      or (die1a='6') and (die2a='5')
      or (die1a='5') and (die2a='6')
      and (x <= 1) then
begin
  writeln('You win!');
end

else if  (die1a='1') and (die2a='6')
      or (die1a='2') and (die2a='5')
      or (die1a='3') and (die2a='4')
      or (die1a='6') and (die2a='1')
      or (die1a='5') and (die2a='2')
      or (die1a='4') and (die2a='3')
      or (die1a='6') and (die2a='5')
      or (die1a='5') and (die2a='6')
      and (x >= 2) then
begin
  writeln('You Lose!');
end;

if        (die1a<>'1') or (die1a<>'8')
    and (die2a<>'1') or (die2a<>'8')
    and (x > 1) then
begin
  writeln('Roll again.');
      x := x + 1;
end;
end;

procedure output;
begin
  write(die1a:1);
  write(die2a:1);
      readln;

repeat
  writeln(die1a:1);
  writeln(die2a:1);
      readln;
until ();
end;

begin
    x := 1;
    header;
    readln;
    clrscr;
    craps;
    output;

readln;
donewincrt;
end.

I got lost with the procedure output. Because I am not sure how I would write the program where if the first roll isn't 7 or 11 then you keep rolling until you reach your first roll number again. But if you get 7 or 11 while rolling for the number you got the first time then you lose. So I am kind of lost. If you could give me some help with my coding I would appreciate it. And remember I am new at this, so I may have done stuff that seems very stupid.
SquareGamerGuy is offline   Reply With Quote
Old Apr 9th, 2005, 10:57 AM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Simple:
repeat
    craps;
    output;
until finished;
finished, in this case, is a global boolean variable set to true or false by the craps function.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 9th, 2005, 11:27 AM   #6
SquareGamerGuy
Newbie
 
Join Date: Apr 2005
Posts: 4
Rep Power: 0 SquareGamerGuy is on a distinguished road
ok. For the output, what would be my readlns and until? Because if try something like this

  writeln(die1a:1);
     readln(a);
  writeln(die2a:1);
     readln(b);

repeat
  writeln(die1a:1);
     readln(a2);
  writeln(die2a:1);
     readln(b2);
until (a2 = a) or (a2 = b) and (b2 = a) or (b2 = b) and (x >=2);

But at the same time. Other numbers can also run equal to what you rolled the first time. For example I rolled a 3 and a 2 to get five but I rolled a 1 and 2 the next time. It needs to say they won. But the more I think about it the more I get lost. And this seems the be the only program out of the whole set that confuses me. I did a slot machine eariler and it works just fine. And in some ways this is equal to that. or so it seems to me.
SquareGamerGuy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:46 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC