Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mark Dixon Page 1 15 – Structured Programming. Mark Dixon Page 2 Admin: Coursework 3 – Test In class test –9 Feb 2010 –2 Feb 2010: revision (technique)

Similar presentations


Presentation on theme: "Mark Dixon Page 1 15 – Structured Programming. Mark Dixon Page 2 Admin: Coursework 3 – Test In class test –9 Feb 2010 –2 Feb 2010: revision (technique)"— Presentation transcript:

1 Mark Dixon Page 1 15 – Structured Programming

2 Mark Dixon Page 2 Admin: Coursework 3 – Test In class test –9 Feb 2010 –2 Feb 2010: revision (technique) session 50 mins short answer (5 - 6 words max) 25% of coursework mark

3 Mark Dixon Page 3 Questions: Functions Consider the following code: Function Smallest(num1, num2) If num1 < num2 Then Smallest = num1 Else Smallest = num2 End If End Function name a function. what is left in small after the following is executed? Dim small small = Smallest(23, 15) 15 Smallest

4 Mark Dixon Page 4 Session Aims & Objectives Aims –To highlight the fundamental ideas of the structured programming paradigm Objectives, by end of this week’s sessions, you should be able to: –create an abstract data type, which includes data, and routines –use this to reduce code length

5 Mark Dixon Page 5 Example: Ball Bounce v1 Ball Bounce Option Explicit Dim x Dim y Dim xInc Dim yInc Sub window_onLoad() window.setinterval "Main()", 20 xInc = 5 yInc = 3 End Sub Sub Main() x = imgBall.style.posLeft + xInc If x = document.body.clientWidth - imgBall.width Then xInc = -xInc Else imgBall.style.posLeft = x End If y = imgBall.style.posTop + yInc If y = document.body.clientHeight - imgBall.height Then yInc = -yInc Else imgBall.style.posTop = y End If End Sub

6 Mark Dixon Page 6 Structured Paradigm Program made up of –data structures, and –routines (procedures and functions) that process the data within those structures. Each routine should perform a single, clearly identifiable operation. Each routine should be self-contained Abstract data type = structure + procedures

7 Mark Dixon Page 7 Example: Ball Bounce v2 Option Explicit Dim x Dim y Dim xInc Dim yInc Sub Init(tmpXInc, tmpYInc) xInc = tmpXInc yInc = tmpYInc End Sub Sub Move(img) x = img.style.posLeft + xInc If x = document.body.clientWidth - img.width Then xInc = -xInc Else img.style.posLeft = x End If y = img.style.posTop + yInc If y = document.body.clientHeight - img.height Then yInc = -yInc Else img.style.posTop = y End If End Sub Ball Bounce Option Explicit Sub window_onLoad() window.setinterval "Main()", 20 Init 5, 3 End Sub Sub Main() Move imgBall End Sub BallBounce.htm Sprite.vbs

8 Mark Dixon Page 8 Example: Balloon Shoot Question: –what objects? –what variables? –what procedures / functions?

9 Mark Dixon Page 9 Tutorial Exercise: Ball Bounce Learning Objective: To create and use your own class. Task 1: Get the Ball Bounce examples (1, 2, and 5) from the lecture working. Task 2: Add a hit method to the sprite class, which detects the collision with another sprite. Task 3: Modify your page to count the number of hits between the two sprites. Task 4: Modify your page to make sprites bounce off each other. Task 5: Add another sprite.

10 Mark Dixon Page 10 Tutorial Exercise: Balloon Shoot Learning Objective: To create and use your own classes. Task 1: Create the Balloon Shoot example (from the lecture) using object oriented concepts (classes, properties, methods, and instances) hint: use some of the code from your Interceptor example (from last week)


Download ppt "Mark Dixon Page 1 15 – Structured Programming. Mark Dixon Page 2 Admin: Coursework 3 – Test In class test –9 Feb 2010 –2 Feb 2010: revision (technique)"

Similar presentations


Ads by Google