Skip to main content
Code Review

Return to Question

add tag
Link
edited title
Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Do I need inheritance or no? Creating a game with rectangular shapes

Post Reopened by Jamal, Vedran Šego, Jeff Vanzella, Nikita B, palacsint
added 10 characters in body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

I'm using Pygame to create a small game with few rectangle shapes. However, howere I wanttowant to learn more about classes, and I'm trying to use them. I'm I'm very newbienew to classes and inheritance, but I want to learn the best habit'shabits possible. I'm using Python 3.3.2.

import pygame
class Screen(object):
 ''' Creates main window and handles surface object. '''
 def __init__(self, width, height):
 self.WIDTH = width
 self.HEIGHT = height
 self.SURFACE = pygame.display.set_mode((self.WIDTH, self.HEIGHT), 0, 32)
class GameManager(object):
 ''' Handles game state datas and updates. '''
 def __init__(self, screen):
 self.screen = screen
pygame.init()
Window = Screen(800, 500)
Game = GameManager(Window)

I skipedskipped a few functions to make it simpler, the. The thing that bothers me is that iI've been told that I dontdon't need GameManager to be subclasses of Screen, I. I was advised to use this implementation., but I find it very strange to use 'Window' as a parameter to GameManager.

Do I need to use inheritance, should i? Should I use super()? Later Later on, I will have class Player and I will need some of the attributes from the Screen class. From From the view pointviewpoint of designing OO for a GUI game using Pygame.

I'm using Pygame to create a small game with few rectangle shapes, howere I wantto learn more about classes, and I'm trying to use them. I'm very newbie to classes and inheritance but I want to learn the best habit's possible. I'm using Python 3.3.2.

import pygame
class Screen(object):
 ''' Creates main window and handles surface object. '''
 def __init__(self, width, height):
 self.WIDTH = width
 self.HEIGHT = height
 self.SURFACE = pygame.display.set_mode((self.WIDTH, self.HEIGHT), 0, 32)
class GameManager(object):
 ''' Handles game state datas and updates. '''
 def __init__(self, screen):
 self.screen = screen
pygame.init()
Window = Screen(800, 500)
Game = GameManager(Window)

I skiped few functions to make it simpler, the thing that bothers me is that i been told that I dont need GameManager to be subclasses of Screen, I was advised to use this implementation. but I find it very strange to use 'Window' as a parameter to GameManager.

Do I need to use inheritance, should i use super()? Later on, I will have class Player and I will need some of the attributes from the Screen class. From the view point of designing OO for a GUI game using Pygame.

I'm using Pygame to create a small game with few rectangle shapes. However, I want to learn more about classes, and I'm trying to use them. I'm very new to classes and inheritance, but I want to learn the best habits possible. I'm using Python 3.3.2.

import pygame
class Screen(object):
 ''' Creates main window and handles surface object. '''
 def __init__(self, width, height):
 self.WIDTH = width
 self.HEIGHT = height
 self.SURFACE = pygame.display.set_mode((self.WIDTH, self.HEIGHT), 0, 32)
class GameManager(object):
 ''' Handles game state datas and updates. '''
 def __init__(self, screen):
 self.screen = screen
pygame.init()
Window = Screen(800, 500)
Game = GameManager(Window)

I skipped a few functions to make it simpler. The thing that bothers me is that I've been told that I don't need GameManager to be subclasses of Screen. I was advised to use this implementation, but I find it very strange to use 'Window' as a parameter to GameManager.

Do I need to use inheritance? Should I use super()? Later on, I will have class Player and I will need some of the attributes from the Screen class. From the viewpoint of designing OO for a GUI game using Pygame.

The question was for SO, now edited to fit in CR.
Source Link
dragons
  • 359
  • 1
  • 9
Loading
Post Closed as "Not suitable for this site" by Gareth Rees, svick, palacsint, Jamal, Brian Reichle
Source Link
dragons
  • 359
  • 1
  • 9
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /