Example #1
0
 def testBoard(self):
     b = Board()
     self.assertEquals(b.getFromPosition(0, 0), 0)
     b.setOnPosition(0, 0, 1)
     self.assertEquals(b.getFromPosition(0, 0), 1)
     b.makeMove(Point(1, 2))
     self.assertEquals(b.getFromPosition(1, 2), 4)
     p = Plane(Point(1, 2), 'S', 'Player')
     with self.assertRaises(Exception):
         b.addPlane(p)
     p = Plane(Point(2, 2), 'S', 'Player')
     b.addPlane(p)
Example #2
0
 def testPlane(self):
     a = Plane(Point(0, 2), 'S', 'Player')
     for i in [
             Point(1, 0),
             Point(1, 1),
             Point(1, 2),
             Point(1, 3),
             Point(1, 4),
             Point(2, 2),
             Point(3, 1),
             Point(3, 2),
             Point(3, 3)
     ]:
         assert i in a.getOtherPositions()
     with self.assertRaises(Exception):
         a = Plane(Point(0, 2), 'N', 'Player')
Example #3
0
 def get_availalbe_aircraft_list(self):
     totalTime = self.chosen_destinaiton.totalTime
     available_aircrafts_list = self.llAPI_in.getAvailablePlanes(
         self.dateTime, totalTime)
     print(''' ___________________________________________''')
     print('''|         NaN Air - Choose aircraft         |''')
     print(''' ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾''')
     counter = 1
     line_list = []
     working_list = []
     for aircraft in available_aircrafts_list:
         print(' ({})'.format(counter), end=" ")
         for val in aircraft.values():
             print(val, end="  ")
             line_list.append(val)
         working_list.append(line_list)
         line_list = []
         print()
         counter += 1
     print()
     user_choice = input("Input: ")
     chosen_aircraft_registration = working_list[int(user_choice) - 1][0]
     chosen_aircraft_type = working_list[int(user_choice) - 1][1]
     self.chosen_aircraft = Plane(chosen_aircraft_registration,
                                  chosen_aircraft_type)
     return None
Example #4
0
    def print_voyage_list(self, voyage_list, header_list):
        if header_list == None:
            print(''' ___________________________________________''')
            print('''|      All voyages are fully staffed!       |''')
            print(''' ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ ''')
            print()
            input("Press enter to go back to home page!")
            print()

        else:
            print("{:<5}{:<10}{:<10}{:<15}{:<25}{:<25}{:<10}".format(
                header_list[0], header_list[1], header_list[2], header_list[3],
                header_list[4], header_list[5], header_list[6]))
            print(100 * "_")
            print()
            id_list = []
            for voyage in voyage_list:
                print("{:<5}{:<10}{:<10}{:<15}{:<25}{:<25}{:<10}".format(
                    voyage[0], voyage[1], voyage[2], voyage[3], voyage[4],
                    voyage[5], voyage[6]))
                id_list.append(int(voyage[0]))

            while True:
                print()
                user_choice = input("Enter ID of voyage you want to staff: ")
                print()
                try:
                    user_choice = int(user_choice)
                except:
                    print()
                    print("Invalid input!")
                    print("Please enter valid ID")
                    continue

                if int(user_choice) not in id_list:
                    print("Invalid input!")
                    print("Please enter valid ID")
                    continue

                for voy in voyage_list:
                    if voy[0] == str(user_choice):
                        voyage = voy
                break

            self.planeType = self.llAPI_in.getPlaneType(voyage[6])
            plane_obj = Plane(voyage[6], self.planeType)

            destination_obj = self.createDestinationObject(voyage[3])
            departure_datetime = datetime.datetime.strptime(
                voyage[4], '%Y-%m-%dT%H:%M:%S')

            self.voyage_obj = Voyage(destination_obj, plane_obj,
                                     departure_datetime, voyage[0])
            self.listAvailablePilots()
            self.listAvailableCabincrew()
            if self.print_crew_review() == None:
                return None
Example #5
0
 def get_plane_info(self):
     print(' __________________________________________')
     print("| NaN Air - Enter plane information        |")
     print(" ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ ")
     self.plane_type = self.choose_plane_type()
     self.registration = input("Enter aircraft registration: ")
     self.plane = Plane(self.registration, self.plane_type)
     self.display_info()
     return None
Example #6
0
    def storePlaneToFile(self, plane_in):
        registration = Plane.get_registration(plane_in)
        planeType_obj = plane_in.get_planeType()
        planeType_str = planeType_obj.get_plane_type()

        plane_info = '\n{},{}'.format(registration, planeType_str)

        with open(self.filename, 'a') as f:
            f.write(plane_info)
Example #7
0
    def chooseAiPlanes(self):
        """
		chooses the planes for the ai
		"""
        orientations = ['N', 'S', 'E', 'W']
        while Game.aiPlanes != 3:
            try:
                startX = random.randint(0, 10)
                startY = random.randint(0, 10)
                orient = random.randint(0, 4)
                Game.aiPlanes += 1
                self._board.addPlane(
                    Plane(Point(startX, startY), orientations[orient], 'Ai'))
            except Exception:
                Game.aiPlanes -= 1
Example #8
0
    def list_of_voyage(self):
        id_list = []
        # Hérna prentast út listi af voyages
        # Fallið sér einnig um að villutjékka inputin hjá usernum - þeas að það sé in range
        # Og í lokin býr það til tilvik af voyage og planeType
        v_list, h_list = self.llAPI_in.getFullyStaffedVoyages()
        self.dict_of_voyages = self.llAPI_in.getVoyages()
        print()
        if v_list != None and h_list != None:
            print(
                "{:<5}{:<10}{:<10}{:<15}{:<25}{:<25}{:<10}{:<15}{:<15}{:<15}{:<15}{:<15}"
                .format(h_list[0], h_list[1], h_list[2], h_list[3], h_list[4],
                        h_list[5], h_list[6], h_list[7], h_list[8], h_list[9],
                        h_list[10], h_list[11]))

            print("__" * 90, "\n")

            for line in v_list:
                print(
                    "{:<5}{:<10}{:<10}{:<15}{:<25}{:<25}{:<10}{:<15}{:<15}{:<15}{:<15}{:<15}"
                    .format(line[0], line[1], line[2], line[3], line[4],
                            line[5], line[6], line[7], line[8], line[9],
                            line[10], line[11]))
                id_list.append(int(line[0]))
            print("\n\n")

            print()
            legal_input = False
            while legal_input == False:
                self.selectedVoyage = input("Enter ID of voyage to update: ")
                try:
                    int(self.selectedVoyage)
                    if int(self.selectedVoyage) not in id_list:
                        legal_input = False
                        print()
                        print("Error! The selected ID is not in range!")
                        print()
                        continue
                    else:
                        legal_input = True
                except ValueError:
                    print()
                    print("Error!")
                    print()
                    continue

        self.voy = []
        for line in v_list:
            if line[0] == self.selectedVoyage:
                self.voy.append(line)

        self.planeType = self.llAPI_in.getPlaneType(self.voy[0][6])
        self.plane_obj = Plane(self.voy[0][6], self.planeType)
        self.dep_dt_obj = datetime.datetime.strptime(self.voy[0][4],
                                                     "%Y-%m-%dT%H:%M:%S")
        self.dest_obj = self.llAPI_in.createDestinationObject(self.voy[0][3])

        self.voyage_obj = Voyage(self.dest_obj, self.plane_obj,
                                 self.dep_dt_obj, self.voy[0][0])
        self.voyage_obj.assignCaptain(self.voy[0][7])
        self.voyage_obj.assignCopilot(self.voy[0][8])
        self.voyage_obj.assingFSM(self.voy[0][9])
        self.voyage_obj.assignFA1(self.voy[0][10])
        self.voyage_obj.assignFA2(self.voy[0][11])

        self.date = str(self.voyage_obj.get_Departure().date())

        self.captain = self.voyage_obj.get_Captain()
        self.cop = self.voyage_obj.get_Copilot()
        self.fsm = self.voyage_obj.get_FSM()
        self.fa1 = self.voyage_obj.get_FA1()
        self.fa2 = self.voyage_obj.get_FA2()

        choose_emp = self.choose_employees()
        if choose_emp == "back":
            return "back"
        elif choose_emp == None:
            return None
Example #9
0
    def addPlane(self, x, y, orientation):
        """
		adds a plane on a given position with a given orientation
		input: a x, y position and a orientation
		"""
        self._board.addPlane(Plane(Point(x, y), orientation.upper(), 'Player'))