index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Monopoly Ledger</title>
  5. <link rel="stylesheet" href="styles.css">
  6. </head>
  7. <body>
  8. <h1>Monopoly Ledger</h1>
  9. <div id="setup">
  10. <h2>Setup</h2>
  11. <div class="wrap">
  12. <label for="numPlayers">Number of Players:</label>
  13. <input type="number" id="numPlayers">
  14. <br>
  15. <label for="startingValue">Starting Value:</label>
  16. <input type="number" id="startingValue">
  17. <br>
  18. <button onclick="initialize()">Set</button>
  19. </div>
  20. </div>
  21. <div id="balances">
  22. <h2>Balances</h2>
  23. <div id="output"></div>
  24. </div>
  25. <div id="transactions">
  26. <h2>Transactions</h2>
  27. <form id="transactionsForm" onsubmit="event.preventDefault();">
  28. <label for="fromAcc">From:</label>
  29. <select id="fromAcc">
  30. <option value="pot">Pot</option>
  31. <option value="bank">Bank</option>
  32. <!-- Generate player options dynamically -->
  33. </select>
  34. <br>
  35. <label for="toAcc">To:</label>
  36. <select id="toAcc">
  37. <option value="pot">Pot</option>
  38. <option value="bank">Bank</option>
  39. <!-- Generate player options dynamically -->
  40. <option value="all">All</option>
  41. </select>
  42. <br>
  43. <label for="amount">Amount:</label>
  44. <input type="number" id="amount">
  45. <br>
  46. <button onclick="sendMoney()">Send</button>
  47. </form>
  48. </div>
  49. <div id="levies">
  50. <h2>Levies</h2>
  51. <div class="wrap">
  52. <label for="levyAmount"></label>
  53. <input type="number" id="levyAmount">
  54. <label for="levyType"></label>
  55. <select id="levyType">
  56. <option value="money">Percentage of Money</option>
  57. <option value="property">Percentage of Property Values</option>
  58. <option value="wealth">Percentage of Wealth</option>
  59. </select>
  60. <br />
  61. <label for="levyDestination"></label>
  62. <select id="levyDestination">
  63. <option value="bank">To the Bank</option>
  64. <option value="pot">To the Pot</option>
  65. </select>
  66. <br />
  67. <button onclick="applyLevy()">Submit</button>
  68. </div>
  69. </div>
  70. <div id="propertyList">
  71. <h2>Properties</h2>
  72. <ul id="propertyItems"></ul>
  73. </div>
  74. <script>
  75. var numPlayers = 0;
  76. var accounts = [];
  77. // Property list data
  78. var properties = [
  79. // Brown Properties
  80. { name: "Mediterranean Avenue", owner: "none", improvements: 0, price: 60 },
  81. { name: "Baltic Avenue", owner: "none", improvements: 0, price: 60 },
  82. // Light Blue Properties
  83. { name: "Oriental Avenue", owner: "none", improvements: 0, price: 100 },
  84. { name: "Vermont Avenue", owner: "none", improvements: 0, price: 100 },
  85. { name: "Connecticut Avenue", owner: "none", improvements: 0, price: 120 },
  86. // Pink Properties
  87. { name: "St. Charles Place", owner: "none", improvements: 0, price: 140 },
  88. { name: "States Avenue", owner: "none", improvements: 0, price: 140 },
  89. { name: "Virginia Avenue", owner: "none", improvements: 0, price: 160 },
  90. // Orange Properties
  91. { name: "St. James Place", owner: "none", improvements: 0, price: 180 },
  92. { name: "Tennessee Avenue", owner: "none", improvements: 0, price: 180 },
  93. { name: "New York Avenue", owner: "none", improvements: 0, price: 200 },
  94. // Red Properties
  95. { name: "Kentucky Avenue", owner: "none", improvements: 0, price: 220 },
  96. { name: "Indiana Avenue", owner: "none", improvements: 0, price: 220 },
  97. { name: "Illinois Avenue", owner: "none", improvements: 0, price: 240 },
  98. // Yellow Properties
  99. { name: "Atlantic Avenue", owner: "none", improvements: 0, price: 260 },
  100. { name: "Ventnor Avenue", owner: "none", improvements: 0, price: 260 },
  101. { name: "Marvin Gardens", owner: "none", improvements: 0, price: 280 },
  102. // Green Properties
  103. { name: "Pacific Avenue", owner: "none", improvements: 0, price: 300 },
  104. { name: "North Carolina Avenue", owner: "none", improvements: 0, price: 300 },
  105. { name: "Pennsylvania Avenue", owner: "none", improvements: 0, price: 320 },
  106. // Dark Blue Properties
  107. { name: "Park Place", owner: "none", improvements: 0, price: 350 },
  108. { name: "Boardwalk", owner: "none", improvements: 0, price: 400 },
  109. // Railroads
  110. { name: "Reading Railroad", owner: "none", improvements: 0, price: 200 },
  111. { name: "Pennsylvania Railroad", owner: "none", improvements: 0, price: 200 },
  112. { name: "B. & O. Railroad", owner: "none", improvements: 0, price: 200 },
  113. { name: "Short Line Railroad", owner: "none", improvements: 0, price: 200 },
  114. // Utilities
  115. { name: "Electric Company", owner: "none", improvements: 0, price: 150 },
  116. { name: "Water Works", owner: "none", improvements: 0, price: 150 }
  117. // Add more properties as needed
  118. ];
  119. function printBalances() {
  120. var output = document.getElementById("output");
  121. output.innerHTML = "";
  122. // Create the table element
  123. var table = document.createElement("table");
  124. table.classList.add("centered-table"); // Add CSS class for centering the table
  125. // Create the table header row
  126. var headerRow = document.createElement("tr");
  127. var headers = ["Player", "Money", "Property"];
  128. headers.forEach(function(headerText) {
  129. var headerCell = document.createElement("th");
  130. headerCell.textContent = headerText;
  131. headerRow.appendChild(headerCell);
  132. });
  133. table.appendChild(headerRow);
  134. // Create the table rows for each player
  135. accounts.forEach(function(account) {
  136. var playerName = account[0];
  137. var money = account[1];
  138. var combinedPropertyValue = (playerName !== "Pot") ? calculateCombinedPropertyValue(playerName) : "";
  139. var row = document.createElement("tr");
  140. var playerNameCell = document.createElement("td");
  141. playerNameCell.textContent = playerName;
  142. row.appendChild(playerNameCell);
  143. var moneyCell = document.createElement("td");
  144. moneyCell.textContent = money;
  145. row.appendChild(moneyCell);
  146. var combinedPropertyValueCell = document.createElement("td");
  147. combinedPropertyValueCell.textContent = (playerName !== "Pot") ? combinedPropertyValue : "";
  148. row.appendChild(combinedPropertyValueCell);
  149. table.appendChild(row);
  150. });
  151. output.appendChild(table);
  152. }
  153. function calculateCombinedPropertyValue(playerName) {
  154. var combinedValue = calculatePropertyValue(playerName) + calculateImprovementsValue(playerName);
  155. return combinedValue;
  156. }
  157. function calculatePropertyValue(playerName) {
  158. var propertyValue = 0;
  159. properties.forEach(function(property) {
  160. if (property.owner === playerName) {
  161. propertyValue += property.price;
  162. }
  163. });
  164. return propertyValue;
  165. }
  166. function calculateImprovementsValue(playerName) {
  167. var improvementsValue = 0;
  168. properties.forEach(function(property) {
  169. if (property.owner === playerName) {
  170. improvementsValue += property.improvements;
  171. }
  172. });
  173. return improvementsValue;
  174. }
  175. function initialize() {
  176. var numPlayersInput = document.getElementById("numPlayers");
  177. var startingValueInput = document.getElementById("startingValue");
  178. numPlayers = parseInt(numPlayersInput.value);
  179. var startingValue = parseInt(startingValueInput.value);
  180. if (numPlayers < 2 || isNaN(numPlayers) || isNaN(startingValue)) {
  181. alert("Invalid input. Please enter a valid number of players and starting value.");
  182. return;
  183. }
  184. accounts = [];
  185. var initialProperties = [...properties]; // Copy the initial properties
  186. accounts.push(["Pot", 0]);
  187. for (var i = 1; i <= numPlayers; i++) {
  188. accounts.push(["Player " + i, startingValue]);
  189. }
  190. properties = [...initialProperties]; // Restore the initial properties
  191. resetPropertyOwners();
  192. generatePropertyList();
  193. printBalances();
  194. generatePlayerOptions();
  195. }
  196. function resetPropertyOwners() {
  197. // Reset property owners to "none"
  198. for (var i = 0; i < properties.length; i++) {
  199. properties[i].owner = "none";
  200. }
  201. }
  202. function generatePlayerOptions() {
  203. var fromAccSelect = document.getElementById("fromAcc");
  204. var toAccSelect = document.getElementById("toAcc");
  205. // Clear existing options
  206. fromAccSelect.innerHTML = "";
  207. toAccSelect.innerHTML = "";
  208. // Add options for Pot and Bank
  209. var potOption = document.createElement("option");
  210. potOption.value = "pot";
  211. potOption.text = "Pot";
  212. fromAccSelect.add(potOption.cloneNode(true));
  213. toAccSelect.add(potOption.cloneNode(true));
  214. var bankOption = document.createElement("option");
  215. bankOption.value = "bank";
  216. bankOption.text = "Bank";
  217. fromAccSelect.add(bankOption.cloneNode(true));
  218. toAccSelect.add(bankOption.cloneNode(true));
  219. // Add player options
  220. for (var i = 1; i <= numPlayers; i++) {
  221. var playerOption = document.createElement("option");
  222. playerOption.value = i.toString();
  223. playerOption.text = "Player " + i;
  224. fromAccSelect.add(playerOption.cloneNode(true));
  225. toAccSelect.add(playerOption.cloneNode(true));
  226. }
  227. // Add option for "All" to the "To" dropdown
  228. var allOption = document.createElement("option");
  229. allOption.value = "all";
  230. allOption.text = "All";
  231. toAccSelect.add(allOption.cloneNode(true));
  232. }
  233. function generatePropertyList() {
  234. var propertyItems = document.getElementById("propertyItems");
  235. propertyItems.innerHTML = ""; // Clear existing property list
  236. properties.forEach(function(property) {
  237. var listItem = document.createElement("li");
  238. listItem.innerHTML = `
  239. <select class="ownershipDropdown" onchange="updateOwnership(this.value, '${property.name}')">
  240. <option value="none">None</option>
  241. ${generatePlayerOptionsHTML()}
  242. </select>
  243. ${property.name} (${property.price})
  244. <input type="number" class="improvementsInput" onchange="updateImprovements(this.value, '${property.name}')" value="${property.improvements}">
  245. `;
  246. propertyItems.appendChild(listItem);
  247. });
  248. }
  249. function updateOwnership(player, propertyName) {
  250. properties.forEach(function(property) {
  251. if (property.name === propertyName) {
  252. property.owner = player;
  253. return;
  254. }
  255. });
  256. printBalances();
  257. }
  258. function updateImprovements(value, propertyName) {
  259. if (value == "") {
  260. value = 0;
  261. }
  262. var newValue = parseInt(value);
  263. properties.forEach(function(property) {
  264. if (property.name === propertyName) {
  265. property.improvements = newValue;
  266. return;
  267. }
  268. });
  269. printBalances();
  270. }
  271. function generatePlayerOptionsHTML() {
  272. var optionsHTML = "";
  273. for (var i = 1; i <= numPlayers; i++) {
  274. optionsHTML += `<option value="Player ${i}">Player ${i}</option>`;
  275. }
  276. return optionsHTML;
  277. }
  278. function applyLevy() {
  279. var levyAmountInput = document.getElementById("levyAmount");
  280. var levyTypeSelect = document.getElementById("levyType");
  281. var levyDestinationSelect = document.getElementById("levyDestination");
  282. var levyAmount = parseFloat(levyAmountInput.value);
  283. var levyType = levyTypeSelect.value;
  284. var levyDestination = levyDestinationSelect.value;
  285. if (isNaN(levyAmount) || levyAmount <= 0) {
  286. alert("Invalid levy amount. Please enter a valid number greater than zero.");
  287. return;
  288. }
  289. switch (levyType) {
  290. case "money":
  291. levyBasedOnMoney(levyAmount, levyDestination);
  292. break;
  293. case "property":
  294. levyBasedOnPropertyValues(levyAmount, levyDestination);
  295. break;
  296. case "wealth":
  297. levyBasedOnWealth(levyAmount, levyDestination);
  298. break;
  299. default:
  300. alert("Invalid levy type. Please select a valid levy type.");
  301. return;
  302. }
  303. printBalances();
  304. }
  305. function levyBasedOnMoney(levyAmount, levyDestination) {
  306. accounts.forEach(function (account) {
  307. var money = account[1];
  308. var levy = Math.round(money * (levyAmount / 100));
  309. if (levyDestination === "pot") {
  310. account[1] -= levy;
  311. accounts[0][1] += levy; // Add to the pot
  312. } else {
  313. account[1] -= levy; // Remove from account
  314. }
  315. });
  316. }
  317. function levyBasedOnPropertyValues(levyAmount, levyDestination) {
  318. accounts.forEach(function (account) {
  319. var playerPropertyValues = 0;
  320. properties.forEach(function (property) {
  321. if (property.owner === account[0]) {
  322. playerPropertyValues += (property.price + property.improvements);
  323. }
  324. });
  325. var levy = Math.round(playerPropertyValues * (levyAmount / 100));
  326. if (levyDestination === "pot") {
  327. account[1] -= levy;
  328. accounts[0][1] += levy; // Add to the pot
  329. } else {
  330. account[1] -= levy; // Remove from account
  331. }
  332. });
  333. }
  334. function levyBasedOnWealth(levyAmount, levyDestination) {
  335. accounts.forEach(function (account) {
  336. var money = account[1];
  337. var levy = Math.round(money * (levyAmount / 100));
  338. properties.forEach(function (property) {
  339. if (property.owner === account[0]) {
  340. levy += Math.round((property.price + property.improvements) * (levyAmount / 100));
  341. }
  342. });
  343. if (levyDestination === "pot") {
  344. account[1] -= levy;
  345. accounts[0][1] += levy; // Add to the pot
  346. } else {
  347. account[1] -= levy; // Remove from account
  348. }
  349. });
  350. }
  351. function sendMoney() {
  352. var fromAcc = document.getElementById("fromAcc").value;
  353. var toAcc = document.getElementById("toAcc").value;
  354. var amount = parseInt(document.getElementById("amount").value);
  355. // DEBIT
  356. if (fromAcc !== "bank") {
  357. if (fromAcc === "pot") {
  358. fromAcc = 0;
  359. } else {
  360. fromAcc = parseInt(fromAcc);
  361. }
  362. accounts[fromAcc][1] -= amount;
  363. }
  364. // CREDIT
  365. if (toAcc !== "bank") {
  366. if (toAcc === "all") {
  367. var remainder = amount;
  368. var i = 1;
  369. while (remainder > 0) {
  370. if (i !== fromAcc) {
  371. remainder -= 1;
  372. accounts[i][1] += 1;
  373. }
  374. i = (i % numPlayers) + 1;
  375. }
  376. } else {
  377. if (toAcc === "pot") {
  378. toAcc = 0;
  379. } else {
  380. toAcc = parseInt(toAcc);
  381. }
  382. accounts[toAcc][1] += amount;
  383. }
  384. }
  385. printBalances();
  386. }
  387. </script>
  388. <div id="footer">
  389. Monopoly Ledger is a project of the <a href="https://www.colorado.edu/lab/medlab/">Media Economies Design Lab</a> at the University of Colorado Boulder<br />
  390. <a href="https://git.medlab.host/MEDLab/MonopolyLedger/">Code</a> is free and open-source on an MIT license
  391. </div>
  392. </body>
  393. </html>