Skip to content

Commit

Permalink
final edit for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Negarbsh committed Jul 21, 2021
1 parent 8faa92f commit c898029
Show file tree
Hide file tree
Showing 222 changed files with 851 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions server/BackToMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server;

public class BackToMenu extends Exception {
public BackToMenu() {
super();
}
}
34 changes: 34 additions & 0 deletions server/ClientThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package server;

import server.menus.Menu;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class ClientThread extends Thread {
Socket socket;
DataInputStream dataInputStream;
DataOutputStream dataOutputStream;

public ClientThread(Socket socket) {
try {
this.socket = socket;
dataInputStream = new DataInputStream(socket.getInputStream());
dataOutputStream = new DataOutputStream(socket.getOutputStream());
} catch (IOException ignored) {

}
}

@Override
public void run() {
Menu menu = new Menu();
try {
menu.run(dataInputStream, dataOutputStream);
} catch (IOException e) {
System.out.println("Caught an error!");
}
}
}
21 changes: 21 additions & 0 deletions server/ServerClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package server;

import server.ClientThread;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerClass {
public static void main(String[] args) {
try {
ServerSocket server = new ServerSocket(7776);
while (true) {
Socket socket = server.accept();
new ClientThread(socket).start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
69 changes: 69 additions & 0 deletions server/controller/FileHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package server.controller;
//TODO THERE ARE MANY THINGS TO HANDLE!
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import server.model.User;

import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;

public class FileHandler {
public static void loadThings() {
// CardLoader.loadCsv();
loadUsers();
// loadAssets();
}

// private static void loadAssets() {
// PreCard.setPictures();
// Wallpaper.setAllWallpapers();
// DeckImageButton.setDeckImages();
//
//// setCurtainPictures("gifs/out");
//// Reader.figureCatalog(new String[]{"Items/Coins/Bronze/with-star"});
// }

// private static void setCurtainPictures(String folderPath) {
// Reader.figureCatalog(new String[]{folderPath});
// }

private static void loadUsers() {
try {

Gson gsonExt = null;
{
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(PreCard.class, new PreCardAdapter());
gsonExt = builder.create();
}
String json = new String(Files.readAllBytes(Paths.get("users.json")));
Type type = new TypeToken<ArrayList<User>>() {
}.getType();
User.setAllUsers(gsonExt.fromJson(json, type));
} catch (IOException e) {
e.printStackTrace();
}
}

public static void saveUsers() {
try {
Gson gsonExt = null;
{
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(PreCard.class, new PreCardAdapter());
gsonExt = builder.create();
}
FileWriter fileWriter = new FileWriter("users.json");
fileWriter.write(gsonExt.toJson(User.getAllUsers()));
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}
7 changes: 7 additions & 0 deletions server/exceptions/ActivateEffectNotSpell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class ActivateEffectNotSpell extends Exception {
public ActivateEffectNotSpell() {
super("Activate effect is only for spell cards.");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/AlreadyActivatedEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class AlreadyActivatedEffect extends Exception {
public AlreadyActivatedEffect() {
super("You have already activated this card");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/AlreadyDoneAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class AlreadyDoneAction extends Exception {
public AlreadyDoneAction(String action) {
super("You have already " + action + " on this turn");
}
}
8 changes: 8 additions & 0 deletions server/exceptions/AlreadyExistingError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package server.exceptions;

public class AlreadyExistingError extends MyException{

public AlreadyExistingError(String type, String subType, String name) {
super(String.format("%s with %s %s already exists", type, subType, name));
}
}
7 changes: 7 additions & 0 deletions server/exceptions/AlreadyInWantedPosition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class AlreadyInWantedPosition extends Exception {
public AlreadyInWantedPosition() {
super("this card is already in the wanted position");
}
}
8 changes: 8 additions & 0 deletions server/exceptions/BeingFull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package server.exceptions;


public class BeingFull extends Exception{
public BeingFull(String name) {
super(String.format("%s is full", name));
}
}
7 changes: 7 additions & 0 deletions server/exceptions/ButtonCantDoAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class ButtonCantDoAction extends Exception {
public ButtonCantDoAction() {
super("this button is not designed for this action");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/CantAttackDirectlyException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class CantAttackDirectlyException extends Exception {
public CantAttackDirectlyException() {
super("you can’t attack the opponent directly");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/CantDoActionWithCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class CantDoActionWithCard extends Exception {
public CantDoActionWithCard(String action) {
super("You can’t " + action + " this card");
}
}
8 changes: 8 additions & 0 deletions server/exceptions/CardAttackedBeforeExeption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package server.exceptions;

public class CardAttackedBeforeExeption extends Exception {
public CardAttackedBeforeExeption() {
super("This card already attacked");
}
}

7 changes: 7 additions & 0 deletions server/exceptions/CardCantAttack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class CardCantAttack extends Exception {
public CardCantAttack() {
super("you can’t attack with this card");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/CardCreatorException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class CardCreatorException extends Exception {
public CardCreatorException(String s) {
super(s);
}
}
7 changes: 7 additions & 0 deletions server/exceptions/EmptyFieldException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class EmptyFieldException extends Exception {
public EmptyFieldException() {
super("you have at least one empty field");
}
}
8 changes: 8 additions & 0 deletions server/exceptions/EqualPasswordException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package server.exceptions;

public class EqualPasswordException extends Exception{

public EqualPasswordException() {
super("please enter a new password");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/InvalidCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class InvalidCommand extends Exception {
public InvalidCommand() {
super("invalid command");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/InvalidDeck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class InvalidDeck extends Exception {
public InvalidDeck(String username) {
super(username + "’s deck is invalid");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/InvalidName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class InvalidName extends Exception {
public InvalidName(String group, String name) {
super("There is no " + group + " with this " + name);
}
}
7 changes: 7 additions & 0 deletions server/exceptions/InvalidRitualPreparations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class InvalidRitualPreparations extends Exception {
public InvalidRitualPreparations() {
super("there is no way you could ritual summon a monster");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/InvalidSelection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class InvalidSelection extends Exception {
public InvalidSelection() {
super("invalid selection");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/InvalidThing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class InvalidThing extends Exception {
public InvalidThing(String thing) {
super(thing + " is invalid!");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/InvalidTributeAddress.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class InvalidTributeAddress extends Exception {
public InvalidTributeAddress() {
super("there no monsters on this address");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/LoginError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class LoginError extends Exception {
public LoginError() {
super("Username and password didn't match!");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/MenuNavigationError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class MenuNavigationError extends Exception {
public MenuNavigationError() {
super("menu navigation is not possible");
}
}
11 changes: 11 additions & 0 deletions server/exceptions/MyException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package server.exceptions;

public class MyException extends Exception {
public MyException() {
super();
}

public MyException(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions server/exceptions/NeedToLogin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class NeedToLogin extends Exception {
public NeedToLogin() {
super("please login first");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/NoActiveDeck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class NoActiveDeck extends Exception {
public NoActiveDeck(String username) {
super(username + " has no active deck");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/NoCardFound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class NoCardFound extends Exception {
public NoCardFound() {
super("no card found in the given position");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/NoCardToAttack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class NoCardToAttack extends Exception {
public NoCardToAttack() {
super("there is no card to attack here");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/NoSelectedCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class NoSelectedCard extends Exception {
public NoSelectedCard() {
super("no card is selected");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/NotAppropriateCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class NotAppropriateCard extends Exception {
public NotAppropriateCard(String cardType) {
super(String.format("only %s cards can be selected!", cardType));
}
}
7 changes: 7 additions & 0 deletions server/exceptions/NotCorrectDeck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class NotCorrectDeck extends Exception{
public NotCorrectDeck(boolean side) {
super("this card is not slected from the " + (side?"side" : "main") + " deck");
}
}
7 changes: 7 additions & 0 deletions server/exceptions/NotEnoughMoney.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.exceptions;

public class NotEnoughMoney extends Exception {
public NotEnoughMoney() {
super("you don't have enough money!");
}
}
Loading

0 comments on commit c898029

Please sign in to comment.