Friday, May 19, 2017

GUI Background, Evolution

 Different Stages of our Game GUI:
First Image
Second Image

Third Image
Final Image

Sunday, May 7, 2017

Added new Animations and 2 Characters

New Donkey Character, team Mexican
Running


Donkey Dying Animation

Donkey fighting Animation

Mexican Dying Animation

Mexican Fighting Animation
New Bull Character - Team Trump
Walking Animation



Dying Animation Trump

Fighting Animation Trump

Monday, April 24, 2017

Java | Memorry Consumtion | LinkedList Vs ArrayList

If memory matters, use ArrayList!
LinkedList might allocate fewer entries, but those entries are astronomically more expensive than they'd be for ArrayList -- enough that even the worst-case ArrayList is cheaper as far as memory is concerned.Louis Wasserman

Sunday, April 16, 2017

JavaFX | Having access of other Controllers from a specific Controller

There are some good ways to do this:
  1. Create a reference of a Controller
  2. private ControllerClass controller;
    
    /*...
    
    Parent root;
    FXMLLoader fxmlLoader = new FXMLLoader();
    fxmlLoader.setLocation(getClass().getResource("/path/ofYourFxml.fxml"));
    
    controller = fxmlloader.getController();
    //Now you can use a method like getter and setter to set or get any value of variable
    controller.yourMethodToCall()
    
    Stage stage = new Stage();
    stage.setScene(new Scene(root, 1200, 700));
    stage.show()
    
  3. For dirt and dirty solution: declare any variable you want to use in other class as static (Not recommended for a complex application(static problem))
  4. Use a shared data Model among Controllers
  5. Explaination follows...
    
    

Saturday, April 15, 2017

Java | Probably the most unused keyword in Java | The "volatile" keyword

In multithreaded application the behavior or the result of some processes might look very strange to a new programmer. (including me when i write this post)

The Problem

In multi cores computers, different Threads can be run on different cores. It make sense since you want to get the advantages of having multi cores. The problem comes when you are using primitive data types to control processes that handled by different threads. Primitive data types are stored in cache (L1) of a core in your CPU. These data are not shared between the cores. So the data that are using in one core is not equals with the data that used in other cores. This will lead to unexpected result of your program.

The Solution

Decorate your variable with a keyword "volatile" like this <code>private volatile int someInteger;</code>

JavaFx | How to populate a ListView with an arrayList

It is very simple: you have to pass your list (Collection.List) to an ObservableArrayList (FXCollection) like this. ObservableList anyList = FXCollections.observableArrayList(yourList)
transform an ArrayList into observableArrayList

Friday, April 14, 2017

First Trump character created

Today I created the second character of the game, the basic Trump character. It is a guy pushing the border wall, trying to keep the mexicans out. This will be the most basic character of the Trump team. He will cost little, move at an avarage pace and have little health.
Although that could change later. (Maybe we will create a character without a wall to be the basic one and have this a a character with much health.)
Anyway here are some sketches and then the final animation. As you can see the wall is quite heavy for Mr. Trump to push so he is breathing heavely.
First sketches
Final animation

Saturday, April 1, 2017

JavaFX | Make an update of the UI | Platform.runlater

In javaFX any update of the user interface should be done by the javaFX application thread. Any other thread trying to update the UI will crash the application. So if you have a multi threaded application every line of code that update the UI should be wrapped in Platform.runLater block like this:
Platform.runLater(new Runnable() {
    @Override
    public void run() {
        // Update UI here.
    }
});
Or using lambda Expression:
Platform.runLater(
  () -> {
    // Update UI here.
  }
);

Wednesday, March 29, 2017

First game character created

Last weekend I created our first character to play in the game. This is the basic sombrero character that tries to get over the wall. I created it in Adobe Animate, alltough I have never used that programm it didn't take long to learn the basic features. Also it is easy to export it as a sprite sheet, which we will have to use to implement in the game.

First "Sombrero" character animated

First I thought about the design og the hat, because all the sombrero characters will wear a sombrero hat. I had already drawn a hat for the Logo I made so I used that one. You can see the Logo here, alltough I will probably update this Logo and make it better for when the final version of our game comes out.
Logo, probably not the final version

Now back to the process of the first character. I started to think simple and only have a hat with feet. Also to learn the programm better. I came up with this:
First animated character

After that I started drawing some sketches at home. I started by looking at the "zombie" characters from the "Plants vs Zombies" game. I switched his head back, changed his mouth, added some big eyebrows (with a nice little animation) and made his clothes a little more "Mexican style". You can see the comparison below. I should probably make his head a little bigger.
Basic "Sombrero" character
"Plants vs Zombies" character





















As you can see this was quite a process and the next character will be a "Sombrero" on a donkey, in the game he will cost more recources than the basic version, but have more speed.

Saturday, March 25, 2017

JUnit | Adding JUnit Library to IntelliJ IDE

IntelliJ is shipped with JUnit versions but they are not added to your project by default. You have to add JUnit libraries to your project manually. I'll show you how to do it the easy way.
  1. Place the cursor at the end of the class name.
  2. The cursor should be exactly at the end of the class name
  3. Press Alt + Enter
  4. Alt-Enter pressed
  5. Click create test and choose the latest JUnit version. If JUnit is not in the module, press Fix
  6. Fix button shown up
  7. Use the JUnit library that comes with IntelliJ and check all the methods you want to test
  8. choose IntelliJ's JUnit distribution
    check the boxes and press ok!
  9. Go to project structure and set the scope to compile
Remark: It's conventional to have the same test class name as the class tested with the suffix 'test'.

Thursday, March 23, 2017

Off-Topic | Ubuntu | No wifi connection after standby modus

If you're using Ubuntu on Lenovo ThinkPad T430 series, you might have the same problem as me: No internet connection after you've woken up your laptop from standby modus.

I haven't found any better solution yet but this will solve your problem: go to terminal and run this code sudo service network-manager restart please write comments if you have more automated solution for me.

Wednesday, March 22, 2017

Java | The power of Anonymous Class

Overloading a method in an Anonymous class

Client Class
Client Controller JavaFX
As you can see on the pictures above, display method is defined and called in the client class. If we want that any process from the display method to be done in a different class, we can use an anonymous class. The idea is simple. you create an instance of a class that immediately invoked itself and overload all the methods which are defined and called in that class to be done in the target class.

Sunday, March 12, 2017

JavaFx | Basic Knowledge

The Stage

In JavaFX the The user interface is the 'Stage'. Like in a theater, the stage is where all the events will be presented to the audiences or the users.
To create a JavaFX application on IntelliJ, you simply have to create a new JavaFX class.
Creating JavaFX application
After you created the JavaFX application, you can see, there is a start method to be implemented. For now the curtains of the stage is still closed. You can open the curtains by adding primaryStage.show(); to the start method.
adding show method to open the stage
If you now run the application, you'll see an empty 'stage'. The stage is there, now it is up to you to perform a show

The Scene

Now that you have a stage, you might want to perform a show. To do that, you'll need a scene. In a scene, there are some props or in Java terms, 'nodes'. A node can be a button, text field or just a label. To create a good scene you might want all these nodes to be organized nicely. Some nodes that build one feature, should also be placed side by side so the user will know intuitively what these nodes are about. Nodes is organized in a class called Parent. In Web term, it is similar to div tags. You can organize the nodes vertically using VBox Parent or horizontally using HBox Parent.

Layouts

BorderPane
BorderPane is a layout with five areas: Top, left, center, right and bottom.
GridPane
As the name said, GridPane works with grid system.
use indexes to organize the nodes
use hgap and vgap to control the space between grid
when there is not enough space, the nodes will shrink to fit the window

Java Client Server | Simple Socket Programming

To make an application that can communicate with other applications like chat-app or multiplayer games, we need a server that serve data between clients. A Client send data to the server and the server send it to another client. Server and client send data to each other via sockets.
How to create a Server
  • Create a class with a main method
  • Create an instance of ServerSocket. You need to pass any port number as a parameter ServerSocket ss = new ServerSocket(9999);
  • In order to accept an incoming client connection, we have to call the ServerSocket.accept() method. As soon as connection request is made from client, this method will return a socket that created specifically for this client.
  • To send and receive data from client, you can use OutputStreamWriter and BufferedReader
  • The Server
How to create a Client
  • Create a class with a main method
  • Create an instance of Socket class and pass the port number and the private ip address of your server as parameter.  You can use localhost instead of ip for local testing. Socket s = new Socket(ip, port);
  • To send and receive data from client, you can use OutputStreamWriter and BufferedReader
  • The Client
How it works
Run the server. once the accept() method is called, the server will wait for a client to connect. When you run the client, a connection request is made and ServerSocket will then create a socket that is connected to the client's socket until Socket.close() method is called. To make a simple chat application, put a Writer and a Reader in a while loop and use a Scanner to take user input.

Saturday, March 11, 2017

Java | Try with resources statement

Since Java 1.7 you can declare all resources that can be closed. e.g BufferedReader right after the try statement. With this feature, all resources will be closed and errors will be caught automatically. Before Java 1.7 you'll have to close all resources manually. like this:
managing resources before java 1.7
Since Java 1.7 this is simplified to this:
managing resources after java 1.7

Git | Github | Summary

Quick setup

  • Install git, sudo apt-get install git
  • Create Github account
  • In terminal, generate SSH key cd ~/.ssh && ssh-keygen leave passphrase empty, just press enter until the key is created
  • While still in ssh directory, cat id_rsa.pub and copy the entire key
  • Go to your Github setting, SSH and add SSH. paste the key in the key field. Give it a proper name and save
  • Go back to terminal, setup username and email on git git config --global user.name "john" and git config --global user.email "john.doe@gmail.com" Remember the username and email address muss be the same as the ones used for Github account
  • Go back to Github, create a new repository.
  • Now go to the folder of your application. cd /path/of/your/application and run these command
  • git init
  • git add -A
  • git commit -m "any message e.g. 'my first commit'"
  • Add your ssh URL or copy paste from your Github repository page git remote add origin ssh://login@IP/path/to/repository
  • git push -u origin master

Thursday, March 9, 2017

Java | UDP Socket Programming

There are two types of Internet Protocols that maintain a network conversation between applications. TCP (Transmission Control Protocol) and UDP (User Datagram Protocol.

In UDP we don't have a continuous connection. Each time a data exchange is done, the relationship is done. Therefore, every package should know where they are going. You must mention IP address and Port number in every package

Tuesday, February 28, 2017

Group Meeting | 28.02.2017

Who were there: Syarif, Adalstein, Nils, Damian
  • Festlegung des Spiels
  • Verteilung der Verantwortungen
  • A: Logo vorgestellt
  • Präsentationsvorbereitung Inhalt
  • zu fragen: white-/blacklist? Real-Time Aufwand?

Monday, February 27, 2017