Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html ng-app="app">

<body ng-controller="MainCtrl">
  <div ng-hide="started">
    <h2>Game of Thrones Simulator</h2>
    <h5>A story-based minigame by <a href="https://www.reddit.com/u/dSolver" target="_blank">dSolver</a>. You run a House, and try to survive.</h5>
    <hr>
    <div style="padding: 1em">
      <h6>Step One: Build your House:</h6>
      <div class="content">
        <form>
          <div class="row">
            <div class="large-12 columns">
              <label>
                <input type="text" ng-model="family.name" ng-blur="checkFamilyName()" placeholder="Name your House">
              </label>
            </div>
          </div>
          <div class="row">
            <div class="medium-6 columns">
              <label>
                <span>Starting funds: {{family.steel}} Gold Dragons</span>
                <input type="range" min=1000 max=10000 step=50 ng-model="family.steel">
              </label>
              <label>
                <span>Starting soldiers: {{family.soldiers}} Soldiers</span>
                <input type="range" min=20 max=150 ng-model="family.soldiers">
              </label>
            </div>
            <div class="medium-6 columns">
              <div>Family Members: {{family.members.length}}/8</div>
              <div ng-repeat="member in family.members track by $index" class="deletable alert-box" ng-click="family.members.splice($index, 1)">{{member.name}} <a href="#" class="close">&times;</a></div>
              <div ng-show="family.members.length === 0">No family members. Why not add some?
              </div>
              <div ng-show="family.members.length<8">
                <div style="padding:0.5em">
                  <div class="row collapse">
                    <div class="small-9 columns">
                      <input type="text" ng-model="newMemberName" placeholder="New Family Member Name">
                    </div>
                    <div class="small-3 columns">
                      <button class="postfix" ng-click="addMember(newMemberName)">Add</button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </form>
      </div>
      <div class="row text-center">
        <div>
          <label>Pace: Slow
            <input type="range" min=0 max=19 ng-model="pace">Fast
          </label>
        </div>
        <hr>

        <a href="#" class="button [radius round]" ng-disabled="family.name.length == 0 || family.members.length == 0" ng-click="start()">To the Throne!</a>
      </div>
    </div>
  </div>
  <div ng-show="started">
    <h3>House {{family.name}} - Day {{family.day}}</h3>
    <div class="row">
      <div class="small-6 columns">
        Funds: {{family.steel}} Gold Dragons
        <br>
        <button ng-click="collectTaxes()" ng-disabled="taxCD">Collect Taxes</button>
      </div>
      <div class="small-6 columns">
        <div>Soldiers: {{family.soldiers}}</div>
        <div class="button-bar">
          <div>Hire Soldiers:</div>
          <ul class="button-group round" style="font-size:75%">
            <li><a href="#" class="button" ng-click="hireSoldiers(10)" ng-disabled="family.steel < 100">10  (100 Gold)</a></li>
            <li><a href="#" class="button" ng-click="hireSoldiers(100)" ng-disabled="family.steel < 1000">100  (1K Gold)</a></li>
            <li><a class="button" ng-click="hireSoldiers(family.steel/10)">Max [{{family.steel/10 | number:0}}]</a></li>
          </ul>
        </div>
      </div>
    </div>
    <div class="row">
      <div>Places:</div>
      <div class="place" ng-repeat="place in places">
        {{place.name}} - House {{place.house}}
      </div>
      <hr>
    </div>
    <div class="row">
      <div class="small-6 columns">
        <h5>Log</h5>
        <div style="max-height: 250px; overflow: auto;">
          <div ng-repeat="log in logs track by $index" class="log">{{log}}</div>
        </div>
      </div>
      <div class="small-6 columns">
        <h5>Family:</h5>
        <div ng-repeat="member in family.members track by $index" class="family" ng-class="{dead:!member.alive}">
          <div>
            {{member.name}}
          </div>
          <div>Location: {{member.location}}</div>
        </div>
        <div class="box">
          <h5>Enemies</h5>
          <div ng-repeat="person in family.enemies track by $index" class="deletable" ng-click="confirmAssassination(person)">{{person}}</div>
        </div>
        <div class="box">
          <h5>Allies</h5>
          <div ng-repeat="person in family.allies track by $index">{{person}}</div>
        </div>
      </div>
    </div>
  </div>
  <div style="text-align:center; font-size:80%; color: #444;">
    <hr>
    <div>
      Like this game? Check out my games at <a href="http://plaza.dsolver.ca/#!/m/dSolver" target="_blank">The Incremental Games Plaza</a>
    </div>
    <div>
      While I'm at it, this game is completely Open Source (MIT License). Feel free to <a href="https://www.codepen.io/dSolver/pen/GJvaNp" target="_blank">Fork and Modify</a> it to your own tastes. Character and location names Copyright of George R. R.
      Martin.
    </div>

  </div>
  <div ng-show="showAssassinOptions" class= "modal">
    So you wish to kill {{assassinationTarget}}? Who do you wish to hire?
    <hr>
    <div class="button-group">
      <button class="button tiny" ng-repeat="assassin in assassins" ng-click="orderKill(assassin, assassinationTarget)" ng-disabled="assassin.price > family.steel">{{assassin.name}} ({{assassin.price}} Gold)</button>
      <button class="button tiny" ng-click="cancelAssassination()">Cancel</button>
    </div>
  </div>
  <div ng-show="gameOver" class="modal">
    <h3>{{gameOver}}</h3>
  </div>
</body>

</html>
              
            
!

CSS

              
                *{
  transition: all 0.2s ease
}
label>span{
  width: 200px;
  display: inline-block
}

.deletable{
  cursor: pointer;
  transition: all 0.5s ease;
}

.dead {
  text-decoration: line-through;
  background: #aa0000;
  color: #ccc;
  opacity: 0.8;
}

.deletable:hover{
  background-color:#dd0000
}

.modal{
  position: fixed;
  top:0;
  left:0;
  right:0;
  height: 140px;
  overflow:auto;
  border-bottom: solid 1px black;
  padding: 1em;
  background: rgb(200, 200, 200);
}

.log{
  font-size: 80%;
  border-bottom: solid 1px #444;
}

.family{
  padding: 0.25em;
  border: solid 1px #333;
  border-radius: 1em;
}

.button{
  padding: 0.25em 0.5em;
}

.place{
  float: left;
  width: 300px;
  padding: 10px;
}

.box{
  margin: 0.25em;
  padding: 0.25em;
  border: solid 1px #444;
}

.box h5{
  text-decoration:underline
}
              
            
!

JS

              
                var app = angular.module("app", []);

app.controller("MainCtrl", function($scope, $timeout, $interval) {

  $scope.pace = 8;
  $scope.paused = false;
  $scope.logs = [];
  $scope.log = function(msg) {
    msg = "Day " + $scope.family.day + " - " + msg;
    $scope.logs.unshift(msg);
    if ($scope.logs.length > 50) {
      $scope.logs.pop();
    }
  }
  $scope.taxCD = 0;
  $scope.collectTaxes = function() {
    if ($scope.taxCD === 0) {
      var taxes = Math.round(Math.random() * 300);

      $scope.family.steel += taxes;

      $scope.log("Your tax collection netted " + taxes + " Gold Dragons for your House");
      $scope.taxCD = 15;
    }
  }
  $scope.stage = 0;
  $scope.hireSoldiers = function(amt) {
    amt = Math.floor(amt);
    if ($scope.family.steel >= amt * 10) {
      $scope.family.steel -= amt * 10;
      $scope.family.soldiers += amt;

      $scope.log("You hired " + amt + " soldiers");
    } else {
      $scope.log("Not enough funds to hire soldiers");
    }
  }
  $scope.checkFamilyName = function() {
    if ($scope.houses.indexOf($scope.family.name.toLowerCase().trim()) >= 0) {
      $scope.family.name += "-wannabe";
    }
  }
  $scope.places = [{
    name: 'Winterfell',
    house: 'Stark'
  }, {
    name: 'Castle Black',
    house: 'Night\'s Watch'
  }, {
    name: 'The Dreadfort',
    house: 'Bolton'
  }, {
    name: 'King\'s Landing',
    house: 'Baratheon'
  }, {
    name: 'Casterly Rock',
    house: 'Lannister'
  }, {
    name: 'Braavos',
    house: 'Braavos'
  }, {
    name: 'Iron Islands',
    house: 'Greyjoy'
  }, {
    name: 'Riverlands',
    house: 'Tully'
  }, {
    name: 'Vale of Arryn',
    house: 'Arryn'
  }, {
    name: 'Lannisport',
    house: 'Lannister'
  }, {
    name: 'High Garden',
    house: 'Tyrell'
  }, {
    name: 'Dorne',
    house: 'Martell'
  }, {
    name: 'White Harbour',
    house: 'Stark'
  }];

  $scope.family = {
    name: "",
    steel: 1000,
    soldiers: 20,
    members: [],
    day: 0,
    enemies: [],
    allies: []
  }

  $scope.addMember = function(name) {
    $scope.newMemberName = "";
    $scope.family.members.push({
      name: name,
      alive: true,
      location: "Home"
    });

  }
  $scope.houses = [
    "stark",
    "lannister",
    "baratheon",
    "greyjoy",
    "bolton",
    "martell",
    "targaryen",
    "tully",
    "arryn",
    "tyrell",
    "clegane",
    "frey"
  ]

  $scope.lords = [
    "Little Finger",
    "Varys",
    "Ned Stark",
    "Robb Stark",
    "Cersei Lannister",
    "Robert Baratheon",
    "Theon Greyjoy",
    "Roose Bolton",
    "Joffrey Baratheon",
    "Stannis Baratheon",
    "Tywin Lannister",
    "Tyrion Lannister",
    "Doran Martell",
    "Margery Tyrell",
    "Ollena Tyrell",
    "Selyse Baratheon",
    "Balon Greyjoy"
  ]

  $scope.people = [
    "Little Finger",
    "Varys",
    "Ned Stark",
    "Robb Stark",
    "Balon Greyjoy",
    "Cersei Lannister",
    "Robert Baratheon",
    "Theon Greyjoy",
    "Ramsay Bolton",
    "Jaime Lannister",
    "Joffrey Baratheon",
    "Tommen Baratheon",
    "Stannis Baratheon",
    "Renley Baratheon",
    "Brienne of Tarth",
    "Jon Snow",
    "Tywin Lannister",
    "Tyrion Lannister",
    "Davos Seaworth",
    "Melisandre",
    "Doran Martell",
    "Margery Tyrell",
    "Gregor Clegane",
    "Sandor Clegane",
    "Hodor",
    "Edmure Tully",
    "Ollena Tyrell",
    "Maester Aemon",
    "Samwell Tarley",
    "Roose Bolton",
    "Walder Frey",
    "Meryn Trant",
    "Mance Rayder",
    "Selyse Baratheon",
    "Wylla",
    "Allister Thorne",
    "Loras Tyrell",
    "Kevan Lannister"
  ]

  $scope.run = function() {
    $timeout(function() {
      var event = $scope.events[Math.floor(Math.random() * $scope.events.length)];
      console.log(event);
      event();
      $scope.updateState();
      if (!$scope.paused) {
        $scope.family.day++;
        $scope.run();
      }
    }, 2000 - $scope.pace * 100);
  }
  $scope.pause = function() {
    $scope.paused = true;
  }
  $scope.continue = function() {
    if ($scope.paused) {
      $scope.paused = false;

      $scope.run();
    }
  }

  $scope.start = function() {
    $scope.pace = parseInt($scope.pace);
    if ($scope.family.name.length > 0 && $scope.family.members.length > 0) {
      $scope.started = true;
      angular.forEach($scope.family.members, function(member) {
        if (member.name.indexOf($scope.family.name) < 0) {
          member.name += " " + $scope.family.name;
        }
      });

      $scope.family.soldiers = parseInt($scope.family.soldiers);
      $scope.family.steel = parseInt($scope.family.steel);
      $scope.run();
    }

  }

  $scope.end = function(message) {

    $timeout(function() {
      $scope.gameOver = message;
    }, 2500);

  }

  $scope.randomFamily = function(onlyAlive) {
    var pool = [];
    angular.forEach($scope.family.members, function(member) {
      if (onlyAlive && member.alive || !onlyAlive) {
        pool.push(member);
      }
    });
    if (pool.length > 0) {
      return pool[Math.floor(Math.random() * pool.length)]
    } else {
      return null
    }
  }

  $scope.updateState = function() {
    var someFamilyIsAlive = false;
    var somebodyIsAlive = $scope.people.length > 0;
    if ($scope.taxCD > 0) {
      $scope.taxCD--;
    }
    if ($scope.assassinationCD > 0) {
      $scope.assassinationCD--;
    }
    if ($scope.territoryTax > 0) {
      $scope.territoryTax--;
    }
    angular.forEach($scope.family.members, function(member) {
      if (member.alive) {
        someFamilyIsAlive = true;
      }
    });

    if (!somebodyIsAlive) {
      $scope.pause();
      $scope.end("Well, look at that, you killed everyone who poses a threat to you, well done. You survived Westeros.")
    }

    if (!someFamilyIsAlive) {
      $scope.pause();
      $scope.end("Welp, there goes the last of your House, you survived " + $scope.family.day + " days in Westeros.");
    }
  }
  $scope.assassins = [{
    name: "Some Street Thug",
    price: 20,
    successRate: 0.01
  }, {
    name: "Quickfinger",
    price: 500,
    successRate: 0.12
  }, {
    name: "The Sorrowful Men",
    price: 1000,
    successRate: 0.25
  }, {
    name: "Sand Vipers",
    price: 2000,
    successRate: 0.4
  }, {
    name: "The Alchemist",
    price: 2500,
    successRate: 0.5
  }, {
    name: "The Faceless Men",
    price: 30000,
    successRate: 0.95
  }]
  $scope.showAssassinOptions = false;
  $scope.assassinationTarget = "";
  $scope.assassinationCD = 0;
  $scope.cancelAssassination = function() {
    $scope.showAssassinOptions = false;
    $scope.continue();
  }
  $scope.confirmAssassination = function(person) {
    if ($scope.assassinationCD === 0 && $scope.stage >= 0) {
      if ($scope.stage < 1 && person === "Joffrey Baratheon") {
        $scope.log("He's a twat, yes, but still a kid. Can't assassinate him yet.")
      } else {
        $scope.assassinationTarget = person;
        $scope.pause();
        $scope.showAssassinOptions = true;
      }

    }
  }

  $scope.orderKill = function(assassin, person) {
    if ($scope.family.steel >= assassin.price) {
      $scope.family.steel -= assassin.price;
      $scope.showAssassinOptions = false;
      var roll = Math.random();
      if (roll < assassin.successRate) {
        $scope.killPerson(person);
        $scope.log("You hired " + assassin.name + " to kill " + person + ", and the attempt was successful");
      } else {
        $scope.log("Unfortunately, " + assassin.name + " has failed the attempt on " + person + "'s life, but quickly retreated before being caught");
      }
      $scope.continue();
      $scope.assassinationCD = 25;
    }

  }

  $scope.killPerson = function(person) {
    if ($scope.family.allies.indexOf(person) >= 0) {
      $scope.family.allies.splice($scope.family.allies.indexOf(person), 1);
    }
    if ($scope.family.enemies.indexOf(person) >= 0) {
      $scope.family.enemies.splice($scope.family.enemies.indexOf(person), 1);
    }

    $scope.people.splice($scope.people.indexOf(person), 1);
  }

  $scope.events = []
  $scope.territoryTax = 0;
  var taxCollection = function() {
    var tax = 0;
    if ($scope.territoryTax == 0) {
      angular.forEach($scope.places, function(place) {
        if (place.house === $scope.family.name) {
          tax += 1200;
        }
      });

      if (tax > 0) {
        $scope.territoryTax = 30;
        $scope.family.steel += tax;
        $scope.log("Your House collected " + tax + " Gold Dragons from territories");
      }
    }
  }
  $scope.events.push(taxCollection);

  var invasion = function() {
    if (Math.random() < 0.05) {
      if ($scope.family.soldiers > 0) {
        var enemies = Math.floor(Math.random() * $scope.family.soldiers + 10);
        $scope.family.soldiers -= Math.floor(enemies * Math.random() * 0.5);

        var invader = $scope.people[Math.floor(Math.random() * $scope.people.length)];

        if ($scope.family.enemies.indexOf(invader) >= 0) {
          $scope.log("That scallywag, " + invader + " attacked your home with an army of " + enemies + ". Your defending soldiers are now " + $scope.family.soldiers);

        } else if ($scope.family.allies.indexOf(invader) >= 0) {
          $scope.log("Oh no! " + invader + " decided to backstab you. With an army of " + enemies + " Your soldiers fought valiantly against what they thought were friends. " + $scope.family.soldiers + " of your men left standing, and they want revenge. " + invader + " has been moved to the enemies list for this betrayal");
          $scope.family.allies.splice($scope.family.allies.indexOf(invader), 1);
          $scope.family.enemies.push(invader);
        } else {
          $scope.log("Who knows what pushed " + invader + " to attack you with an army of " + enemies + "? In any case, they are now enemies.");
          $scope.family.enemies.push(invader);
        }
      }
    }
  }
  $scope.events.push(invasion);

  var assassin = function() {
    if (Math.random() < 0.01) {
      var victim = $scope.randomFamily(true);
      if (victim) {
        victim.alive = false;
        var perpetrator = $scope.people[Math.floor(Math.random() * $scope.people.length)];
        $scope.log("In the depth of night at " + victim.location + ", an assassin murdered " + victim.name + " in cold blood, and silently left, leaving behind only a note: 'Regards, " + perpetrator + "'. Could this be the one who hired the assassin?");
        if ($scope.family.allies.indexOf(perpetrator) >= 0) {
          $scope.family.allies.splice($scope.family.allies.indexOf(perpetrator), 1);
        }

        if ($scope.family.enemies.indexOf(perpetrator) < 0) {
          $scope.family.enemies.push(perpetrator);
        }

      }
    }

  }
  $scope.events.push(assassin);

  var allianceWith = function() {
    if (Math.random() < 0.13) {
      var person = $scope.people[Math.floor(Math.random() * $scope.people.length)];

      if ($scope.family.allies.indexOf(person) < 0) {
        if ($scope.family.enemies.indexOf(person) >= 0) {
          if (Math.random() < 0.3) {
            $scope.log(person + " came to you to beg forgiveness. In a move that will go down in history as 'Extremely stupid', you do. Oh well, lets see what happens next");
            $scope.family.enemies.splice($scope.family.enemies.indexOf(person), 1);
          } else {
            $scope.log(person + " came to you to beg forgiveness. You cleverly rejected the proposal. Well done.");
          }
        } else {
          if (Math.random() < 0.3) {
            $scope.log(person + " proposed to form an alliance with you. You decided against the proposal, they seem difficult to trust");
          } else {

            if (person === "Hodor") {
              $scope.log("Hodor wants to help you - 'Hodor'");
            } else {

              var msg = person + " proposed to form an alliance with you, and you gladly accepted it. ";
              if ($scope.lords.indexOf(person) >= 0) {
                var steel = Math.round(Math.random() * 10000 + 400);
                var soldier = Math.round(Math.random() * 400 + 20);
                $scope.family.steel += steel;
                $scope.family.soldiers += soldier;
                msg += "In celebration, " + person + " gifted you with " + steel + " Gold Dragons and " + soldier + " Soldiers";
              }
              $scope.log(msg);
            }

            $scope.family.allies.push(person);

          }
        }
      }
    }
  }
  $scope.events.push(allianceWith);

  var invadePlace = function() {
    if (Math.random() < 0.2 && $scope.stage > 0) {
      var randPlace = $scope.places[Math.floor(Math.random() * $scope.places.length)];
      if (randPlace.house != $scope.family.name && randPlace.name != "Castle Black") {
        if (Math.random() < 0.2 && $scope.family.soldiers > 400) {
          var newMen = Math.round(Math.random() * 100) + 5;
          var newSteel = Math.round(Math.random() * 3000) + 100;

          var leader = $scope.randomFamily(true);

          $scope.log(leader.name + " marched against " + randPlace.name + " and took it with " + $scope.family.soldiers + " men. Turns out, the people of " + randPlace.name + " welcomed your house, and provided you with " + newMen + " new soldiers and " + newSteel + " Gold Dragons");

          leader.location = randPlace.name;
          randPlace.house = $scope.family.name;
          $scope.family.steel += newSteel;
          $scope.family.soldiers += newMen;
        } else if ($scope.family.soldiers > 400) {
          var soldiersDied = Math.floor(Math.random() * $scope.family.soldiers * 0.8);

          var leader = $scope.randomFamily(true);

          $scope.log(leader.name + " marched against " + randPlace.name + " but failed to take it. In the process, " + soldiersDied + " soldiers died. It was a devastating loss");

          $scope.family.soldiers -= soldiersDied;
        }
      }
    }
  }
  $scope.events.push(invadePlace);

  var summons = function() {
    if (Math.random() < 0.2 && $scope.stage === 0 && $scope.family.steel > 400) {
      var summoned = $scope.randomFamily(true);
      summoned.location = "King's Landing";
      $scope.log(summoned.name + " has been summoned to King's Landing to serve as Hand of the King. Your House received 20,000 Gold Dragons and 1500 Soldiers for the service")

      var soldiers = 1500;
      var steel = 20000;

      $scope.family.steel += steel;
      $scope.family.soldiers += soldiers;

      $scope.stage = 1;
    }
  }
  $scope.events.push(summons);

  var kingDies = function() {
    if (Math.random() < 0.2 && $scope.stage == 1) {
      angular.forEach($scope.family.members, function(member) {
        member.location = "Home";
      });
      $scope.log("News of the King's Death spread. Everyone in your house returned Home safely to prepare for the worst.");
      $scope.stage = 2;
    } else if ($scope.stage == 1) {
      angular.forEach($scope.family.members, function(member) {
        if (member.location === "King's Landing" && member.alive) {
          member.alive = false;
          $scope.log(member.name + " was beheaded in King's Landing by order of Joffrey Baratheon");
          if ($scope.family.enemies.indexOf("Joffrey Baratheon") < 0) {
            $scope.family.enemies.push("Joffrey Baratheon");
          }
        }
        $scope.stage = 2;
      });
      $scope.stage = 2;
    }
  }

  $scope.events.push(kingDies);

  var winterIsComing = function() {
    if (Math.random < 0.1 && $scope.stage <= 1) {
      $scope.stage = 2;
      $scope.log("The Night's Watch sent a raven: Winter is Coming");
      $scope.nightsWatchRecruiting = true;
    }
  }
  $scope.events.push(winterIsComing);

  var visitsNightsWatch = function() {
    if (Math.random() < 0.02 && $scope.stage == 2 && $scope.nightsWatchRecruiting) {
      var person = $scope.randomFamily(true);
      person.location = "Castle Black";
      $scope.log(person.name + " journeyed to Castle Black to learn about the Night's Watch. They speak of White Walkers, but they're extinct... right?");
      $scope.nightsWatchRecruiting = false;
    }
  }
  $scope.events.push(visitsNightsWatch);

  var allyKilled = function() {
    if ($scope.family.allies.length > 0 && Math.random() < 0.2 && $scope.stage > 1) {
      var victim = $scope.family.allies[Math.floor(Math.random() * $scope.family.allies.length)];

      var roll = Math.random();
      if (roll < 0.2) {
        $scope.log("Your ally, " + victim + " died in the night, \"peacefully\"");
      } else if (roll < 0.6) {
        $scope.log("Your ally, " + victim + " died of poison. The one responsible has not been caught");
      } else if (roll < 0.9) {
        $scope.log(victim + " died en route to Winterfell. Wonder who was behind it?");
      } else {
        $scope.log(victim + " died horrifically being burnt alive. Let this be a lesson about playing with fire.");
      }

      $scope.killPerson(victim);
    }
  }
  $scope.events.push(allyKilled);

  $scope.ollied = false;
  var olly = function() {
    if (!$scope.ollied && Math.random() < 0.13) {
      var person = null;
      angular.forEach($scope.family.members, function(member) {
        if (member.alive && member.location == "Castle Black") {
          person = member;
        }
      });
      if (person) {
        $scope.log("Some Men of the Watch branded " + person.name + " a traitor. There was a log of stabbing, and blood, and Olly, whose parents died.");
        person.alive = false;
        $scope.ollied = true;
      }
    }
  }
  $scope.events.push(olly);

  $scope.melisandered = false;
  var melisander = function() {
    if (!$scope.melisandered && Math.random() < 0.02 && $scope.family.allies.indexOf("Melisandre") >= 0) {
      var alive = 0;
      var victim;
      angular.forEach($scope.family.members, function(member) {
        if (member.alive) {
          alive++;
          victim = member;
        }
      });
      if (alive > 1) {
        $scope.log("Melisandre convinced your House to burn " + victim.name + " in the name of the Lord of Light to melt some snow. After having done the deed, she quickly left at the realization of her mistake.");
        victim.alive = false;

      } else {
        $scope.log("Melisandre is displeased with the lack of progress for the Iron Throne, and decided to leave you. Might as well, she was suggesting something about burning royalty");

      }
      $scope.family.allies.splice($scope.family.allies.indexOf("Melisandre"), 1);
      $scope.melisandered = true;
    }
  }
  $scope.events.push(melisander);

  $scope.demonBabied = false;
  var demonBaby = function() {
    if ($scope.family.allies.indexOf("Melisandre") >= 0 && !$scope.melisandered && $scope.family.enemies.length > 0 && !$scope.demonBabied) {
      $scope.demonBabied = true;
      var person = $scope.randomFamily(true);
      var victim = $scope.family.enemies[Math.floor(Math.random() * $scope.family.enemies.length)];
      $scope.log(person.name + " was seduced by Melisandre, they made love, then she gave birth to a demon baby, because. Then this demon baby killed " + victim + ", so there's that. Hope " + person.name + " didn't get an STD in the process.");

      $scope.killPerson(victim);
    }
  }
  $scope.events.push(demonBaby);

  $scope.trialled = false;
  var trialByCombat = function() {
    if ($scope.stage >= 2 && !$scope.trialled) {
      $scope.trialled = true;
      var person = $scope.randomFamily(true);
      person.location = "King's Landing";
      var msg = person.name + " was forcibly taken to King's Landing under the charge of Treason. ";
      if ($scope.family.allies.indexOf("Doran Martell") >= 0) {
        msg += "Oberyn Martell decided to be your Champion as his brother Doran is allied with you. He's a pretty nice guy, but maybe his emotions got in the way. Anyway, he died pretty gruesomely in the duel. ";
        if (Math.random() < 0.75 && $scope.family.allies.length > 0) {
          var ally = $scope.family.allies[Math.floor(Math.random() * $scope.family.allies.length)];
          msg += person.name + " however managed to escape with the help of " + ally;
          person.location = "Home";
        } else {
          person.alive = false;
          msg += person.name + " was summarily executed on the spot by the Crown's champion";
        }
      } else {
        msg += person.name + " decided to be cleared of charges via trial by combat. ";
        if (Math.random() < 0.5) {
          msg += person.name + " won, and was let go";
          person.location = "Home";
        } else {
          msg += person.name + " died by sword through gut.";
          person.alive = false;
        }
      }
      $scope.log(msg);
    }
  }
  $scope.events.push(trialByCombat);

  var territoryChange = function() {
    if ($scope.stage > 1 && Math.random() < 0.3 && $scope.people.length > 1) {
      var person = $scope.people[Math.floor(Math.random() * $scope.people.length)];

      var place = $scope.places[Math.floor(Math.random() * $scope.places.length)];

      var personHouse = "";
      angular.forEach($scope.houses, function(house) {
        if (person.toLowerCase().indexOf($scope.houses) >= 0) {
          personHouse = house;
          personHouse = personHouse.substring(0, 1).toUpperCase() + personHouse.substring(1);
        }
      });

      if (personHouse && personHouse !== place.house) {
        place.house = personHouse;
        $scope.log(person + " attacked " + place.name + " and took control of it.");
      }
    }

  }

  console.log("events", $scope.events);
});
              
            
!
999px

Console