Commit c64cb1f1 authored by soldier.mh.2001's avatar soldier.mh.2001
Browse files

some classes added to server

parent 6297193a
......@@ -9,6 +9,15 @@ import java.util.ArrayList;
public class MainClient {
private static String token;
public static String getToken() {
return token;
}
public static void setToken(String token) {
MainClient.token = token;
}
private static Socket socket;
private static DataInputStream dataInputStream;
......@@ -42,25 +51,14 @@ public class MainClient {
private static void restoreDatabase() throws Exception {
createResourceFileIfNeeded();
CreateNewCard.deserialize();
//think about it later:
AllCardsInitiator.fillAllCards();
AllCardsInitiator.setPrices();
MonsterCard.deserialize();
SpellCard.deserialize();
TrapCard.deserialize();
User.deserialize();
}
private static void createResourceFileIfNeeded() throws IOException {
ArrayList<File> files= new ArrayList<>();
files.add(new File("src/UserOutput.json"));
files.add(new File("src/MonsterCardsOutput.json"));
files.add(new File("src/SpellCardsOutput.json"));
files.add(new File("src/TrapCardsOutput.json"));
files.add(new File("src/DecksOutput.json"));
files.add(new File("src/NewMonsterOutput.json"));
files.add(new File("src/NewTrapOutput.json"));
files.add(new File("src/NewSpellOutput.json"));
File cardsFolder = new File("src/ExportedCards");
cardsFolder.mkdir();
for (File file : files)
......
......@@ -16,6 +16,7 @@ import java.util.Random;
public class User {
@Expose
private String username;
@Expose
......
import java.io.DataInputStream;
import java.io.DataOutputStream;
import model.MonsterCard;
import model.SpellCard;
import model.TrapCard;
import model.User;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -11,9 +16,46 @@ public class MainServer {
public static void main(String[] args){
MainServer server = new MainServer();
try {
restoreDatabase();
} catch (Exception e) {
e.printStackTrace();
}
server.initializeNetwork();
}
private static void restoreDatabase() throws Exception {
createResourceFileIfNeeded();
// CreateNewCard.deserialize();
// AllCardsInitiator.fillAllCards();
// AllCardsInitiator.setPrices();
MonsterCard.deserialize();
SpellCard.deserialize();
TrapCard.deserialize();
User.deserialize();
}
private static void createResourceFileIfNeeded() throws IOException {
ArrayList<File> files= new ArrayList<>();
files.add(new File("src/UserOutput.json"));
files.add(new File("src/MonsterCardsOutput.json"));
files.add(new File("src/SpellCardsOutput.json"));
files.add(new File("src/TrapCardsOutput.json"));
files.add(new File("src/DecksOutput.json"));
// files.add(new File("src/NewMonsterOutput.json"));
// files.add(new File("src/NewTrapOutput.json"));
// files.add(new File("src/NewSpellOutput.json"));
for (File file : files)
if(!file.exists()){
file.createNewFile();
FileWriter writer = new FileWriter(file);
writer.write("[]");
writer.close();
}
}
public void initializeNetwork() {
try {
serverSocket = new ServerSocket(7877);
......
package model;
import java.util.ArrayList;
import java.util.Collections;
public class Scoreboard {
ArrayList<User> users;
public Scoreboard(ArrayList<User> users) {
this.users = users;
}
public String toString() {
StringBuilder scoreboardToStringBuilder = new StringBuilder();
sortUsers();
int upperTeamRanking = 1;
int upperTeamScore = -1;
for(int i=1; i <= users.size(); i++){
if(users.get(i-1).getScore() == upperTeamScore){
scoreboardToStringBuilder.append(upperTeamRanking);
} else {
upperTeamRanking = i;
upperTeamScore = users.get(i-1).getScore();
scoreboardToStringBuilder.append(i);
}
scoreboardToStringBuilder.append("- ");
scoreboardToStringBuilder.append(users.get(i-1).getNickname());
scoreboardToStringBuilder.append(": ");
scoreboardToStringBuilder.append(users.get(i-1).getScore());
scoreboardToStringBuilder.append("\n");
}
return scoreboardToStringBuilder.toString();
}
private void sortUsers() {
for (int i = 0; i < users.size(); i++) {
for (int j = 0; j < users.size() - 1; j++) {
if (users.get(j).getScore() < users.get(j + 1).getScore()) {
Collections.swap(users, j, j + 1);
} else if (users.get(j).getScore() == users.get(j + 1).getScore() &&
Utilities.compareAlphabetical(users.get(j).getNickname(), users.get(j + 1).getNickname()) > 0) {
Collections.swap(users, j, j + 1);
}
}
}
}
}
package model.enums;
import org.model.MonstersDescriptions;
public enum MonsterPower {
NONE,
......@@ -21,31 +20,7 @@ public enum MonsterPower {
EXPLODER_DRAGON,
TERRATIGER_THE_EMPOWERED_WARRIOR,
THE_TRICKY,
RITUAL;
public String description;
static {
COMMAND_KNIGHT.description = MonstersDescriptions.commandKnight;
YOMI_SHIP.description = MonstersDescriptions.yomiShip;
SUIJIN.description = MonstersDescriptions.suijin;
MAN_EATER_BUG.description = MonstersDescriptions.manEaterBug;
GATE_GUARDIAN.description = MonstersDescriptions.gateGuardian;
SCANNER.description = MonstersDescriptions.scanner;
CRAB_TURTLE.description = MonstersDescriptions.crabTurtle;
SKULL_GUARDIAN.description = MonstersDescriptions.skullGuardian;
MARSHMALLON.description = MonstersDescriptions.marshmallon;
BEAST_KING_BARBAROS.description = MonstersDescriptions.beastKing;
TEXCHANGER.description = MonstersDescriptions.texChanger;
THE_CALCULATOR.description = MonstersDescriptions.theCalculator;
MIRAGE_DRAGON.description = MonstersDescriptions.mirageDragon;
HERALD_OF_CREATION.description = MonstersDescriptions.heraldOfTheCreation;
EXPLODER_DRAGON.description = MonstersDescriptions.exploderDragon;
TERRATIGER_THE_EMPOWERED_WARRIOR.description = MonstersDescriptions.terraTigerTheEmpoweredWarrior;
THE_TRICKY.description = MonstersDescriptions.theTricky;
}
RITUAL,
}
package model.enums;
import org.model.SpellsDescription;
public enum SpellEffect {
MONSTER_REBORN,
TERRAFORMING,
......@@ -25,32 +23,5 @@ public enum SpellEffect {
BLACK_PENDANT,
UNITED_WE_STAND,
MAGNUM_SHIELD,
ADVANCED_RITUAL_ART;
public String description;
static {
MONSTER_REBORN.description = SpellsDescription.monsterReborn;
TERRAFORMING.description = SpellsDescription.terrafoming;
POT_OF_GREED.description = SpellsDescription.potOfGreed;
RAIGEKI.description = SpellsDescription.raigeki;
CHANGEOFHEART.description = SpellsDescription.changeOfHearts;
SWORDS_OF_REVEALING_LIGHT.description = SpellsDescription.swordOfRevealingLight;
HARPIES_FEATHER_DUSTER.description = SpellsDescription.harpies;
DARK_HOLE.description = SpellsDescription.darkHole;
SUPPLY_SQUAD.description = SpellsDescription.supplySquad;
SPELL_ABSORPTION.description = SpellsDescription.spellAbsorption;
MESSENGER_OF_PEACE.description = SpellsDescription.messengerOfPeace;
TWIN_TWISTERS.description = SpellsDescription.twinTwister;
MYSTICAL_SPACE_TYPHOON.description = SpellsDescription.mysticalSpaceTyphoon;
RING_OF_DEFENCE.description = SpellsDescription.ringOfDefence;
YAMI.description = SpellsDescription.yami;
FOREST.description = SpellsDescription.forest;
CLOSED_FOREST.description = SpellsDescription.closedForest;
UMIIRUKA.description = SpellsDescription.umiiruka;
SWORD_OF_DARK_DESTRUCTION.description = SpellsDescription.swordOfDestruction;
BLACK_PENDANT.description = SpellsDescription.blackPendant;
UNITED_WE_STAND.description = SpellsDescription.unitedWeStand;
MAGNUM_SHIELD.description = SpellsDescription.magnumShield;
ADVANCED_RITUAL_ART.description = SpellsDescription.advancedRitualArt;
}
ADVANCED_RITUAL_ART,
}
package model.enums;
import org.model.TrapsDescription;
public enum TrapEffect {
TRAP_HOLE,
MIRROR_FORCE,
......@@ -13,18 +11,5 @@ public enum TrapEffect {
SOLEMN_WARNING,
MAGIC_JAMMER,
CALL_OF_THE_HAUNTED;
public String description;
static {
TRAP_HOLE.description = TrapsDescription.trapHole;
MIRROR_FORCE.description = TrapsDescription.mirrorForce;
MAGIC_CYLINDER.description = TrapsDescription.magicCylinder;
MIND_CRUSH.description = TrapsDescription.mindCrush;
TORRENTIAL_TRIBUTE.description = TrapsDescription.torrentialTribute;
TIME_SEAL.description = TrapsDescription.timeSeal;
NEGATE_ATTACK.description = TrapsDescription.negateAttack;
SOLEMN_WARNING.description = TrapsDescription.solemnWarning;
MAGIC_JAMMER.description = TrapsDescription.magicJammer;
CALL_OF_THE_HAUNTED.description = TrapsDescription.callOfTheHaunted;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment