Back to project page diploma-assignment.
The source code is released under:
MIT License
If you think the Android project diploma-assignment listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.me.main; /* ww w . j ava 2 s . com*/ import com.me.openingscreen.Constants; import com.badlogic.gdx.utils.Json; import com.badlogic.gdx.utils.JsonValue; public class Player implements Json.Serializable{ private long gold; private int maxMana; private int manaReg; private String name; private int[] upList; private int[] unlockedList; private int[] killed; private int level; private long allGold; public Player(){ } public Player(String n){ name=n; gold=2000; maxMana=400; manaReg=2; upList=new int[]{0,0,0,0,0,0,0}; killed=new int[]{0,0,0,0,0,0,0}; unlockedList=new int[]{1,0,0,0,0,0,0}; level=1; allGold=gold; } public boolean unlock(int index){ if (index<0 || index>=unlockedList.length) return false; if(gold<Constants.unlockedPrice[index] || unlockedList[index]==1) return false; gold-=Constants.unlockedPrice[index]; unlockedList[index]=1; return true; } public boolean upgrade(int index){ if (index<0 || index>=upList.length) return false; if(gold<Constants.upPrice[index] || upList[index]==1) return false; gold-=Constants.upPrice[index]; upList[index]=1; return true; } public void kill(int index){ if (index>=0 || index<killed.length) killed[index]++; } public void increaseLevel() { level++; if(level%3==0){ maxMana=maxMana+150; manaReg=manaReg+1; } } public void setName(String name) { this.name = name; } public final long getGold() { return gold; } public final long getAllGold() { return allGold; } public final int[] getUnlockedList() { return unlockedList; } public final int[] getUpList() { return upList; } public final int[] getKilled() { return killed; } public void increaseGold(long gold) { this.gold += gold; allGold+=gold; } public final int getMaxMana() { return maxMana; } public void setMaxMana(int maxMana) { this.maxMana = maxMana; } public final int getManaReg() { return manaReg; } public void setManaReg(int manaReg) { this.manaReg = manaReg; } public final int getLevel() { return level; } public final String getName() { return name; } @Override public void write(Json json) { // TODO Auto-generated method stub json.writeValue("gold",gold); json.writeValue("maxMana",maxMana); json.writeValue("manaReg",manaReg); json.writeValue("name",name); json.writeValue("level",level); json.writeValue("upList",upList); json.writeValue("unlockedList",unlockedList); json.writeValue("killed",killed); json.writeValue("allGold",allGold); } @Override public void read(Json json, JsonValue jsonData) { // TODO Auto-generated method stub gold=json.readValue("gold",long.class,jsonData); maxMana=json.readValue("maxMana",int.class,jsonData); manaReg=json.readValue("manaReg",int.class,jsonData); name=json.readValue("name",String.class,jsonData); level=json.readValue("level",int.class,jsonData); upList=json.readValue("upList",int[].class,jsonData); unlockedList=json.readValue("unlockedList",int[].class,jsonData); killed=json.readValue("killed",int[].class,jsonData); allGold=json.readValue("allGold",long.class,jsonData); } }