Skip to main content
edited body
Source Link
toolic
  • 16.4k
  • 6
  • 29
  • 221

UX

When I run the code, it just hangs in my shell. The code has this line:

a = input()

This means that the code is waiting for user input, but there is no indication of that. You should add text to the prompt which providedprovides instructions for the user. For example:

a = input('Enter an option. To exit hit e, to reload hit r, to show remaining hit Enter ')

Also, a is not a very descriptive name for a variable in this context. action would be more appropriate. Since the function is already named action, I recommend renaming the function as run_game.

Import

It is a good practice to split each import onto its own line. Change:

import random, pygame, sys

to:

import random
import pygame
import sys

OOP

Using object is no longer needed:

class MachineGun(object):

It is simpler as:

class MachineGun():

You should structure the class such that you don't use the class name itself within the class. For example, it would be better if you did not use MachineGun in the line below:

if MachineGun.bullets >= 50 :

Generally, you should reference a class variable with self.

f-string

The following line:

print("Bullets remaining : {}".format(self.magazine))

is simpler with an f-string:

print(f"Bullets remaining : {self.magazine}")

Documentation

The PEP 8 style guide recommends adding doctrings to describe your class and functions. It would be nice to add a doctrings to summarize the purpose of the code as well. This header docstring would also contain instructions for the user as well as notifying the user that input .wav files are needed to run the code.

Whitespace

The code uses inconsistent whitespace. The black program can be used to automatically format the code consistently.

Assignment

This line:

MachineGun.bullets = MachineGun.bullets-50

can be simplified using a special assignment operator:

MachineGun.bullets -= 50

There are other instances of this. In fact, you already used it here:

self.magazine += MachineGun.bullets

UX

When I run the code, it just hangs in my shell. The code has this line:

a = input()

This means that the code is waiting for user input, but there is no indication of that. You should add text to the prompt which provided instructions for the user. For example:

a = input('Enter an option. To exit hit e, to reload hit r, to show remaining hit Enter ')

Also, a is not a very descriptive name for a variable in this context. action would be more appropriate. Since the function is already named action, I recommend renaming the function as run_game.

Import

It is a good practice to split each import onto its own line. Change:

import random, pygame, sys

to:

import random
import pygame
import sys

OOP

Using object is no longer needed:

class MachineGun(object):

It is simpler as:

class MachineGun():

You should structure the class such that you don't use the class name itself within the class. For example, it would be better if you did not use MachineGun in the line below:

if MachineGun.bullets >= 50 :

Generally, you should reference a class variable with self.

f-string

The following line:

print("Bullets remaining : {}".format(self.magazine))

is simpler with an f-string:

print(f"Bullets remaining : {self.magazine}")

Documentation

The PEP 8 style guide recommends adding doctrings to describe your class and functions. It would be nice to add a doctrings to summarize the purpose of the code as well. This header docstring would also contain instructions for the user as well as notifying the user that input .wav files are needed to run the code.

Whitespace

The code uses inconsistent whitespace. The black program can be used to automatically format the code consistently.

Assignment

This line:

MachineGun.bullets = MachineGun.bullets-50

can be simplified using a special assignment operator:

MachineGun.bullets -= 50

There are other instances of this. In fact, you already used it here:

self.magazine += MachineGun.bullets

UX

When I run the code, it just hangs in my shell. The code has this line:

a = input()

This means that the code is waiting for user input, but there is no indication of that. You should add text to the prompt which provides instructions for the user. For example:

a = input('Enter an option. To exit hit e, to reload hit r, to show remaining hit Enter ')

Also, a is not a very descriptive name for a variable in this context. action would be more appropriate. Since the function is already named action, I recommend renaming the function as run_game.

Import

It is a good practice to split each import onto its own line. Change:

import random, pygame, sys

to:

import random
import pygame
import sys

OOP

Using object is no longer needed:

class MachineGun(object):

It is simpler as:

class MachineGun():

You should structure the class such that you don't use the class name itself within the class. For example, it would be better if you did not use MachineGun in the line below:

if MachineGun.bullets >= 50 :

Generally, you should reference a class variable with self.

f-string

The following line:

print("Bullets remaining : {}".format(self.magazine))

is simpler with an f-string:

print(f"Bullets remaining : {self.magazine}")

Documentation

The PEP 8 style guide recommends adding doctrings to describe your class and functions. It would be nice to add a doctrings to summarize the purpose of the code as well. This header docstring would also contain instructions for the user as well as notifying the user that input .wav files are needed to run the code.

Whitespace

The code uses inconsistent whitespace. The black program can be used to automatically format the code consistently.

Assignment

This line:

MachineGun.bullets = MachineGun.bullets-50

can be simplified using a special assignment operator:

MachineGun.bullets -= 50

There are other instances of this. In fact, you already used it here:

self.magazine += MachineGun.bullets
Source Link
toolic
  • 16.4k
  • 6
  • 29
  • 221

UX

When I run the code, it just hangs in my shell. The code has this line:

a = input()

This means that the code is waiting for user input, but there is no indication of that. You should add text to the prompt which provided instructions for the user. For example:

a = input('Enter an option. To exit hit e, to reload hit r, to show remaining hit Enter ')

Also, a is not a very descriptive name for a variable in this context. action would be more appropriate. Since the function is already named action, I recommend renaming the function as run_game.

Import

It is a good practice to split each import onto its own line. Change:

import random, pygame, sys

to:

import random
import pygame
import sys

OOP

Using object is no longer needed:

class MachineGun(object):

It is simpler as:

class MachineGun():

You should structure the class such that you don't use the class name itself within the class. For example, it would be better if you did not use MachineGun in the line below:

if MachineGun.bullets >= 50 :

Generally, you should reference a class variable with self.

f-string

The following line:

print("Bullets remaining : {}".format(self.magazine))

is simpler with an f-string:

print(f"Bullets remaining : {self.magazine}")

Documentation

The PEP 8 style guide recommends adding doctrings to describe your class and functions. It would be nice to add a doctrings to summarize the purpose of the code as well. This header docstring would also contain instructions for the user as well as notifying the user that input .wav files are needed to run the code.

Whitespace

The code uses inconsistent whitespace. The black program can be used to automatically format the code consistently.

Assignment

This line:

MachineGun.bullets = MachineGun.bullets-50

can be simplified using a special assignment operator:

MachineGun.bullets -= 50

There are other instances of this. In fact, you already used it here:

self.magazine += MachineGun.bullets