Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
4.2 responding to events
1. Microsoft® Small Basic Responding to Events Estimated time to complete this lesson: 1 hour
2. Responding to Events In this lesson, you will learn about: Creating interactive games in Small Basic that respond to events.
3. Fun with Shapes And you also know that you can use these shapes, controls, and events collectively to create interactive games in Small Basic. Let’s see how… So far, you have learned to insert and animate various shapes in your Small Basic programs. You have also learned to use controls and keyboard and mouse events to include interactivity in your Small Basic program.
4. Make the Turtle Draw – The Game In this simple game, you tell the Turtle to draw unique shapes in the graphics window by defining the number of sides. Notice how you use the Turtle object to draw shapes and how you use mouse and keyboard events to choose the color and the number of sides. The game demonstrates how the user can make the Turtle draw colorful, unique shapes by specifying a color and the number of sides.
5.
6. Next, you specify the number of sides, so you can define what the Turtle should draw.
7.
8. Bounce the Ball – The Game Let’s move to a complex game now. In this game, you keep a ball above the ground by using the mouse to click the ball to keep it afloat. Notice how we use mouse events to keep the ball from touching the ground. The ball responds to mouse clicks and stays afloat. The objective of the game is to keep the ball afloat as long as possible.
Solution:' Copyright (c) Microsoft Corporation. All rights reserved.GraphicsWindow.Hide()gw = 500gh = 350scoreBoxLeft = 200passedQuestion = 0score = 0Clicked = ""i = 1Q[1] = "Nile is the longest river in the world."Q[2] = "The highest mountain in the world is Mount Everest."Q[3] = "Zambia is also known as the 'Country of Copper'."Q[4] = "The coldest place on the earth is in Siberia."Q[5] = "Sydney is the capital of the USA."Q[6] = "The river Jordan flows out into the Dead sea."Q[7] = "Mumbai is the capital of India."Q[8] = "Africa is the largest coffee growing continent in the world."Q[9] = "The largest desert in the world is Sahara Desert."Q[10] = "London is the capital of the UK."A[1] = "True"A[2] = "True"A[3] = "True"A[4] = "True"A[5] = "False"A[6] = "True"A[7] = "False"A[8] = "False"A[9] = "True"A[10] = "True"ArrayRandom[1] = "5234162"ArrayRandom[2] = "1896523"ArrayRandom[3] = "5974216"ArrayRandom[4] = "2756194"randomNumber = Math.GetRandomNumber(Array.GetItemCount(ArrayRandom))GraphicsWindow.CanResize = "False"GraphicsWindow.Width = gwGraphicsWindow.Height = ghGraphicsWindow.Top = (Desktop.Height - gh) / 2GraphicsWindow.Left = (Desktop.Width - gw) / 2GraphicsWindow.Title = "True or False"GraphicsWindow.Show()Controls.ButtonClicked = OnButtonClickedCreateUI()Sub CreateUIGraphicsWindow.BrushColor = "Purple"GraphicsWindow.FontName = "Verdana"GraphicsWindow.FontSize = 14GraphicsWindow.DrawRectangle(10, 10, 480, 330) trueButton = Controls.AddButton("True", 30, 210) falseButton = Controls.AddButton("False", 320, 210) Controls.SetSize(trueButton, 150, 100)Controls.SetSize(falseButton, 150, 100)GraphicsWindow.DrawText(220, 300, "Result")resultTextBox = Shapes.AddText("")Shapes.Move(resultTextBox, 220, 250)scoreTextBox = Shapes.AddText("Score: 0")Shapes.Move(scoreTextBox, 404, 15)StartGame() EndSubSub StartGamepassedQuestion = Text.GetSubText(ArrayRandom[randomNumber], i, 1) If i <= 7 Thenqx = 60qy = 90 GraphicsWindow.BrushColor = "LightBlue"GraphicsWindow.FillRectangle(200, 220, 100, 80) GraphicsWindow.FillRectangle(20, 50, 460, 100) GraphicsWindow.BrushColor = "Blue"GraphicsWindow.DrawBoundText(qx - 20, qy, 420 "" + Q[passedQuestion])currentAnswer = A[passedQuestion]Else Program.Delay(1000)GraphicsWindow.ShowMessage("Your Score is " + score, "Game Over")Program.End()EndIfi = i + 1EndSubSub OnButtonClickedclickedButtonCaption = Controls.GetButtonCaption(Controls.LastClickedButton)If currentAnswer = clickedButtonCaption Then lastAnswer = "Correct"Shapes.Move(resultTextBox, 220, 250) score = score + 1ElselastAnswer = "Incorrect"Shapes.Move(resultTextBox, 212, 250)EndIfShapes.SetText(resultTextBox, lastAnswer) Shapes.SetText(scoreTextBox, "Score: " + score)StartGame()EndSub