CSC250_Spring2021_HeartOfStoneDeckTracker

  • q6_416883
    了解作者
  • 4.3KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-27 01:16
    上传日期
CSC250_Spring2021_HeartOfStoneDeckTracker
CSC250_Spring2021_HeartOfStoneDeckTracker-main.zip
  • CSC250_Spring2021_HeartOfStoneDeckTracker-main
  • .gitignore
    6B
  • src
  • CardParser.java
    2.7KB
  • URLReader.java
    779B
  • Driver.java
    253B
  • HeartstoneCard.java
    671B
  • .classpath
    402B
  • .project
    380B
  • .gitattributes
    66B
内容介绍
import java.util.ArrayList; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; public class CardParser { private String urlString; private ArrayList<HeartstoneCard> theMinions; private JSONArray obj; public CardParser(String urlString) { this.urlString = urlString; theMinions = new ArrayList< HeartstoneCard >(); URLReader hearthstoneURLReader = new URLReader(this.urlString); Object obj = JSONValue.parse(hearthstoneURLReader.getTheURLContents()); if(obj instanceof JSONArray) { JSONArray array = (JSONArray)obj; for(int i = 0; i < array.size(); i++) { JSONObject cardData = (JSONObject)array.get(i); if(cardData.containsKey("cost") && cardData.containsKey("name")) { if(cardData.containsKey("type") && cardData.get("type").equals("MINION")) { System.out.println(cardData.keySet().toString()); String name = (String)cardData.get("name"); int cost = Integer.parseInt(cardData.get("cost").toString()); int attack = Integer.parseInt(cardData.get("attack").toString()); int health = Integer.parseInt(cardData.get("health").toString()); HeartstoneCard temp = new HeartstoneCard(name, cost, attack, health); theMinions.add(temp); } } } } } public void showMinions() { for(int i = 0; i < this.theMinions.size(); i++) { this.theMinions.get(i).display(); } } public void insertionSortLowestCostToHighestCost() { for(int currStart = 1; currStart < this.theMinions.size(); currStart++) { HeartstoneCard currValue = this.theMinions.get(currStart); int currIndex = currStart; HeartstoneCard temp; while(currIndex > 0 && this.theMinions.get(currIndex).getCost() < this.theMinions.get(currIndex-1).getCost()) { temp = this.theMinions.get(currIndex); this.theMinions.set(currIndex, this.theMinions.get(currIndex-1)); this.theMinions.set(currIndex-1, temp); currIndex --; } } } public void sortLowestCostToHighestCost() { ArrayList<HeartstoneCard> theSortedList = new ArrayList<HeartstoneCard>(); HeartstoneCard nextSmallest; while(this.theMinions.size() > 0) { nextSmallest = this.findSmallest(); theSortedList.add(nextSmallest); } this.theMinions = theSortedList; } private HeartstoneCard findSmallest() { HeartstoneCard currWinner = this.theMinions.get(0); int indexOfWinner = 0; for(int i = 1; i < this.theMinions.size(); i++) { if(this.theMinions.get(i).getCost() > currWinner.getCost()) { currWinner = this.theMinions.get(i); indexOfWinner = i; } } this.theMinions.remove(indexOfWinner); return currWinner; } }
评论
    相关推荐
    • spring
      spring-framework-2.5.2.zip
    • spring
      春天 1,HelloSpring IOC创建对象spring1模块 2,依赖注入spring2模块 3,自动装配spring3模块 4,注释spring4模块 5,JavaConfig spring5模块
    • spring 集成
      spring 集成spring 集成spring 集成spring 集成spring 集成spring 集成spring 集成spring 集成spring 集成
    • springspring
      spring开发包 spring开发包 spring开发包 spring开发包
    • spring API
      spring API,Spring2.5-中文参考手册.chm,Spring3.0.2-RELEASE-API.chm,spring中文API.chm
    • spring 4.3.9
      spring 4-x: spring-framework-4.3.9.RELEASE-dist spring-framework-4.3.9.RELEASE-docs spring-framework-4.3.9.RELEASE-schema spring-framework-4.3.10.RELEASE-dist
    • spring 5.0.8
      spring 5-x: spring-framework-5.0.8.RELEASE-dist spring-framework-5.0.8.RELEASE-docs spring-framework-5.0.8.RELEASE-schema
    • spring2.5.6
      spring-bean-2.5.6.jar spring-context-2.5.6.jar spring-core-2.5.6.jar spring-web-2.5.6.jar
    • spring资源
      开发时可能需要用到spring资源,spring-context-3.1.1.RELEASE,spring-context-support-3.1.1.RELEASE,spring-core-3.1.1.RELEASE
    • Spring IoC
      实现Spring IoC功能的基本包,版本为3.2.8: commons-logging.jar spring-beans-3.2.8.RELEASE.jar spring-context-3.2.8.RELEASE.jar spring-core-3.2.8.RELEASE.jar spring-expression-3.2.8.RELEASE.jar