我该如何将 JavaScript 变成 Java?

How would I go about turning JavaScript into Java?

我想在 Android studio 中使用以下代码,而不是通过网络浏览器。但是,我无法将 javascript 转换为 java。特别是定义下面几个其他变量的第一个变量。我将不胜感激。这是放置游戏的开始。

main.js

 var gameData = {
        Points: 0,
        PointsPerClick: 1,
        PointsPerClickCost: 10
      }
    
      const perClickUpgrade = document.getElementById("perClickUpgrade"); 
    
      perClickUpgrade.addEventListener("click", function handleClick() { 
      
      perClickUpgrade.textContent = "Upgrade Evolution Level (Currently Level " + gameData.PointsPerClick + ") Cost: " + gameData.PointsPerClickCost + " Points";
      
      }); 
    
      function Upgrade() {
        gameData.Points += gameData.PointsPerClick
        document.getElementById("EvolPoints").innerHTML = gameData.Points + " Evolution Points"
    
      }
    
      function BuyPointsPerClick() {
        if (gameData.Points >= gameData.PointsPerClickCost) {
          gameData.Points-= gameData.PointsPerClickCost
          gameData.PointsPerClick += 1
          gameData.PointsPerClickCost *= 2
          document.getElementById("EvolPoints").innerHTML = gameData.Points + " Evolution Points"
        document.getElementById("perClickUpgrade").innerHTML = "Upgrade Evol Level (Currently Level " + gameData.PointsPerClick + ") Cost: " + gameData.PointsPerClickCost + " Points"
        }
    
    
        var mainGameLoop = window.setInterval(function() {
          Upgrade()
        }, 1000)
      
    function LevelTen() {
    if (gameData.Points >= 10 ) {
      alert("This is an alert message box.");  // display string message
    }
    
    }
    
      }
      function LevelTen() {
        if (gameData.PointsPerClick > 9 && gameData.PointsPerClick < 11) {
          alert("Your Creature Has Evolved to Level Ten!");  // display string message      
        }
        }

index.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Evolution Idle Game</title>
    <link rel="stylesheet" href="idlescreen.css">
    
  </head>
  <body>
    <body style="background-color:rgb(0, 0, 0);" ></body>
    <p id="EvolPoints" class="evol-points">0 Evolution Points</p>
    <button onclick="Upgrade(), LevelTen()" style="background-color:#f14e4e" class="btn2">Click to Upgrade</button>
    <button onclick="BuyPointsPerClick(), LevelTen()" style="background-color:#f1bb4e" id="perClickUpgrade" class="btn2">Click to Start Automation</button>
    <script src="main.js" charset="utf-8" type="text/javascript"></script>
    <img src="./Pictures/bat.png" >
  </body>
</html>

idlescreen.css

.evol-points {
  color: #ffffff
}

  .btn2 {padding: 15px 25px;
    font-size: 24px;
    text-align: center;
    text-decoration: none;
    outline: none;
    color: #fff;
    cursor: pointer;
    background-color: #4CAF50;
    border: none;
    border-radius: 15px;
    box-shadow: 0 9px #999;
  }
  
  .btn2:hover {background-color: #3e8e41}
  
  .btn2:active {
    background-color: #3e8e41;
    box-shadow: 0 5px #666;
    transform: translateY(4px);
  }

Particularly the first variable that defines several other variables below. I would appreciate assistance.

一个解决方案是创建一个名为 GameData 的 class,其中包含可公开访问的静态变量:

class GameData {
    public static int points = 0;
    public static int pointsPerClick = 1;
    public static int PointsPerClickCost = 10;
}    

现在您可以使用点符号访问这些变量:GameData.points

但是,我应该指出这不是惯用的 Java。惯用的解决方案是创建一个名为 GameData 的 class,然后使用 new 关键字实例化该 class 的对象。