-
Notifications
You must be signed in to change notification settings - Fork 0
/
hanoi.ba
55 lines (55 loc) · 1.75 KB
/
hanoi.ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
0 B$=CHR$(243)
1 DIMBL$(6):FORI=0TO6:BL$(I)=STRING$(6-I," ")+STRING$(2*I+1,B$)+STRING$(6-I," "):NEXT
2 BL$=" "
5 DIMT$(2)
9 CLS
10 PRINT"Quanti dischi (2-7)? ";:X0=2:X1=7:GOSUB41000
15 TL=X9
20 X0=X9:GOSUB42000
30 CLS:GOSUB60000
40 IFLEN(T$(1))=TLORLEN(T$(2))=TLTHEN100
50 GOSUB43000
60 A=X0-1:B=X1-1
70 T$(B)=LEFT$(T$(A),1)+T$(B)
80 T$(A)=RIGHT$(T$(A),LEN(T$(A))-1)
85 GOSUB60000
90 GOTO40
100 PRINT@0," H A I V I N T O ";
105 SOUND3000,10:SOUND4000,10
110 IFINKEY$=""THEN110
120 CLS:END
39999 END
40000 REM WaitForDigit
40010 XT$=INKEY$:IFXT$=""THEN40010
40020 IFXT$>="0"ANDXT$<="9"THENXT=ASC(XT$)-48:GOTO40100
40030 XT=INSTR("#]"+CHR$(34)+"'(_}",XT$):IFXT>0THEN40100
40040 GOTO40010
40100 X9=XT
40110 IFX9>=X0ANDX9<=X1THENRETURN
40120 GOTO40010
41000 REM InputDigit
41010 PRINTCHR$(244);:GOSUB40000:XT=(40*CSRLIN)+POS(0)-1:PRINT@XT,MID$(STR$(X9),2);CHR$(244);
41020 RETURN
42000 REM CreateTowers
42010 T$(1)="":T$(2)="":T$(0)=""
42020 FORXT=1TOX0:T$(0)=T$(0)+CHR$(48+XT):NEXT
42030 RETURN
43000 REM InputGame
43005 X0=1:X1=3
43006 PRINT@20,"A: ";
43010 PRINT@0,"Da: ";:GOSUB41000:T1=X9
43015 IFT$(T1-1)=""THENPRINT@0,"Da: ";:BEEP:GOTO43010
43016 PRINT@5," ";
43020 PRINT@20,"A: ";:GOSUB41000:T2=X9
43030 P1=VAL(LEFT$(T$(T1-1),1))
43040 IFT$(T2-1)=""THENP2=1000:GOTO43060
43050 P2=VAL(LEFT$(T$(T2-1),1))
43060 IFP2<=P1THENPRINT@0,"Da: ";:PRINT@20,"A: ";:BEEP:GOTO43010
43070 X0=T1:X1=T2:RETURN
60000 REM DrawTowers
60010 FORI=0TO2:L=LEN(T$(I)):X=13*I
60020 IFL=0THENPRINT@(280+X),BL$;:GOTO60040
60030 K=0:FORJ=LEN(T$(I))TO1STEP-1:K=K+1:PRINT@(320-(K*40)+X),BL$(VAL(MID$(T$(I),J,1))-1);:NEXT
60035 IFLEN(T$(I))<7THENPRINT@(320-((LEN(T$(I))+1)*40)+X),BL$;
60040 NEXT
60050 PRINT@0,"";:RETURN