Advertisement
Guest User

Davids Hemsdia

a guest
Sep 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.51 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!-- David Söderberg 980805-6734-->
  3.  
  4. <html>
  5.  
  6. <head>
  7. <meta charset="UTF-8">
  8. <title>Hammurabi</title>
  9. <link rel="stylesheet" type="text/css" href="hammurabi.css">
  10. <script type="text/javascript" src="hammurabi.js">
  11. </script>
  12. </head>
  13.  
  14. <body onload="gameStart();">
  15. <div class="game">
  16. <h1>O Great Hammurabi!</h1>
  17. <h2 id="year">The report for year:</h2>
  18.  
  19. <ul id="people">
  20. <li id="starved">Starved:</li>
  21. <li id="newcomers">Newcomers:</li>
  22. <li id="population">Population:</li>
  23. </ul>
  24.  
  25. <ul id="economy">
  26. <li id="acres">Acres:</li>
  27. <li id="bushels">Bushels:</li>
  28. <li id="harvest">Harvest:</li>
  29. <li id="rats">Rats:</li>
  30. <li id="price">Price:</li>
  31. </ul>
  32.  
  33. <form>
  34. <div class="game_economy">
  35. <fieldset class="fieldset">
  36. <legend>Acres to sell / buy <span id="outputAcrestosellbuy"></span></legend>
  37. <input type="button" value="-" id="minusbuttonAcrestosellbuy" onclick="onChangeAcres('minusbuttonAcrestosellbuy');">
  38. <input type="range" id="sliderAcrestosellbuy" onchange="onChangeAcres('sliderAcrestosellbuy');">
  39. <input type="button" value="+" id="plusbuttonAcrestosellbuy" onclick="onChangeAcres('plusbuttonAcrestosellbuy');">
  40. </fieldset>
  41. <fieldset class="fieldset">
  42. <legend>Feed people <span id="outputFeedpeople"></span></legend>
  43. <input type="button" value="-" id="minusbuttonFeedpeople" onclick="onChangeFeeding('minusbuttonFeedpeople');">
  44. <input type="range" id="sliderFeedpeople" onchange="onChangeFeeding('sliderFeedpeople');">
  45. <input type="button" value="+" id="plusbuttonFeedpeople" onclick="onChangeFeeding('plusbuttonFeedpeople');">
  46. </fieldset>
  47. <fieldset class="fieldset">
  48. <legend>Plant with seed <span id="outputPlantwithseed"></span></legend>
  49. <input type="button" value="-" id="minusbuttonPlantwithseed" onclick="onChangePlanting('minusbuttonPlantwithseed');">
  50. <input type="range" id="sliderPlantwithseed" onchange="onChangePlanting('sliderPlantwithseed');">
  51. <input type="button" value="+" id="plusbuttonPlantwithseed" onclick="onChangePlanting('plusbuttonPlantwithseed');">
  52. </fieldset>
  53. </div>
  54.  
  55. <div class="game_buttons">
  56. <button type="button" onclick="gameStart();">Restart</button>
  57. <button type="button" onclick="finishTurn();">So be it!</button>
  58. <button type="button" id="help_btn" onclick="showHelp()">Help</button>
  59. <div id="help" class="help">
  60. <div class="help-content">
  61. <div class="help-header">
  62. <span class="close">&times;</span>
  63. <h2>Instruktioner för spelet</h2>
  64. </div>
  65. <div class="help-body">
  66. <p>Detta spel är rätt så simpelt spel och går helt enkelt ut på att du ska
  67. samla på dig så mycket hektar land, folk och spannmål som möjligt. Detta gör man
  68. genom att köpa och sälja land, plantera grödor för det nästa året och att mata
  69. din befolkning. Men se upp, du kan också ha otur och bli drabbad av saker som
  70. pesten, eller råttor som äter upp ditt spannmål. Det kan alltså bli en liten
  71. utmaning att lyckas styra landet i 10år utan att förlora makten.
  72. </p>
  73. <h3> Reglerna: </h3>
  74. <ol>
  75. <li>Spelet håller på i 10 år, varje runda är ett år.</li>
  76. <li>Varje år ska du bestämma hur mycket hektar du ska köpa/sälja, hur mycket
  77. mat du ska ge din befolkning och hur mycket du ska plantera för nästa år.</li>
  78. <li>Varje person behöver 20 skäppor spannmål varje år för att överleva och kan
  79. som mest ploga 10 hektar land.</li>
  80. <li>Varje hektar av land behöver en skäppa spannmål för att plantera frön.</li>
  81. <li>Priset för varje hektar av land varierar mellan 17 till 26 skäppor spannmål.</li>
  82. <li>Om omständigheterna i ditt land blir för dåligt så kommer folket att göra
  83. uppror och du förlorar spelet.</li>
  84. </ol>
  85. </div>
  86. </div>
  87. </div>
  88.  
  89. </div>
  90. </form>
  91. </div>
  92.  
  93. <div class="info">
  94. <h1> Information om Hammurabi</h1>
  95. <h2> Om Hammurabi</h2>
  96. <p><strong>Hammurabi</strong> var den sjätte kungen i Babylon (nuvarande Irak)
  97. och levde från ungefär 1810 f.Kr till 1750 f.Kr. Han tog över och blev kung
  98. efter sin far som dog då Hammurabi endast var 18 år gammal.
  99. </p>
  100.  
  101. <h2> Hammurabis lagar</h2>
  102. <p> Hammurabi är inte bara känd för sina stora framgångar han hade med sina
  103. eröveringar,utan han är också känd för det sätt han styrde sitt rike. Han var
  104. personligen inblandad och engagerad i admininistranationen av riket och det är
  105. just därför <em>Hammurabis lagar</em> existerar. Trots hans engagement av
  106. administrationen så blev den aldrig effektiv under hans styre. Vilket kan vara
  107. en av anledningarna till varför administrationen också föll samman efter hans
  108. död.
  109. </p>
  110. <p>
  111. Lagarna Hammurabi skapade är bland de <em>första</em> lagarna i världen och går
  112. att hitta på en stor 2,25m hög
  113. <a href="https://upload.wikimedia.org/wikipedia/commons/6/64/P1050763_Louvre_cod
  114. e_Hammurabi_face_rwk.JPG">stele.</a>
  115. Själva skriften på stelen är uppbygt på följande sätt: först en inledning med
  116.  
  117. </p>
  118. </div>
  119. </body>
  120.  
  121. </html>
  122.  
  123.  
  124.  
  125.  
  126. ____
  127.  
  128. /* David Söderberg 980805-6734 */
  129.  
  130. /* BODY, FONTS etc*/
  131.  
  132. body {
  133. width: 90%;
  134. margin-left: 5%;
  135. margin-right: 5%;
  136. background-color: #fff;
  137. background-image: linear-gradient(90deg, transparent 2.75em, #abced4 2.75em, #abced4 2.875em, transparent 2.875em),
  138. linear-gradient(#eee .1em, transparent .1em);
  139. background-size: 100% 1.2em;
  140. }
  141.  
  142. h2{
  143. margin-bottom: -0.2em;
  144. }
  145.  
  146.  
  147. /* CONTENT */
  148.  
  149. /* CONTENT / GAME */
  150.  
  151. .game{
  152. width: 49%;
  153. float: left;
  154. }
  155.  
  156. .game_economy{
  157. width: 49%;
  158. float: left;
  159. }
  160.  
  161. #economy {
  162. display: block;
  163. padding-left: 1em;
  164. border: black 1px solid;
  165. border-radius: 0.2em;
  166. background: #8be0ef;
  167. list-style: none;
  168. }
  169.  
  170. #economy li {
  171. margin-bottom: 1px;
  172. }
  173.  
  174. #people {
  175. display: block;
  176. padding-left: 1em;
  177. border: black 1px solid;
  178. border-radius: 0.2em;
  179. background: #8be0ef;
  180. list-style: none;
  181. }
  182.  
  183. #people li {
  184. display: inline;
  185. margin-right: 10px;
  186. }
  187.  
  188. .game_buttons{
  189. width: 49%;
  190. float: right;
  191. }
  192.  
  193. .game_buttons button {
  194. padding: 0.625em 0.938em;
  195. float: none;
  196. width: 50%;
  197. display: inline-block;
  198. margin-left: 0%;
  199. margin-bottom: 1em;
  200. margin-top: 1em;
  201. border-radius: 0.2em;
  202. }
  203.  
  204. .fieldset {
  205. border-style: none;
  206. }
  207.  
  208. input[type=button]{
  209. border-radius: 0.2em;
  210. }
  211.  
  212. /* CONTENT / GAME / HELP */
  213.  
  214. .help {
  215. display: none;
  216. position: fixed;
  217. z-index: 1;
  218. left: 0;
  219. top: 0;
  220. width: 100%;
  221. height: 100%;
  222. background-color: rgba(0,0,0,0.4);
  223. }
  224.  
  225. .help h2 {
  226. margin: 0;
  227. }
  228.  
  229. .help-content {
  230. background-color: #fefefe;
  231. margin: 15% auto;
  232. padding: 0.75em;
  233. border: 2px solid #abced4;
  234. border-radius: 0.2em;
  235. width: 80%;
  236. }
  237.  
  238. .help-header {
  239. padding: 0.125em 1em;
  240. background-color: #8be0ef;
  241. border-radius: 0.2em;
  242. color: white;
  243. text-shadow: -0.0625em 0 black, 0 0.0625em black, 0.0625em 0 black, 0 0.0625em black;
  244. }
  245.  
  246. .help-body {
  247. padding: 2px 16px;
  248. }
  249.  
  250. .close {
  251. color: #aaa;
  252. float: right;
  253. font-size: 1.75em;
  254. font-weight: bold;
  255. }
  256.  
  257. .close:hover, .close:focus {
  258. color: black;
  259. text-decoration: none;
  260. cursor: pointer;
  261. }
  262.  
  263. .help ol{
  264. margin-top: -1em;
  265. list-style-type: decimal;
  266. }
  267.  
  268.  
  269. /* CONTENT / INFORMATION*/
  270.  
  271. .info {
  272. width: 49%;
  273. float: right;
  274. }
  275.  
  276.  
  277.  
  278. /* MEDIA QUERIES */ /* Gör sidan scaleable */
  279. @media only screen and ( max-width: 68.875em) { /* 1102px, för att där går sidan "sönder" */
  280.  
  281. .game{
  282. width: 100%;
  283. float: none;
  284. }
  285.  
  286. .game_economy fieldset{
  287. text-align: center;
  288. }
  289. .info{
  290. width: 100%;
  291. }
  292. }
  293.  
  294. @media only screen and ( max-width: 65em) { /* 1040px */
  295. body{
  296. background-image: linear-gradient(#eee .1em, transparent .1em);
  297. }
  298. }
  299.  
  300. @media only screen and ( max-width: 30.25em) { /* 532px */
  301.  
  302. #people li {
  303. display: block;
  304. }
  305.  
  306. .game_buttons{
  307. width: 100%;
  308. }
  309.  
  310. .game_buttons button{
  311. padding: 0.625em 0.938em;
  312. float: none;
  313. width: 80%;
  314. display: inline-block;
  315. margin-left: 10%;
  316. margin-right: 10%;
  317. margin-bottom: 1em;
  318. margin-top: 1em;
  319. border-radius: 0.2em;
  320. }
  321.  
  322. .game_economy{
  323. width: 100%;
  324. }
  325.  
  326. }
  327.  
  328. ___
  329.  
  330. // This is the game state.
  331.  
  332. var gameState;
  333.  
  334. gameState = {
  335. year : 0,
  336. starved : 0,
  337. newcomers : 0,
  338. population : 0,
  339. acres : 0,
  340. bushels : 0,
  341. harvest : 0,
  342. rats : 0,
  343. price : 0,
  344. internalAcres : 0,
  345. internalBushels : 0,
  346. totalStarved: 0
  347. };
  348.  
  349. /* Returns the minimum of the three input values. */
  350.  
  351. function minimum(firstValue, secondValue, thirdValue) {
  352. if (firstValue <= secondValue) {
  353. if (firstValue <= thirdValue) {
  354. return firstValue;
  355. } else {
  356. return thirdValue;
  357. }
  358. } else if (secondValue <= thirdValue) {
  359. return secondValue;
  360. } else {
  361. return thirdValue;
  362. }
  363. }
  364.  
  365. /* Returns the slider which has the id sliderId. */
  366.  
  367. function getSlider(sliderId) {
  368. return document.getElementById(sliderId);
  369. }
  370.  
  371. /* Outputs the value of the slider with the id sliderId
  372. to the element with the id outputElementId. */
  373.  
  374. function updateSliderValueOutput(sliderId, outputElementId) {
  375. document.getElementById(outputElementId).innerHTML = document.getElementById(sliderId).value;
  376. }
  377.  
  378. /* Helper function.
  379.  
  380. function helperFunction(sliderId, outputElementId) {
  381. var slider = document.getElementById(sliderId);
  382. outputElement = document.getElementById(outputElementId);
  383. outputElement.innerHTML = " " + slider.min + " " + slider.max + " " + slider.step;
  384. }*/
  385.  
  386. /* Outputs the momentary game state. */
  387.  
  388. function writeGameState() {
  389. document.getElementById("year").innerHTML = "The report for year: " + gameState.year;
  390. document.getElementById("starved").innerHTML = "Starved: " + gameState.starved;
  391. document.getElementById("newcomers").innerHTML = "Newcomers: " + gameState.newcomers;
  392. document.getElementById("population").innerHTML = "Population: " + gameState.population;
  393. document.getElementById("acres").innerHTML = "Acres: " + gameState.acres;
  394. document.getElementById("bushels").innerHTML = "Bushels: " + gameState.bushels;
  395. document.getElementById("harvest").innerHTML = "Harvest: " + gameState.harvest;
  396. document.getElementById("rats").innerHTML = "Rats: " + gameState.rats;
  397. document.getElementById("price").innerHTML = "Price: " + gameState.price;
  398.  
  399. updateSliderValueOutput("sliderAcrestosellbuy", "outputAcrestosellbuy");
  400. updateSliderValueOutput("sliderFeedpeople", "outputFeedpeople");
  401. updateSliderValueOutput("sliderPlantwithseed", "outputPlantwithseed");
  402. }
  403.  
  404. /* Sets and outputs the initial game state. */
  405.  
  406. function gameStart() {
  407. gameState.year = 1;
  408. gameState.starved = 0;
  409. gameState.newcomers = 5;
  410. gameState.population = 100;
  411. gameState.acres = 1000;
  412. gameState.bushels = 2800;
  413. gameState.harvest = 3;
  414. gameState.rats = 200;
  415. gameState.price = randomNumber(10) + 16;
  416. gameState.internalAcres = gameState.acres;
  417. gameState.internalBushels = gameState.bushels;
  418. gameState.totalStarved = 0;
  419.  
  420. /* We have to set value after we set min and max,
  421. because if min and max are set after value has
  422. been set the Google Chrome browser changes value
  423. again which leads to a bug in the game.
  424.  
  425. We could not figure out the concrete operation
  426. of the Google Chrome browser which leads to this
  427. behaviour, despite extensive search on the internet.
  428.  
  429. Issue found out: 12/15/2011 */
  430.  
  431. var acresSlider = getSlider("sliderAcrestosellbuy");
  432. acresSlider.min = -gameState.acres;
  433. acresSlider.max = Math.floor(gameState.internalBushels / gameState.price);
  434. acresSlider.value = 0;
  435. acresSlider.step = 1;
  436.  
  437. var feedSlider = getSlider("sliderFeedpeople");
  438. feedSlider.min = 0;
  439. feedSlider.max = gameState.internalBushels;
  440. feedSlider.value = 0;
  441. feedSlider.step = 1;
  442.  
  443. var plantSlider = getSlider("sliderPlantwithseed");
  444. plantSlider.min = 0;
  445. plantSlider.max = minimum(gameState.internalAcres, 10 * gameState.population, gameState.internalBushels);
  446. plantSlider.value = 0;
  447. plantSlider.step = 1;
  448.  
  449. writeGameState();
  450. }
  451.  
  452. /* Takes the value of the slider for acres to sell or buy
  453. and adds it to the acres value. The result is stored
  454. in internal acres. */
  455.  
  456. function updateInternalAcres() {
  457. gameState.internalAcres = gameState.acres + parseInt(getSlider("sliderAcrestosellbuy").value);
  458. }
  459.  
  460. /* Takes the values of the sliders for acres to sell or buy,
  461. feed people and plant with seed, subtracts them from
  462. bushels and stores the result in internal bushels. */
  463.  
  464. function updateInternalBushels() {
  465. var acresToSellOrBuy = parseInt(getSlider("sliderAcrestosellbuy").value);
  466. var bushelsForFeeding = parseInt(getSlider("sliderFeedpeople").value);
  467. var bushelsForPlanting = parseInt(getSlider("sliderPlantwithseed").value);
  468. gameState.internalBushels = gameState.bushels - acresToSellOrBuy * gameState.price - bushelsForFeeding - bushelsForPlanting;
  469. }
  470.  
  471. /* Updates the max property of the acres to buy or sell slider. */
  472.  
  473. function updateMaximumAcresToSellBuy() {
  474. var acresSlider = getSlider("sliderAcrestosellbuy");
  475. acresSlider.max = Math.floor(gameState.internalBushels / gameState.price) + parseInt(acresSlider.value);
  476. }
  477.  
  478. /* Updates the max property of the feed people slider. */
  479.  
  480. function updateMaximumFeedPeople() {
  481. var feedSlider = getSlider("sliderFeedpeople");
  482. feedSlider.max = gameState.internalBushels + parseInt(feedSlider.value);
  483. }
  484.  
  485. /* Updates the max property of the plant with seed slider. */
  486.  
  487. function updateMaximumPlantWithSeed() {
  488. var plantSlider = getSlider("sliderPlantwithseed");
  489. plantSlider.max = minimum(gameState.internalAcres, 10 * gameState.population, gameState.internalBushels + parseInt(plantSlider.value));
  490. }
  491.  
  492. /* This function gets called when the value of the slider
  493. which determines how much acres will be bought or sold
  494. is changed.
  495.  
  496. It changes the value of the internal acres as following:
  497.  
  498. - minus button: decrement the internal acres by 1
  499. - plus button: increment the internal acres by 1
  500. - slider: add the new value to internal acres
  501.  
  502. The values of the internal bushels, the maximum of
  503. feed people and plant with seed are also changed. */
  504.  
  505. function onChangeAcres(elementId) {
  506. if (elementId === "minusbuttonAcrestosellbuy") {
  507. getSlider("sliderAcrestosellbuy").value = parseInt(getSlider("sliderAcrestosellbuy").value) - 1;
  508. } else if (elementId === "plusbuttonAcrestosellbuy") {
  509. getSlider("sliderAcrestosellbuy").value = parseInt(getSlider("sliderAcrestosellbuy").value) + 1;
  510. }
  511. updateSliderValueOutput("sliderAcrestosellbuy", "outputAcrestosellbuy");
  512. updateInternalAcres();
  513. updateInternalBushels();
  514. updateMaximumFeedPeople();
  515. updateMaximumPlantWithSeed();
  516. }
  517.  
  518. /* This function gets called when the value of the slider
  519. which determines how much bushels will be used for feeding
  520. is changed.
  521.  
  522. The values of the internal bushels, the maximum of
  523. acres to sell or buy and plant with seed are changed. */
  524.  
  525. function onChangeFeeding(elementId) {
  526. if (elementId === "minusbuttonFeedpeople") {
  527. getSlider("sliderFeedpeople").value = parseInt(getSlider("sliderFeedpeople").value) - 1;
  528. } else if (elementId === "plusbuttonFeedpeople") {
  529. getSlider("sliderFeedpeople").value = parseInt(getSlider("sliderFeedpeople").value) + 1;
  530. }
  531. updateSliderValueOutput("sliderFeedpeople", "outputFeedpeople");
  532. updateInternalBushels();
  533. updateMaximumAcresToSellBuy();
  534. updateMaximumPlantWithSeed();
  535. }
  536.  
  537. /* This function gets called when the value of the slider
  538. which determines how much bushels will be used for planting
  539. is changed.
  540.  
  541. The values of the internal bushels, the maximum of
  542. acres to sell or buy and feed people are changed. */
  543.  
  544. function onChangePlanting(elementId) {
  545. if (elementId === "minusbuttonPlantwithseed") {
  546. getSlider("sliderPlantwithseed").value = parseInt(getSlider("sliderPlantwithseed").value) - 1;
  547. } else if (elementId === "plusbuttonPlantwithseed") {
  548. getSlider("sliderPlantwithseed").value = parseInt(getSlider("sliderPlantwithseed").value) + 1;
  549. }
  550. updateSliderValueOutput("sliderPlantwithseed", "outputPlantwithseed");
  551. updateInternalBushels();
  552. updateMaximumAcresToSellBuy();
  553. updateMaximumFeedPeople();
  554. }
  555.  
  556. /* Returns a random number between 1 and maxValue. */
  557.  
  558. function randomNumber(maxValue) {
  559. var number = Math.floor(Math.random() * maxValue + 1);
  560. return number;
  561. }
  562.  
  563. /* Returns 15% of the time the boolean value true
  564. and 85% of the time the boolean value false. */
  565.  
  566. function plague() {
  567. var plagueOccurs;
  568. if (randomNumber(100) <= 15) {
  569. plagueOccurs = true;
  570. } else {
  571. plagueOccurs = false;
  572. }
  573. return plagueOccurs;
  574. }
  575.  
  576. /* Returns 40% of the time the boolean value true
  577. and 60% of the time the boolean value false. */
  578.  
  579. function ratsProblem() {
  580. var ratsProblemOccurs;
  581. if (randomNumber(10) <= 4) {
  582. ratsProblemOccurs = true;
  583. } else {
  584. ratsProblemOccurs = false;
  585. }
  586. return ratsProblemOccurs;
  587. }
  588.  
  589. /* If there is a problem with rats, they eat 1/10, 2/10 or
  590. 3/10 of the bushels. Otherwise they eat none. */
  591.  
  592. function bushelsEatenByRats() {
  593. var bushelsEaten;
  594. if (ratsProblem()) {
  595. bushelsEaten = Math.floor((randomNumber(3) / 10) * gameState.bushels);
  596. } else {
  597. bushelsEaten = 0;
  598. }
  599. return bushelsEaten;
  600. }
  601.  
  602. /* Returns a random number between 1 and 8. */
  603.  
  604. function harvestPerAcre() {
  605. var harvest = randomNumber(8);
  606. return harvest;
  607. }
  608.  
  609. /* Calculates how many people starved, depending on
  610. the number of bushels which were used to feed
  611. people. */
  612.  
  613. function calculateStarvedPeople() {
  614. var numberPeopleStarved = gameState.population - Math.floor(parseInt(getSlider("sliderFeedpeople").value) / 20);
  615. if (numberPeopleStarved <= 0) {
  616. return 0;
  617. } else {
  618. return numberPeopleStarved;
  619. }
  620. }
  621.  
  622. /* Calculates the number of newcomers, depending on
  623. the internal number of acres, internal number of
  624. bushels and the size of the population.
  625.  
  626. Formula:
  627. (20 * number of acres you have + amount of grain you have in storage) / (100 * population) + 1*/
  628.  
  629. function calculateNewcomers() {
  630. return Math.floor((20 * gameState.internalAcres + gameState.internalBushels) / (100 * gameState.population)) + 1;
  631. }
  632.  
  633. /* The function returns true if more than 45% of the
  634. original population starved. Otherwise it returns
  635. false. */
  636.  
  637. function tooManyPeopleStarved() {
  638. var originalPopulation = gameState.population + gameState.starved - gameState.newcomers;
  639. if (Math.floor((gameState.starved / originalPopulation) * 100) > 45) {
  640. return true;
  641. } else {
  642. return false;
  643. }
  644. }
  645.  
  646. /* Så att du ska kunna få hjälp om spelet. */
  647.  
  648. function showHelp() {
  649. var help = document.getElementById('help');
  650. var btn = document.getElementById("help_btn");
  651. var span = document.getElementsByClassName("close")[0];
  652. help.style.display = "block";
  653.  
  654. span.onclick = function() {
  655. help.style.display = "none";
  656. }
  657. window.onclick = function(event) {
  658. if (event.target == help) {
  659. help.style.display = "none";
  660. }
  661. }
  662. }
  663.  
  664. /* If the maximum number of turns is not fulfilled yet and
  665. not too many people starved, the new game state is being
  666. calculated and outputted.
  667. If too many people starved the user is being informed
  668. that he is kicked out of office.
  669. Otherwise the end-page is shown which informs the user
  670. about his performance. */
  671.  
  672. function finishTurn() {
  673. if (plague()) {
  674. alert("A horrible plague occured!\n" + "Half of your population died.");
  675. gameState.population = Math.floor(gameState.population / 2);
  676. }
  677. gameState.starved = calculateStarvedPeople();
  678. gameState.totalStarved = gameState.totalStarved + gameState.starved;
  679. gameState.newcomers = calculateNewcomers();
  680. gameState.population = gameState.population - gameState.starved + gameState.newcomers;
  681. gameState.harvest = harvestPerAcre();
  682. gameState.bushels = gameState.internalBushels + gameState.harvest * parseInt(getSlider("sliderPlantwithseed").value);
  683. gameState.rats = bushelsEatenByRats();
  684. gameState.bushels = gameState.bushels - gameState.rats;
  685. gameState.internalBushels = gameState.bushels;
  686. gameState.price = randomNumber(10) + 16;
  687. gameState.acres = gameState.internalAcres;
  688.  
  689. if (gameState.year < 10 && !tooManyPeopleStarved()) {
  690. gameState.year++;
  691.  
  692. var acresSlider = getSlider("sliderAcrestosellbuy");
  693. acresSlider.min = -gameState.acres;
  694. acresSlider.max = Math.floor(gameState.internalBushels / gameState.price);
  695. acresSlider.value = 0;
  696. acresSlider.step = 1;
  697.  
  698. var feedSlider = getSlider("sliderFeedpeople");
  699. feedSlider.min = 0;
  700. feedSlider.max = gameState.internalBushels;
  701. feedSlider.value = 0;
  702. feedSlider.step = 1;
  703.  
  704. var plantSlider = getSlider("sliderPlantwithseed");
  705. plantSlider.min = 0;
  706. plantSlider.max = minimum(gameState.internalAcres, 10 * gameState.population, gameState.internalBushels);
  707. plantSlider.value = 0;
  708. plantSlider.step = 1;
  709.  
  710. writeGameState();
  711. } else if (tooManyPeopleStarved()) {
  712. alert("You have starved over 45% of the population!\n" + "You have been kicked out of office.\n" + "Try again.");
  713. gameStart();
  714. } else {
  715. var averagePeopleStarved = Math.floor(gameState.totalStarved / 10);
  716. var acrePerPerson = Math.floor(gameState.acres / gameState.population);
  717. alert("Overall performance\n" + "Average people starved per year: " + averagePeopleStarved + "\n" + "Population: " + gameState.population + "\n" + "Acres per person: " + acrePerPerson);
  718. gameStart();
  719. }
  720. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement