Case Study: Game2D with Method Design

Slides:



Advertisements
Similar presentations
Chapter 18 Building the user interface. This chapter discusses n Javas graphical user interface. n Swing: an enhancement of a library called the Abstract.
Advertisements

Chapter 16 Graphical User Interfaces
Game Procedures Who does what, where, when, and how?
EEE436 / CS422 Preliminary Presentation Group
Chapter 8 Improving the User Interface
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
RAPTOR Syntax and Semantics By Lt Col Schorsch
Graphic User Interfaces Layout Managers Event Handling.
11 Reaction Timer Game Session 8.1. Session Overview  Find out how an XNA program can measure the passage of time and trigger events at certain points.
Teaching Software Development by Example Evelyn Stiller and Cathie LeBlanc Dept. Computer Science and Technology.
EEE436 / CS422 Final Presentation Group
Chapter 6 Introduction to Defining Classes
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Copyright W. Howden1 Lecture 7: Functional and OO Design Descriptions.
1 L54 Networking (3). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Event Handling Events and Listeners Timers and Animation.
Review CSC 171 FALL 2004 LECTURE 21. Topics Objects and Classes Fundamental Types Graphics and Applets Decisions Iteration Designing Classes Testing and.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
IS660Z – Programming Games Using Visual Basic Required session 3 June 16, 2004.
Graphics not part of C++ libraries –X libraries –QT library –OS specific.
Model View Controller (MVC) Architecture. Terminology and History MVC evolved from Smalltalk-80 Has become a key pattern in web based applications – If.
© The McGraw-Hill Companies, 2006 Chapter 16 Two-dimensional arrays.
Graphical User Interfaces A Quick Outlook. Interface Many methods to create and “interface” with the user 2 most common interface methods: – Console –
Applets Java API.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Field Trip #26 Create a Find a Word Puzzle in Java By Keith Lynn.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
1 Phase Testing. \ 2 Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine subphases) Define Coding Standards.
SOLVING SUDOKU WITH MATLAB Raluca Marinescu, Andrea Garcia, Ivan Castro, Eduard Enoiu Mälardalen University, Västerås,
Putting together a complete system Chapter 10. Overview  Design a modest but complete system  A collection of objects work together to solve a problem.
Spong Bluetooth game Developed by: Erik Matzols Fredrik Lindberg.
A Case Study in OO Design and Team Development The Game of SET: Maria Litvin Phillips Academy Andover, Massachusetts Advance Placement Program Professional.
Chapter 12 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
Session 10 CannonGame and Event-driven Programming.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Alice in Action with Java Chapter 14 Events and GUIs.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
DotNetFM Chris Zamanillo Ana Rodriguez Allen Lee Peter Singh
Visual Basic Games: Week 4 Recap Parallel structures Initialization Prepare for Memory Scoring Shuffling Homework: when ready, move on to next game/chapter.
Control flow for interactive applications CSE 3541 Matt Boggus.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Object Oriented Programming.  Interface  Event Handling.
Field Trip #25 Creating a Client/Server By Keith Lynn.
Game Procedures Who does what, where, when, and how?
Chapter 9 Putting together a complete system. This chapter discusses n Designing a complete system. n Overview of the design and implementation process.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
Field Trip #23 Hangman By Keith Lynn. JApplet A JApplet is a top-level container An applet is a small Java program that is executed by another program.
Chapter 5 Introduction to Defining Classes
Mouse Listeners Moving the mouse will also generate events like the Timer –To have your program respond, you must implement either or both of MouseListener.
Computer Science 209 GUIs Model/View/Controller Layouts.
DOTSNBOXES. Overview Dots and Boxes is played originally with the use of paper, pen and 2 players. The Game board is a matrix of points and vary in size.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
Chomp. How is the game played Human player goes first choose a square, all to the right and down are “eaten” computer takes a turn whoever is forced to.
Arrays & Enum & Events. Arrays Arrays are data structures consisting of related data items of the same type. Arrays are fixed-length entities—they remain.
GUI Tutorial Day 4. More GUI action  adding a Mouse Listener  SimpleDots  Simple mouse listener  Draw an oval where the mouse is clicked  Box example.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Systems Analysis and Design in a Changing World, Fourth Edition
Creation of an Android App By Keith Lynn
Chapter 5 Processing Input with Applets
Copyright  1997 Oxford University Press All Rights Reserved
Agenda for Unit 5: Control Structures
Presentation transcript:

Case Study: Game2D with Method Design Chapter 6 Case Study: Game2D with Method Design

Objectives of Game2D Simple 2 player game To be played over the Internet The game board consists of a two-dimensional grid Dots randomly appear on the grid, and alternate between two colors (red and blue) Each player is assigned a color, either red or blue

More Objectives of Game2D The objective of the game is for each player to cause dots of his/her color to disappear by clicking on the dots A player loses if two neighboring dots of his/her color appears on the gird

Supported Activity List Allow registration of two players for each game Display a simple table (grid) of initially empty cells When two players have been registered and one of them clicks the start button, the game begins Randomly display dots in the cells at regular intervals. The dots alternate in color between red and blue Allow the player to adjust the interval at which dots are displayed

Supported Activity List Continued Assign one of two colors (red or blue) to each player so that each player is concerned with dots of that color only Respond to mouse clicks. If either player clicks on a dot, the dot disappears in response to that click Keep track of points (the score). Each time a player clicks on a dot of his or her color. He or she earns a point If two dots of the same color appear next to each other, the player corresponding to that color loses. Notify each player of their win or loss

Human-Computer Interface

Requirements Analysis List of nouns Player Game Internet Table Cell Start Game button Dot Interval Color Mouse Mouse click Point (score) Loser

Analysis of List of Nouns Retained information Needed services Multiple attributes Common attributes Common operations Essential requirements

Primary Classes Player Game Cell Dot

Use Case Development Client communicates player sign-on Client communicates player action (mouse click) Server communicates that dot is removed from cell Server communicates that dot is set in cell Server communicates that game is won/lost

Use Case: Client Communicates Player Action Main flow of events: This use case begins when the player clicks the left mouse button in the applet window. The goal of each player is to erase as many dots of his or her associated color as possible. In other words, the blue player wishes to erase blue dots, while the red player wishes to erase red dots. A player erases a dot by pressing the left mouse button over a cell containing that dot. When the mouse button is clicked, the event is trapped and the coordinates of the mouse event are translated into a specific reference to a Cell object.

Use Case: Client Communicates Player Action (continued) Main flow of events (continued): The Cell object is queried to determine if a Dot is present in that Cell and what its color is. If no Dot exists in this Cell, the use case ends. If a Dot matching the player's color is present, the player receives a point. If a Dot of any color is present, the Dot is removed from the Cell and the information to remove the Dot from the Cell is transmitted to the server. The use case then ends.

Use Case: Client Communicates Player Action (continued) Exceptional flow of events: If a player clicks the mouse on an area of the applet where no Cell object is rendered, the use case ends with no information being transmitted to the server. (see deliverable 6.11 for associated scenario)

Refined Class List Player Game2DServer Game Timer Cell Dot

An Initial Class Diagram(Partial) GameServer Timer (see deliverable 6.16 for complete diagram) starts prompts Game communicates with Player contains contains Dot Cell contains

Use Case Diagram for Game2D Signon Player Internet removeDot setDot Game Won/Lost Action

State Machine for Game2D (Partial) Communicate Game status Wait for other players connect player #2 connects game initiation Wait for dots Get name Select color (see deliverable 6.18 for complete diagram)

Revised Class Diagram for Game2D (Partial) prompts Game2DInitiator Timer prompts starts Communicates with unsetDot Game2DServer Listener Game2DServer Game2DClient Communicates with unsetDot Game2DClient Listener (see deliverable 6.19 for complete diagram)

Game2D: Interaction Diagram (Partial) :Game2DServer :Game2DClient setColor(color) setDot(row,col,color) unsetDot(row,col) win() lose() unsetDot(row,col) :Game2DClient Listener :Game2DServer Listener {messages} (see deliverable 6.20 for complete diagram)

Game2D: Object Diagram (Partial) :Game2DClientListener Applet Socket :Game2DClient grid Cell[][] Socket color = 1 grid[0][0]:Cell X=0 y=0 width=15 height=15 Applet hasDot=false color= 0 (see deliverable 6.22 for complete diagram)

Game2D: Reuse Cell boolean hasDot; int color; checkDot(int color) setDot(int color) unsetDot(int color) Graphical Cell Applet app; int x, y int width, height; setDot(int color) unsetDot(int color) draw()

Game2D: Class Skeleton (Partial) (see deliverable 6.23 for complete skeleton) public class Game2DClient extend Applet implements Mouselistener, ActionListener { // Class semantics and roles // This class embodies the GUI which the player interacts // Instance variables: private Graphical_Cell grid[][]; // 2D array of cells: game state private int color; // the player’s color 1 = blue, 2 = red private Socket sock; // Socket connection to game server private PrintWriter out; // output stream built over socket connection // Nonstatic Methods public void paint(Graphics g) // Override Applet method to render the array of graphic cells public void setDot(int I, int j, int c) // send message to graphical cell object at row i, column j array grid // set color to Color.blue, if c = 1 otherwise set it to Color.red // precondition: 2D array of graphical cells has been allocated and c // c has value of 1 or 2. Postcondition : either a red or blue dot appears // in the graphic cell grid[I][j] .

Method Design Techniques for specifying algorithms Nassi-Shneiderman charts Flowcharts Pseudocode Decision tables

Decision Table and Psuedocode Example pick random number between 0 and MAX-1 set dot in cell grid[I][j] to color c grid[i+1] [j] has dot color c player c loses player c loses grid[i-1] [j] has dot color c grid[i] [j+1] has dot color c player c loses grid[i] [j-1] has dot color c player c loses

Creating Quality Methods Cohesive Loosely coupled Encapsulated Reusable