More on OO Programming Our programs will no longer just be a main method or a main which calls a collection of other methods –instead, a program will be.

Slides:



Advertisements
Similar presentations
Differentiating with Questioning
Advertisements

Game Idea : Rogue-Like. Basic Idea A rogue-like game is one that is characterized by procedural level generation, tile-based graphics, and permanent death.
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
Games and Simulations O-O Programming in Java The Walker School
Space Rescue Chad Seippel Cory VanHooser. Story 2050 brand new International Space Station Distress call from ISS about “alien attack” No further communication.
Best-First Search: Agendas
Advanced Class 6. Topics Inheritance Class methods / static methods Class data vs. instance data.
CSCI 101 Introduction to Software Development and Design.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
Writing Classes You have already used classes –String, Random, Scanner, Math, Graphics, etc –To use a class: import the class or the package containing.
Artificial Intelligence in Game Design
Chapter 13 Recursion. Topics Simple Recursion Recursion with a Return Value Recursion with Two Base Cases Binary Search Revisited Animation Using Recursion.
MOM! Phineas and Ferb are … Aims:
1 Ch. 7 Recursion similar to iteration in that you repeatedly do a little bit of the task and then “loop” again and work on a smaller piece - eventually.
Production Systems A production system is –a set of rules (if-then or condition-action statements) –working memory the current state of the problem solving,
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 3.0.
Art 315 Lecture 6 Dr. J. Parker. Variables Variables are one of a few key concepts in programming that must be understood. Many engineering/cs students.
Game Programming Patterns Type Object From the book by Robert Nystrom
BitTorrent Nathan Marz Raylene Yung. BitTorrent BitTorrent consists of two protocols – Tracker HTTP protocol (THP) How an agent joins a swarm How an agent.
Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning.
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
Maths on the move Cookie Count Room 13 – Year 2 Class 2007.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Draw a Door card Safe Room! Monster card? Combat! Curse card? It affects you! Else… Put it in your hand Look for Trouble Fight a monster from your hand.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
Linked List. Background Arrays has certain disadvantages as data storage structures. ▫In an unordered array, searching is slow ▫In an ordered array, insertion.
CE Operating Systems Lecture 14 Memory management.
Introduction to Algorithms Chapter 16: Greedy Algorithms.
Recursion – means to recur or to repeat – A different way to get a robot to repeat an action A programming language that allows recursive definitions (and.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Visual Basic Games: Week 4 Recap Parallel structures Initialization Prepare for Memory Scoring Shuffling Homework: when ready, move on to next game/chapter.
Catch the Train. Research log Date Sources of Information obtainedDescription of Information obtainedNotes 07/10/2013 WikipediaDonkey KongVertical Levels.
Minecraftology By Lauren.
© Glenn Rowe AC Lab 3 An adventure game.
CSCI-100 Introduction to Computing
Introduction to Planning Dr. Shazzad Hosain Department of EECS North South Universtiy
Event Card Tutorial Francelette’s Kindness Adventure.
Part 3 Linear Programming
RPG 2 By the Dude 1 You are sitting in a throne with your holy grail at your side. Then suddenly an old man comes in and gives you a stick. Suddenly,
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 12 Object-Oriented Programming Starting Out with Games & Graphics.
Decision Theoretic Planning. Decisions Under Uncertainty  Some areas of AI (e.g., planning) focus on decision making in domains where the environment.
Chapter 8 Testing. Principles of Object-Oriented Testing Å Object-oriented systems are built out of two or more interrelated objects Å Determining the.
Problem Reduction So far we have considered search strategies for OR graph. In OR graph, several arcs indicate a variety of ways in which the original.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "___________________" in Java Purpose –Reuse code –Modularize.
For Programming Challenge N. H. N. D. de Silva. Introduction General Game Architecture Server Architecture Joining the game Game initiation Moving and.
Tank Game Part 3 of 6. Secondary Weapons and Pick ups Pick ups will appear randomly in the battle area and can be collected by driving into them. Each.
CS12230 Introduction to Programming Extra example– More on responsibilities 1.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Object Orientated Programming in Perl Simulated Models of Termites.
May contain few bloody slides. Not suitable children under 18 P.s. that is sarcastic.
The Law of Averages. What does the law of average say? We know that, from the definition of probability, in the long run the frequency of some event will.
GAME:IT Mario Creating Platform Games Level 4 with GML Game Maker Language (GML) allows users more flexibility in game design. GML is similar to how real.
A gaming study By: Evan Bailey. For my independent study I played my favorite games and studied how they work and what I can do to improve my performance.
World of Wokcraft The very best in Single pan cooking themed fantasy gaming!
LINKED LISTS.
Loops Brent M. Dingle Texas A&M University Chapter 6 – Section 6.3 Multiway Branches (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Shlomo Hershkop Basics overview. Shlomo Hershkop Basic Review - Overview Practice coding Practice coding finger guessing game finger guessing.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
FLOWCHARTS Part 1.
MPCS – Advanced java Programming
Methods Chapter 6.
Topic 1: Problem Solving
Put it all together Lesson 5.
Managing a Project Life Cycle of a System.
TEXT ADVENTURE GAME.
Presentation transcript:

More on OO Programming Our programs will no longer just be a main method or a main which calls a collection of other methods –instead, a program will be a group of objects that work together to solve a problem –the main method will create objects and then call upon those objects to perform tasks This is a different kind of programming strategy than we previously had where we just listed instructions to execute –we have to now think about what types of objects are needed to create a game that comprises multiple objects of different types of classes

Example: Adventure Game Consider a 1-player adventure game, just you against the various monsters you will fight –lets create a class called Adventurer the Adventurer will be an object with –hit points –weapons –armor –other items like treasure, food, potions, etc and the Adventurer will need to have methods to –move to a new room, search a room, pick up items found –fight another Adventurer –change weapons/armor, eat food, take potions, cast spells, rest We can create other objects –Adventurer objects (with their own hit points and armor) –Weapons and Armor that can be picked up, put down, and used/worn –Food that, when eaten, might heal the player –Rooms that contain Adventurers and other items (Weapons, Food)

The Adventurer Class We will assume an Adventurer can be either the human player (the user) or a Creature to fight or even cooperate with –What will describe an Adventurer? a name and/or type (e.g., Ogre, Wizard, etc) its hit points (how much damage it can take before dying) how many attacks it gets per turn the maximum amount of damage it can do per attack its defense (how hard it is for another Adventurer to attack it or to hit it) what it currently is holding (Weapon, Armor, Food, etc)

Adventurer Methods The previous list will make up the class’ instance data, but what about methods? –we need a constructor to initialize the Adventurer’s values so that we can create a new Adventurer with code like this: Adventurer a1 = new Adventurer(“Fred”, “Fighter”, 31, 2, 8, 14, null, null); –Fred is a Fighter with 31 hit points who can attack twice per turn for a maximum damage of 8, and a defense of 14, Fred currently has no weapons or armor –We will need to write methods for attack – attack another Adventurer (monster, creature) isAttacked – when this Adventurer is attacked, how much damage has he/she/it taken on? isAlive – is this Adventurer still alive? pickUpWeapon – add a Weapon to what it is carrying similarly for Armor and Treasure and Food and accessors for each of its instance variables

The attacks Method How do we get one Adventurer to attack another? –the code may look like this: –while(a1.isAlive( ) && a2.isAlive( )) { a1.attacks(a2); if(a2.isAlive( )) a2.attacks(a1); } So how does attacks work? –a1 can attack numAttacks time (numAttacks is an instance data), so we use a for loop to iterate that many times –each time, we roll a 20 sided die, if the roll > a2.getDefense( ) then this attack hits a2 –we generate the damage done as a random number from 1 to maxDamageAmount (the amount of damage we can cause in one attack): damage = g.nextInt(maxDamageAmount) + 1; –now we have to tell a2 that we have hit him for that amount: a2.isAttacked(damage);

Objects Interacting with Objects Notice how one Object (a1) can interact with another (a2) This is the basis for OOP, having objects interacting with each other in different ways: –Object containing Object (Adventurer has a Weapon, Room has a Weapon or Treasure) –Object operating positively with an Object (Adventurer picks up a Weapon) –Object operating negatively with an Object (Adventurer attacks another Adventurer and causes the other Adventurer to lose hit points) We need to properly implement our methods and classes for these types of interactions

Classes Containing Classes Lets expand our Adventure game as follows: –the Adventurer (user) will be in a Room which contains objects –a Room is a class that has instance data for: a creature to fight (of type Adventurer), items lying around (some type of Treasure, a discarded Weapon, some Armor) We might define a Room like this: –Room r1 = new Room(new Adventurer(“Ogre”, “Fighter”, 16, 1, 12, 11), new Treasure(“Gold”, 25), null, new Armor(“Chain Mail”, 15); –thus, r1 is a Room that contains an Ogre to fight and 25 pieces of gold, but no Weapon, and a piece of Chain Mail offering 15 defense points –the Ogre has 16 hit points, 1 attack per turn of 12 maximum damage points, and defense of 11 The Room class might have methods –to access each instance data and to remove or add items to the Room for instance, if we kill the Ogre, we can take the Treasure and thus remove it from the room or we might pick up the Chain Mail and drop our own Leather Armor, thus we drop one piece of armor and add another

Making a Dungeon/Adventure Space So we can define a Room, how about multiple Rooms? –Room[ ] rooms = new Room[5]; our dungeon has 5 rooms –rooms[0] = new Room(…); –rooms[1] = new Room(…); we populate each Room individually by specifying in the … what Adventurer (monster), Treasure, Weapon, Armor is in the room, if any We can connect Rooms together too, lets assume we add these instance data to the Room class: –Room north, south, east, west If we do rooms[0].north = rooms[1]; –Then room 0 connects to room 1 by going north out of rooms[0] –of course we should also do rooms[1].south = rooms[0]; or else it is a 1-way trip through that doorway!

A Full Adventure Game In order to create a full game: –you need to define each class Room, Weapon, Armor, Treasure, Adventurer –each class needs proper constructors and accessor methods (an accessor method for each instance data) and probably a toString to describe the object –additional methods as needed: take an object from a Room, drop an object in a Room (the Adventurer and Room classes will need methods to perform this) go from Room to Room (the Adventurer and the Room classes will need methods to perform this) rest or eat food or drink potions to heal (Adventurer will need this) Before starting, design the entire thing!