index.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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" class="section">
  10. <h2>Setup</h2>
  11. <div class="wrap">
  12. <label for="numPlayers">Number of Players:</label>
  13. <input type="number" id="numPlayers" value="2">
  14. <br>
  15. <label for="startingValue">Starting Balance:</label>
  16. <input type="number" id="startingValue" value="1500">
  17. <br>
  18. <button onclick="initialize()">Begin</button>
  19. </div>
  20. </div>
  21. <div id="rules" class="section">
  22. <h2>Rules</h2>
  23. <div class="wrap">
  24. <select id="ruleSelect">
  25. <option value="">Preset rules</option>
  26. <option>Change rules by consensus</option>
  27. <option>Change rules by majority vote</option>
  28. <option>Pay rents to pot</option>
  29. <option>Pay rents to all other players</option>
  30. <option>Pay levies to the pot</option>
  31. <option>Pot distributed to player who rolls doubles</option>
  32. <option>Property levy on passing Go</option>
  33. <option>Wealth levy on passing Go</option>
  34. <option>Inflation levy on money every full round of turns</option>
  35. <option>Distribute basic income every full round</option>
  36. <option>Ban on trades or gifts of assets</option>
  37. <option>Ban improvements by a player on more than one color on each side of board</option>
  38. <option>Allow fractional ownership and revenues</option>
  39. <option>Goal: Every player builds first hotel</option>
  40. <option>Goal: Hotel on every buildable space</option>
  41. <option>Goal: Use the pot as the bank and bankrupt the pot</option>
  42. </select>
  43. <br>
  44. <input type="text" id="customRuleInput" placeholder="Enter custom rule">
  45. <button onclick="addCustomRule()">Add Custom Rule</button>
  46. </div>
  47. <div>
  48. <ul id="chosenRulesList"></ul>
  49. </div>
  50. </div>
  51. <div id="section" class="section">
  52. <h2>Balances</h2>
  53. <div id="output"></div>
  54. </div>
  55. <div id="transactions" class="section">
  56. <h2>Transactions</h2>
  57. <form id="transactionsForm" onsubmit="event.preventDefault();">
  58. <label for="fromAcc">From:</label>
  59. <select id="fromAcc">
  60. <option value="pot">Pot</option>
  61. <option value="bank">Bank</option>
  62. <!-- Generate player options dynamically -->
  63. </select>
  64. <br>
  65. <label for="toAcc">To:</label>
  66. <select id="toAcc">
  67. <option value="pot">Pot</option>
  68. <option value="bank">Bank</option>
  69. <!-- Generate player options dynamically -->
  70. <option value="all">All</option>
  71. </select>
  72. <br>
  73. <label for="amount">Amount:</label>
  74. <input type="number" id="amount">
  75. <br>
  76. <button onclick="sendMoney()">Send</button>
  77. </form>
  78. </div>
  79. <div id="levies" class="section">
  80. <h2>Levies</h2>
  81. <div class="wrap">
  82. <label for="levyAmount"></label>
  83. <input type="number" id="levyAmount">
  84. <label for="levyType"></label>
  85. <select id="levyType">
  86. <option value="money">Percentage of Money</option>
  87. <option value="property">Percentage of Property Values</option>
  88. <option value="wealth">Percentage of Wealth</option>
  89. </select>
  90. <br />
  91. <label for="levyDestination"></label>
  92. <select id="levyDestination">
  93. <option value="bank">To the Bank</option>
  94. <option value="pot">To the Pot</option>
  95. </select>
  96. <br />
  97. <button onclick="applyLevy()">Submit</button>
  98. </div>
  99. </div>
  100. <div id="propertyList" class="section">
  101. <h2>Properties</h2>
  102. <ul id="propertyItems"></ul>
  103. </div>
  104. <script>
  105. var numPlayers = 0;
  106. var accounts = [];
  107. // Property list data
  108. var properties = [
  109. // Brown Properties
  110. { name: "Mediterranean Avenue", owner: "none", improvements: 0, price: 60 },
  111. { name: "Baltic Avenue", owner: "none", improvements: 0, price: 60 },
  112. // Light Blue Properties
  113. { name: "Oriental Avenue", owner: "none", improvements: 0, price: 100 },
  114. { name: "Vermont Avenue", owner: "none", improvements: 0, price: 100 },
  115. { name: "Connecticut Avenue", owner: "none", improvements: 0, price: 120 },
  116. // Pink Properties
  117. { name: "St. Charles Place", owner: "none", improvements: 0, price: 140 },
  118. { name: "States Avenue", owner: "none", improvements: 0, price: 140 },
  119. { name: "Virginia Avenue", owner: "none", improvements: 0, price: 160 },
  120. // Orange Properties
  121. { name: "St. James Place", owner: "none", improvements: 0, price: 180 },
  122. { name: "Tennessee Avenue", owner: "none", improvements: 0, price: 180 },
  123. { name: "New York Avenue", owner: "none", improvements: 0, price: 200 },
  124. // Red Properties
  125. { name: "Kentucky Avenue", owner: "none", improvements: 0, price: 220 },
  126. { name: "Indiana Avenue", owner: "none", improvements: 0, price: 220 },
  127. { name: "Illinois Avenue", owner: "none", improvements: 0, price: 240 },
  128. // Yellow Properties
  129. { name: "Atlantic Avenue", owner: "none", improvements: 0, price: 260 },
  130. { name: "Ventnor Avenue", owner: "none", improvements: 0, price: 260 },
  131. { name: "Marvin Gardens", owner: "none", improvements: 0, price: 280 },
  132. // Green Properties
  133. { name: "Pacific Avenue", owner: "none", improvements: 0, price: 300 },
  134. { name: "North Carolina Avenue", owner: "none", improvements: 0, price: 300 },
  135. { name: "Pennsylvania Avenue", owner: "none", improvements: 0, price: 320 },
  136. // Dark Blue Properties
  137. { name: "Park Place", owner: "none", improvements: 0, price: 350 },
  138. { name: "Boardwalk", owner: "none", improvements: 0, price: 400 },
  139. // Railroads
  140. { name: "Reading Railroad", owner: "none", improvements: 0, price: 200 },
  141. { name: "Pennsylvania Railroad", owner: "none", improvements: 0, price: 200 },
  142. { name: "B. & O. Railroad", owner: "none", improvements: 0, price: 200 },
  143. { name: "Short Line Railroad", owner: "none", improvements: 0, price: 200 },
  144. // Utilities
  145. { name: "Electric Company", owner: "none", improvements: 0, price: 150 },
  146. { name: "Water Works", owner: "none", improvements: 0, price: 150 }
  147. // Add more properties as needed
  148. ];
  149. function printBalances() {
  150. var output = document.getElementById("output");
  151. output.innerHTML = "";
  152. // Create the table element
  153. var table = document.createElement("table");
  154. table.classList.add("centered-table"); // Add CSS class for centering the table
  155. // Create the table header row
  156. var headerRow = document.createElement("tr");
  157. var headers = ["Player", "Money", "Property"];
  158. headers.forEach(function(headerText) {
  159. var headerCell = document.createElement("th");
  160. headerCell.textContent = headerText;
  161. headerRow.appendChild(headerCell);
  162. });
  163. table.appendChild(headerRow);
  164. // Create the table rows for each player
  165. accounts.forEach(function(account) {
  166. var playerName = account[0];
  167. var money = account[1];
  168. var combinedPropertyValue = (playerName !== "Pot") ? calculateCombinedPropertyValue(playerName) : "";
  169. var row = document.createElement("tr");
  170. var playerNameCell = document.createElement("td");
  171. playerNameCell.textContent = playerName;
  172. row.appendChild(playerNameCell);
  173. var moneyCell = document.createElement("td");
  174. moneyCell.textContent = money;
  175. row.appendChild(moneyCell);
  176. var combinedPropertyValueCell = document.createElement("td");
  177. combinedPropertyValueCell.textContent = (playerName !== "Pot") ? combinedPropertyValue : "";
  178. row.appendChild(combinedPropertyValueCell);
  179. table.appendChild(row);
  180. });
  181. output.appendChild(table);
  182. }
  183. function calculateCombinedPropertyValue(playerName) {
  184. var combinedValue = calculatePropertyValue(playerName) + calculateImprovementsValue(playerName);
  185. return combinedValue;
  186. }
  187. function calculatePropertyValue(playerName) {
  188. var propertyValue = 0;
  189. properties.forEach(function(property) {
  190. if (property.owner === playerName) {
  191. propertyValue += property.price;
  192. }
  193. });
  194. return propertyValue;
  195. }
  196. function calculateImprovementsValue(playerName) {
  197. var improvementsValue = 0;
  198. properties.forEach(function(property) {
  199. if (property.owner === playerName) {
  200. improvementsValue += property.improvements;
  201. }
  202. });
  203. return improvementsValue;
  204. }
  205. async function initialize() {
  206. var numPlayersInput = document.getElementById("numPlayers");
  207. var startingValueInput = document.getElementById("startingValue");
  208. numPlayers = parseInt(numPlayersInput.value);
  209. var startingValue = parseInt(startingValueInput.value);
  210. if (numPlayers < 2 || isNaN(numPlayers) || isNaN(startingValue)) {
  211. alert("Invalid input. Please enter a valid number of players and starting value.");
  212. return;
  213. }
  214. accounts = [];
  215. var initialProperties = [...properties]; // Copy the initial properties
  216. accounts.push(["Pot", 0]);
  217. for (var i = 1; i <= numPlayers; i++) {
  218. accounts.push(["Player " + i, startingValue]);
  219. }
  220. properties = [...initialProperties]; // Restore the initial properties
  221. resetPropertyOwners();
  222. generatePropertyList();
  223. printBalances();
  224. generatePlayerOptions();
  225. // Rules
  226. resetRuleDropdown();
  227. }
  228. function resetPropertyOwners() {
  229. // Reset property owners to "none"
  230. for (var i = 0; i < properties.length; i++) {
  231. properties[i].owner = "none";
  232. }
  233. }
  234. function generatePlayerOptions() {
  235. var fromAccSelect = document.getElementById("fromAcc");
  236. var toAccSelect = document.getElementById("toAcc");
  237. // Clear existing options
  238. fromAccSelect.innerHTML = "";
  239. toAccSelect.innerHTML = "";
  240. // Add options for Pot and Bank
  241. var potOption = document.createElement("option");
  242. potOption.value = "pot";
  243. potOption.text = "Pot";
  244. fromAccSelect.add(potOption.cloneNode(true));
  245. toAccSelect.add(potOption.cloneNode(true));
  246. var bankOption = document.createElement("option");
  247. bankOption.value = "bank";
  248. bankOption.text = "Bank";
  249. fromAccSelect.add(bankOption.cloneNode(true));
  250. toAccSelect.add(bankOption.cloneNode(true));
  251. // Add player options
  252. for (var i = 1; i <= numPlayers; i++) {
  253. var playerOption = document.createElement("option");
  254. playerOption.value = i.toString();
  255. playerOption.text = "Player " + i;
  256. fromAccSelect.add(playerOption.cloneNode(true));
  257. toAccSelect.add(playerOption.cloneNode(true));
  258. }
  259. // Add option for "All" to the "To" dropdown
  260. var allOption = document.createElement("option");
  261. allOption.value = "all";
  262. allOption.text = "All";
  263. toAccSelect.add(allOption.cloneNode(true));
  264. }
  265. function generatePropertyList() {
  266. var propertyItems = document.getElementById("propertyItems");
  267. propertyItems.innerHTML = ""; // Clear existing property list
  268. properties.forEach(function(property) {
  269. var listItem = document.createElement("li");
  270. listItem.innerHTML = `
  271. <select class="ownershipDropdown" onchange="updateOwnership(this.value, '${property.name}')">
  272. <option value="none">None</option>
  273. ${generatePlayerOptionsHTML()}
  274. </select>
  275. ${property.name} (${property.price})
  276. <input type="number" class="improvementsInput" onchange="updateImprovements(this.value, '${property.name}')" value="${property.improvements}">
  277. `;
  278. propertyItems.appendChild(listItem);
  279. });
  280. }
  281. function updateOwnership(player, propertyName) {
  282. properties.forEach(function(property) {
  283. if (property.name === propertyName) {
  284. property.owner = player;
  285. return;
  286. }
  287. });
  288. printBalances();
  289. }
  290. function updateImprovements(value, propertyName) {
  291. if (value == "") {
  292. value = 0;
  293. }
  294. var newValue = parseInt(value);
  295. properties.forEach(function(property) {
  296. if (property.name === propertyName) {
  297. property.improvements = newValue;
  298. return;
  299. }
  300. });
  301. printBalances();
  302. }
  303. function generatePlayerOptionsHTML() {
  304. var optionsHTML = "";
  305. for (var i = 1; i <= numPlayers; i++) {
  306. optionsHTML += `<option value="Player ${i}">Player ${i}</option>`;
  307. }
  308. return optionsHTML;
  309. }
  310. function applyLevy() {
  311. var levyAmountInput = document.getElementById("levyAmount");
  312. var levyTypeSelect = document.getElementById("levyType");
  313. var levyDestinationSelect = document.getElementById("levyDestination");
  314. var levyAmount = parseFloat(levyAmountInput.value);
  315. var levyType = levyTypeSelect.value;
  316. var levyDestination = levyDestinationSelect.value;
  317. if (isNaN(levyAmount) || levyAmount <= 0) {
  318. alert("Invalid levy amount. Please enter a valid number greater than zero.");
  319. return;
  320. }
  321. switch (levyType) {
  322. case "money":
  323. levyBasedOnMoney(levyAmount, levyDestination);
  324. break;
  325. case "property":
  326. levyBasedOnPropertyValues(levyAmount, levyDestination);
  327. break;
  328. case "wealth":
  329. levyBasedOnWealth(levyAmount, levyDestination);
  330. break;
  331. default:
  332. alert("Invalid levy type. Please select a valid levy type.");
  333. return;
  334. }
  335. printBalances();
  336. }
  337. function levyBasedOnMoney(levyAmount, levyDestination) {
  338. accounts.forEach(function (account) {
  339. var money = account[1];
  340. var levy = Math.round(money * (levyAmount / 100));
  341. if (levyDestination === "pot") {
  342. account[1] -= levy;
  343. accounts[0][1] += levy; // Add to the pot
  344. } else {
  345. account[1] -= levy; // Remove from account
  346. }
  347. });
  348. }
  349. function levyBasedOnPropertyValues(levyAmount, levyDestination) {
  350. accounts.forEach(function (account) {
  351. var playerPropertyValues = 0;
  352. properties.forEach(function (property) {
  353. if (property.owner === account[0]) {
  354. playerPropertyValues += (property.price + property.improvements);
  355. }
  356. });
  357. var levy = Math.round(playerPropertyValues * (levyAmount / 100));
  358. if (levyDestination === "pot") {
  359. account[1] -= levy;
  360. accounts[0][1] += levy; // Add to the pot
  361. } else {
  362. account[1] -= levy; // Remove from account
  363. }
  364. });
  365. }
  366. function levyBasedOnWealth(levyAmount, levyDestination) {
  367. accounts.forEach(function (account) {
  368. var money = account[1];
  369. var levy = Math.round(money * (levyAmount / 100));
  370. properties.forEach(function (property) {
  371. if (property.owner === account[0]) {
  372. levy += Math.round((property.price + property.improvements) * (levyAmount / 100));
  373. }
  374. });
  375. if (levyDestination === "pot") {
  376. account[1] -= levy;
  377. accounts[0][1] += levy; // Add to the pot
  378. } else {
  379. account[1] -= levy; // Remove from account
  380. }
  381. });
  382. }
  383. // TRANSACTIONS
  384. function sendMoney() {
  385. var fromAcc = document.getElementById("fromAcc").value;
  386. var toAcc = document.getElementById("toAcc").value;
  387. var amount = parseInt(document.getElementById("amount").value);
  388. // DEBIT
  389. if (fromAcc !== "bank") {
  390. if (fromAcc === "pot") {
  391. fromAcc = 0;
  392. } else {
  393. fromAcc = parseInt(fromAcc);
  394. }
  395. accounts[fromAcc][1] -= amount;
  396. }
  397. // CREDIT
  398. if (toAcc !== "bank") {
  399. if (toAcc === "all") {
  400. var remainder = amount;
  401. var i = 1;
  402. while (remainder > 0) {
  403. if (i !== fromAcc) {
  404. remainder -= 1;
  405. accounts[i][1] += 1;
  406. }
  407. i = (i % numPlayers) + 1;
  408. }
  409. } else {
  410. if (toAcc === "pot") {
  411. toAcc = 0;
  412. } else {
  413. toAcc = parseInt(toAcc);
  414. }
  415. accounts[toAcc][1] += amount;
  416. }
  417. }
  418. printBalances();
  419. }
  420. // RULES
  421. // Helper function to add a rule to the chosen rules list
  422. function addRuleToList(ruleText) {
  423. var ruleList = document.getElementById("chosenRulesList");
  424. var ruleItem = document.createElement("li");
  425. ruleItem.classList.add("ruleItem");
  426. var ruleTextElement = document.createElement("span");
  427. ruleTextElement.classList.add("ruleText");
  428. ruleTextElement.textContent = ruleText;
  429. ruleItem.appendChild(ruleTextElement);
  430. var deleteButton = document.createElement("button");
  431. deleteButton.classList.add("deleteButton");
  432. deleteButton.textContent = "Delete";
  433. deleteButton.onclick = function() {
  434. ruleItem.remove(); // Remove the rule item when the delete button is clicked
  435. };
  436. ruleItem.appendChild(deleteButton);
  437. ruleList.appendChild(ruleItem);
  438. }
  439. // Add an event listener to the dropdown
  440. var dropdown = document.getElementById("ruleSelect");
  441. dropdown.addEventListener("change", addRule);
  442. function addRule() {
  443. var selectedOption = dropdown.options[dropdown.selectedIndex];
  444. // Get the text content of the selected option
  445. var ruleText = selectedOption.textContent;
  446. addRuleToList(ruleText);
  447. resetRuleDropdown();
  448. }
  449. // Function to handle adding a custom rule to the chosen rules list
  450. function addCustomRule() {
  451. var customRuleInput = document.getElementById("customRuleInput");
  452. var customRule = customRuleInput.value.trim();
  453. if (customRule !== "") {
  454. addRuleToList(customRule);
  455. customRuleInput.value = ""; // Clear the input field after adding the rule
  456. }
  457. }
  458. function resetRuleDropdown() {
  459. var dropdown = document.getElementById("ruleSelect");
  460. dropdown.selectedIndex = 0; // Reset to the first option ("Choose a rule")
  461. }
  462. // Call the initialize function to set up the game on page load
  463. initialize();
  464. </script>
  465. <div id="footer">
  466. <p>Need help? <a href="https://git.medlab.host/MEDLab/MonopolyLedger/src/main/README.md">See the README</a></p>
  467. <p>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</p>
  468. <p><a href="https://git.medlab.host/MEDLab/MonopolyLedger/">Code</a> is free and open-source on an MIT license</p>
  469. </div>
  470. </body>
  471. </html>