Git Product home page Git Product logo

oop-avatar-duel's Introduction

IF2210 Project Template

Image taken from this amazing YouTube video.

Some classes are written in this class diagram : here

Prerequisites

In order to run this program, you must have Java with JDK 8 and its JRE.

Building and Running

Here is an example of project using gradle as the build tools. Try running these commands:

./gradlew run

You will notice that it will open a window that display 'Avatar Duel'.

Screenshots

Credit

This project was worked on by two people:

  • Matthew Kevin Amadeus - 13518035
  • Felicia Gojali - 13518101

I would like to thank:

  • Izharulhaq - 13518092 for helping with the report.

oop-avatar-duel's People

Contributors

feliciagojali avatar mkamadeus avatar rahmannnnn avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

feliciagojali

oop-avatar-duel's Issues

Polymorphism Methods and the use of instanceof

Not really a problem, just some typing issues.

Card card;
public MinicardController(LandCard c)
{
FXMLLoader minicardLoader = new FXMLLoader(AvatarDuel.class.getResource("gui/minicard.fxml"));
minicardLoader.setRoot(this);
minicardLoader.setController(this);
try{
minicardLoader.load();
this.card = c;
this.cardType.setText("Land");
this.cardName.setText(c.getName());
this.cardElement.setText(c.getElement().toString());
this.cardAttack.setText("-");
this.cardDefense.setText("-");
}
catch(Exception e)
{
throw new RuntimeException(e);
}
}
public MinicardController(CharacterCard c)
{
FXMLLoader minicardLoader = new FXMLLoader(AvatarDuel.class.getResource("gui/minicard.fxml"));
minicardLoader.setRoot(this);
minicardLoader.setController(this);
try{
minicardLoader.load();
this.card = c;
this.cardType.setText("Character");
this.cardName.setText(c.getName());
this.cardElement.setText(c.getElement().toString());
this.cardAttack.setText(Integer.toString(c.getAttack()));
this.cardDefense.setText(Integer.toString(c.getDefense()));
}
catch(Exception e)
{
throw new RuntimeException(e);
}
}
public MinicardController(SkillCard c)
{
FXMLLoader minicardLoader = new FXMLLoader(AvatarDuel.class.getResource("gui/minicard.fxml"));
minicardLoader.setRoot(this);
minicardLoader.setController(this);
try{
minicardLoader.load();
this.card = c;
this.cardType.setText("Skill");
this.cardName.setText(c.getName());
this.cardElement.setText(c.getElement().toString());
this.cardAttack.setText(Integer.toString(c.getAttack()));
this.cardDefense.setText(Integer.toString(c.getDefense()));
}
catch(Exception e)
{
throw new RuntimeException(e);
}
}

Because Card inherits the three types of cards, it is necessary for me to create three types of constructors, because there are some methods that are not available on the base class.

@FXML
public void setCardInfo(Card c)
{
System.out.println("pisang goreng tepung");
System.out.println(this.cardInfoSlot.getChildren());
this.cardInfoSlot.getChildren().clear();
System.out.println(this.cardInfoSlot.getChildren());
if(c instanceof CharacterCard)
this.cardInfoSlot.getChildren().add(new MinicardController((CharacterCard)c));
else if(c instanceof LandCard)
this.cardInfoSlot.getChildren().add(new MinicardController((LandCard)c));
else if(c instanceof SkillCard)
this.cardInfoSlot.getChildren().add(new MinicardController((SkillCard)c));
}

By using the instanceof operator, the code works, but is there any other way of writing it so that maybe casting the constructors are not necessary? Should the overall class structure be changed? Or am I missing something here? I'm open to suggestions.

Import * in Java

Is using import com.java.packagename.*; in Java considered a bad practice and should be avoided? If so/not, why?

Restructuring enum / constants

I think in Java, it is better if you move the enums or constants into the correct package instead of having one big package consists of all constants. For example, this Element should be inside card package. One day if you need enum Phase, the enum will be inside gameplay package (just for example), not the constant package.

public enum Element {
WATER,
FIRE,
AIR,
EARTH
};

This issue is only a suggestion. You may argue with it (not all the suggestions are true), challenge it, or come up with another idea yourself.

Package Management

What is considered as a good package separation and naming? E.g, is having the model class a good practice? We're open to suggestions about package management.

Use Element enum instead of String

Here, you use String for element of Card.

What will happen if the string is null? What will happen if the string is lowercase, meanwhile you need sentence case? How the future developer know the value of element? I think the better solution is to use Element enum, that have been defined in Element.java

This issue is only a suggestion. You may ignore it (not all the suggestions are true), challenge it, or come up with another idea yourself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.