Download presentation
Presentation is loading. Please wait.
Published byLuke Hudson Modified over 9 years ago
1
Lecture Roger Sutton c.r.sutton@kent.ac.uk CO331 Visual Programming 18: Program design 1
2
CO331 Visual Programming Introduction When constructing a software solution a number of elements are addressed (These will become more sophisticated as knowledge and experience grows) 1. The user interface (Form1) 2. The program design (a)Class definition / construction / importation (b)Module definition / construction / importation (c)Interface methods (Form1 code) 3. Testing (a)Identify inputs (b)Identify outputs Construct test cases and form test plan 2
3
CO331 Visual Programming Example Consider the game of noughts and crosses played by two people (not against the computer ….yet!) The required program is to provide a platform to play the game by recording the ‘goes’, identifying a winner and keeping score. Accordingly we may envisage something similar to the game played with pencil and paper: 3 Score: Peter John
4
CO331 Visual Programming Form design Requires some knowledge of the implementation (programming language) to be aware of the facilities available. First thoughts! Questions? 4 Finish Score Player 1 Player 2 34 NoughtsCrosses Draw Are players to be identified? Do players take turns to be noughts and then crosses? Who starts? StartGame over – Crosses win
5
CO331 Visual Programming Form design – cont’d Label controls and, if significant, indicate names: 5 Finish Score Player 1 Player 2 34 NoughtsCrosses Abandon PictureBox: picbox Labels RadioButtons: rdbPlayer2 rdbPlayer1 Textboxes: txtPlayer1Score txtPlayer2Score Button: cmdFinish Button: cmdAbandon Start Label (Flashing) Play Button: cmdPlay Label: lblResult
6
CO331 Visual Programming Analysis Suppose : 1. The players are identified as Player 1 and Player 2, and Player 1 is identify before the program is run. 2. Player 1 - Crosses start 3. Play will alternate during a game and on the start of subsequent games 4. A game can be abandoned by clicking the ‘Abandon’ button Picture design: Use 50 pixel black and white squares located by top left vertex 6
7
CO331 Visual Programming Class design 1.Identify any class definitions to be imported: Square 2.Identify any classes to be constructed and specify their members (a)a (chequered) Board display area show: to make the board visible (b)a Game – to record goes and check for winner display area entries: an integer array to store goes, -1 for nought and 1 for cross turns: to store number of turns taken getEntry: to retrieve a give entry value showSymbol: to draw symbol gameOver:to check for winner and indicate winning line or indicate draw 7
8
CO331 Visual Programming Class definitions Board 8
9
CO331 Visual Programming Class definitions – cont’d Game 9
10
CO331 Visual Programming Class definitions – cont’d Game – cont’d 10
11
CO331 Visual Programming Form1 methods Brainstorm what operations need to carried out and order them: Initialisation Set initial values of global (?) variables, E.g. scores Set up interface Start game Initialise variables specific to a particular game, E.g. record of goes, number of turns Display board Flash prompt Manage a ‘go’ 11
12
CO331 Visual Programming Form1 methods – cont’d Decide how methods will be invoked: click-handler, call from within some other method? Initialisation - MyBase.Load Start game - cmdPlay Flash prompt - Timer1.Tick Manage a ‘go’- picBox.MouseDown Check for a win - Game method/function Identify winner - Game method/function In this way the problem is broken down into smaller subtasks. Tackle each of these subtasks; if necessary, develop their solution in separate projects. Assemble the whole and adjust to work. This might mean going back and modifying some of the constituent components. 12 Run
13
CO331 Visual Programming Review code Revisit the code to Eliminate redundancy Make more readable/intelligible by restructuring, breaking large methods into smaller parts, consider introducing functions Check the need for global variables and where possible make local Introduce comments if not already present. Perform tests to identify problems, deficiencies, etc. Each time you complete a set of changes, re-run all test cases. 13
14
CO331 Visual Programming Looking for deficiencies Manage a ‘go’ 14
15
CO331 Visual Programming Example - deficiency What happens if a player selects an occupied cell? What will happen if player continues after game has been won? - Need to identify and prohibit these situations. Accordingly, we have 15
16
CO331 Visual Programming Deficiency – cont’d and: 16 Run
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.