Changeset 6.1.44 for main.py


Ignore:
Timestamp:
08/21/2016 04:08:39 AM (8 years ago)
Author:
David Owen <dsowen@fugue88.ws>
branch-nick:
state
revision id:
dsowen@fugue88.ws-20160821040839-xv2bnfiuxv5lyayg
Message:

Moved perform_mission() to state object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main.py

    r6.1.43 r6.1.44  
    100100        self.team = team
    101101
     102    def perform_mission(self):
     103        failures = 0
     104        for i in self.team:
     105            if self.shared.role_deck[i] == "SPY":
     106                if not self.shared.players[i].perform_mission():
     107                    failures = failures + 1
     108
     109        success = failures < required_failures(self.shared.player_count, self.shared.mission)
     110
     111        for p in self.shared.players:
     112            p.observe_mission(success, failures)
     113
     114        if success:
     115            print("Mission succeeded")
     116            self.shared.wins += 1
     117        else:
     118            print("Mission had {} failures".format(failures))
     119            self.shared.losses += 1
     120
     121        return AdvanceMission(self.shared)
     122
    102123
    103124def main(player_count):
     
    119140
    120141    shared = Shared(player_count, players, role_deck)
    121 
    122     def perform_mission():
    123         failures = 0
    124         for i in state.team:
    125             if state.shared.role_deck[i] == "SPY":
    126                 if not state.shared.players[i].perform_mission():
    127                     failures = failures + 1
    128 
    129         success = failures < required_failures(state.shared.player_count, state.shared.mission)
    130 
    131         for p in state.shared.players:
    132             p.observe_mission(success, failures)
    133 
    134         if success:
    135             print("Mission succeeded")
    136             state.shared.wins += 1
    137         else:
    138             print("Mission had {} failures".format(failures))
    139             state.shared.losses += 1
    140 
    141         return AdvanceMission(shared)
    142 
    143142    state = AdvanceMission(shared)
    144143
     
    149148            state = state.do()
    150149        elif isinstance(state, PerformMission):
    151             state = perform_mission()
     150            state = state.perform_mission()
    152151
    153152        if shared.team_failures == 5:
Note: See TracChangeset for help on using the changeset viewer.