Small Basic: Intermediate Challenge 1 (Sushi restaurant)


sushiNao

Program Listing:    JWF370    http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/bce001cb-ce65-4d23-8645-466098928115/

Intermediate Challenge 1

Write a program to display a menu that a till operator might use in a restaurant.  They click on the items the customer wants and it works out the bill.

………………………………………………………………………………………………………………………….

Code:

‘  Challenge of the month  May 2013     Restaurant  menu order   by  NaochanON

 

InitData()

GUI()

Controls.ButtonClicked=EnterData

Sub EnterData

btnnmb=Controls.LastClickedButton

nm=controls.GetButtonCaption(btnnmb)

if text.IsSubText(Btns,nm) Then  ‘

DNMB= Text.GetSubTextToEnd(btnnmb,7)                     ‘

Newconts= Menu[DNMB]

NewPrice= Price[DNMB]

DataEnter()

elseif  text.IsSubText(Newconts,nm) then

searchNo()

NN=NN+1

Order=order+NN+”: “+nm+”    “+Price[DNMB][PNMB]+CRLF

TotPrice=TotPrice+Price[DNMB][PNMB]

Mes=Order+CRLF+”   Price      = “+Totprice+CRLF

tax=math.floor(5*Totprice)/100

Mes=Mes+”   Tax(5%) = “+tax+CRLF

Mes=Mes+”   Total      = “+(Totprice+tax)+CRLF+CRLF+”   Thank you !”

Controls.SetTextBoxText(receipt,Mes)

EndIf

endsub

sub searchNo

For j=1 To Array.GetItemCount(Newconts)

If nm= Newconts[j] Then

PNMB=j

j=Array.GetItemCount(Newconts)

endif

EndFor

EndSub

Sub DataEnter

If NMB2<>0 Then

For j=1 To NMB2

Controls.HideControl(btn2[j])                  ‘

Controls.HideControl(btn3[j])

EndFor

EndIf

Shapes.Move(redrect,10,130+75*(DNMB-1))                            ‘  Red mark

‘————————————————————————————————————————-

NMB=Array.GetItemCount(Newconts)

GRXY=”W=500;H=”+(NMB*45)

GrayBox()

‘————————————————————————————————————————-

GraphicsWindow.BrushColor=”Navy”

For i=1 To NMB

btn2[i]=Controls.AddButton(Newconts[i],440,135+40*(i-1))         ‘  menu

btn3[i]=Controls.AddButton(“US$ “+NewPrice[i],760,135+40*(i-1))  ‘  price

Controls.SetSize(btn2[i],280,35)

Controls.SetSize(btn3[i],120,35)

EndFor

‘————————————————————————————————————————-

NMB2=NMB                                               ‘

endsub

Sub GrayBox

Shapes.Remove(GRBOX)

GraphicsWindow.BrushColor=”Lightgray”

GRBOX=Shapes.AddRectangle(GRXY["W"],GRXY["H"])           ‘  gray  box

Shapes.Move(GRBOX,400,120)

Shapes.SetOpacity(GRBOX,60)

EndSub

Sub GUI

GraphicsWindow.Width=Desktop.Width

GraphicsWindow.Height=Desktop.Height

GraphicsWindow.Top=0

GraphicsWindow.Left=0

GraphicsWindow.FontName=”Gergia”

GraphicsWindow.FontItalic=”true”

GraphicsWindow.DrawImage(back,0,0)                       ‘  background image

‘————————————————————————————————————————-

photo=Shapes.AddImage(Img)                               ‘  Sushi photo

Shapes.Zoom(photo,550/imgw,350/imgh)

Shapes.Move(photo,400,380)

Shapes.SetOpacity(photo,60)

‘————————————————————————————————————————-

GraphicsWindow.penColor=”Red”

GraphicsWindow.BrushColor=”Red”

redrect= Shapes.AddRectangle(30,30)

Shapes.Move(redrect,10,-100)

GraphicsWindow.FontSize=25

TTL=Shapes.AddText(” Sushi Restaurent  Order System  “)  ‘  Title

Shapes.Move(TTL,500,10)

‘————————————————————————————————————————-

GraphicsWindow.FontSize=25

GraphicsWindow.BrushColor=”Navy”

For i=1 To array.GetItemCount(Btns)

btn[i]= Controls.AddButton(Btns[i],50,125+75*(i-1))    ‘   Menu

Controls.SetSize(btn[i],250,55)

EndFor

‘————————————————————————————————————————-

GraphicsWindow.FontSize=16

receipt=Controls.AddMultiLineTextBox(1000,125)           ‘   receipt box

Controls.SetSize(receipt,350,600)

Shapes.SetOpacity(receipt,70)

EndSub

Sub InitData

back=ImageList.LoadImage(“C:\Windows\Web\Wallpaper\Scenes\img29.jpg”)

url= “http://farm7.static.flickr.com/6109/6245861119_1f06dabea8.jpg&#8221;

‘url=Flickr.GetRandomPicture(“Sushi”)

img= imagelist.LoadImage(url)

imgw= ImageList.GetWidthOfImage(img)

imgh= ImageList.GetHeightOfImage(img)

Btns=”1=Hot Appetizer;2=Cold Appetizer;3=Nigiri;4=Special Rolls;5=Sea Food;6=Dinner;7=Deserts&Beverage “

‘————————————————————————————————————————-

Menu[1]=”1=Japanese Eggplant;2=Tempura;3=Softshell Crab;4=Crab Cake;5=Oyster Saute”

Menu[2]=”1=Crab and Shrimp Sunomono;2=Aji tako Salad;3=Salmon radish Roll;4=Tuna with rice Biscuit”

Menu[3]=”1=Crab;2=Eel Sea;3=Halibut;4=Mackerel;5=Octopus;6=Omelet;7=Salmon;8=Salmon Roe;9=Scallop;10=Sea Urchin;11=Squid;12=Tuna”

Menu[4]=”1=Alaskan Roll;2=Hawaian Roll;3=Mexican Roll;4=Eel Roll;5=Avocado Roll”

Menu[5]=”1=Salmon;2=Scallops;3=Sea Bass;4=Tuna;5=Monk Fish;6=Black Cod;7=Yellow tail”

Menu[6]=”1=Chicken Teriyaki;2=Assorted Tempura;3=Sushi Deluxe;4=Assorted Sashimi Plate;5=Chirashi Sushi”

Menu[7]=”1=Ice Cream;2=Soda;3=Cola;4=Hot Tea;5=Cold Tea”

‘————————————————————————————————————————-

Price[1]=”1=7.00;2=7.00;3=8.50;4=9.50;5=7.00″

Price[2]=”1=7.00;2=9.50;3=9.50;4=10.50″

Price[3]=”1=3.50;2=5.00;3=4.50;4=3.50;5=4.00;6=3.00;7=4.00;8=5.00;9=4.50;10=7.50;11=3.75;12=4.50″

Price[4]=”1=12.00;2=12.50;3=11.50;4=10.50;5=7.50″

Price[5]=”1=12.00;2=14.00;3=16.50;4=15.50;5=13.00;6=13.50;7=14.50″

Price[6]=”1=12.00;2=13.00;3=22.00;4=24.50;5=22.50″

Price[7]=”1=2.50;2=1.50;3=1.50;4=2.00;5=1.50″

CRLF= Text.GetCharacter(13)+Text.GetCharacter(10)

EndSub

El objeto Flickr en Small Basic (código)


a2

Un ejercicio agradable
Con el objeto de Flickr obtenemos imágenes aleatorias.
Cambian 10 veces las imágenes con un delay = 200 msegundos
Y se ajusta el tamaño de la pantalla con el tamaño de cada imagen
Divertido !

  1. GraphicsWindow.Title =      “imagen”
  2. For i = 1 To 10
  3. img =      Flickr.GetRandomPicture(“animals”)
  4. Ancho =      ImageList.GetWidthOfImage(img)
  5. Alto =      ImageList.GetHeightOfImage(img)
  6. GraphicsWindow.Width = Ancho
  7. GraphicsWindow.Height = Alto
  8. GraphicsWindow.DrawResizedImage(img,      0, 0, Ancho, Alto)
  9. Program.Delay(200)
  10. EndFor