Using a different image than normal Multiple images for a class Controlling the mouse click Controlling the keys pressed Launching an input dialog box.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

MS-Word XP Lesson 7.
Follow the man….. Read the phrases on the shimmering neon lights and write down the correct economic term to match that phrase.
Microsoft Excel Khan Mohammad Mahmud Hasan
CPIT 102 CPIT 102 CHAPTER 1 COLLABORATING on DOCUMENTS.
 Draft timetable has the same times as this semester: - ◦ Monday 9:00 am to 12:00 noon, 1:00 pm to 3:00 pm. ◦ Tuesday 9:00 am to 12:00 noon, 1:00 pm.
Program: Little Crab Mr Gano.
Add the word linked between the words or and information in the first line of the text. submit.
Arrays, Loops weeks 4-6 (change from syllabus for week 6) Chapter 4.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Using the Unity 98 Cordless Response System Directions : Courtesy of IHC public relations.
Structure of GridWorld classes Creating a GridWorld project without the jar file Modifying GridWorld classes Removing grid lines Changing the color of.
Guided Lesson.  In this lesson, you will learn how to modify existing bullets, insert new bulleted and numbered lists, select symbols as bullets, and.
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
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.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
GridWorld Case Study1 Barbara Ericson Georgia Tech Jan 2008.
Database Applications – Microsoft Access Lesson 9 Designing Special Queries Updated 4/11.
Database Applications – Microsoft Access Lesson 9 Designing Special Queries.
Copyright 2007, Paradigm Publishing Inc. EXCEL 2007 Chapter 7 BACKNEXTEND 7-1 LINKS TO OBJECTIVES Record & run a macro Record & run a macro Save as a macro-
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
1 Performing Spreadsheet What-If Analysis Applications of Spreadsheets.
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?
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
KeyListener and Keyboard Events Another type of listener listens for keyboard entry – the KeyListener which generates KeyEvents –to implement KeyListener,
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
Social Science Research Design and Statistics, 2/e Alfred P. Rovai, Jason D. Baker, and Michael K. Ponton Entering Data Manually PowerPoint Prepared by.
© A+ Computer Science - Row = 0 Column = 0.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
Scratch Programming Lesson 4 Question asking and answering.
GridWorld Case Study Barbara Ericson March 24, 2007.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
© A+ Computer Science - Grid is an interface that details the behaviors expected of a grid. All its methods are abstract methods.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
CIS 3.5 Lecture 2.2 More programming with "Processing"
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Creating a Multiple-Form Interface.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
The GridWorld Case Study Program Section 1 - Overview of the Class Hierarchies Section 2 - The Actor Class Section 3 - The Rock and Flower Classes Section.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Microsoft PowerPoint Prepared by the Academic Faculty Members of IT.
11 Using the Keyboard in XNA Session 9.1. Session Overview  Discover more detail on how the XNA keyboard is implemented  Find out how to use arrays.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
1 /25 Working with Return Templates with TaxWise Online © 2006, Universal Tax Systems, Inc. All Rights Reserved. TaxWise Online Return Templates Objectives.
Java for android Development Nasrullah Khan. Using instanceof in Android Development the classes such as Button, TextView, and CheckBox, which represent.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
Modifying GridWorld Classes.
Conditions and Ifs BIS1523 – Lecture 8.
Use proper case (ie Caps for the beginnings of words)
© A+ Computer Science - GridWorld © A+ Computer Science -
More programming with "Processing"
© A+ Computer Science - GridWorld The GridWorld case study provides a graphical environment where visual objects inhabit and interact.
CISC101 Reminders Assignment 3 due today.
Microsoft Excel 2007 – Level 2
Presentation transcript:

Using a different image than normal Multiple images for a class Controlling the mouse click Controlling the keys pressed Launching an input dialog box Launching a display dialog box Displaying messages Removing grid lines STEP button RUN button

The first and easiest option to extend Actor with a different image is to do the following: 1.Extend Actor and override the act method 2.Create a.GIF image file with the same name as the class. 3.Store the.GIF file in the same directory as the class file Note: You don’t have to extend Actor for this to work. It works for any grid occupant.

However, if you have a grid of Actors and you want to occupy some of the cells with something other than Actor images, you can follow this process: import info.gridworld.gui.DefaultDisplay; public class PlayActor_JohnDoeDisplay extends DefaultDisplay { //Since nothing is coded here, it disregards the Actor.gif //Without this class the gui will use the closest //related gif file - Actor.gif } 1.Create an empty class that is named ClassnameDisplay and extends DefaultDisplay. In other words, if you are creating an object class named PlayActor_JohnDoe, then create an empty PlayActor_JohnDoeDisplay class as follows:

public String getText() { return ""+ number; } 2.The default is that the image is shown as text in a colored cell. However, if this is not what you want, then you can override the getText() method in your class and display what you want. The following example shows how you could output a number: 3.Optionally, instead of defining the getText() method, you can define the toString() method and that will be used to display the image: public String toString() { return ""+ name; } Note: in either case the first 8 characters of the string are displayed in the cell

4.If a getColor() method is defined in your class or the superclass, it will be used to determine how to fill the background color in the cell. Therefore if you extend Actor, you can use setColor() to set the color and this will be the background color. 5.If you have a textColor instance variable of type Color defined in your class, its value will be used to determine the color of the text. You can create an accessor method to retrieve the textColor. Note: if the background color and the text color are the same, then the text color will automatically be the reverse of the background color.

You can have multiple images for a grid occupant. Suppose you have 52 card images, and all of these are Card objects. You could simply name each of the GIF files with the name of the class followed by a suffix. Then you would override the getImageSuffix method in the Card class. Here are the instructions: 1.Create a GIF file of each card image 2.Name the files: Card_AceOfHearts.gif, Card_TwoOfClubs.gif 3.Save the files in the same Java package as the class file 4.You must have a file named Card.gif even if you don’t use it 5.Override the getImageSuffix method in the Card class and GridWorld will use this to find the image file with this suffix: public String getImageSuffix() { return "_" + cardSuffix; // cardSuffix is instance variable containing suffix }

World class Methods commonly used in games NameUse public boolean locationClicked (Location loc) Activated by a mouse click in the grid. If overriding this method you should always return true. This method allows you to control what happens when clicking a cell. public boolean keyPressed (String description, Location loc) Activated by pressing a key. The description is the name of the key (i.e. SPACE, shift H, UP, DOWN, etc.). Note: Normally you would not want to override the arrow keys. If overriding this method you should always return true.

World class Methods commonly used in games NameUse public void setMessage (String newMessage) The yellow area above the grid is the message display. You can use the setMessage method to determine what is displayed here. i.e. setMessage(“Location “ + loc + “ was clicked”); public void step()Override this method to determine what is done when the STEP button is pressed. public void run()Override this method to determine what is done when the RUN button is pressed. By default it will perform the step method continuously.

BoundedGrid grid; grid = new BoundedGrid (5,5); grid.put(new Location(2,2),4); grid.put(new Location(1,1),9); grid.put(new Location(0,4),11); grid.put(new Location(4,3),5); grid.put(new Location(2,0),1); World world; world = new World (grid); world.show();

This is one way to make grid lines disappear. When the background and the grid lines are both black, you cannot see the grid lines. Check out the lecture “Modifying GridWorld Classes” for another way of making grid lines disappear. Code in driver program: BoundedGrid grid = new BoundedGrid(4,7); //4 rows and 7 columns for(int r=0; r<grid.getNumRows(); r++) for (int c=0; c<grid.getNumCols(); c++) grid.put(new Location(r,c), new Background(Color.BLACK)); CardWorld world = new CardWorld(grid); world.show(); public class Background extends Actor { public Background(Color color) { setColor(color); } public String getText() { return ""; } } public class BackgroundDisplay extends DefaultDisplay { }

import info.gridworld.world.World; import info.gridworld.grid.Location; public class NumberWorld extends World { public boolean locationClicked(Location loc) { add(loc, new RowColMultiplyBug(loc.getCol()*loc.getRow())); System.out.println("Location "+loc+" clicked"); return true; }

public boolean keyPressed(String description, Location loc) { if (description.equals("SPACE")) //when user presses spacebar, perform swapCards(loc) { String yesNo = JOptionPane.showInputDialog("Do you want to swap cards (Y/N)?"); if (yesNo.equals("Y")) { swapCards(loc); //method to swap cards return true; } return false; } else if (description.equals("H") || description.equals("shift H")) //when user presses h or H { JOptionPane.showMessageDialog(null, "This is not really a game. \n" + "Click on the cards you want to swap."); return true; } else { return false; } Helpful Tip: To determine the description of a key, simply put a print statement in this keyPressed method to print description to the console; then press the key

Here is how you could simulate clicking on all objects in the world when the STEP button is pressed: public void step() { ArrayList occupiedCells = getGrid().getOccupiedLocations(); for (int i=1; i<occupiedCells.size(); i++) { locationClicked(occupiedCells.get(i)); } setMessage("Step is pressed"); }