Exemplo n.º 1
0
def play_game():

  print 'picking up'
  print session.get('state')
  # pick up wherever we left off
  adventure = AdventureMachine(state=session.get('state'))
  from_number = request.form.get('From')
  choice = request.form.get('Body', '').lower()

  adventure.on_transition = lambda x,y: twilio_output(from_number, y)

  # As the user progresses save their state
  def save_state(state):
    print 'changing state'
    print state
    session['state'] = state
  adventure.on_state_change = save_state

  if not choice or not len(adventure._states):
    adventure.play()
  else:
    try:
      adventure.transition_to(choice)
    except:
      twilio_output(from_number, 'Not a valid choice')
  return ''
Exemplo n.º 2
0
def doStep(step):
    ad = Adventure('data.json')

    click.clear()
    if ad.type(step) is not None:
        quiz.run(ad.getStep(step))

    click.echo(click.style(ad.title(step), bold=True))
    click.echo(click.style(ad.text(step)))

    if ad.choices(step) is None:
        click.echo(click.style('End of your journey goodbye.', fg='red'))
        quit()

    for idx, option in enumerate(ad.choices(step)):
        click.echo(click.style('['+str(idx+1)+'] ' + option['text']))

    choice = click.prompt('What do you want to do ?', type = int)
    doStep(ad.choices(step)[choice-1]['link'])
Exemplo n.º 3
0
            window.clear()
            window.border(0)
            prompt_string = "How many candles?"
            window.addstr(1, 1, prompt_string)
            curses.echo()
            candles_added = int(window.getstr())
            adventurer.add_candles(candles_added)
            curses.noecho()
        if command == ord('4'):
            window.clear()
            window.border(0)
            prompt_string = "How many flasks?"
            window.addstr(1, 1, prompt_string)
            curses.echo()
            lantern_oil_added = int(window.getstr())
            adventurer.add_lantern_oil(lantern_oil_added)
            curses.noecho()

current_adventure = Adventure()
torch1 = LightSource("Torch", 2, 2, 2)
torch2 = LightSource("Torch", 2, 2, 2)
current_adventure.add_lightsource(torch1)
current_adventure.add_lightsource(torch2)
myscreen = curses.initscr()
curses.cbreak()
curses.noecho()
myscreen.border(0)
main_command_loop(myscreen, current_adventure)
myscreen.refresh()
curses.endwin()
Exemplo n.º 4
0
if __name__ == "__main__":
    print(World())
    print("Predominant architectural feature: {}".format(Architecture()))
    print("---")
    for i in range(random.choice([2, 3])):
        print("Animal:\n{}\n".format(Animal()))
    print("---")
    for i in range(random.choice([2, 3])):
        print("Political Party:\n{}\n".format(PoliticalParty()))
    print("---")
    for i in range(random.choice([2, 3])):
        print("Corporation:\n{}\n".format(Corporation()))
    print("---")
    for i in range(random.choice([1, 2])):
        print(
            random.choice([
                "Religion:\n{}\n".format(Religion()),
                "Heresy:\n{}\n".format(Heresy())
            ]))
    print("---")
    print("Local Faction: {}".format(Faction()))
    print("---")
    print("Prominent NPCs:")
    for i in range(random.choice([3, 4, 5])):
        print("-\n{}".format(NPC()))
    print("---")
    print("Adventure Seeds:")
    for i in range(3):
        print(Adventure())
    print(Trade())
Exemplo n.º 5
0
async def on_message(ctx, adventureName, minPlayers: int, maxPlayers: int):
    newAdv = Adventure(adventureName, minPlayers, maxPlayers)
    listOfAdventures.append(newAdv)
    await ctx.send(f'Added {adventureName}')
Exemplo n.º 6
0
from termcolor import colored
from sys import argv
from os.path import dirname, basename

if len(argv) == 1:
    path = "testing"
    fileName = "testAdventure.yaml"
elif len(argv) == 2:
    path = dirname(argv[1])
    fileName = basename(argv[1])
else:
    print("Takes 0 or 1 args:")
    print("1. path to adventure file")
    exit()

ad = Adventure(path, fileName)
print("*******************************************************")
print("* " + ad.name)
print("*******************************************************")
print(ad.getQuest())
print("*******************************************************")

while ad.running:
    print(ad.getLocalDescription())
    action = input(colored(ad.player.name + " >> ", 'red')).split()

    if len(action) == 0:
        verb = ' '
    else:
        verb = action[0]
Exemplo n.º 7
0
from adventure import Adventure

class GameCmd(cmd.Cmd):
    prompt = '\nWhat would you like to do? > '

    def default(self, arg):
        """The default action to take when the action is not understood."""
        print('I do not understand that command. Type "help" for a list of commands.')

    def do_quit(self, arg):
        """Quit the game."""
        return True

    def do_go(self, arg):
        print(fill(maze.go(arg)))

    def do_look_at(self, arg):
        """Examine something"""
        print(fill(maze.look_at(arg)))

    def do_search(self, arg):
        print(fill(maze.search(arg)))


if __name__ == "__main__":
    maze = Adventure("labyrinth.json")
    print(maze.describe_location())
    game = GameCmd()
    game.cmdloop()

Exemplo n.º 8
0
#!/usr/bin/env python3

from adventure import Adventure
import os

if __name__ == "__main__":
    adventure = Adventure(os.path.dirname(os.path.realpath(__file__)))
    adventure.play()
Exemplo n.º 9
0
import sys

from adventure import Adventure as AdventureMachine

if __name__ == '__main__':
  adventure = AdventureMachine()

  def print_output(from_result, to_result):
    print to_result
    input = raw_input("choose: ")
    # Wrapping around incorrect choices
    try:
      adventure.transition_to(input)
    except:
      print_output(None, "Not a valid choice")

  adventure.on_transition = print_output
  adventure.play()
Exemplo n.º 10
0
 def setUp(self):
   main.app.config['TESTING'] = True
   self.app = main.app.test_client()
   self.machine = AdventureMachine()
   self.machine.play() 
Exemplo n.º 11
0
class AdventureTestCase(unittest.TestCase):

  def setUp(self):
    main.app.config['TESTING'] = True
    self.app = main.app.test_client()
    self.machine = AdventureMachine()
    self.machine.play() 

  def tearDown(self):
    pass

  def test_state_initial(self):
    self.assertEqual(self.machine.current_state.__name__, 'initial')

  def test_transition(self):
    output = self.machine.transition_to('craigslist')
    self.assertEqual(self.machine.current_state.__name__, 'craigslist')
    self.assertTrue(self.machine.visited(AdventureMachine.initial))

  def test_serial_killer(self):
    self.machine.transition_to('craigslist')
    self.machine.transition_to('initial')
    output = self.machine.transition_to('craigslist')
    idiot = "And now both of your kidneys are gone (seriously?)\na: Try again"
    self.assertEqual(output, [None, idiot])

  def test_reading_emails(self):
    self.machine.transition_to('emails')
    self.machine.transition_to('groveling_developer')
    self.machine.transition_to('emails')
    current_transitions = self.machine.current_state.transitions(self.machine)
    self.assertEqual(len(current_transitions.items()), 2)

  def test_mapping_letters(self):
    self.machine.transition_to('emails')
    self.machine.transition_to('b')
    self.machine.transition_to('a')
    self.machine.transition_to('b')
    self.assertEqual(self.machine.current_state.__name__, 'boss')

  def test_restart(self):
    self.machine.transition_to('emails')
    self.machine.transition_to('b')
    self.machine.transition_to('RESTART')
    self.assertEqual(self.machine.current_state.__name__, 'initial')

  def test_back(self):
    self.machine.transition_to('emails')
    self.machine.transition_to('b')
    self.machine.transition_to('BACK')
    self.assertEqual(self.machine.current_state.__name__, 'emails')
Exemplo n.º 12
0
	def __loopGame(self):
		gameSettings = None
		while not self.isClosed():
			if self.state == 'menu':
				gui = SplashGUI(self.__width, self.__height)
				gui.draw(self)
				# checks if a button on the menu was pressed, and acts accordingly
				# syntax: updateSplashScreen(mouse)
				# parameter:
					# mouse: mouse click in on menu (graphics.Point)
				# returns: None
				def updateSplashScreen(mouse):
					nonlocal gameSettings
					gui.checkClick(mouse)
					if gui.buttonPressed == 'custom':
						gameSettings = gui.getSettings()
						gui.undraw()
						self.state = 'custom'
					elif gui.buttonPressed == 'adventure':
						gui.undraw()
						self.state = 'adventure'
						
				self.__processUserInput(updateSplashScreen)
			elif self.state == 'custom':
				self.play(**gameSettings)
				gui = GameGUI(self.__width, self.__height, self.__gameBoard)
				gui.sync()
				gui.draw(self)
				# run a turn of a custom game
				# syntax: updateCustomGame(mouse)
				# parameters: 
					# mouse: mouse click in game (graphics.Point)
				# returns: None
				def updateCustomGame(mouse):
					self.__gameBoard.clickTile(mouse)
					gui.checkClick(mouse)
					gui.sync()
					if not self.__gameBoard.isRunning:
						self.state = 'ended'
				self.__processUserInput(updateCustomGame)
			elif self.state == 'adventure':
				adventure = Adventure(self.__width, self.__height)
				adventure.draw(self)
				adventure.showCutscene(self)
				gameGUI = None
				# run a turn of an adventure game
				# syntax: updateAdventureGame(mouse)
				# parameters: 
					# mouse: mouse click in game (graphics.Point)
				# returns: None
				def updateAdventureGame(mouse):
					nonlocal gameGUI
					if not self.__gameBoard:
						adventure.hideCutscene()
						self.play(isAdventure = True, **adventure.getPlaySettings())
						gameGUI = GameGUI(self.__width, self.__height, self.__gameBoard)
						gameGUI.sync()
						gameGUI.draw(self)
						
					gameGUI.sync()
					gameGUI.checkClick(mouse)
					self.__gameBoard.clickTile(mouse)
					if not self.__gameBoard.isRunning:
						self.state = 'ended'
					if self.__gameBoard.hasWon:
						self.__gameBoard.undraw()
						gameGUI.undraw()
						adventure.win()
						self.__gameBoard = False
						if adventure.isDone:
							self.state = 'menu'
						else:
							adventure.showCutscene(self)
							
					
				self.__processUserInput(updateAdventureGame)
			elif self.state == 'ended':
				self.close()