class MainMenuController(PygameController):
    """ Controller for the Pygame Main Menu """
    
    def __init__(self):
        """ Initialize the Main Menu Controller """
        self.currentPlayer = PlayerFactory.getLastPlayer()
        
        
        entries = [TextMenuEntry("New", self.newGame),
                   TextMenuEntry("Options", self.runOptions),
                   TextMenuEntry("Exit", self.stopRunning)]
        self.menu = Menu(entries)
        
        if self.currentPlayer is not None:
            continueMenuEntry = TextMenuEntry("Continue", self.continueGame)
            entries.insert(1, continueMenuEntry)
            self.menu.down()
        
        screen = MainMenuScreen(self.menu, self.currentPlayer)
        PygameController.__init__(self, screen, commands = {commands.UP:self.menu.up,
                                                            commands.DOWN:self.menu.down,
                                                            commands.EXIT:self.stopRunning,
                                                            commands.SELECT:self.menu.enter})
        
    def newGame(self, entry):
        """ Start a New Game """
        PlayerFactory.createNewPlayer("Doe")
        
    def continueGame(self, entry):
        """ Continue the Game """
        self.runController(ModeMenuController(self.currentPlayer))
        
    def runOptions(self, entry):
        """ Run Options Controller """
        self.runController(OptionsMenuController())
 def setUp(self):
     """ Build the Menu and Entries for the test """
     self.menu = Menu()
     self.firstEntry = TextMenuEntry("1", None)
     self.secondEntry = TextMenuEntry("2", None)
     self.thirdEntry = TextMenuEntry("3", None)
     self.menu.entries = [
         self.firstEntry, self.secondEntry, self.thirdEntry
     ]
     self.menu.selectEntry()
class changeSelected(unittest.TestCase):
    """ Test cases of changeSelected """
    def setUp(self):
        """ Build the Menu and Entries for the test """
        self.menu = Menu()
        self.firstEntry = TextMenuEntry("1", None)
        self.secondEntry = TextMenuEntry("2", None)
        self.thirdEntry = TextMenuEntry("3", None)
        self.menu.entries = [
            self.firstEntry, self.secondEntry, self.thirdEntry
        ]
        self.menu.selectEntry()

    def selectedChanged(self):
        """ Test that the selected Entry Changed """
        current = self.menu.current
        assert self.firstEntry.selected, "First Entry should be selected"
        self.menu.changeSelected(1)

        assert self.menu.current == current + 1, "Current Entry should have increased by one"
        assert not self.firstEntry.selected, "First Entry should be deselected"
        assert self.secondEntry.selected, "Second Entry should be selected"

    def wrapAround(self):
        """ Test that the selection can wrap around by going negative """
        current = self.menu.current
        assert self.firstEntry.selected, "First Entry should be selected"
        self.menu.changeSelected(-1)

        assert self.menu.current == (current - 1) % len(
            self.menu.entries), "Current Entry should have increased by one"
        assert not self.firstEntry.selected, "First Entry should be deselected"
        assert self.thirdEntry.selected, "Third Entry should be selected"

    def fullRotationBackwards(self):
        """ Test that the selection can be fully rotated through all possible actions and return to the start """
        current = self.menu.current
        assert self.firstEntry.selected, "First Entry should be selected"
        self.menu.changeSelected(-1 * len(self.menu.entries))

        assert self.menu.current == current, "Current Entry should have be the same"
        assert self.firstEntry.selected, "First Entry should be selected"

    def fullRotationForwards(self):
        """ Test that the selection can be fully rotated through all possible actions and return to the start """
        current = self.menu.current
        assert self.firstEntry.selected, "First Entry should be selected"
        self.menu.changeSelected(len(self.menu.entries))

        assert self.menu.current == current, "Current Entry should have be the same"
        assert self.firstEntry.selected, "First Entry should be selected"
Exemplo n.º 4
0
class changeSelected(unittest.TestCase):
    """ Test cases of changeSelected """
    
    def  setUp(self):
        """ Build the Menu and Entries for the test """
        self.menu = Menu()
        self.firstEntry = TextMenuEntry("1", None)
        self.secondEntry = TextMenuEntry("2", None)
        self.thirdEntry = TextMenuEntry("3", None)
        self.menu.entries = [self.firstEntry, self.secondEntry, self.thirdEntry]
        self.menu.selectEntry()
        
    def selectedChanged(self):
        """ Test that the selected Entry Changed """
        current = self.menu.current
        assert self.firstEntry.selected, "First Entry should be selected"
        self.menu.changeSelected(1)
        
        assert self.menu.current == current + 1, "Current Entry should have increased by one"
        assert not self.firstEntry.selected, "First Entry should be deselected"
        assert self.secondEntry.selected, "Second Entry should be selected"
        
    def wrapAround(self):
        """ Test that the selection can wrap around by going negative """
        current = self.menu.current
        assert self.firstEntry.selected, "First Entry should be selected"
        self.menu.changeSelected(-1)
        
        assert self.menu.current == (current - 1)% len(self.menu.entries), "Current Entry should have increased by one"
        assert not self.firstEntry.selected, "First Entry should be deselected"
        assert self.thirdEntry.selected, "Third Entry should be selected"
        
    def fullRotationBackwards(self):
        """ Test that the selection can be fully rotated through all possible actions and return to the start """
        current = self.menu.current
        assert self.firstEntry.selected, "First Entry should be selected"
        self.menu.changeSelected(-1*len(self.menu.entries))
        
        assert self.menu.current == current, "Current Entry should have be the same"
        assert self.firstEntry.selected, "First Entry should be selected"
        
    def fullRotationForwards(self):
        """ Test that the selection can be fully rotated through all possible actions and return to the start """
        current = self.menu.current
        assert self.firstEntry.selected, "First Entry should be selected"
        self.menu.changeSelected(len(self.menu.entries))
        
        assert self.menu.current == current, "Current Entry should have be the same"
        assert self.firstEntry.selected, "First Entry should be selected"
Exemplo n.º 5
0
    def __init__(self, pokemon, battle, screen):
        """ Initialize the Battle Round Controller """
        self.pokemon = pokemon
        self.battle = battle
        self.action = None

        entries = [
            TextMenuEntry("Fight", self.chooseAttack),
            TextMenuEntry("Switch", self.switch),
            TextMenuEntry("Item", None),
            TextMenuEntry("Run", None)
        ]
        self.menu = Menu(entries, columns=2)

        self.view = ActionMenuWidget(self.menu,
                                     self.getWindow().width * .9,
                                     self.getWindow().height * .3)
        screen.setBottomView(self.view)
        cmds = {
            commands.UP: self.menu.up,
            commands.DOWN: self.menu.down,
            commands.LEFT: self.menu.left,
            commands.RIGHT: self.menu.right,
            commands.SELECT: self.menu.enter
        }
        PygameController.__init__(self, screen, commands=cmds)
Exemplo n.º 6
0
    def __init__(self, pokemon, targets, environment, screen):
        """ Initialize the Attack Menu """
        self.pokemon = pokemon
        self.targets = targets
        self.environment = environment
        self.action = None

        entries = []
        for attack in self.pokemon.getAttacks():
            entries.append(AttackMenuEntry(attack, self.setAction))
        self.menu = Menu(entries, columns=2)

        screen.setBottomView(
            ActionMenuWidget(self.menu,
                             self.getWindow().width * .9,
                             self.getWindow().height * .3,
                             MenuEntryWidget=AttackMenuEntryWidget))
        cmds = {
            commands.UP: self.menu.up,
            commands.DOWN: self.menu.down,
            commands.LEFT: self.menu.left,
            commands.RIGHT: self.menu.right,
            commands.SELECT: self.menu.enter,
            commands.EXIT: self.stopRunning
        }
        PygameController.__init__(self, screen, commands=cmds)
Exemplo n.º 7
0
    def __init__(self, pokemon, targets, battle):
        """ Builds the Attack Controller """
        self.pokemon = pokemon
        self.targets = targets
        self.battle = battle
        self.action = None

        entries = []
        for attack in self.pokemon.getAttacks():
            entries.append(AttackMenuEntry(attack, self.setAction))
        self.menu = Menu(entries, columns=2)

        screen = ActionMenuScreen(self.menu, battle)
        cmds = {
            ENDL: self.menu.enter,
            KAO_UP: self.menu.up,
            KAO_DOWN: self.menu.down,
            KAO_RIGHT: self.menu.right,
            KAO_LEFT: self.menu.left
        }

        ConsoleController.__init__(self,
                                   screen,
                                   commands=cmds,
                                   cancellable=True)
Exemplo n.º 8
0
 def  setUp(self):
     """ Build the Menu and Entries for the test """
     self.menu = Menu()
     self.firstEntry = TextMenuEntry("1", None)
     self.secondEntry = TextMenuEntry("2", None)
     self.thirdEntry = TextMenuEntry("3", None)
     self.menu.entries = [self.firstEntry, self.secondEntry, self.thirdEntry]
     self.menu.selectEntry()
Exemplo n.º 9
0
    def run_main(self):
        """
        Runs the menu and then the game based on what the user does in the menu
        """
        clock = pygame.time.Clock()  # TODO: Fix time step
        Menu(self.screen)
        Run(self.user_id, self.user, self.highscore, self.screen, 1500, 900)

        clock.tick(60)  # Use for later reference
Exemplo n.º 10
0
 def __init__(self):
     """ Initialize the Main Menu Controller """
     self.currentPlayer = PlayerFactory.getLastPlayer()
     
     
     entries = [TextMenuEntry("New", self.newGame),
                TextMenuEntry("Options", self.runOptions),
                TextMenuEntry("Exit", self.stopRunning)]
     self.menu = Menu(entries)
     
     if self.currentPlayer is not None:
         continueMenuEntry = TextMenuEntry("Continue", self.continueGame)
         entries.insert(1, continueMenuEntry)
         self.menu.down()
     
     screen = MainMenuScreen(self.menu, self.currentPlayer)
     PygameController.__init__(self, screen, commands = {commands.UP:self.menu.up,
                                                         commands.DOWN:self.menu.down,
                                                         commands.EXIT:self.stopRunning,
                                                         commands.SELECT:self.menu.enter})
Exemplo n.º 11
0
    def __init__(self, lastController):
        """ Initialize the Zone Menu Controller """
        entries = [TextMenuEntry("Exit", self.exitZone)]
        self.menu = Menu(entries)
        self.lastController = lastController

        screen = ZoneMenuScreen(self.menu, lastController.screen)
        PygameController.__init__(self,
                                  screen,
                                  commands={
                                      commands.UP: self.menu.up,
                                      commands.DOWN: self.menu.down,
                                      commands.EXIT: self.stopRunning,
                                      commands.SELECT: self.menu.enter
                                  })
Exemplo n.º 12
0
    def __init__(self):
        """ Builds the Main Menu Controller """
        entries = [
            TextMenuEntry("Start", self.startGame),
            TextMenuEntry("Options", self.runOptions),
            TextMenuEntry("Exit", self.stopRunning)
        ]
        self.menu = Menu(entries)

        screen = MainMenuScreen(self.menu)
        cmds = {
            KAO_UP: self.menu.up,
            KAO_DOWN: self.menu.down,
            ENDL: self.menu.enter
        }

        ConsoleController.__init__(self, screen, commands=cmds)
 def __init__(self, pokemon, lastScreen):
     """ Initialize the Attack Picker Controller """
     self.pokemon = pokemon
     self.attack = None
     
     entries = []
     for attack in self.pokemon.getAttacks():
         entries.append(AttackMenuEntry(attack, self.pickAttack))
     self.menu = Menu(entries, columns=2)
     menuWidget = ActionMenuWidget(self.menu, self.getWindow().width*.9, self.getWindow().height*.3, MenuEntryWidget=AttackMenuEntryWidget)
     
     screen = AttackPickerScreen(menuWidget, lastScreen)
     cmds = {commands.UP:self.menu.up,
             commands.DOWN:self.menu.down,
             commands.LEFT:self.menu.left,
             commands.RIGHT:self.menu.right,
             commands.SELECT:self.menu.enter,
             commands.EXIT:self.stopRunning}
     PygameController.__init__(self, screen, commands=cmds)
 def __init__(self, pokemon, cancellable=True):
     """ Initialize the Switch Menu """
     self.pokemon = pokemon
     self.action = None
     
     entries = []
     for pokemon in self.pokemon.getTrainer().beltPokemon:
         entries.append(PokemonMenuEntry(pokemon, self.setAction))
     self.menu = Menu(entries, columns=2)
     
     screen = SwitchMenuScreen(self.menu)
     cmds = {commands.UP:self.menu.up,
             commands.DOWN:self.menu.down,
             commands.LEFT:self.menu.left,
             commands.RIGHT:self.menu.right,
             commands.SELECT:self.menu.enter}
     if cancellable:
         cmds[commands.EXIT] = self.stopRunning
             
     PygameController.__init__(self, screen, commands=cmds)
Exemplo n.º 15
0
    def __init__(self, currentPlayer):
        """ Initialize the Mode Menu Controller """
        self.currentPlayer = currentPlayer

        entries = [
            TextMenuEntry("Story", self.playStory),
            TextMenuEntry("Marathon", self.runMarathon),
            TextMenuEntry("Back", self.stopRunning)
        ]
        self.menu = Menu(entries)

        screen = MainMenuScreen(self.menu, self.currentPlayer)
        PygameController.__init__(self,
                                  screen,
                                  commands={
                                      commands.UP: self.menu.up,
                                      commands.DOWN: self.menu.down,
                                      commands.EXIT: self.stopRunning,
                                      commands.SELECT: self.menu.enter
                                  })
Exemplo n.º 16
0
 def __init__(self, pokemon, battle):
     """ Builds the Action Controller """
     self.pokemon = pokemon
     self.battle = battle
     self.action = None
     
     entries = [TextMenuEntry("Fight", self.chooseAttack),
                TextMenuEntry("Switch", self.switch),
                TextMenuEntry("Item", None),
                TextMenuEntry("Run", None)]
     self.menu = Menu(entries, columns=2)
     
     screen = ActionMenuScreen(self.menu, battle)
     cmds = {ENDL:self.menu.enter,
             KAO_UP:self.menu.up,
             KAO_DOWN:self.menu.down,
             KAO_RIGHT:self.menu.right,
             KAO_LEFT:self.menu.left}
                  
     ConsoleController.__init__(self, screen, commands=cmds)
Exemplo n.º 17
0
    def __init__(self, pokemon, cancellable=True):
        """ Builds the Switch Controller """
        self.pokemon = pokemon
        self.action = None

        entries = []
        for pokemon in self.pokemon.getTrainer().beltPokemon:
            entries.append(PokemonMenuEntry(pokemon, self.setAction))
        self.menu = Menu(entries, columns=2)
        screen = PokemonMenuScreen(self.menu)  # Need different screen

        cmds = {
            ENDL: self.menu.enter,
            KAO_UP: self.menu.up,
            KAO_DOWN: self.menu.down,
            KAO_RIGHT: self.menu.right,
            KAO_LEFT: self.menu.left
        }

        ConsoleController.__init__(self,
                                   screen,
                                   commands=cmds,
                                   cancellable=cancellable)
Exemplo n.º 18
0
 def __init__(self, callback):
     """ Initialize the Trainer Menu """
     self.callback = callback
     Menu.__init__(self)
Exemplo n.º 19
0
 def __init__(self, callback):
     """ Initialize the Trainer Menu """
     self.callback = callback
     Menu.__init__(self)
Exemplo n.º 20
0
    def run_main(self):
        clock = pygame.time.Clock()  # TODO: Fix time step
        Menu(self.screen)
        Run(self.user_id, self.user, self.screen, 1500, 900)

        clock.tick(60)  # Use for later reference
Exemplo n.º 21
0
import pygame
from Menu.menu import Menu
from Menu.savesettings import GetRes

#Code to initialise Menu and program
pygame.init()
width = int(GetRes()[0])
height = int(GetRes()[1])

mode = (GetRes()[2])
if mode == "fullscreen":
    screen = pygame.display.set_mode((width, height), pygame.FULLSCREEN)
else:
    screen = pygame.display.set_mode([width, height])

mainmenu = Menu(screen)
mainmenu.MainMenu()