salve ... mi serve un aiuto

peter74

Utente Attivo
27 Nov 2006
32
0
0
{Prova questo!!!!! Funziona già testato.
Se ti vuoi complicare le cose poi giocare con due giocatori o contro il pc. Buon divertimento.:) :) :) }

program sette_e_mezzo;
uses wincrt;
var
x:integer;
f:real;
scelta:char;
begin
randomize;
f:=0;
writeln('simulazione gioco 7½');
Writeln;
writeln('premi invio per giocare');
readln;
repeat
clrscr;
x:=random(10)+1;
case x of
1:f:=f+1;
2:f:=f+2;
3:f:=f+3;
4:f:=f+4;
5:f:=f+5;
6:f:=f+6;
7:f:=f+7;
8:f:=f+0.5;
9:f:=f+0.5;
10:f:=f+0.5;
end;
if (f>7.5) or (f=7.5) then
scelta:='s'
else
begin
writeln(' il tuo punteggio è: ',f:1:1);
writeln(' vuoi fermarti? (s/n)');
readln(scelta);
end;
until (scelta='s');
clrscr;
if (f=7.5) then
writeln('ke Cool - Hai fatto 7½')
else
if (f>7.5) then
writeln('Mi spiace ma hai superato 7½ - RITENTA')
else
writeln(' il tuo punteggio migliore è: ',f:1:1);
end.
 

peter74

Utente Attivo
27 Nov 2006
32
0
0
Ovviamente il programma si può migliorare riducendo al minimo i controlli. Non ho molto tempo se vuoi modificalo a tuo piacimento.
 

vegehacker

Nuovo Utente
16 Feb 2007
10
0
0
non capisco come attribuire un punteggio al computer ... nn posso mettere la scritta vuoi andare avanti se il computer lo fa in automatico ... help plz :=)
 

peter74

Utente Attivo
27 Nov 2006
32
0
0
non capisco come attribuire un punteggio al computer ... nn posso mettere la scritta vuoi andare avanti se il computer lo fa in automatico ... help plz :=)

dipende dalla strategia di gioco che vuoi impostare per il pc. Es. se il pc fa da mazziere, quindi gioca dopo di te, deve andare avanti con le carte fino a quando non supera il tuo punteggio anche a rischio di superare 7,5.
Se vuoi rendere la scelta di andare avanti casuale imposta una random con vero e falso.
 

peter74

Utente Attivo
27 Nov 2006
32
0
0
Ho implementato il prog prevedendo l'uscita della matta e il gioco contro il pc. Mi devi un favore.
Cerca di studiartelo per bene cercando di capire cosa ho fatto altrimenti se ne accorgono subito che l'hai copiato.



program sette_e_mezzo;
uses wincrt;
var
x,c,b:integer;
f,g:real;
scelta,r:char;
begin
randomize;
f:=0;
(*utilizzo la variabile r per verificare se è già uscita la matta*)
r:='n';
writeln('simulazione gioco 7½');
Writeln;
writeln('prova a battere il pc, premi invio per giocare');
readln;
(* giocatore *)
repeat
clrscr;
x:=random(10)+1;
if (x=10) and (r='n') then
begin
c:=random(2);
x:=x+c;
if x=11 then r:='s';
end;
case x of
1:f:=f+1;
2:f:=f+2;
3:f:=f+3;
4:f:=f+4;
5:f:=f+5;
6:f:=f+6;
7:f:=f+7;
8:f:=f+0.5;
9:f:=f+0.5;
10:f:=f+0.5;
11:begin
(* la funzione frac prende la parte non intera di f*)
f:=frac(f);
f:=f+7;
end;
end;
if (f>7.5) or (f=7.5) then
scelta:='s'
else
begin
writeln(' il tuo punteggio è: ',f:1:1);
writeln(' vuoi fermarti? (s/n)');
readln(scelta);
end;
until (scelta='s');
clrscr;
if (f=7.5) then
writeln('ke Cool - Hai fatto 7½')
else
if (f>7.5) then
begin
b:=1;
writeln('Mi spiace ma hai superato 7½ - Hai Perso - RITENTA')
end
else
writeln(' il tuo punteggio migliore è: ',f:1:1);
(* conservo il tuo punteggio in una variabile di appoggio g*)
g:=f;
readln;

(* computer *)
if b<>1 then
begin
repeat
clrscr;
x:=random(10)+1;
if (x=10) and (r='n') then
begin
c:=random(2);
x:=x+c;
if x=11 then r:='s';
end;
case x of
1:f:=f+1;
2:f:=f+2;
3:f:=f+3;
4:f:=f+4;
5:f:=f+5;
6:f:=f+6;
7:f:=f+7;
8:f:=f+0.5;
9:f:=f+0.5;
10:f:=f+0.5;
11:begin
(* la funzione frac prende la parte non intera di f*)
f:=frac(f);
f:=f+7;
end;
end;
if (f>7.5) or (f=7.5) then
scelta:='s'
else
if (f>g) or (f=g) then
scelta:='s';

until (scelta='s');
clrscr;
if (f=7.5) then
writeln('ke sfiga - il pc Ha fatto 7½ - Hai perso')
else
if (f>7.5) then
writeln('ke Cool il pc ha superato 7½ - Hai Vinto')
else
begin
writeln(' il tuo punteggio migliore è : ',g:1:1);
writeln(' il punteggio migliore del pc è: ',f:1:1);
if g>f then
writeln('Hai Vinto')
else
writeln('Hai Perso');
end;
end;
end.
 

peter74

Utente Attivo
27 Nov 2006
32
0
0
Scusami ma mi sa che c'è un errore. In alcuni casi il programma non funge. Ora non ho tempo per controllare tutti i casi possibili e trovare gli eventuali errori. Dai un occhiata tu fai delle prove magari mi suggerisci cosa non va e come risolvere:cool:
 
Discussioni simili
Autore Titolo Forum Risposte Data
S Salve a tutta la comunity Presentati al Forum 2
E salve a tutti Presentati al Forum 1
D Salve Presentati al Forum 1
G Salve Presentati al Forum 0
B Salve a tutti Presentati al Forum 1
L Salve a tutti Presentati al Forum 1
A Salve a tutti Presentati al Forum 2
H Salve a tutti Presentati al Forum 1
I salve a tutti gli iscritti. Presentati al Forum 1
M Salve Gente! Presentati al Forum 0
FDF182 Salve ragazzi!!!! Presentati al Forum 1
C Salve a tutti Presentati al Forum 0
J Salve a tutti Presentati al Forum 0
M Salve a tutti Presentati al Forum 0
N Salve! Presentati al Forum 0
M Salve a tutti Presentati al Forum 0
O Salve a tutti! Presentati al Forum 0
C salve a tuttiii Presentati al Forum 0
M Salve a tutti. Presentati al Forum 0
G Salve a tutti! Presentati al Forum 0
R Salve a tutti Presentati al Forum 1
E Salve a tutti Presentati al Forum 0
D Salve a tutti Presentati al Forum 0
R Salve a tutti. Presentati al Forum 0
N Salve Presentati al Forum 0
F salve a tutti Presentati al Forum 1
8 Salve a tutti Presentati al Forum 2
socket32 Salve a tutti! Presentati al Forum 1
F Salve a tutti! Presentati al Forum 0
A SALVE SALVE Presentati al Forum 0
J Salve a Tutti Presentati al Forum 0
M Salve a tutti Presentati al Forum 2
G Salve a tutti Community Presentati al Forum 0
P Salve. Presentati al Forum 0
A Salve a tutti Presentati al Forum 0
S Salve! Presentati al Forum 0
G Salve Presentati al Forum 0
O Salve a tutti! Presentati al Forum 0
S Salve a tutti Presentati al Forum 0
A Salve a tutti Presentati al Forum 0
C Salve a tutti, sono uno studente Presentati al Forum 1
S Salve a tutti Presentati al Forum 0
R salve a tutti sono un insegnante di pianoforte e a tempo perso mi sto dedicando ad access Presentati al Forum 1
F Salve a tutti Presentati al Forum 0
P Salve a tutti Presentati al Forum 0
F Salve a tutti Presentati al Forum 1
N Buongiorno e salve a tutti Presentati al Forum 0
C Salve Presentati al Forum 0
panchouino #stiamoacasa Salve a tutti Presentati al Forum 1
X Salve a tutti! :) Presentati al Forum 1

Discussioni simili