Sorry I'm too hairy, it's pawn not paw !
This commit is contained in:
parent
7232aa9bd8
commit
a148c75ab2
2 changed files with 21 additions and 21 deletions
26
Morpion.py
26
Morpion.py
|
@ -5,16 +5,16 @@ class Player:
|
||||||
"""self, number (int), pawn (str), name (str)
|
"""self, number (int), pawn (str), name (str)
|
||||||
A player of the party"""
|
A player of the party"""
|
||||||
self.number = number # The number of the player
|
self.number = number # The number of the player
|
||||||
self.pawn = pawn # The paw of the player
|
self.pawn = pawn # The pawn of the player
|
||||||
self.name = name # The name of the player
|
self.name = name # The name of the player
|
||||||
self.pawns = list() # All the paws on the grid of the player
|
self.pawns = list() # All the pawns on the grid of the player
|
||||||
self.points = 0 # The points of the player
|
self.points = 0 # The points of the player
|
||||||
|
|
||||||
def add_pawn(self, enemy: list, pos: int):
|
def add_pawn(self, enemy: list, pos: int):
|
||||||
"""self, enemy (list), pos (int)
|
"""self, enemy (list), pos (int)
|
||||||
Check if position is free by the enemy grid and add to the grid"""
|
Check if position is free by the enemy grid and add to the grid"""
|
||||||
if (pos not in self.pawns) and (pos not in enemy): # Check the enemy grid
|
if (pos not in self.pawns) and (pos not in enemy): # Check the enemy grid
|
||||||
self.pawns.append(pos) # Add the paw to the player grid
|
self.pawns.append(pos) # Add the pawn to the player grid
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -62,18 +62,18 @@ class Player:
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
"""self
|
"""self
|
||||||
Return the number of player's paws"""
|
Return the number of player's panws"""
|
||||||
return len(self.pawns)
|
return len(self.pawns)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""self
|
"""self
|
||||||
Setup iterable for paws list"""
|
Setup iterable for pawns list"""
|
||||||
self.iterable = 0
|
self.iterable = 0
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
"""self
|
"""self
|
||||||
Return iterable of paws"""
|
Return iterable of pawns"""
|
||||||
if self.iterable <= len(self.pawns)-1: # check is not exceed
|
if self.iterable <= len(self.pawns)-1: # check is not exceed
|
||||||
self.iterable += 1
|
self.iterable += 1
|
||||||
return self.pawns[self.iterable-1]
|
return self.pawns[self.iterable-1]
|
||||||
|
@ -82,19 +82,19 @@ class Player:
|
||||||
|
|
||||||
|
|
||||||
class Board:
|
class Board:
|
||||||
"""self, p1_paw (str), p1_name (str), p2_paw (str), p2_name (str)
|
"""self, p1_pawn (str), p1_name (str), p2_pawn (str), p2_name (str)
|
||||||
A party object"""
|
A party object"""
|
||||||
def __init__(self, p1_paw: str, p1_name : str, p2_paw: str, p2_name: str):
|
def __init__(self, p1_pawn: str, p1_name : str, p2_pawn: str, p2_name: str):
|
||||||
"""self, p1_paw (str), p1_name (str), p2_paw (str), p2_name (str)
|
"""self, p1_pawn (str), p1_name (str), p2_pawn (str), p2_name (str)
|
||||||
A party object"""
|
A party object"""
|
||||||
# Security if conflict with players paws and name
|
# Security if conflict with players pawns and name
|
||||||
if p1_paw == p2_paw:
|
if p1_pawn == p2_pawn:
|
||||||
raise ValueError("The pawns are the same !")
|
raise ValueError("The pawns are the same !")
|
||||||
elif p1_name == p2_name:
|
elif p1_name == p2_name:
|
||||||
raise ValueError("The name are the same !")
|
raise ValueError("The name are the same !")
|
||||||
|
|
||||||
self.player1 = Player(1, p1_paw, p1_name) # Set player 1
|
self.player1 = Player(1, p1_pawn, p1_name) # Set player 1
|
||||||
self.player2 = Player(2, p2_paw, p2_name) # Set player 2
|
self.player2 = Player(2, p2_pawn, p2_name) # Set player 2
|
||||||
self.curr_turn = [self.player1, self.player2] # Set turn order
|
self.curr_turn = [self.player1, self.player2] # Set turn order
|
||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
|
|
16
gui.py
16
gui.py
|
@ -36,11 +36,11 @@ def case(posi: int):
|
||||||
|
|
||||||
|
|
||||||
def set_players():
|
def set_players():
|
||||||
"""Set players paws and name before start the party"""
|
"""Set players pawns and name before start the party"""
|
||||||
if "" in [p1_paw.get(), p1_name.get(), p2_paw.get(), p2_name.get()]: # check if any empty entry
|
if "" in [p1_pawn.get(), p1_name.get(), p2_pawn.get(), p2_name.get()]: # check if any empty entry
|
||||||
showerror("Error", "A entry is blank !") # Show a warning
|
showerror("Error", "A entry is blank !") # Show a warning
|
||||||
elif p1_paw.get() == p2_paw.get(): # Check if players paws are same
|
elif p1_pawn.get() == p2_pawn.get(): # Check if players pawns are same
|
||||||
showerror("Error", "Players paws are identical !") # Show a warning
|
showerror("Error", "Players pawns are identical !") # Show a warning
|
||||||
elif p1_name.get() == p2_name.get(): # Check if players names are same
|
elif p1_name.get() == p2_name.get(): # Check if players names are same
|
||||||
showerror("Error", "Players names are identical !") # Show a warning
|
showerror("Error", "Players names are identical !") # Show a warning
|
||||||
else: # If everything is fine
|
else: # If everything is fine
|
||||||
|
@ -62,20 +62,20 @@ players_p2f = LabelFrame(players_f, text="Player 2")
|
||||||
players_p1f.grid(row=0, column=0)
|
players_p1f.grid(row=0, column=0)
|
||||||
players_p2f.grid(row=0, column=1)
|
players_p2f.grid(row=0, column=1)
|
||||||
|
|
||||||
p1_paw, p1_name, p2_paw, p2_name = StringVar(), StringVar(), StringVar(), StringVar() # Setup entry value
|
p1_pawn, p1_name, p2_pawn, p2_name = StringVar(), StringVar(), StringVar(), StringVar() # Setup entry value
|
||||||
|
|
||||||
# Generate symmetrically widgets for player infos
|
# Generate symmetrically widgets for player infos
|
||||||
for i in [[players_p1f, p1_paw, p1_name], [players_p2f, p2_paw, p2_name]]: # List contain the frame and the entry var
|
for i in [[players_p1f, p1_pawn, p1_name], [players_p2f, p2_pawn, p2_name]]: # List contain the frame and the entry var
|
||||||
Label(i[0], text="Player name:").pack()
|
Label(i[0], text="Player name:").pack()
|
||||||
Entry(i[0], textvariable=i[2], width=20).pack()
|
Entry(i[0], textvariable=i[2], width=20).pack()
|
||||||
Label(i[0], text="Player paw:").pack()
|
Label(i[0], text="Player pawn:").pack()
|
||||||
Entry(i[0], textvariable=i[1], width=5).pack()
|
Entry(i[0], textvariable=i[1], width=5).pack()
|
||||||
|
|
||||||
Button(players, text="Submit", command=set_players).pack() # Create the submit button
|
Button(players, text="Submit", command=set_players).pack() # Create the submit button
|
||||||
|
|
||||||
players.mainloop()
|
players.mainloop()
|
||||||
|
|
||||||
board = Board(p1_paw.get(), p1_name.get(), p2_paw.get(), p2_name.get()) # Create a party board
|
board = Board(p1_pawn.get(), p1_name.get(), p2_pawn.get(), p2_name.get()) # Create a party board
|
||||||
|
|
||||||
# Create party window
|
# Create party window
|
||||||
windows = Tk()
|
windows = Tk()
|
||||||
|
|
Loading…
Reference in a new issue