예제 #1
0
    def calculateStarBaseCommand(self, game):
        '''Command to calculate the distance to dock to a starbase in the current quadrant'''
        
        if game.EnterpriseQuadrant.NoOfStarBases == 0:
            Util.printMessage('There are no starbases in this quadrant.')
        else:
            for starbase in game.EnterpriseQuadrant.StarBases:  
                dist = GeoMath.distance(game.TheEnterprise.Position.GetSectorCoordinates(), starbase.Position.GetSectorCoordinates())
                direction = 0.0
                print """Starbase in sector %s.
Direction: %.2f
Distance:  %.2f""" %(starbase.Position.GetSector(), direction, dist)
        Util.prompt()
예제 #2
0
	def displayAllRangeScan(self, message):
		''' Display the current quadrant in which is the Enterprise '''
		
		CST_GAP_SR_INFO = 3
		CST_GAP_INFO_LR = 2
		CST_SHORT_RANGE_MAP = 26
		
		
		Util.clear()
		gap_len_FirstInfo = len(self.getEnterpriseInformation(1))
		
		if len(message) > 0:
			Util.printMessage("STAR TREK - {0}",message)
		else:
			Util.printMessage("STAR TREK")
			
		firstLineGap = CST_SHORT_RANGE_MAP - len('SHORT RANGE SCAN') + CST_GAP_SR_INFO + gap_len_FirstInfo + 3 * CST_GAP_INFO_LR 

		Util.printMessage('SHORT RANGE SCAN' + ' ' * firstLineGap + 'LONG RANGE SCAN')
		
		for line in range(1, 11):
			print self.getShortRangeScan(line),
			print ' ' * CST_GAP_SR_INFO,
			print self.getEnterpriseInformation(line),
			print ' ' * CST_GAP_INFO_LR, 
			print self.getLongRangeScan(line)
예제 #3
0
    def calculateStarBaseCommand(self, game):
        '''Command to calculate the distance to dock to a starbase in the current quadrant'''

        if game.EnterpriseQuadrant.NoOfStarBases == 0:
            Util.printMessage('There are no starbases in this quadrant.')
        else:
            for starbase in game.EnterpriseQuadrant.StarBases:
                dist = GeoMath.distance(
                    game.TheEnterprise.Position.GetSectorCoordinates(),
                    starbase.Position.GetSectorCoordinates())
                direction = 0.0
                print """Starbase in sector %s.
Direction: %.2f
Distance:  %.2f""" % (starbase.Position.GetSector(), direction, dist)
        Util.prompt()
예제 #4
0
 def phaserCommand(self, game):
     '''Command to fire with phaser'''
     
     if game.EnterpriseQuadrant.NoOfKlingons == 0:
         Util.printMessage('There are no Klingon ships in this quadrant.')
         return
     
     Util.printMessage('Phasers locked on target.')
     Util.printMessage('Enter phaser energy (1 - {0}):', game.TheEnterprise.Energy)
     Util.prompt()
예제 #5
0
    def phaserCommand(self, game):
        '''Command to fire with phaser'''

        if game.EnterpriseQuadrant.NoOfKlingons == 0:
            Util.printMessage('There are no Klingon ships in this quadrant.')
            return

        Util.printMessage('Phasers locked on target.')
        Util.printMessage('Enter phaser energy (1 - {0}):',
                          game.TheEnterprise.Energy)
        Util.prompt()
예제 #6
0
	def command(self):
		'''Wait commands from the user '''
		answer = Util.prompt()
		self.isRestart(answer)
		
		message = ''
			
		if lower(answer) == 'nav':
			message = self.Commands.navigationCommand(self)
		elif lower(answer) == 'pha':
			self.Commands.pahserCommand()
		elif lower(answer) == 'tor':
			self.Commands.torpedoCommand()
		elif lower(answer) == 'she':
			self.Commands.shieldCommand(self)
		elif lower(answer) == 'com':
			self.Commands.computerCommand(self)
		
		Util.clear()
		self.displayAllRangeScan(message)
		self.displayCondition()
		Util.displayCommands()
예제 #7
0
	def displayCondition(self):
		''' Display the condition of the Enterprise '''
		
		Util.printMessage('-')
		if self.EnterpriseQuadrant.NoOfKlingons > 0 and  self.TheEnterprise.Shield == 0:
			self.CurrentCondition = 'RED'
			print 'Condition %s: %s' %(self.CurrentCondition, 'Klingon ship detected')
			Util.printMessage('Warning: Shields are down')
		elif self.EnterpriseQuadrant.NoOfKlingons > 0 and self.TheEnterprise.Shield > 0:
			self.CurrentCondition = 'RED'
			print 'Condition %s: %s' %(self.CurrentCondition, 'Klingon ship detected')
		elif self.map.getBlockedStarbase() != None:
			pos = self.map.getBlockedStarbase()
			self.CurrentCondition = 'RED'
			print 'Condition %s: %s' %(self.CurrentCondition, 'Starbase K-%d%d is blocked by Klingons' %(pos.QuadrantX, pos.QuadrantY))
		elif self.TheEnterprise.Energy < 300:
			self.CurrentCondition = 'YELLOW'
			print 'Condition %s: %s' %(self.CurrentCondition, 'Low energy level, return to starbase.')
		else:
			self.CurrentCondition = 'GREEN'
			print 'Condition %s: %s' %(self.CurrentCondition, 'This quadrant is clear.')
		Util.printMessage('-')
예제 #8
0
	def start(self):
		'''The entry method of the game'''
		
		Util.clear()
		Util.asciiArt()
		
		Util.printMessage('DO YOU NEED INSTRUCTIONS (YES/NO)')
		answer = Util.prompt()
		
		if answer != None and (lower(answer) == 'y' or lower(answer) == 'yes'):
			Help.displayHelp()
		else:
			Util.clear()
		
		Util.displayOrders(self.TotalKlingons, self.CurrentStarDate + self.RemainingStarDays, self.RemainingStarDays, self.TotalStarBases)
		
		answer = Util.prompt()
		self.isRestart(answer)
			
		self.displayAllRangeScan("")
		self.displayCondition()
		Util.displayCommands()
		
		while(True):
			self.command()
예제 #9
0
	def __init__(self):
		''' some game initialisations'''
		Util.resizeConsole(120, 45)
		self.initGame()
예제 #10
0
    def torpedoCommand(self, game):
        '''Command to fire a torpedo'''

        if game.EnterpriseQuadrant.NoOfKlingons == 0:
            print 'There are no Klingon ships in this quadrant.'
        else:
            Util.displayDirections()

            for ship in game.EnterpriseQuadrant.Klingons:
                Util.printMessage('Klingon ship in sector {0}',
                                  ship.Position.GetSector())

            Util.printMessage('Enter firing direction (1.0--9.0):')
            Util.prompt()

            #get direction from input
            try:
                direction = float(Util.prompt())
                if direction < 1.0 or direction > 9.0:
                    Util.printMessage('Invalid direction.')
                return ''
            except ValueError:
                Util.printMessage('Invalid direction.')
                return ''
예제 #11
0
 def shieldCommand(self, game):
     '''Command to change the shields '''
     
     currentShield = game.TheEnterprise.Shield
     currentEnergy = game.TheEnterprise.Energy
     
     Util.displayShieldCommand(currentShield, currentEnergy)
     
     try:
         shield = int(Util.prompt())    
         if shield < (-currentShield) or shield > currentEnergy:
             Util.printMessage('Invalid amount of energy.')
             return
     except ValueError: 
         Util.printMessage('Invalid amount of energy.')
         return
     
     game.TheEnterprise.Shield += shield
     game.TheEnterprise.Energy -= shield
     
     Util.printMessage('Shield strength is now {0}. Energy level is now {1}', game.TheEnterprise.Shield, game.TheEnterprise.Energy)
     Util.prompt()
예제 #12
0
 def torpedoCommand(self, game):
     '''Command to fire a torpedo'''
     
     if game.EnterpriseQuadrant.NoOfKlingons == 0:
         print 'There are no Klingon ships in this quadrant.'
     else:
         Util.displayDirections()
         
         for ship in game.EnterpriseQuadrant.Klingons:
             Util.printMessage('Klingon ship in sector {0}', ship.Position.GetSector())
         
         Util.printMessage('Enter firing direction (1.0--9.0):')
         Util.prompt()
         
         #get direction from input
         try:
             direction = float(Util.prompt())    
             if direction < 1.0 or direction > 9.0:
                 Util.printMessage('Invalid direction.')
             return ''
         except ValueError: 
                 Util.printMessage('Invalid direction.')
                 return ''
예제 #13
0
    def computerCommand(self, game):
        '''Displays the computer commands'''

        Util.clear()
        game.displayAllRangeScan('')
        game.displayCondition()
        Util.displayComputerCommands()

        command = Util.prompt()

        if lower(command) == 'rec':
            Util.clear()
            Util.displayRecordCommand(game.map.Quadrants)
            Util.prompt()
        elif lower(command) == 'sta':
            Util.clear()
            Util.displayStatusCommand(game.RemainingStarDays,
                                      game.TotalKlingons, game.TotalStarBases,
                                      game.TheEnterprise)
            Util.prompt()
        elif lower(command) == 'bas':
            self.calculateStarBaseCommand(game)
        elif lower(command) == 'nav':
            self.calculateNavigationCommand(game)
예제 #14
0
    def navigationCommand(self, game):
        '''Command to move the Enterprise '''

        Util.displayNavigationCommand(NavParam.COURSE)

        try:
            course = float(Util.prompt())
            if course < 1.0 or course > 9.0:
                Util.printMessage('Invalid course.')
                return ''
        except ValueError:
            Util.printMessage('Invalid course.')
            return ''

        Util.displayNavigationCommand(NavParam.WARP_FACTOR)

        try:
            warp = float(Util.prompt())
            if warp < 0.1 or warp > 8.0:
                Util.printMessage('Invalid warp factor.')
                return ''
        except ValueError:
            Util.printMessage('Invalid warp factor.')
            return ''

        (canMove,
         newPos) = game.map.moveEnterprise(course, warp,
                                           game.TheEnterprise.Position)
        if not canMove:
            return 'Error! the path is blocked'
        else:
            game.TheEnterprise.Position = newPos
            game.EnterpriseQuadrant = game.map.Quadrants[newPos.QuadrantX][
                newPos.QuadrantY]
            return 'Warp engine engaged'
예제 #15
0
    def shieldCommand(self, game):
        '''Command to change the shields '''

        currentShield = game.TheEnterprise.Shield
        currentEnergy = game.TheEnterprise.Energy

        Util.displayShieldCommand(currentShield, currentEnergy)

        try:
            shield = int(Util.prompt())
            if shield < (-currentShield) or shield > currentEnergy:
                Util.printMessage('Invalid amount of energy.')
                return
        except ValueError:
            Util.printMessage('Invalid amount of energy.')
            return

        game.TheEnterprise.Shield += shield
        game.TheEnterprise.Energy -= shield

        Util.printMessage(
            'Shield strength is now {0}. Energy level is now {1}',
            game.TheEnterprise.Shield, game.TheEnterprise.Energy)
        Util.prompt()
예제 #16
0
	def isRestart(self, answer):
		if lower(answer) == 'xxx':
			Util.clear()
			self.initGame()
			self.start()
예제 #17
0
 def navigationCommand(self, game):
     '''Command to move the Enterprise '''
     
     Util.displayNavigationCommand(NavParam.COURSE)
     
     try:
         course = float(Util.prompt())    
         if course < 1.0 or course > 9.0:
             Util.printMessage('Invalid course.')
             return ''
     except ValueError: 
         Util.printMessage('Invalid course.')
         return ''
         
     Util.displayNavigationCommand(NavParam.WARP_FACTOR)
     
     try:
         warp = float(Util.prompt())    
         if warp < 0.1 or warp > 8.0:
             Util.printMessage('Invalid warp factor.')
             return ''
     except ValueError: 
         Util.printMessage('Invalid warp factor.')
         return ''
     
     (canMove, newPos) = game.map.moveEnterprise(course, warp, game.TheEnterprise.Position)
     if not canMove: 
         return 'Error! the path is blocked'
     else:
         game.TheEnterprise.Position = newPos
         game.EnterpriseQuadrant = game.map.Quadrants[newPos.QuadrantX][newPos.QuadrantY]
         return 'Warp engine engaged'
예제 #18
0
from Classes.UtilClass import Util

#test printmessage
Util.printMessage("STAR TREK")

Util.printMessage("STAR TREK - {0}", 'ana are mere')

Util.printMessage("STAR TREK - {0} - {1}", 'ana are mere', 'bb')
예제 #19
0
 def computerCommand(self, game):
     '''Displays the computer commands'''
     
     Util.clear()
     game.displayAllRangeScan('')
     game.displayCondition()
     Util.displayComputerCommands()
     
     command = Util.prompt()
     
     if lower(command) == 'rec':
         Util.clear()
         Util.displayRecordCommand(game.map.Quadrants)
         Util.prompt()
     elif lower(command) == 'sta':
         Util.clear()
         Util.displayStatusCommand(game.RemainingStarDays, game.TotalKlingons, game.TotalStarBases, game.TheEnterprise)
         Util.prompt()
     elif lower(command) == 'bas':
         self.calculateStarBaseCommand(game)
     elif lower(command) == 'nav':
         self.calculateNavigationCommand(game)