Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
GameChangers/game.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
72 lines (51 sloc)
2.14 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional, Tuple | |
import random | |
class Game: | |
def __init__(self, player1: str, player2: str) -> None: | |
self.player1 = player1 # Save player1 data in self.player1 | |
self.player2 = player2 | |
self.player1_space = None | |
self.player2_space = None | |
self.turn = player1 | |
#self.player1_dice = player1_dice | |
#self.player2_dice = player2_dice | |
def get_player1_name(self) -> str: | |
"Returns the name of Player 1 as a string." | |
return self.player1 | |
def get_player2_name(self) -> str: | |
"Returns the name of Player 2 as a string." | |
return self.player2 | |
def get_player1_space(self) -> Optional[int]: | |
"""Returns either None (for Start) or the space number player 1 is currently on""" | |
return self.player1_space | |
def get_player2_space(self) -> Optional[int]: | |
"""Returns either None (for Start) or the space number player 2 is currently on""" | |
return self.player2_space | |
def get_current_player(self) -> str: | |
"""Returns the name of the current player.""" | |
return self.turn | |
def roll_dice(self) -> None: | |
"""Updates the game in-place by rolling dice.""" | |
#dice1 = random.randint(1,6) | |
#dice2 = random.randint(1,6) | |
#self.player1_dice = dice1 + dice2 | |
#dice1 = random.randint(1,6) | |
if self.turn == self.player1: | |
self.turn = self.player2 | |
else: | |
self.turn = self.player1 | |
if self.player1_space == None: | |
self.player1_space = 0 | |
if self.player2_space == None: | |
self.player2_space = 0 | |
self.player1_space += random.randint(1,6) + random.randint(1,6) | |
self.player2_space += random.randint(1, 6) + random.randint(1, 6) | |
def get_last_dice_roll(self) -> Optional[Tuple[int, int]]: | |
"""Returns either None or a pair of die rolls, like (2, 6)""" | |
return None | |
def is_over(self) -> bool: | |
"""Returns True if game is over.""" | |
return False | |
def get_winner(self) -> Optional[str]: | |
"""Returns None (if the game is not over) or the name of the winner""" | |
return None | |