MonopolyLedger.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Monopoly Ledger</title>
  5. </head>
  6. <body>
  7. <h1>Monopoly Ledger</h1>
  8. <div id="setup">
  9. <h2>Setup</h2>
  10. <label for="numPlayers">Number of Players:</label>
  11. <input type="number" id="numPlayers">
  12. <br>
  13. <label for="startingValue">Starting Value:</label>
  14. <input type="number" id="startingValue">
  15. <br>
  16. <button onclick="initialize()">Set</button>
  17. </div>
  18. <div id="balances">
  19. <h2>Balances</h2>
  20. <div id="output"></div>
  21. </div>
  22. <div id="transactions">
  23. <h2>Transactions</h2>
  24. <form id="transactions" onsubmit="event.preventDefault();">
  25. <label for="fromAcc">From:</label>
  26. <select id="fromAcc">
  27. <option value="pot">Pot</option>
  28. <option value="bank">Bank</option>
  29. <!-- Generate player options dynamically -->
  30. </select>
  31. <br>
  32. <label for="toAcc">To:</label>
  33. <select id="toAcc">
  34. <option value="pot">Pot</option>
  35. <option value="bank">Bank</option>
  36. <!-- Generate player options dynamically -->
  37. <option value="all">All</option>
  38. </select>
  39. <br>
  40. <label for="amount">Amount:</label>
  41. <input type="number" id="amount">
  42. <br>
  43. <button onclick="sendMoney()">Send</button>
  44. </form>
  45. </div>
  46. <!-- Add property list -->
  47. <div id="propertyList">
  48. <h2>Properties</h2>
  49. <ul id="propertyItems"></ul>
  50. </div>
  51. <script>
  52. var numPlayers = 0;
  53. var accounts = [];
  54. // Property list data
  55. var properties = [
  56. // Brown Properties
  57. { name: "Mediterranean Avenue", owner: "none", improvements: false, price: 60 },
  58. { name: "Baltic Avenue", owner: "none", improvements: false, price: 60 },
  59. // Light Blue Properties
  60. { name: "Oriental Avenue", owner: "none", improvements: false, price: 100 },
  61. { name: "Vermont Avenue", owner: "none", improvements: false, price: 100 },
  62. { name: "Connecticut Avenue", owner: "none", improvements: false, price: 120 },
  63. // Pink Properties
  64. { name: "St. Charles Place", owner: "none", improvements: false, price: 140 },
  65. { name: "States Avenue", owner: "none", improvements: false, price: 140 },
  66. { name: "Virginia Avenue", owner: "none", improvements: false, price: 160 },
  67. // Orange Properties
  68. { name: "St. James Place", owner: "none", improvements: false, price: 180 },
  69. { name: "Tennessee Avenue", owner: "none", improvements: false, price: 180 },
  70. { name: "New York Avenue", owner: "none", improvements: false, price: 200 },
  71. // Red Properties
  72. { name: "Kentucky Avenue", owner: "none", improvements: false, price: 220 },
  73. { name: "Indiana Avenue", owner: "none", improvements: false, price: 220 },
  74. { name: "Illinois Avenue", owner: "none", improvements: false, price: 240 },
  75. // Yellow Properties
  76. { name: "Atlantic Avenue", owner: "none", improvements: false, price: 260 },
  77. { name: "Ventnor Avenue", owner: "none", improvements: false, price: 260 },
  78. { name: "Marvin Gardens", owner: "none", improvements: false, price: 280 },
  79. // Green Properties
  80. { name: "Pacific Avenue", owner: "none", improvements: false, price: 300 },
  81. { name: "North Carolina Avenue", owner: "none", improvements: false, price: 300 },
  82. { name: "Pennsylvania Avenue", owner: "none", improvements: false, price: 320 },
  83. // Dark Blue Properties
  84. { name: "Park Place", owner: "none", improvements: false, price: 350 },
  85. { name: "Boardwalk", owner: "none", improvements: false, price: 400 },
  86. // Railroads
  87. { name: "Reading Railroad", owner: "none", improvements: false, price: 200 },
  88. { name: "Pennsylvania Railroad", owner: "none", improvements: false, price: 200 },
  89. { name: "B. & O. Railroad", owner: "none", improvements: false, price: 200 },
  90. { name: "Short Line Railroad", owner: "none", improvements: false, price: 200 },
  91. // Utilities
  92. { name: "Electric Company", owner: "none", improvements: false, price: 150 },
  93. { name: "Water Works", owner: "none", improvements: false, price: 150 }
  94. // Add more properties as needed
  95. ];
  96. function printBalances() {
  97. var output = document.getElementById("output");
  98. output.innerHTML = "";
  99. accounts.forEach(function(account) {
  100. output.innerHTML += account[0] + ": " + account[1] + "<br>";
  101. });
  102. }
  103. function initialize() {
  104. var numPlayersInput = document.getElementById("numPlayers");
  105. var startingValueInput = document.getElementById("startingValue");
  106. numPlayers = parseInt(numPlayersInput.value);
  107. var startingValue = parseInt(startingValueInput.value);
  108. if (numPlayers < 2 || isNaN(numPlayers) || isNaN(startingValue)) {
  109. alert("Invalid input. Please enter a valid number of players and starting value.");
  110. return;
  111. }
  112. accounts = [];
  113. var initialProperties = [...properties]; // Copy the initial properties
  114. accounts.push(["Pot", 0]);
  115. for (var i = 1; i <= numPlayers; i++) {
  116. accounts.push(["Player " + i, startingValue]);
  117. }
  118. properties = [...initialProperties]; // Restore the initial properties
  119. resetPropertyOwners();
  120. generatePropertyList();
  121. printBalances();
  122. generatePlayerOptions();
  123. numPlayersInput.value = "";
  124. startingValueInput.value = "";
  125. }
  126. function resetPropertyOwners() {
  127. // Reset property owners to "none"
  128. for (var i = 0; i < properties.length; i++) {
  129. properties[i].owner = "none";
  130. }
  131. }
  132. function generatePlayerOptions() {
  133. var fromAccSelect = document.getElementById("fromAcc");
  134. var toAccSelect = document.getElementById("toAcc");
  135. // Clear existing options
  136. fromAccSelect.innerHTML = "";
  137. toAccSelect.innerHTML = "";
  138. // Add options for Pot and Bank
  139. var potOption = document.createElement("option");
  140. potOption.value = "pot";
  141. potOption.text = "Pot";
  142. fromAccSelect.add(potOption.cloneNode(true));
  143. toAccSelect.add(potOption.cloneNode(true));
  144. var bankOption = document.createElement("option");
  145. bankOption.value = "bank";
  146. bankOption.text = "Bank";
  147. fromAccSelect.add(bankOption.cloneNode(true));
  148. toAccSelect.add(bankOption.cloneNode(true));
  149. // Add player options
  150. for (var i = 1; i <= numPlayers; i++) {
  151. var playerOption = document.createElement("option");
  152. playerOption.value = i.toString();
  153. playerOption.text = "Player " + i;
  154. fromAccSelect.add(playerOption.cloneNode(true));
  155. toAccSelect.add(playerOption.cloneNode(true));
  156. }
  157. // Add option for "All" to the "To" dropdown
  158. var allOption = document.createElement("option");
  159. allOption.value = "all";
  160. allOption.text = "All";
  161. toAccSelect.add(allOption.cloneNode(true));
  162. }
  163. function generatePropertyList() {
  164. var propertyItems = document.getElementById("propertyItems");
  165. propertyItems.innerHTML = ""; // Clear existing property list
  166. properties.forEach(function(property) {
  167. var listItem = document.createElement("li");
  168. listItem.innerHTML = `
  169. ${property.name}
  170. <select class="ownershipDropdown" onchange="updateOwnership(this.value, '${property.name}')">
  171. <option value="none">None</option>
  172. ${generatePlayerOptionsHTML()}
  173. </select>
  174. `;
  175. propertyItems.appendChild(listItem);
  176. });
  177. }
  178. function generatePlayerOptionsHTML() {
  179. var optionsHTML = "";
  180. for (var i = 1; i <= numPlayers; i++) {
  181. optionsHTML += `<option value="Player ${i}">Player ${i}</option>`;
  182. }
  183. return optionsHTML;
  184. }
  185. function updateOwnership(player, propertyName) {
  186. properties.forEach(function(property) {
  187. if (property.name === propertyName) {
  188. property.owner = player;
  189. return;
  190. }
  191. });
  192. }
  193. function sendMoney() {
  194. var fromAcc = document.getElementById("fromAcc").value;
  195. var toAcc = document.getElementById("toAcc").value;
  196. var amount = parseInt(document.getElementById("amount").value);
  197. // DEBIT
  198. if (fromAcc !== "bank") {
  199. if (fromAcc === "pot") {
  200. fromAcc = 0;
  201. } else {
  202. fromAcc = parseInt(fromAcc);
  203. }
  204. accounts[fromAcc][1] -= amount;
  205. }
  206. // CREDIT
  207. if (toAcc !== "bank") {
  208. if (toAcc === "all") {
  209. var remainder = amount;
  210. var i = 1;
  211. while (remainder > 0) {
  212. if (i !== fromAcc) {
  213. remainder -= 1;
  214. accounts[i][1] += 1;
  215. }
  216. i = (i % numPlayers) + 1;
  217. }
  218. } else {
  219. if (toAcc === "pot") {
  220. toAcc = 0;
  221. } else {
  222. toAcc = parseInt(toAcc);
  223. }
  224. accounts[toAcc][1] += amount;
  225. }
  226. }
  227. printBalances();
  228. }
  229. </script>
  230. </body>
  231. </html>