Mortgage.jsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React from 'react';
  2. import {gameService} from "./services/GameService";
  3. const Mortgage = (props) => {
  4. const mortgageValue = Math.floor(Number(props.property.price .substring(1))/ 2);
  5. const tenPercent = Math.ceil(mortgageValue * 0.1);
  6. const mortgageBuyout = mortgageValue + tenPercent;
  7. const canMortgage = gameService.canMortgage(props.property, props.game);
  8. const isOwner = props.property.owner === gameService.currentPlayer;
  9. console.log('is owner ?', isOwner);
  10. const toggleMortgage = () => {
  11. console.log('new mortgage = ', !props.property.mortgaged);
  12. gameService.toggleMortgageProperty(props.property, props.type)
  13. }
  14. return (<div>
  15. <hr/>
  16. <div>
  17. Mortgage <small><a href="https://monopoly.fandom.com/wiki/Mortgage" target="_blank">(rules)</a></small>:
  18. </div>
  19. <div>
  20. Mortgage value: ${mortgageValue}
  21. </div>
  22. <div>
  23. To unmortgage pay: ${mortgageBuyout}
  24. </div>
  25. <div>
  26. To transfer mortgage: ${tenPercent}
  27. </div>
  28. {canMortgage && <div>
  29. <label>
  30. <input type="checkbox" checked={props.property.mortgaged} onChange={toggleMortgage}/>
  31. Mortgage property
  32. </label>
  33. </div>}
  34. {!canMortgage && isOwner && <div>
  35. <small><em>You can only mortgage if there are no remaining houses or hotel on any properties of this
  36. color</em></small>
  37. </div>}
  38. </div>)
  39. }
  40. export default Mortgage;