コード例 #1
0
 def test_random_advance(self):
     tracker = TripTracker()
     oxen = InventoryItem()
     oxen.value = 220
     tracker.random_advance(oxen)
     self.assertGreaterEqual(tracker.mileage, 200)
     self.assertLess(tracker.mileage, 210)
コード例 #2
0
 def test_reached_oregon(self):
     tracker = TripTracker()
     tracker.add_mileage(1800)
     oxen = InventoryItem()
     oxen.value = 220
     tracker.random_advance(oxen)  # maximum added advance of 210
     self.assertFalse(tracker.reached_oregon())
     last_turn_mileage = tracker.mileage - 1800
     last_turn_mileage += tracker.total_trip_distance - tracker.mileage
     tracker.add_mileage(tracker.total_trip_distance - tracker.mileage)
     self.assertTrue(tracker.reached_oregon())
コード例 #3
0
 def test_construction(self):
     tracker = TripTracker()
     self.assertEqual(tracker.mileage, 0)
     self.assertEqual(tracker.last_turn_fraction, 0)
     self.assertEqual(tracker.total_trip_distance, 2040)
     self.assertEqual(tracker.distance_to_mountains, 950)
     self.assertFalse(tracker.cleared_south_pass)
     self.assertFalse(tracker.cleared_blue_mountains)
コード例 #4
0
ファイル: oregon.py プロジェクト: evanandr/oregon-trail
from oregon.events.mountains import mountains
from oregon.events.turn import turn_event_selection
from oregon.events.instructions import print_instructions
from oregon.events.purchases import initial_purchases
from oregon.events.completed_trip import completed_trip

if __name__ == "__main__":

    if ask_yes_no("DO YOU NEED INSTRUCTIONS  (YES/NO)"):
        print_instructions()

    # initial purchases generate an inventory
    inventory = initial_purchases()

    calendar = Calendar()
    tracker = TripTracker()
    turn = TurnState()

    while not calendar.is_final_turn() and not tracker.reached_oregon():
        calendar.print_date()
        inventory.zeroize_negative_values()

        # Resolve health issues from the previous turn
        if turn.illness or turn.injured:
            inventory.spend(20)
            if inventory.money < 0:
                print("YOU CAN'T AFFORD A DOCTOR")
                if turn.illness:
                    print("YOU DIED OF PNEUMONIA")
                elif turn.injured:
                    print("YOU DIED OF INJURIES")
コード例 #5
0
 def test_reached_mountains(self):
     tracker = TripTracker()
     self.assertFalse(tracker.reached_mountains())
     tracker.add_mileage(tracker.distance_to_mountains)
     self.assertTrue(tracker.reached_mountains())
コード例 #6
0
 def test_reached_oregon_zero_division(self):
     tracker = TripTracker()
     tracker.add_mileage(tracker.total_trip_distance)
     self.assertTrue(tracker.reached_oregon())
     self.assertEqual(tracker.last_turn_fraction, 0)
コード例 #7
0
 def test_subtract_mileage_less_than_zero(self):
     tracker = TripTracker()
     tracker.subtract_mileage(10)
     self.assertEqual(tracker.mileage, 0)
コード例 #8
0
 def test_subtract_mileage(self):
     tracker = TripTracker()
     tracker.add_mileage(10)
     self.assertEqual(tracker.mileage, 10)
     tracker.subtract_mileage(5)
     self.assertEqual(tracker.mileage, 5)
コード例 #9
0
 def test_add_mileage(self):
     tracker = TripTracker()
     tracker.add_mileage(10)
     self.assertEqual(tracker.mileage, 10)