• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
KuraiTsubasa

OOP is so confusing[wrong question]

9 posts in this topic

Hi guys i want to know the process of object orientated programming(OOP) i tried my best to understand what is exactly the process but i have no idea what is it.I have a code like this:







class Song(object):

	def __init__(self, lyrics):
		self.lyrics = lyrics
	
	def sing_me_a_song(self):
		for line in self.lyrics:
			print line
			
happy_bday = Song(["Happy birthday to you",
		   "I don't want to get sued",
                   "So I'll stop right there"])	
	   
bulls_on_parade = Song(["They rally around the family",
			"With pockets full of shell"])
						
happy_bday.sing_me_a_song()

bulls_on_parade.sing_me_a_song()

And i don't understand what is "for" and "in" statement it is really confusing me. and i don't understand what :







self.lyrics = lyrics

and 







for line in self.lyric:
        print line

is do for .Sorry for asking to muchunsure.png

Edited by Kurai Tsubasa
0

Share this post


Link to post
Share on other sites

Where did you find this code? Are you reading a book or following a tutorial online? If so, are you doing the excersizes after each chapter?

 

A good set of introductory material should be explaining each of these concepts on their own.

0

Share this post


Link to post
Share on other sites

 

Hi guys i want to know the process of object orientated programming(OOP) i tried my best to understand what is exactly the process but i have no idea what is it.I have a code like this:



class Song(object):

	def __init__(self, lyrics):
		self.lyrics = lyrics
	
	def sing_me_a_song(self):
		for line in self.lyrics:
			print line
			
happy_bday = Song(["Happy birthday to you",
		   "I don't want to get sued",
                   "So I'll stop right there"])	
	   
bulls_on_parade = Song(["They rally around the family",
			"With pockets full of shell"])
						
happy_bday.sing_me_a_song()

bulls_on_parade.sing_me_a_song()

And i don't understand what is "for" and "in" statement it is really confusing me. and i don't understand what :



self.lyrics = lyrics

and 



for line in self.lyric:
        print line

is do for .Sorry for asking to muchunsure.png

 

This problem here is nothing really to do with object oriented programming. Keywords like 'for' and 'in' are fundamental to python (and a lot of other programming languages -- object oriented or not) so I would suggest that you take I look a 'getting started' tutorial for python.

 

-Josh

 

 

 

The question has nothing to do with object orientation. That is simply Python's for loop. I would strongly suggest taking a few steps back, you should learn more about the fundamentals of your chosen language before you try learning about more advanced concepts.

 

 

Where did you find this code? Are you reading a book or following a tutorial online? If so, are you doing the excersizes after each chapter?

 

A good set of introductory material should be explaining each of these concepts on their own.

 

oh,sorry i think i misunderstanding this,i was thinking this is OOP.Sorry ^^a

0

Share this post


Link to post
Share on other sites

The code involves OOP, sure. But the root cause is that you seem to be trying to understand a (relatively) complex example while being new to the language and not sufficiently exposed to the various constructs.

Yeah i still beginner and i think i'm trying to understand that i haven't ready yet.i guess i will try to find some free books that is easy to learn for beginner^^

Edited by Kurai Tsubasa
0

Share this post


Link to post
Share on other sites

Attempting ton understand some of the more complex constructs in a language before learning the basics can be quite a bit confusing.

 

"for" is a loop statement

"in" is used to iterate through a list, dictionary, or array

"self" is a class variable construct - The syntax is a lot like C++ and is confusing to learn at first

 

 I would strongly recommend reading How to Think Like a Computer Scientist: Java or How to Think Like a Computer Scientist: Python and doing the exercises at the end of each chapter.

 The Ebooks are free.

Edited by Shippou
2

Share this post


Link to post
Share on other sites

To understand OOP (Object Oriented Programming), it's likely best to understand what an Object is when referring to programming.

 

Consider the following:

 

Scenario #1

You are a car mechanic. 

A car is delivered to you, and it requires a tune up.

You find that several nuts and bolts are lose on examination.

You search for and acquire an adjustable wrench.

Using the adjustable wrench, you tighten the nuts and bolts.

The result of using the adjustable wrench returns a task completed.

Since there are no other tasks associated with this tune up, the tuneup is completed.

 

Scenario #2

A second car comes in.

The car requires a replacement radiator.

On examination of the radiator, you determine that an array of tools are required, including an adjustable wrench.

You search for and acquire an adjustable wrench.

You use the adjustable wrench to loosen bolts.

You use other tools to further allow the removal and replacement of the radiator.

A new radiator is installed.

You use a combination of tools to again mount the radiator.

You again use the adjustable wrench to tighten the bolts.

The result of using the adjustable wrench returns a completed task (as with the other tools).

Since there are no other tasks associated with this radiator replacement, the replacement is completed.

 

An object seen in the two examples above would be the adjustable wrench

 

In programming, a object is essentially a class that gets instantiated, meets a criteria, and can be reused. For proper object creation, it must meet these four requirements:

It must support polymorphism.

It must support overloading.

It should support overriding (for consistency).

It should support encapsulation (for security).

 

Much like the adjustable wrench in the above example, the adjustable wrench was performed on both a tune up and a radiator replacement. It essentially was used to remove and tighten bolts and nuts in two different scenarios.  The nuts and bolts between the two cars were different, but were classified as the same type of property of which an adjustable wrench be used with. Likewise, two different sets of code may require the use of a class for different reasons, but pass a similar type of peropty and require a similar return value. This is essentially polymorphism, because the same object was used for the same reason with a different set or properties in two different scenarios (you had to adjust the wrench size for different size nuts/bolts two separate jobs, but got the job done with one adjustable wrench).

 

Polymorphism

The biggest challenge in OOP is thinking outside of primitives. As novice programmers, we tend to think int, float, double... and the associated values to such. But OOP is both similar and different. An object is a container of values/properties. The easiest way to truly understand an object is to understand a structure in C. You have an entity, and that entity has properties. When you use that entity, you can call one property, a set of properties, or all properties stored. If you want to get more complicated, you can stored objects within objects, and would have to iterate through the first object to access the nested objects, for the values stored in the desired object. Tricky, huh?  wink.png To further understand this, I would highly recommend studying data structures.  

 

Overloading

Overload is hard to explain without confusing people.  I would recommend researching it. In simplest definition, overloading is when you call the same function/method of a class, pass a different set of parameters. The parameters define which of the identically named function/methods you are calling.

 

Overriding

Overriding is when you are quite literately calling a method of identical name and parameter, but of a child class, which invokes the use of that method over the identical method of a super class.  A clean example of this is when you define a default constructor which is required in instantiating a class (for Java and C#). Another way to look at this is saying you have two classes, class 1, and class 2. You have a function/method called public int GetMe(int i) in both. To get to class 2, you must first instantiate class 1, then using that object, instantiate class 2. But instead of using GetMe(int i) in class 1, you use it in Class 2. You are overriding the GetMe(int i) method of class 1 with the GetMe(int i) method of class 2.

 

Encapsulation

Encapsulation is when you use access modifiers like private, protected, etc to hide variables from super classes, but give access to change such values through methods like setters/getters.

 

Again, if you truly want to understand OOP, study polymorphism, overloading, overriding and encapsulation. I would also advise studying further into containers and data structures, and learn how to use iterators. You'll never ask this question again if you know these key aspects. Best of luck to you.

Edited by Subtle_Wonders
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0