Tirer au Craps

Programme avec Texte Seulement

PC-BASIC

CRAPS.BAS

Le jeu de craps a de nombreuses variantes, mais elles reposent toutes sur des sommes de dés. Le nombre de sommes possibles à deux dés est de 36, comme indiqué dans le tableau ci-dessous.

Au craps, le joueur qui lance les deux dés est appelé le lanceur. Le premier lancer du tireur est appelé le come-out roll.

Si une somme de dés de 7 ou 11 est lancée lors du come-out roll, alors le joueur gagne et la manche est terminée.

Mais si la somme des dés est 2, 3 ou 12, alors le joueur a chié (perdu) et le tour est terminé.

Il existe également une troisième possibilité : le tireur décroche une somme de 4, 5, 6, 8, 9 ou 10 - appelée un nombre de points - lors du come-out roll.

Dans ce cas, le joueur entre dans la phase de points, qui ne se termine que lorsque le joueur lance une somme de 7 ou lance le nombre de points une deuxième fois. Sinon, le joueur continue de lancer les dés.

Au CRAPS.BAS, illustré ci-dessous, vous jouez à un jeu de craps contre l'ordinateur. Il n'y a pas beaucoup de stratégie impliquée; préparez-vous simplement à appuyer plusieurs fois sur la touche Entrée.

Le programme est divisé en trois parties :

une introduction au jeu (lignes  10 à 120), le tour du joueur (humain) (lignes 130 à 280) et le tour de l'ordinateur (lignes 300 à 410).

Notez que deux sous-programmes sont appelés à plusieurs reprises : le chèque bancaire, pour voir si le joueur ou l'ordinateur est à court d'argent (lignes 500 à 530) ; et la routine lancer les dés (lignes  900 à 950).

L'écriture de ces lignes dans le cadre de sous-programmes nous évite d'avoir à les taper à plusieurs reprises dans le programme - nous pouvons simplement les appeler en utilisant GOSUB à la place.

Bien que ce programme basé sur du texte joue un jeu de craps satisfaisant, il laisse beaucoup à désirer. Pour une chose les graphismes : CRAPS. BAS vous laissera à peine à bout de souffle avec l'anticipation du prochain lancer.

Utiliser POSITION.BAS (détaillé dans un chapitre ultérieur) pour dessiner une table de craps à l'écran peut rendre le jeu plus intéressant.

Au-delà de la cosmétique, cependant, il existe un certain nombre d'éléments de gameplay qui pourraient être ajoutés ou améliorés.

Par exemple, le contrôle des paris et des options pour modifier certaines des règles du jeu aiderait à rendre l'expérience de jouer au craps sur GW-BASIC un peu moins nulle, eh bien mieux.

10 KEY OFF:SCREEN 9:SCREEN 0:CLS
11 PBANK=1000:CBANK=1000 'Set initial banks for player and computer
15 RANDOMIZE TIMER
20 PRINT TAB(20);"--- CRAPS ---"
30 PRINT:PRINT"You will take the first turn, followed by the computer."
35 PRINT"Both you and the computer begin with $1000 each."
40 PRINT"You, the shooter, will roll two dice (called the come-out roll)."
50 PRINT"If the sum of the dice is 2, 3, or 12, then the round is over (you crap out)."
60 PRINT"But if the come-out roll is 7 or 11, then you win."
70 PRINT"If you roll a 4, 5, 6, 8, 9, or 10, then you've rolled a point number."
80 PRINT"Once you have rolled a point number, if you roll the same point number"
90 PRINT"again, then you win. But if you roll a 7 then round is over."
100 PRINT"Roll anything else, then you roll again."
110 PRINT:PRINT"PRESS <ENTER> TO BEGIN
120 LINE INPUT A$
130 'Player takes his turn
135 GOSUB 500
140 PRINT:PRINT"You are the shooter. You and the computer have put $100 each into the pot,"
150 PRINT"therefore the pot is worth $200."
155 PRINT"It is time for your come-out roll "
160 GOSUB 900 'Player rolls die
190 IF SUM=7 OR SUM=11 THEN PBANK=PBANK+200:CBANK=CBANK-200
195 IF SUM=7 OR SUM=11 THEN PRINT"You win the $200 pot. You now have $";PBANK;" and the computer has $";CBANK:GOTO 300
200 IF SUM=2 OR SUM=3 OR SUM=12 THEN PBANK=PBANK-200:CBANK=CBANK+200
205 IF SUM=2 OR SUM=3 OR SUM=12 THEN PRINT"You crapped out. You now have $";PBANK;" and the computer has $";CBANK:GOTO 300
210 'Player enters point phase
220 PRINT"You have entered the point phase."
230 PRINT"You can't get out until you roll'the same point number to win, or a 7 to lose "
240 PREVSUM=SUM 'Sets point number
245 GOSUB 900 'Player rolls die
250 IF SUM=PREVSUM THEN PBANK=PBANK+200:CBANK= CBANK-200
255 IF SUM=PREVSUM THEN PRINT"You hit your point number, so you win--you now have $";PBANK:PRINT "and the computer currently has $";CBANK:GOTO 300
260 IF SUM=7 THEN PBANK=PBANK-200:CBANK=CBANK+200
265 IF SUM=7 THEN PRINT"You didn't get your point number before rolling a 7, so you lose."
270 IF SUM=7 THEN PRINT"You now have $";PBANK;", while the computer has $";CBANK:GOTO 300
280 GOTO 245 'Player stuck in the point phase
300 'Computer takes its turn
305 GOSUB 500
310 PRINT:PRINT"The computer is now the shooter. It's time for the come-out roll."
315 PRINT"You and the computer have each put $100 into the pot."
320 GOSUB 900 'Computer rolls
330 IF SUM=7 OR SUM=11 THEN PBANK=PBANK-200:CBANK=CBANK+200
332 IF SUM=7 OR SUM=11 THEN PRINT"The computer has won the round. You have $";PBANK;" and the computer has $";CBANK:GOTO 130
340 IF SUM=2 OR SUM=3 OR SUM=12 THEN PBANK=PBANK+200:CBANK=CBANK-200
345 IF SUM=2 OR SUM=3 OR SUM=12 THEN PRINT"The computer has crapped out. You have $";PBANK;"and the computer has $";CBANK:GOTO 130
350 PRINT"The computer now enters the point phase."
360 PRINT"The computer can't get out until the same point number or a 7 is rolled."
370 PREVSUM=SUM 'Sets point number
380 GOSUB 900 'Computer rolls
390 IF SUM=PREVSUM THEN PBANK=PBANK-200:CBANK=CBANK+200
395 IF SUM=PREVSUM THEN PRINT"The computer hit its point number. You have $";PBANK;" and it has $";CBANK:GOTO 130
400 IF SUM=7 THEN PBANK=PBANK+200:CBANK=CBANK-200
405 IF SUM=7 THEN PRINT"The computer didn't hit its point number before rolling a 7, so it loses."
406 IF SUM=7 THEN PRINT"You have $";PBANK;" and it has $";CBANK:GOTO 130
410 GOTO 380 'Computer stuck in the point phase
500 'Check to see if player/computer went bust
510 IF PBANK<=0 THEN PRINT"Sorry, you have lost all of your money. Game over.":END
520 IF CBANK<=0 THEN PRINT"Congrats! The computer has gone bust. You win!":END
530 RETURN
900 'Prompt to roll die
910 PRINT:PRINT"PRESS <ENTER> TO SEE THE ROLL OF THE DICE...";
920 LINE INPUT A$
930 DIEl=1+INT(l+6*RND):IF DIE1>6 THEN 930
932 DIE2=1+INT(l+6*RND):IF DIE2>6 THEN 932
935 SUM=DIEl+DIE2
940 PRINT"Die 1 = ";DIEl;" Die 2 = ";DIE2;" Sum of dice = ";SUM
945 PRINT
950 RETURN

 

 

 

 

 

 

 

Recherche personnalisée