Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor unnecessary else / elif when if block has a return statement #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions minesweeper/GameElements.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def __str__(self):
"""
if self.isFlagged:
return "F" # this element was flagged
else:
return "*" # this element has neither been flagged nor revealed
return "*" # this element has neither been flagged nor revealed

@abstractmethod
def flag(self):
Expand Down Expand Up @@ -52,8 +51,7 @@ class Mine(GameElement):
def __str__(self):
if self.isRevealed:
return "X" # the bomb explodes
else:
return super().__str__()
return super().__str__()

def flag(self):
"""
Expand All @@ -64,8 +62,7 @@ def flag(self):
super().flag()
if self.isFlagged:
return 1
else:
return -1
return -1

def reveal(self):
"""
Expand All @@ -87,8 +84,7 @@ def __init__(self, counter):
def __str__(self):
if self.isRevealed:
return str(self.counter) # show the bomb counter
else:
return super().__str__()
return super().__str__()

def flag(self):
"""
Expand All @@ -109,5 +105,4 @@ def reveal(self):
super().reveal()
if self.counter == 0:
return True
else:
return False
return False
12 changes: 5 additions & 7 deletions minesweeper/GameLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ def flag(self, x, y):
self.ended = True
self.won = True
return self.__str__
else:
return "You have to reveal at least one field before you can use flag."
return "You have to reveal at least one field before you can use flag."

def reveal(self, x, y, nop=False):
"""
Expand Down Expand Up @@ -170,8 +169,7 @@ def reveal(self, x, y, nop=False):
self.won = True
if nop:
return ""
else:
return self.__str__
return self.__str__

def reveal_adjacent_counters(self, x, y):
"""
Expand Down Expand Up @@ -277,13 +275,13 @@ def parse_input(self, message: str) -> str:
if message[4:8] == "easy":
self.game_round = GameRound(8, 8, 10)
return self.game_round.print_empty()
elif message[4:8] == "hard":
if message[4:8] == "hard":
self.game_round = GameRound(30, 16, 99)
return self.game_round.print_empty()
elif message[4:10] == "medium":
if message[4:10] == "medium":
self.game_round = GameRound(16, 16, 40)
return self.game_round.print_empty()
elif message[4:10] == "custom":
if message[4:10] == "custom":
index_x = message.find("x", 11)
index = message.find(",", 11)
try:
Expand Down