1 / 13

Programming games using Visual Basic

Programming games using Visual Basic. Files; files vs. databases Reprise on state of program Lab/HW: work on projects, final project. Files. also known as ‘flat files’ or external files.

Download Presentation

Programming games using Visual Basic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming games using Visual Basic Files; files vs. databases Reprise on state of program Lab/HW: work on projects, final project.

  2. Files • also known as ‘flat files’ or external files. • Files exist independently of the VB program. Used to hold data that must be maintained ‘in-between’ executions of the program. • Files hold records • Records may hold individual fields • Only structure is sequencing of records. • You code everything: additions, modifications, deletions of records.

  3. Databases • Databases are complex collections of data. • tables • records • fields • reports (queries) • relationships (cross-references) among fields • built-in checks • Databases are implemented with ‘stand-alone’ database management systems (for example, File Maker Pro, Access, MySQL, DBII, Oracle products)

  4. File versus database • File implementation • generally cheaper (no use of DBMS) • less storage space • quicker execution • quicker implementation (assuming simple tasks) • Database implementation • quicker implementation (assuming that requirement is for all the standard tasks: sequencing to record, implementation of queries, adding, modifying, deleting)

  5. Files versus databases • Move to databases (or initiate project with databases) if • Complex • and tables suit the complexity. Certain applications are not suited to tables. • more than one program using the information • potential for expansion • already have database software installed & programmers trained

  6. Game applications • Saving set of best scores • Saving state of game in order to resume the game • ?

  7. Side trip: strings • Visual Basic strings are • DIM strName as String • Basic data type • Flexible in length but you can specify a fixed length string: • DIM strCourseName as String * 10 • Other programming languages may handle strings differently: • Char as the primitive data type, with strings implemented as arrays of Char's.

  8. VB types fixed length string Private Type bestdata strBname as String * 20 intBscore as Integer End Type … Dim newbest as bestdata … newbest.strBname = strPlayername intTop = newbest.intBscore

  9. VB Files: Opening intLen = Len(newBest) Open “best.dat” for Random as intBest Len=intLen Open is used to allow VB to set up use of the file. best.dat is the filename & extension Random indicates how the file will be used. It is the most general: additions, deletions, changes, and in any order intBest sets up a file number. (Since only one file is used in the bestscores project, it could be replaced by the constant 1) intLen tells VB how big the records are for this file.

  10. VB files: read & write Get #intBest, i, oldbest intBest indicates the file. The # is required. Use what you coded in the Open statement i indicates which record number oldbest is where the data will be put Put #intBest, i, newbest newbest holds the data (in this case, a string and an integer) to be written to the file.

  11. File issues • Does the file need to exist before the application? • If you open a file for writing (output), will 'the system' create the file for you? • Visual Basic will create the file if it does not exist. • When reading from a file, how do you know when you have reached the end-of-file? • See chapter 10.

  12. State of the game • What information is required to store and resume • mix & match cartoons • chance • memory • hangman • cannonball • quiz show • minesweeper • tic tac toe • variations • When would you want to store the history of a game?

  13. Homework/lab • Manage your time • work on your final project • Be prepared to show projects next week • We do have Wednesday class • Final quiz 5/13 • Last day to show work: 5/8.

More Related