TGC Codebase Backup



Game NumberX by Brux

7th Sep 2012 17:21
Summary

Game like Mastermind,but I have used numbers



Description

My apologies for my English....
Game like Mastermind. But I have used numbers.
You must guess a number from 2 to 6 digits
When you guess a number in exact position, appears a green box
When you guess a number, but in wrong position,appears a red box
If you don't guess no number, appears a red "X"
You have 13 attemps



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem *****************************************************************************
Rem *                                 NUMBERX                                   *
Rem *                  E.Manzoni <ITALY> email: me52@libero.it                  *
Rem *                                                                           *
Rem *     Game similar to Mastermind, rather than 'guess the colors, you have   *
Rem *      to guess a number consists of 6 digits different from each other     *
Rem *               read the instructions under the heading symbols             *
Rem *****************************************************************************
Rem *
Rem define colors
red=Rgb(255,0,0)
white=Rgb(255,255,255)
gray=Rgb(90,90,90)
green=Rgb(0,200,0)
blu=Rgb(0,64,128)
azzurro=Rgb(0,192,255)
yellow=Rgb(255,255,0)
Rem *** Dimensiono variabili ****
Dim flag(10)
Dim button(10)
Sync on:Sync Rate 60
Load Sound "Jump3.wav",1
nmax=2
Main:
Set Text Size 38
Center Text 320,10,"CHOOSE LEVEL"
Make_Button(azzurro,210,100,410,330,white,black,1)
Make_Button(black,250,140,370,290,white,black,1)
Make_Button(blu,220,200,245,220,white,black,1)
Make_Button(blu,375,200,400,220,white,black,1)
Make_Button(blu,290,300,330,325,white,black,1)
Intesto(220,180,240,190,"+",white)
Intesto(375,180,395,190,"-",white)
Intesto(285,280,315,300,"OK",white)
Set Text Size 72
Intesto(240,120,340,220,Str$(nmax),white)
Repeat
sync
Until Mouseclick()=1
 mx=Mousex()
 my=Mousey()
 If mx>220 And mx<245 And my>200 And my<220
  anim_button(220,200,245,220)
  Inc nmax
  If nmax>6 Then nmax=2
  Goto main
 EndIf
If mx>375 And mx<400 And my>200 And my<220
  anim_button(375,200,400,220)
  Dec nmax
  If nmax<2 Then nmax=6
  Goto main
 EndIf
 If mx>290 And mx<330 And my>300 And my<325
 anim_button(290,300,330,325)
 Endif

Set Text Size 12
If nmax<2 Then nmax=2
If nmax>6 Then nmax=6
Cls 0
Ink blu,blu
Box 10,10,630,470
Ink white,white
Set Text Size 32
Center Text 320,20,"NUMBERX"
Rem Make 0-9 Buttons
Set Text Size 10
py=0 : i$=""
For i=0 To 9 :flag(i)=0:button(i)=0:Next i
For i=0 To 9
 Make_Button(azzurro,30,100+py,50,120+py,azzurro,black,1)
 i$=Str$(i)
 Intesto(30,100+py,50,90+py,i$,blu)
 Inc py,30
Next i
Rem Make Button Menu
Make_Button(azzurro,490,100,600,130,white,black,1):Intesto(490,100,600,100,"DON'T KNOW",black)
Make_Button(black,500,200,580,230,yellow,black,1):Intesto(500,160,580,180,"The Number was",white)
Rem *********************************Symbols**********************************
Rem * Right number in exact position
Make_Button(green,530,260,550,280,white,black,0):Intesto(530,280,550,280,"RIGHT",white)
Rem * Right number ,but in wrong position
Make_Button(red,530,320,550,340,white,black,0):Intesto(530,340,550,340,"WRONG",white)
Rem * No number
Make_Button(blu,530,380,550,400,yellow,yellow,0):Intesto(530,380,550,370,"X",red)
Intesto(530,400,550,400,"NO",white):Intesto(530,420,550,420,"NUMBER",white)
Rem Draw Boxes
py=0:px=0
For a=1 To 13
 For b=1 To nmax
  make_button(blu,65+px,60+py,85+px,80+py,white,white,0)
  Make_Button(blu,300+px,60+py,320+px,80+py,yellow,yellow,0)
  Inc px,30
 Next b
 px=0:Inc py,30
Next a
Rem Create number
Randomize Rnd(100)
px=0:py=0:lb=0:fine=0:count=0
Guess$=""
YourNumber$=""
For i=1 To nmax
riconta:
x=Rnd(9)
If flag(x)=1 Then Goto riconta
flag(x)=1
Guess$=Guess$+Str$(x)
Next i
Rem ************************************************************************************
Rem *To understand the game, you can print the number on the screen the first few times*
Rem ************************************************************************************
Rem print Guess$
Sync
Rem ***************************** MainLoop **********************************************
MainLoop:
numero=0
Repeat
If Mouseclick()=1
 mx=Mousex()
 my=Mousey()
Rem ...You don't know
If mx>490 And my>100 And mx<600 And my<130
  anim_button(490,100,600,130)
  Intesto(500,200,580,200,Guess$,white)
  fine=1 : Exit
EndIf
Rem Numbers from 0 to 9
If mx>30 And mx<50 And my>100 And my<120 And button(0)=0
 anim_button(30,100,50,120)
 button(0)=1:inc numero:yournumber$=yournumber$+Str$(0)
 make_button(blu,65+px,60+py,85+px,80+py,white,white,0):Intesto(65+px,60+py,85+px,50+py,"0",white)
 Inc px,30
EndIf
If mx>30 And mx<50 And my>130 And my<150 And button(1)=0
 anim_button(30,130,50,150)
 button(1)=1:inc numero:yournumber$=yournumber$+Str$(1)
 make_button(blu,65+px,60+py,85+px,80+py,white,white,0):Intesto(65+px,60+py,85+px,50+py,"1",white)
 Inc px,30
EndIf
If mx>30 And mx<50 And my>160 And my<180 And button(2)=0
 anim_button(30,160,50,180)
 button(2)=1:inc numero:yournumber$=yournumber$+Str$(2)
 make_button(blu,65+px,60+py,85+px,80+py,white,white,0):Intesto(65+px,60+py,85+px,50+py,"2",white)
 Inc px,30
EndIf
If mx>30 And mx<50 And my>190 And my<210 And button(3)=0
 anim_button(30,190,50,210)
 button(3)=1:inc numero:yournumber$=yournumber$+Str$(3)
 make_button(blu,65+px,60+py,85+px,80+py,white,white,0):Intesto(65+px,60+py,85+px,50+py,"3",white)
 Inc px,30
EndIf
If mx>30 And mx<50 And my>220 And my<240 And button(4)=0
 anim_button(30,220,50,240)
 button(4)=1:inc numero:yournumber$=yournumber$+Str$(4)
 make_button(blu,65+px,60+py,85+px,80+py,white,white,0):Intesto(65+px,60+py,85+px,50+py,"4",white)
 Inc px,30
EndIf
If mx>30 And mx<50 And my>250 And my<270 And button(5)=0
 anim_button(30,250,50,270)
 button(5)=1:inc numero:yournumber$=yournumber$+Str$(5)
 make_button(blu,65+px,60+py,85+px,80+py,white,white,0):Intesto(65+px,60+py,85+px,50+py,"5",white)
 Inc px,30
EndIf
If mx>30 And mx<50 And my>280 And my<300 And button(6)=0
 anim_button(30,280,50,300)
 button(6)=1:inc numero:yournumber$=yournumber$+Str$(6)
 make_button(blu,65+px,60+py,85+px,80+py,white,white,0):Intesto(65+px,60+py,85+px,50+py,"6",white)
 Inc px,30
EndIf
If mx>30 And mx<50 And my>310 And my<330 And button(7)=0
 anim_button(30,310,50,330)
 button(7)=1:inc numero:yournumber$=yournumber$+Str$(7)
 make_button(blu,65+px,60+py,85+px,80+py,white,white,0):Intesto(65+px,60+py,85+px,50+py,"7",white)
 Inc px,30
EndIf
If mx>30 And mx<50 And my>340 And my<360 And button(8)=0
 anim_button(30,340,50,360)
 button(8)=1:inc numero:yournumber$=yournumber$+Str$(8)
 make_button(blu,65+px,60+py,85+px,80+py,white,white,0):Intesto(65+px,60+py,85+px,50+py,"8",white)
 Inc px,30
EndIf
If mx>30 And mx<50 And my>370 And my<390 And button(9)=0
 anim_button(30,370,50,390)
 button(9)=1:inc numero:yournumber$=yournumber$+Str$(9)
 make_button(blu,65+px,60+py,85+px,80+py,white,white,0):Intesto(65+px,60+py,85+px,50+py,"9",white)
 Inc px,30
EndIf
EndIf
Sync
Until numero =nmax
If fine=1 Then Goto fine
Gosub check

Rem Check Guess$>yournumber$
If j$=""
px=0
For i=1 To nmax
 Intesto(300+px,65+py,320+px,45+py,"X",red):Inc px,30
Next i
 Goto continua_gioco
EndIf
px=0
For i=1 to nmax
 If Mid$(j$,i)="V"
  make_button(green,300+px,60+py,320+px,80+py,white,black,0)
  Inc px,30:Inc lb
 EndIf
If Mid$(j$,i)="R"
  make_button(red,300+px,60+py,320+px,80+py,white,black,0)
  Inc px,30
 EndIf
Next i
Rem Indovinato ?
If lb=nmax
 Intesto(500,200,580,200,Guess$,white)
 Intesto(500,220,580,230,"RIGHT NUMBER",yellow)
 Play Sound 1
 Goto fine
EndIf
continua_gioco:
inc py,30:px=0
Rem ReSet value
For i=0 To 9
 button(i)=0
Next i
YourNumber$="":lb=0
inc count
Rem count>12 end program
If count>12
 Intesto(500,200,580,200,Guess$,white)
 Goto fine
EndIf
Goto MainLoop

check:
a=1:j$=""
Repeat
xx$=Mid$(Guess$,a)
zz$=Mid$(yournumber$,a)
If xx$=zz$
 J$=j$+"V"
 Goto continua
EndIf
j=0
For c=1 To nmax
If zz$=Mid$(Guess$,c)
 J=1
EndIf
Next c
If j=1
 j$=j$+"R"
EndIf
continua:
Inc a
Until a>nmax
Return

fine:
Intesto(140,10,200,20,"AGAIN (S/N)",yellow)
Repeat
j$=Inkey$()
jasc=Asc(j$)
Sync
Until j$>""
If jasc=115 Then Cls 0 : Goto main
Sleep 50
End

Rem Functions

Function Make_Button(co1,Left,Top,Right,Bottom,co2,co3,shadow)
 Ink 0,0
 If shadow=1 Then Box left,top,right,bottom
 If shadow=2 Then Box left-2,top-2,right+2,bottom+2
 Ink co1,co1
 Box left+1,top+1,right-1,bottom-1
 Ink co2,co2
 Line Left,Bottom,Left,Top : Line Left,Top,Right,Top
 Ink co3,co3
 Line Right,Top,Right,Bottom : Line Right,Bottom,Left,Bottom
EndFunction


Function Intesto(x,y,x1,y1,txt$,ct)
 Ink ct,ct
 c=((x1-x)/2)-((8*Len(txt$))/2)
 Text x+c,y1-((y1-y)/2)+8,txt$
EndFunction

Function Anim_Button(Ax,Ay,Bx,By)
    Copy Bitmap 0,Ax-1,Ay-1,Bx,By,0,Ax,Ay,Bx+1,By+1
    While MouseClick()=1 : Sync :  EndWhile
    Copy Bitmap 0,Ax,Ay,Bx+1,By+1,0,Ax-1,Ay-1,Bx,By
EndFunction