Visual Basic .NET BASICS

Slides:



Advertisements
Similar presentations
Microsoft® Small Basic
Advertisements

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
Object Oriented Programming with Java (150704).   Applet  AWT (Abstract Window Toolkit)  Japplet  Swing Types of Applet.
Visual Basic.NET BASICS Lesson 10 Do Loops. 2 Objectives Explain what a loop is. Use the Do While and Do Until loops. Use the InputBox function. Use the.
© by Pearson Education, Inc. All Rights Reserved. continued …
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
Chapter 13: Advanced GUI and Graphics
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 3 Working with Symbols and Interactivity.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
XP Tutorial 5 Buttons, Behaviors, and Sounds. XP New Perspectives on Macromedia Flash MX Buttons Interactive means that the user has some level.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
CST238 Week 6 Questions / Concerns? Announcements – HW#2 due next Monday (project concept/preliminary design) – Check-off Take Home lab#5 Comment about.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
BIM211 – Visual Programming Objects, Collections, and Events 1.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 12: How Long Can This Go On?
Review for Mid-term! October 26, Review Homework Worksheet True or False Operators are symbols that perform specific operations in Visual Basic.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
KeyListener and Keyboard Events Another type of listener listens for keyboard entry – the KeyListener which generates KeyEvents –to implement KeyListener,
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Events with Data Arguments Data Values Travel with e.
Visual Basic.NET BASICS Lesson 3 Events and Code.
Visual Basic.NET BASICS Lesson 5 Exponentiation, Order of Operations, and Error Handling.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Visual Basic Programming Chapter Six Notes Repetition and the Do Statement ADDING ICONS TO YOUR FORM –It is possible to add an ______________ to your title.
Tutorial 6 The Repetition Structure
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Learning Unity. Getting Unity
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
Macromedia Flash 8 Revealed WORKING WITH SYMBOLS AND INTERACTIVITY.
Test 2 Review. General Info. All tests are comprehensive. You are still responsible for the material covered prior to the first exam. You will be tested.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Events with Data Arguments Data Values Travel with e.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Microsoft Visual Basic 2005 BASICS Lesson 3 Events and Code.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
Visual Basic.NET BASICS Lesson 11 List Boxes, For Next Loops, and Label Settings.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
Visual Basic.NET BASICS Lesson 14 Menus and Printing.
PaintPictureBoxDemo Refers to the PaintPictureBoxDemo Visual Basic Program Included With The Lecture.
Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
(More) Event handling. Input and Windowed-OS’s Windowed OS’s (Windows, OSX, GUI-linux’s) send messages (events) when the user does something “on” the.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Objective of the lesson Use Blockly to make a dice for Snakes and Ladders All of you will: – Make an image which displays when you press a button Most.
Programming Right from the Start with Visual Basic .NET 1/e
Visual Basic .NET BASICS
PYGAME.
Using Procedures and Exception Handling
Event Driven Programming
Items, Group Boxes, Check Boxes & Radio Buttons
ICT Gaming Lesson 3.
Microsoft Visual Basic 2005 BASICS
GUI Programming in Visual Studio .NET
Presentation transcript:

Visual Basic .NET BASICS Lesson 16 Case Study — Snake Game

Objectives Run the Snake Game. yo Objectives Run the Snake Game. Draw with individual pixels and use the Paint event. Describe how the Snake Game draws and controls the direction of the snake. Describe how the code of the Snake Game functions.

Running the Snake Game The Snake Game that you created in Lesson 1 is an example of how a simple game can be created in Visual Basic .NET with very little code. Writing a program like the Snake Game is based on a very simple principle.

Drawing with Pixels and Using the Paint Event Handler There are only four Visual Basic .NET features that the Snake Game uses that you have not learned: The feature that allows you to create an image and draw it on your form The method that allows you to draw on an image one pixel at a time A feature that allows you to retrieve the color of a specific pixel A paint event that prevents the graphics you draw from being erased if another window covers the graphic you have already drawn

Creating a Graphic Image A Bitmap object is an object used to work with images defined by pixel data. A Bitmap object and a Graphics object are created using Dim statements. The DrawImage method can be called directly after any change has been made to the image. The Paint method is called whenever the form needs to be drawn.

Using the SetPixel Method The SetPixel method of the Bitmap object is an easy-to-use feature that allows you to change the color of individual pixels on a bitmap. To use SetPixel, you identify the X,Y coordinates and specify a color for the pixel.

Using the GetPixel Method The GetPixel method returns the Color structure of a pixel at the specified pixel. Use SetPixel to change the color of a pixel and use GetPixel to determine the current color of a pixel. The ToArgb method is used to convert this structure into a more easily compared integer value.

Handling the Paint Event The Paint event is called whenever an object is resized, covered, uncovered, minimized, and then restored or when the Refresh event is called. This event can make sure that the board is redrawn or repainted to prevent from losing data from the form.

How the Snake Game Draws the Snake The snake that appears on the Snake Game is drawn one pixel at a time using SetPixel. There are four variables that are key in controlling the snake.

Analyzing the Snake Game Code The primary work of the game is done in the Start Game button’s Click event procedure. The Application.DoEvents function allows other events to be processed as the Start Game button’s Click event procedure is being executed. The Do Events function also allows the user to click the direction buttons.

Form-Level Variables There are three form-level variables necessary. First, we need a way to stop the program if the user clicks the Stop Game button. The intXFactor and intYFactor variables must be form-level because the factors will be changed by the direction buttons and used by the Start Game button.

The Start Game Button The Start Game Click event procedure is the primary code for the game. At the heart of the event procedure is a loop. First six local variables are declared to be used in this procedure. Now that all the initial work is done, the DrawBoard method is called to draw a box with a border around it.

The Start Game Button’s Loop The loop adds one pixel to the snake with each interaction. The intXFactor and intYFactor determine where the next pixel is added. The GetPixel method looks at the color of the next pixel that the program would write to and makes sure that it is not already clrSnakeColor. Clicking the End Game button would change the value of blnStop, which would end the game.

Changing the Coordinate Factors The intXFactor and intYFactor variables are adjusted through the Click event procedures of the four direction buttons. Because intXFactor and intYFactor are form-level variables, the new values for these factors will remain set until one of the other direction buttons changes the values.

The Stop Game Button The code for the Stop Game button simply changes the blnStop to True. If the Stop Game button is pressed while the game is in play and blnStop is changed to True, the loop will stop.

The Quit button The Quit button differs from the Stop Game button. The Quit button ends the program.

Summary The Snake Game is an example of a simple game created in Visual Basic. NET. The SetPixel method allows you to change the color of individual pixels on a bitmap. The GetPixel method retrieves the color of the specified pixel on a bitmap. The Refresh method causes the Paint event to execute.

Summary (continued) The Paint event handler can be used to redraw objects that are erased when a form is covered or minimized. The Snake Game keeps track of a point on the form where the next pixel will appear as the snake grows. The snake is controlled by two factors. One factor specifies the change in the X coordi-nate and the other factor specifies the change in the Y coordinate.

Summary (continued) Once in play, the Snake Game continues until the user runs the snake into a wall or the snake’s tail. The Stop Game and Quit buttons also end the game. The direction buttons change the factors that control the direction of the snake. The variables that store the factors are form-level so that multiple buttons can change the value of the factors.

Summary (continued) The color of the wall and snake are con-trolled by changing the value of clrSnakeColor. The speed of the snake is controlled by adjusting the value in the Sleep method call.