220 likes | 406 Views
Programming Games in Visual Basic. Introductions Origin of Book & Course overview Administration Assignment: CourseInfo survey. Start reading textbook. Introductions. Jeanine Meyer Associate professor, Math/Computer Science & New Media formerly at Pace University
E N D
Programming Games in Visual Basic Introductions Origin of Book & Course overview Administration Assignment: CourseInfo survey. Start reading textbook. MAT 1420.45 Meyer Week 1
Introductions • Jeanine Meyer • Associate professor, Math/Computer Science & New Media • formerly at Pace University • IBM (research, manufacturing staff, education, grants) • Staff development for New York City schools • Also teaching: Creating Web Documents • Son in Cornell graduate school, daughter just started at American Health Foundation • Hobbies/interests: origami, flute, cooking and eating, aerobics, reading novels, travel and… programming • Zach Wolliner, teaching assistant • You? MAT 1420.45 Meyer Week 1
Origin of book • Several years ago, at Pace, I programmed minesweeper (programmed the computer action for minesweeper) as a way of getting more familiar with Visual Basic. • Observations: • Fun! Also, did the job. • Most of our CIS 101 students, many CS/IS students • Don’t like programming • Don’t understand how features can be used • Aren’t very good at it • So…I recruited a friend, we wrote, some said it wasn’t serious enough, some said the games were too difficult, we re-wrote, piloted chapters, got a publisher, re-wrote and the textbook is the result! MAT 1420.45 Meyer Week 1
Course topics • Features of Visual Basic common to all programming languages • Logic, statements, compound statements • Variables, subroutines & functions • Features of Visual Basic common or similar to ‘modern’ programming systems • Design of graphical user interface • Event handling • Objects • Some devotees of OO would argue here. • Topics in Paint Shop Pro (Photo Shop is fine). You may also acquire images from Web, scanning, etc. MAT 1420.45 Meyer Week 1
Brief introduction to a few terms • A variable holds values (numbers, strings of characters, Booleans (true or false)) • Statement types include • Assignment statements • Calls to procedures • Compound statements IF/Then/Else; For/Next; Select • An event is something that can happen that Visual Basic can detect (e.g., player clicking a button). • A control object is something that can be placed on a VB form (user interface) that has events and properties. MAT 1420.45 Meyer Week 1
Course administration • Web site: courseinfo.purchase.edu • You will be enrolled in this course. Take survey. • Course schedule. Announcements. Grading. • Discussion forums for problems & comments • Lecture/demonstration & work on games in class. You need to work inside and outside of class. Repetition of concepts! • Presentations in class. You may learn from anyone, including each other, but you are responsible & must be able to explain everything in your projects. • Two quizzes. Turn in projects. • Some choices, including final project can be your own game or enhancement of text game. MAT 1420.45 Meyer Week 1
Rock-paper-scissors Mix & match cartoons Chance dice game Memory Hangman Quiz I Spring Vacation Cannonball Files/best scores feature Final project: enhanced version of text projects (e.g., adding scoring & best scores) advanced text project (quiz show, minesweeper, tic tac toe) your own choice of game, including original game Quiz II (Final) Schedule MAT 1420.45 Meyer Week 1
What is programming? MAT 1420.45 Meyer Week 1
Computers must be programmed • Some one, generally a collection of people, have specified the actions of ‘the computer’. • ‘Actions’ can include • Performing a calculation • Moving data around • Accepting input or producing output • Testing something and doing different things depending on the results MAT 1420.45 Meyer Week 1
Programming involves • Problem solving (more or less independent of the programming language) • Specifying solution in terms of the programming language & environment • Program = sequence of statements (certain statements can change the flow of control, e.g., conditionals & loops) • Additional issue(s) involve the user interface: input (information & directives from the user) & output (information presented & actions taken) MAT 1420.45 Meyer Week 1
Sample statements • Assignment Note: equal sign doesn’t mean equal! • count = 0 • count = count + 1 • studentScores(current) = (project1 + project2 + 2* project3)/4 • If…Then…Else…End If IF class = ‘Visual Basic’ then schedule = ‘Monday/Wednesday’ Else schedule = ‘Tuesday/Thursday’ End IF • Select Case Select Case month Case ‘Sept’, ‘Apr’, ‘Jun’, ‘Nov’ days = 30 Case ‘Feb’ days = 28 Case Else days = 31 End Select MAT 1420.45 Meyer Week 1
If actions must be specified completely…. • How do we put randomness into a program • For example, throw of dice, layout of mines in minesweeper • Answer: VB (and other programming languages) have built in features to produce pseudo-random sequences of numbers. • They appear random, but they are calculated. MAT 1420.45 Meyer Week 1
Pseudo-random functions • VB has Randomize and Rnd • Typical use: Randomize … dice1Value = 1 + Int(Rnd * 6) dice2Value = 1 + Int(Rnd * 6) MAT 1420.45 Meyer Week 1
How to specify the actions for shoe tying • Typical situation: easy to do but more difficult to articulate how to do it. • Atypical: physical actions and not just data/information. • Issues of deciding level of specification. • Get in small groups and write down instructions as you would teach a child. MAT 1420.45 Meyer Week 1
Complete cards • Name • E-mail • Phone number (for emergencies) • Experience / courses in programming • Major (interest/career ideas) MAT 1420.45 Meyer Week 1
Assignment • Start reading text. • After CourseInfo orientation session: Go to http://courseinfo.purchase.edu and sign on to this course. • Take survey • Review schedule, grading allocation. • I teach Tuesdays from noon to 2:20, and will be on campus before & after class. I will be in my office (3003) before class Mon. & Wed. Send e-mail to fix a time to meet. MAT 1420.45 Meyer Week 1
Visual Basic • Design time • Design interface (place controls on the Form) • Program the event handlers (type in code into the specific event procedures one at a time). More advanced projects involve programming user-defined procedures & incorporating other code such as Active X controls. • Run time = execution time • Test program. Turn over to users = players. MAT 1420.45 Meyer Week 1
Controls • A Visual Basic project contains at least one Form (the user interface) and code. • Visual Basic has different things = controls that can be placed on a form. • Textbox, label, command button, more… • Each control (including the form itself) has properties & events. You may choose to write code for the event handlers = event procedures for some of these events. • Properties can be set at design time and read & changed during run time. • You will ignore most of the properties and most of the events. MAT 1420.45 Meyer Week 1
Examples • Form has properties: caption, size, background color, etc. and event Form_Load executed when project is started.. • Textbox has properties: initial text, size, position, color, font, etc. Users can enter text and a program can read and write text. • Label has properties: caption, size, position, color, font. Label captions can be changed by code. • Command button: caption, size, color, etc. One event is the Click event. • Other properties & other events MAT 1420.45 Meyer Week 1
Hello, world • Refers to the typical first program in many introductory texts. • By the end of class today, you will produce a more complex program than you could produce at the end of most introductory classes in other languages. Why? • VB provides built-in controls for the interface & VB runtime handles ‘listening’ for events. • VB programming environment (WYSIWYG) helps in programming and debugging. MAT 1420.45 Meyer Week 1
WARNING on reading/using text • Read the text, especially the first sections. Do not jump to later sections and copy code. • The text is 'in English'. You need to translate into Visual Basic. For example, "…make die1 plus die2 to be the total…" translates to total = die1 + die2 MAT 1420.45 Meyer Week 1
Rock-paper-scissors • Computer does (your programming will make the ‘computer’ do) • Handling of player move • Computer move • Determining who wins • Start work tonight. Read text. Start and see how far you can get. MAT 1420.45 Meyer Week 1