4.4 advanced games

  • 547 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
547
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
6
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • Solution:' Copyright (c) Microsoft Corporation. All rights reserved.GraphicsWindow.Hide()GraphicsWindow.Height = 450GraphicsWindow.Width = 600GraphicsWindow.Top = ( Desktop.Height - 450 ) / 2GraphicsWindow.Left = ( Desktop.Width - 600 ) / 2GraphicsWindow.CanResize = "False"GraphicsWindow.Show()paddleImage = Program.Directory + "
    ectangle.png"ballImage = Program.Directory + "circle.png"Left = 42bStartY = 35CreatUI()hitCount = 0GraphicsWindow.MouseMove = MouseActionFor index = 0 To 15Array.SetValue("PinkBricks", Index, 1)Array.SetValue("VioletBricks", Index, 1)Array.SetValue("AquaBricks", Index, 1)EndforInitBricks()score = 0ShowScore()gw = GraphicsWindow.Widthgh = GraphicsWindow.Heighty = gh - 28Shapes.Move(ball, x, y)dX= 1dY =-2Loop:x = x + dXy = y + dYIf x >= gw - 16 Or x <= 0 ThendX= -dXEndIfIf y <= 0 ThendY = -dYEndIfpadX = Shapes.GetLeft(paddle)If y >= gh - 28 + 2 And x >= padX And x <= padX + 70 Then y = gh - 28 + 2 hitCount = hitCount + 1If Math.Remainder(hitCount, 3) = 0 Then For Index = 0 To 15HidePinkBrick()HideVioletBrick()HideAquaBrick()EndforbStartY = bStartY + 20InitBricks()EndIfTestAqua:For Index = 0 To 15If Array.GetValue("AquaBricks", Index) = 1 ThenIf bStartY > gh - 160 ThenGotoEndGameEndIfEndIfEndForTestViolet:For Index = 0 To 15If Array.GetValue("VioletBricks", Index) = 1 ThenIf bStartY > gh - 100 ThenGotoEndGameEndIfEndIfEndForTestPink:For Index = 0 To 15If Array.GetValue("PinkBricks", Index) = 1 ThenIf bStartY > gh - 40 ThenGotoEndGameEndIfEndIfEndForEndTest:dX= dX- 2 + (x - padX) / 30 If score = oldScore ThenIf score <> 0 Then score = score - 1EndIfEndIfoldScore = scoreShowScore()dY = -dYEndIfShapes.Move(ball, x, y) Program.Delay(5)If y > bStartY - 16 And y < bStartY + 20 Then Index = (x+8) / 40 Index = Math.Floor(Index)If Array.GetValue("PinkBricks", Index) = 1 Then If Index=8 ThenElseArray.SetValue("PinkBricks", Index, 0)HidePinkBrick() Left = Left - 1 score = score + 15ShowScore()EndIfdY = -dYgameFinish() EndIfEndIfIf y > bStartY + 44 And y < bStartY + 80 Then Index = (x + 8) / 40 Index = Math.Floor(Index) If Array.GetValue("VioletBricks", Index) = 1 ThenIf Index=4 Or Index=11 ThenElse Array.SetValue("VioletBricks", Index, 0)HideVioletBrick() Left = Left - 1 score = score + 10ShowScore()EndIfdY = -dYgameFinish() EndIfEndIfIf y > bStartY + 104 And y < bStartY + 140 Then Index = (x + 8) / 40 Index = Math.Floor(Index) If Array.GetValue("AquaBricks", Index) = 1 ThenIf Index = 2 Or Index = 7 Or Index = 13 ThenElse Array.SetValue("AquaBricks", Index, 0)HideAquaBrick() score = score + 5ShowScore() Left = Left - 1EndIfdY = -dYgameFinish()EndIfEndIfIf y < gh Then Goto LoopEndIfEndGame:GraphicsWindow.ShowMessage("Your score is: " + score, "Game Over")Program.End()Sub CreatUIGraphicsWindow.Title = "Paddle Game"GraphicsWindow.FontSize = 14 paddle = Shapes.AddImage(paddleimage) ball = Shapes.AddImage(ballimage)EndSubSub MouseActionpaddleX = GraphicsWindow.MouseXShapes.Move(paddle, paddleX - 10, GraphicsWindow.Height - 14)EndSubSub ShowScoreGraphicsWindow.BrushColor = "White"GraphicsWindow.FillRectangle(520, 10, 200, 20)GraphicsWindow.BrushColor = "Black"GraphicsWindow.DrawText(500, 10, "Score: " + score)EndSubSub InitBricksFor Index = 0 To 15 If Index = 8 ThenGraphicsWindow.PenColor = "Black"GraphicsWindow.BrushColor = "Gray"ElseIf Array.GetValue("PinkBricks", Index) = 1 ThenGraphicsWindow.PenColor = "Black"GraphicsWindow.BrushColor = "Pink"ElseGraphicsWindow.PenColor = "White"GraphicsWindow.BrushColor = "White"EndIfEndIfGraphicsWindow.FillRectangle(Index * 40, bStartY, 40, 20)GraphicsWindow.DrawRectangle(Index * 40, bStartY, 40, 20)GraphicsWindow.BrushColor = "Violet"If Index = 4 Or Index=11 ThenGraphicsWindow.PenColor = "Black"GraphicsWindow.BrushColor = "Gray"ElseIf Array.GetValue("VioletBricks", Index) = 1 ThenGraphicsWindow.PenColor = "Black"GraphicsWindow.BrushColor = "Violet"ElseGraphicsWindow.PenColor = "White"GraphicsWindow.BrushColor = "White"EndIfEndIfGraphicsWindow.FillRectangle(Index * 40, bStartY + 60, 40, 20)GraphicsWindow.DrawRectangle(Index * 40, bStartY + 60, 40, 20)GraphicsWindow.BrushColor = "Aqua"If Index = 2 Or Index = 7 Or Index = 13 ThenGraphicsWindow.PenColor = "Black"GraphicsWindow.BrushColor = "Gray"ElseIf Array.GetValue("AquaBricks", Index) = 1 ThenGraphicsWindow.PenColor = "Black"GraphicsWindow.BrushColor = "Aqua"ElseGraphicsWindow.PenColor = "White"GraphicsWindow.BrushColor = "White"EndIfEndIfGraphicsWindow.FillRectangle(Index * 40, bStartY + 120, 40, 20)GraphicsWindow.DrawRectangle(Index * 40, bStartY + 120, 40, 20)EndForEndSubSub HidePinkBrickGraphicsWindow.PenColor = "White"GraphicsWindow.BrushColor = "White"GraphicsWindow.FillRectangle(Index * 40, bStartY, 40, 20)GraphicsWindow.DrawRectangle(Index * 40, bStartY, 40, 20)EndSubSub HideVioletBrickGraphicsWindow.PenColor = "White"GraphicsWindow.BrushColor = "White"GraphicsWindow.FillRectangle(Index * 40, bStartY + 60, 40, 20)GraphicsWindow.DrawRectangle(Index * 40, bStartY + 60, 40, 20)EndSubSub HideAquaBrickGraphicsWindow.PenColor = "White"GraphicsWindow.BrushColor = "White"GraphicsWindow.FillRectangle(Index * 40, bStartY + 120, 40, 20)GraphicsWindow.DrawRectangle(Index * 40, bStartY + 120, 40, 20)EndSubSub gameFinishIf Left = 0 ThenGraphicsWindow.ShowMessage("Well Done! Your score is: " + score, "Game Over") Program.End() EndIfEndSub

Transcript

  • 1. Microsoft® Small Basic
    Advanced Games
    Estimated time to complete this lesson: 1 hour
  • 2. Advanced Games
    In this lesson, you will learn how to:
    Create advanced games by using basic elements, objects, and other advanced concepts of Small Basic.
  • 3. Advanced Games in Small Basic
    Let’s see how we can use all these concepts in Small Basic to create advanced games.
    Congratulations! You are now well acquainted with programming fundamentals as well as advanced concepts of Small Basic.
    You have learned to use basic programming concepts in Small Basic. You have also been introduced to Small Basic objects and advanced concepts.
  • 4. Tic-Tac-Toe – The Game
    You are familiar with the popular Tic-Tac-Toe game. Let’s see how we can create a Small Basic version of this popular game.
    Notice how you use the Shapes object to draw various game elements. You use mouse events to enable the user to place Xs on the graphics window.
    The user and the computer try to win the game by placing Xs or Os in a horizontal, vertical, or diagonal row before the other does.
  • 5. Tic-Tac-Toe – How to Play
    So how do you play this game?
    Steps to play the game:
    • This game involves 2 players, the user and the computer. Each player takes a turn placing an X or an O on the 3x3 playing area. The game starts with the user placing an X on the board.
    • 6. The players alternately place Xs and Os and on the playing area.
    • 7. The player who first places three Xs or three Os in a horizontal, vertical, or diagonal line wins the game.
  • Tic-Tac-Toe – The Code
    Now let’s understand the code for the game in detail…
    • Use the GraphicsWindowto create the game interface.
    • 8. Use the Shapes object to create the playing area for the Xs and Os on the graphics window.
    • 9. Use mouse events and conditions like If-Else to describe various actions performed by the user and the computer during the game.
  • Let’s Summarize…
    Congratulations! Now you know how to:
    Create advanced games in Small Basic by using basic elements, objects, and advanced concepts of Small Basic.
  • 10. It’s Time to Apply Your Learning…
    Create a game that involves the following objects: a wall of colored and grey blocks, a ball, and a paddle. The wall is slowly moving downwards, towards the paddle. Using the ball, you must get rid of all the colored blocks before the wall hits the paddle.
    You use the mouse to move the paddle; the paddle controls the movement of the ball. The ball will bounce off grey blocks. You win the game if you get rid of all the colored blocks. You lose the game if the paddle misses the ball or if the grey blocks hit the paddle before you can remove all the blocks.