Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson Objectives Aims You should be able to:

Similar presentations


Presentation on theme: "Lesson Objectives Aims You should be able to:"— Presentation transcript:

1 Lesson Objectives Aims You should be able to:
Identify the components of a problem Identify the components of a solution to a problem Determine the order of the steps needed to solve a problem Identify the sub-procedures necessary to solve a problem

2 Note Before we start: This lesson makes use of a task described in the “learn VB” course. You can get a LOT of extra help/hints in that document if you’ve not already read it.

3 Procedure Procedure: A block of code which performs a specific task or sub task It may allow data to be sent in and may give data out again when complete (passing variables) It is re-usable It can be called from anywhere in your code

4 Thinking procedurally
Thinking procedurally is simply the ability to: Break a problem down into chunks Decide which could be a re-usable block of code Work out what inputs the procedure will need to do the task Work out what outputs the procedure should produce Make those procedures

5 Task The only way to learn this is practise, applying it to programming tasks. You are going to make a program which simulates a really simple slot machine type game. It will do the following things: Give the user £1 starting money and take 20p off per go Spin the reels Display the result of the spin – win or loss depending on some simple rules Allow the user to select if they want another go or to take their winnings.

6 Method Decompose the problem – what are the main tasks this program should perform Abstract – Make sure you are only focussing on what is strictly necessary to complete the task Decide what variables your program will need Algorithms – what will your code need to calculate/manipulate/produce Outline algorithm – what will the basic structure of your code be? Decide what procedures you should produce.

7 Have a go, then I’ll walk you through my thinking.

8 As I see it the program will need to:
Decompose/Abstract As I see it the program will need to: Spin the reels Compare the reels to check the outcome Calculate profit/loss It will need to do all of these things whilst the player has enough money to play again (or quits)

9 Variables If we read the task, we obviously need to store the following information: Money Reel 1 value Reel 2 value Reel 3 value

10 Algorithms Loop while money is > 0 and user wants to play again Reduce money by 20p Do spin Show outcome of spin Update money based on outcome Exit loop if no money left Ask user if they want to proceed Exit loop if they don’t want to End loop

11 Procedures Clearly the following things happen repeatedly: Spinning the reels Calculating the outcome of the spin Updating the money the user has

12 Code outline This would lead us to this initial structure in VB:

13 Next steps… The outline algorithm goes in the MAIN() sub and controls our program – it should be trivial to convert to code Final step – outline what each sub will do.

14 Main() Create the game variables Loop round, allowing the user to play until no more money or no more turns required Call DoSpin() Call CompareReels() Display outcomes Call UpdateMoney() Ask if the player wants another turn. DoSpin() – Inputs (none), Outputs (reel values) Generate three random numbers – one for each reel Return these numbers CompareReels() – inputs (reel values), outputs (winnings/losses) Compare the three random numbers to the rules: Return any winnings or losses this combination will cause UpdateMoney() – inputs (player money, winnings/losses), outputs (updated player money) Reduce the player’s available money by 0.2 Increase or decrease the player’s money according to any winnings they may have earned or losses they have made Display the players current balance

15 Next step Code it!

16 Review/Success Criteria
You should know: The


Download ppt "Lesson Objectives Aims You should be able to:"

Similar presentations


Ads by Google