Visual Basic Games: Week 4 Recap Parallel structures Initialization Prepare for Memory Scoring Shuffling Homework: when ready, move on to next game/chapter.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Working with Intrinsic Controls and ActiveX Controls
Programming with Microsoft Visual Basic th Edition
Tonight’s JavaScript Topics 1 Conditional Statements: if and switch The Array Object Looping Statements: for, while and do-while.
Probability theory and average-case complexity. Review of probability theory.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 16 – Craps Game Application Introducing Random-Number.
VBA Modules, Functions, Variables, and Constants
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
Introduction to Arrays Chapter 7 Why use arrays? To store & represent lists of homogeneous values To simplify program code To eliminate the need to reread.
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 2 Tariq Aziz and Kevin Jones.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
CSE 115 Week 12 March 31 – April 4, Announcements March 31 – Exam 8 March 31 – Exam 8 April 6 – Last day to turn in Lab 7 for a max grade of 100%,
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Refreshing Your Skills for Chapter 10.  If you flip a coin, the probability that it lands with heads up is 1/2.  If you roll a standard die, the probability.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
MOM! Phineas and Ferb are … Aims:
Visual Basic Games: Prepare for Hangman
Visual Basic Games: Week 3 Global variables, parameters, Select, KeyDown Enable, Visible, Focus State of Game Read chapter 3.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Programming Games in Visual Basic: Data base Catch up questions Data base: generalities & specifics on Visual Basic links Lab: work on projects.
Chapter 12: How Long Can This Go On?
Recursion, Complexity, and Sorting By Andrew Zeng.
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
Arrays Code: Arrays Controls: Control Arrays, PictureBox, Timer.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming in Microsoft Access using VBA Using VBA to add functionality.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Applications Development
1 Advanced Computer Programming Lab Calculator Project.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
Programming games in Visual Basic Review programming & VB topics Insertion sort. Best times. Generate questions & answer patterns for quiz Lab/Homework:
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Controlling Program Flow with Decision Structures.
Ajax Dice Game Part 1. We saw that we could use the jQuery load() function, to dynamically load a piece of an html document into another html document.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 16 – Craps Game Application Introducing Random-Number.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
COM148X1 Interactive Programming Lecture 8. Topics Today Review.
Chance We will base on the frequency theory to study chances (or probability).
Programming with Visual Basic.NET. Quick Links Program Code The Code Window The Event Procedure Assignment Statements Using AutoList Radio Buttons Buttons.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Computer Science Up Down Controls, Decisions and Random Numbers.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
13 Lesson 1 Let Me Count the Ways Fundamental Counting Principle, Permutations & Combinations CP Probability and Statistics FA 2014 S-ID.1S-CP.3S-CP.5.
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Recap: If, elif, else If <True condition>:
BASIC PROBABILITY Probability – the chance of something (an event) happening # of successful outcomes # of possible outcomes All probability answers must.
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Conditions and Ifs BIS1523 – Lecture 8.
Memory Matching Challenge
CIS16 Application Development and Programming using Visual Basic.net
Items, Group Boxes, Check Boxes & Radio Buttons
Visual Basic: Week 5 Review User defined functions
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
GUI Programming in Visual Studio .NET
Presentation transcript:

Visual Basic Games: Week 4 Recap Parallel structures Initialization Prepare for Memory Scoring Shuffling Homework: when ready, move on to next game/chapter.

First 3 projects What were the controls? What were the events (what event procedures did you write)? What global variables were required? –"State of the game" consists of what is present on the screen plus any global variables.

Statements Assignment statement: intTotal = intDie1 + intDie2 For/Next: For I = 0 to 6 imgDie(I).Visible = False Next I Select Case Select Case intTotal Case intPointnum lblstatus = "You Win" blnfirstmove = true Case 7 lblstatus = "You Lose" blnfirstmove = true End Select If/Else/End If or IF/End If

Another compound statement: Do While For/Next does the statements 'in' the loop a certain number of times (though it can be based on variables) Do While does the statements as long as a condition is true: Do while condition … Loop

Parallel structures In mix & match, the listbox items responded to the elements in the control arrays –Sets of sets here: the items in the lstHats listbox corresponded to the elements of the imgHats control array: “floppy hat”  imgHats(0) In memory, control array holding file names and a control array of images. Using parallel structures is a very common technique. YOU make it happen.

Is there another way? Using parallel structures, call them implicit parallel structures, is necessary because the control objects are distinct and can’t be linked except by your code. For internal variables, there is something called types that puts corresponding data together: Private Type bestdata bname As String * 20 bscore As Integer End Type

Initialization Start of execution (Run menu / Start or the start icon) –Form_Load –Form_Activate (used in Quiz). Necessary when switching between forms. New game –Probably command button Click New move You have to understand, plan and program. Often need to clear / tidy up board. Set variables to 0 or the empty string OR not (wait for first/next action to set values).

Initialization What was required initialization in –Rock-paper-scissors –Mix and match –Chance

Ideas to improve/enhance interface rock paper scissors –add to or replace text with images player and computer? –score –? mix and match –better images—better fit of images –random feature? –? chance –rolling dice and/or random locations –remove text? –score –?

Memory / Concentration: Game Board consists of 16 cards, all showing blank side. Click on a card: it is 'turned over'. Click on a second card: it is 'turned over'. If images match, both cards are removed, otherwise, cards are 'flipped back'. Game is over when all matches made.

Implementation Requirements 8 pairs of images plus blank images for the "backs" names of images—all comparisons are done in terms of the names Pause time before cards removed or flipped back

What are events for which you must write event procedures?

Event procedures Form_load –set up & shuffle cards. This will be done using user- defined procedure so you don't have to write the code twice Click on image –will need to distinguish a first and a second turn New game button –restore cards and shuffle other buttons (Help, End)

User (this means you, the programmer) defined procedure Unlike event procedures, you name it as well as program it. You also issue calls to it. Private Sub delay(interval as Single) Dim sngStart as Single sngStart = Timer Do While Timer < (sngStart + interval) DoEvents Loop End Sub … call delay(1) built-in function. Returns seconds since midnight let's computer to other things, while waiting

About images Our implementation of memory is (purposely) different from mix & match and chance. –LoadPicture method is used to put the appropriate image into the control when required. This means that the images must be in the same drive/same folder as the program.

Scoring Can [just] use visible label, assume lblScore is the label control and intNewScore the internal integer variable holding the addition to the score Initialize: lblScore.Caption = 0 Update: intOldscore = Val(lblScore.Caption) lblScore.Caption = Format(intNewScore + intOldScore, “##0”) Note: this works even if intNewScore is negative. The “##0” makes sure 0 appears. What would be the changes if new scores were money AND if there could be scores with fractional parts?

Shuffling Have an array of N items of some data type Want to shuffle, that is, re-arrange the values to be randomly sorted. What is the criteria for success? –Answer: equal likelihood of any of the N possible permutations. How to do it? –Using Randomize, Rnd, etc.

A Shuffle method 6 things (why six? Because I have a single die) –How many permutations are possible? Start first with the last position. Pick randomly one of the first six to swap this one. Note: so one possibility is swapping with itself, for no change. Now move to next to last (5 th ). Pick randomly one of the first 5 to swap with this one. …

Construct deck of cards strSuits (1 to 4) as String strSuits(1) = “hearts” strSuits(2) = “spades” strSuits(3) = “diamonds” strSuits(4) = “clubs” strFaces(1 to 13) as String –What do I need to do to produce “A”, “1”,… “K” ??

Produce “deck” Sub setupdeck() Dim i As Integer, j As Integer, k As Integer k = 1 For i = 1 To 4 For j = 1 To 13 strDeck(k) = strSuits(i) & strValue(j) k = k + 1 Next j Next i End Sub

Swapping Whenever you swap two things, you will need a temporary variable: thing1, thing2, holder each variables holding a value. An assignment statement takes the value of the right side, in this case, the value in that variable and puts it in (assigned it to) the variable named by the left side. holder = thing1 thing1 = thing2 thing2 = holder

Shuffle Private Sub cmdShuffle_Click() Dim i As Integer, k As Integer Dim holder As String For i = 52 To 1 Step -1 k = Int(Rnd * i) + 1 ' k is random choice 1 to i holder = strDeck(k) strDeck(k) = strDeck(i) strDeck(i) = holder 'swapped values in k and i positions of strDeck array Next i End Sub

Homework Read chapter 4 (Memory/Concentration) and start implementing it You can make your own images!