Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90269

Re: How to properly apply OOP in the bouncing ball code

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'represents': 0.05; 'attribute': 0.07; 'subject:code': 0.07; 'attributes': 0.09; 'logic': 0.09; 'oop': 0.09; 'screen.': 0.09; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; 'ball.': 0.16; 'balls': 0.16; 'bouncing': 0.16; 'exist.': 0.16; 'loop.': 0.16; 'settings,': 0.16; 'similarly,': 0.16; 'subject:OOP': 0.16; 'y):': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'trying': 0.19; '&lt;': 0.19; 'advance.': 0.19; 'settings': 0.22; 'email addr:gmail.com&gt;': 0.22; 'separate': 0.22; 'error': 0.23; '&gt;': 0.26; 'header:In- Reply-To:1': 0.27; 'appreciated.': 0.29; 'am,': 0.29; 'related': 0.29; "doesn't": 0.30; 'errors': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'that.': 0.31; 'ball': 0.31; 'class': 0.32; 'probably': 0.32; 'screen': 0.34; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'received:google.com': 0.35; '(e.g.,': 0.36; 'controls': 0.36; 'method': 0.36; 'thanks': 0.36; 'should': 0.36; 'skip:& 10': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'skip:& 20': 0.39; 'does': 0.39; 'use.': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'new': 0.61; 'name': 0.63; 'details': 0.65; 'here': 0.66; '2015': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=+pSE+HqsCSgyff0pdaDyW56TT0ap054rwmrs8Rxw0dk=; b=NI+Wgu2J30q/PmiAh6eTTxfoVkZ28FOlshsoxAvrLqVpGExhu3zONZO/F2+p+50lb1 Tkh+0jOBxr6fQQgw+caFdy6Bcij3OyqsuIu8OWEt24L1bgeAsNFzXQ5j25iHCgofNqRl FPwyZAUaaiTiiTX3fFhQBhnC6GjdWDLI8pFReqKfi1fUZD9GGIyHXTQ0+VKUsGIAMsSc igLKu/NXUvkV7RxkonEiLlVz+kspRJZBN640vW+ELRYk3ktlirIQxykyiEsMjKkL943/ QvLToClktx3S3CNF1dcKWBocx4TfP9P3ROq33AHHBH6xn5VvPJqbsPl4rgSHpn9BKjWW GqhQ==
MIME-Version 1.0
X-Received by 10.107.136.89 with SMTP id k86mr5750750iod.63.1431102148068; Fri, 08 May 2015 09:22:28 -0700 (PDT)
In-Reply-To <009ceef8-066d-4d92-a6c9-761e86584e75@googlegroups.com>
References <009ceef8-066d-4d92-a6c9-761e86584e75@googlegroups.com>
Date Fri, 8 May 2015 10:22:28 -0600
Subject Re: How to properly apply OOP in the bouncing ball code
From Ian Kelly <ian.g.kelly@gmail.com>
To Python <python-list@python.org>
Content-Type multipart/alternative; boundary=001a1145a0722c534c0515946f83
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.258.1431102150.12865.python-list@python.org> (permalink)
Lines 79
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431102150 news.xs4all.nl 2962 [2001:888:2000:d::a6]:58211
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90269

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On May 8, 2015 9:46 AM, "Tommy C" <tommyc168168@gmail.com> wrote:
>
> I'm trying to apply OOP in this bouncing ball code in order to have
multiple balls bouncing around the screen. The objective of this code is to
create a method called settings, which controls all the settings for the
screen and the bouncing behaviour of multiple balls, under the class Ball.
However, I keep on getting errors related to attributes (e.g., speed). I'm
new to OOP in Python so your help will be much appreciated. Thanks in
advance.

As the error says, the attribute does not exist.

> class Ball:
>     def __init__(self, X, Y):
>         self.velocity = [1,1]

Here where you set it, you call it "velocity".

>         speed = self.velocity

Here you create a local variable called "speed", which you never use.

>                 if balls.ball_boundary.left < 0 or
balls.ball_boundary.right > self.width:
>                     balls.speed[0] = -balls.speed[0]

And here you look up an attribute of Ball called "speed", which doesn't
match the name you used in __init__.

This is a muddled design overall. Your Ball class represents the individual
balls bouncing around the screen. It should not also contain details about
window size and the logic for the event loop. Use a separate class for that.

Similarly, if the purpose of your settings method is to manage settings,
why does it also contain all the bouncing logic? These should probably be
separate methods.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to properly apply OOP in the bouncing ball code Tommy C <tommyc168168@gmail.com> - 2015-05-08 08:40 -0700
  Re: How to properly apply OOP in the bouncing ball code Mel Wilson <mwilson@the-wire.com> - 2015-05-08 18:44 +0000
  Re: How to properly apply OOP in the bouncing ball code Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-08 10:22 -0600
  Re: How to properly apply OOP in the bouncing ball code Tommy C <tommyc168168@gmail.com> - 2015-05-11 08:22 -0700
    Re: How to properly apply OOP in the bouncing ball code Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-05-12 17:53 +0100
  Re: How to properly apply OOP in the bouncing ball code zipher <dreamingforward@gmail.com> - 2015-05-11 08:33 -0700
    Re: How to properly apply OOP in the bouncing ball code Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-11 20:24 -0400
      Re: How to properly apply OOP in the bouncing ball code zipher <dreamingforward@gmail.com> - 2015-05-11 17:42 -0700
        Re: How to properly apply OOP in the bouncing ball code Terry Reedy <tjreedy@udel.edu> - 2015-05-12 11:45 -0400
          Re: How to properly apply OOP in the bouncing ball code Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-13 20:20 +1200

csiph-web