Design of the Video Game Package Comp Sci



















![class Model. Test Attributes v none Behavior v public static void main(String[] args) Comp. class Model. Test Attributes v none Behavior v public static void main(String[] args) Comp.](https://slidetodoc.com/presentation_image_h2/f9f74a5ef69d04cd49f0d8966377c59f/image-20.jpg)

- Slides: 21
Design of the Video Game Package Comp. Sci 4 Video Game Package Design 12. 1
Design of Video Game Package JFrame Or Applet Game. Loop Animation Canvas Mouse Keyboard Comp. Sci 4 Sprite Tracker Video Game Package Design 12. 2
The Plan v v v Basic principles of design Motivate why MVC is needed Model/View/Controller (MVC) overview Model (today) View (when we get to Graphical User Interfaces) Controller (when we get to Event Handling) Comp. Sci 4 Video Game Package Design 12. 3
Basic Principles of Design We want our programs to be v simple v functional v fast (to code and to execute) v correct v easy to modify v easy to extend v capable of reuse Comp. Sci 4 Video Game Package Design 12. 4
Why Simple? v Simple is easy to understand therefore easier to reuse, modify, and extend. v Simple has less likelihood for program errors and is therefore more likely to be correct. v Simple may be faster than complex, certain to code and perhaps in execution time. Comp. Sci 4 Video Game Package Design 12. 5
Why functional? v It has to work. v How well it works is negotiable considering: q q q Comp. Sci 4 speed to release cost to release lifetime of code Video Game Package Design 12. 6
Why fast? v Who wants to wait? v Works better on slower, more out-of-date machines. v Sometimes crucial to application’s purpose q q Comp. Sci 4 air control nuclear plant facilities weather prediction stock prediction Video Game Package Design 12. 7
Why correct? v In some cases, incorrect execution is unacceptable q q v In some cases, incorrect execution can be remedied by re -execution q q v access control online sales operating system locks up, so just reboot database goes down, just restart impacts time coding Comp. Sci 4 Video Game Package Design 12. 8
Why easy to modify? v Users rarely can tell you exactly what they want v Even if they could tell you, what users want changes v Changes in hardware and software mandate code modification (think Y 2 K) Comp. Sci 4 Video Game Package Design 12. 9
Why easy to extend? v Why not make a good thing better? v Enables multiple releases of functional programs q q v Windows 3. 1, 95, 98, 2000, NT, etc. Java 1. 0, 1. 1, 1. 2, 1. 3, 1. 4 and now 1. 5 (5. 0) Keep up with increasing competition and demand Comp. Sci 4 Video Game Package Design 12. 10
Capable of Reuse v No need to reinvent the wheel v Easier to build with tools than starting from scratch v C was used to make C++ compiler, C++ used to v make Java, Java used to make Java compiler! v Reduce, reuse, recycle is good for coding too! Comp. Sci 4 Video Game Package Design 12. 11
Why we need MVC? MVC assists in achieving design principles: v simple idea v fast to code with a clear ready-made design v structure makes reuse, modification and extension simple v MVC design easy to test for correctness Comp. Sci 4 Video Game Package Design 12. 12
What is MVC? v Model q q v View q v representation of the data has no visual component visual display of the data Controller q q Comp. Sci 4 specifies ways in which the model can be changed between model and view Video Game Package Design 12. 13
Simplified 1 D Model v Recall collision detection simulation. v We’re going to apply MVC to solve the problem more generally. v Were going to use Object Oriented Programming q q Comp. Sci 4 what are the objects? what value do they have? how do the values change? how are the values accessible? Video Game Package Design 12. 14
What are our objects? We’re going to model 1 D particles and segments. v Particle (similar to the Sprite class) v Segment (similar to extending the Sprite class) v Tracker 1 D (similar to Tracker) v Velocity. Tracker (similar to Projectile. Tracker) v Model. Test (similar to our JFrame) Comp. Sci 4 Video Game Package Design 12. 15
class Particle Attributes v v double position Tracker 1 D Behavior v v Comp. Sci 4 double get. Position() void set. Position(double) Tracker 1 D get. Tracker() void set. Tracker(Tracker 1 D) Video Game Package Design 12. 16
class Segment extends Particle Attributes v v v double position double width Tracker 1 D Behavior v v v Comp. Sci 4 double get. Position() void set. Position(double) double get. Width() void set. Width(double) Tracker 1 D get. Tracker() void set. Tracker(Tracker 1 D) Video Game Package Design 12. 17
interface Tracker 1 D Attributes v none Behavior v v Comp. Sci 4 double get. Position() void advance. Time(double) Video Game Package Design 12. 18
class Velocity. Tracker Attributes v v double velocity double position Comp. Sci 4 Behavior v v double get. Position() void advance. Time(double) Video Game Package Design 12. 19
class Model. Test Attributes v none Behavior v public static void main(String[] args) Comp. Sci 4 Video Game Package Design 12. 20
More to come…. Comp. Sci 4 Video Game Package Design 12. 21