Skip to content

Commit

Permalink
Added : BMAKE and BFIGHT reception
Browse files Browse the repository at this point in the history
  • Loading branch information
kalahel committed Jan 5, 2018
1 parent 25273bd commit ac5674f
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 89 deletions.
49 changes: 42 additions & 7 deletions app/src/main/java/com/app/remi/test/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,75 @@
import android.hardware.SensorManager;
import android.os.Bundle;

import com.app.remi.test.engine.Moteur;
import com.app.remi.test.engine.Engine;
import com.app.remi.test.engine.Player;

/**
* Activity which serve as a placeholder for drawing the game elements
*/
public class MainActivity extends Activity {

//Moteur will be used as a view
private Moteur moteur;
private Engine engine;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();

int number = intent.getIntExtra("SPELL_BLOCKS_NUMBER",3);
int number = intent.getIntExtra("SPELL_BLOCKS_NUMBER", 3);
//Check if the sensorbutton is on or off
Boolean playWithSensor = intent.getBooleanExtra("BOOLEAN_CHECK", false);
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
//tab[number] qui sera le tableau contenant les sorts

moteur = new Moteur(this, playWithSensor, sensorManager,number);
setContentView(moteur);
//TODO add the class used by players
Player ownPlayer = this.generatePlayer(getIntent().getStringExtra(SpellSelectionActivity.TAG_PLAYER_OWN_INFO));
Player oppPlayer = this.generatePlayer(getIntent().getStringExtra(SpellSelectionActivity.TAG_PLAYER_OPP_INFO));

engine = new Engine(this, playWithSensor, sensorManager, number, ownPlayer, oppPlayer);
setContentView(engine);


}

@Override
protected void onResume() {
super.onResume();
moteur.resume();
engine.resume();
}

@Override
protected void onPause() {
super.onPause();
moteur.pause();
engine.pause();
}

/**
* Generate a player instance from a string containing all the necessary data
* TODO adjust this in function of server protocols changes
*
* @param playerData
* @return
*/
public Player generatePlayer(String playerData) {
Player player;
int hp, shield, ballsNb;
float ballsSpeed, ballsSize, buttonSize, paddleSize;
String login, classPicked;
String[] parsedData = playerData.split(";");
hp = Integer.parseInt(parsedData[0]);
shield = Integer.parseInt(parsedData[1]);
ballsNb = Integer.parseInt(parsedData[2]);
ballsSpeed = Float.parseFloat(parsedData[3]);
ballsSize = Float.parseFloat(parsedData[4]);
buttonSize = Float.parseFloat(parsedData[5]);
paddleSize = Float.parseFloat(parsedData[6]);
classPicked = parsedData[7];
login = parsedData[8];

player = new Player(hp, shield, classPicked, login);
return player;
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.app.remi.test.activities;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
Expand All @@ -12,28 +19,37 @@
import android.widget.ToggleButton;

import com.app.remi.test.R;
import com.app.remi.test.network.backend.Displayable;
import com.app.remi.test.network.backend.NetworkReceiver;
import com.app.remi.test.network.backend.services.NetworkBackendService;

import java.util.ArrayList;

/**
* Menu activity class
* NB : maybe contain some error on background
* TODO Add the spell selection aspect
* Matchmaking activity activity
* The client can choose here to play with the accelerometer
* Bad naming due to early implementation
* TODO rename properly
*/
public class SpellSelectionActivity extends Activity {
public class SpellSelectionActivity extends Activity implements Displayable {

//Button that will launch the game
private Button startButton;

//The textViews
private TextView accelerometerTextView;


//The button to allow or not the player to use the accelerometer
private ToggleButton accelerometerToggleButton;

private LocalBroadcastManager localBroadcastManager;
private NetworkBackendService networkBackendService;
private boolean mBound = false;

private ArrayList<String> spellsList;
public static final String MATCHMAKING_SPELLS_LIST = "com.app.remi.test.activities.SpellSelectionActivity";
public final static String MATCHMAKING_SPELLS_LIST = "com.app.remi.test.activities.SpellSelectionActivity";
public final static String FILTER_MATCHMAKING = "com.app.remi.test.activities.SpellSelectionActivity.FILTER_MATCHMAKING";
public static final String TAG_PLAYER_OWN_INFO = "com.app.remi.test.SpellSelectionActivity.TAG_PLAYER_OWN_INFO";
public static final String TAG_PLAYER_OPP_INFO = "com.app.remi.test.SpellSelectionActivity.TAG_PLAYER_OPP_INFO";


@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -48,19 +64,92 @@ protected void onCreate(Bundle savedInstanceState) {
this.spellsList = getIntent().getStringArrayListExtra(TrueSpellSelectionActivity.TAG_LIST_SPELL);
Log.d("SPELL_SELECTION : ", this.spellsList.toString());

this.localBroadcastManager = LocalBroadcastManager.getInstance(this); // Get an instance of a broadcast manager
BroadcastReceiver myReceiver = new NetworkReceiver(this); // Create a class and set in it the behavior when an information is received
IntentFilter intentFilter = new IntentFilter(FILTER_MATCHMAKING); // The intentFilter action should match the action of the intent send
localBroadcastManager.registerReceiver(myReceiver, intentFilter); // We register the receiver for the localBroadcastManager

}

// Start the game activity
@Override
protected void onStart() {
super.onStart();
Intent intent = new Intent(this, NetworkBackendService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

}

/**
* Defines callbacks for service binding, passed to bindService()
* Source : https://developer.android.com/guide/components/bound-services.html#Binder
*/
private ServiceConnection mConnection = new ServiceConnection() {

@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
NetworkBackendService.LocalBinder binder = (NetworkBackendService.LocalBinder) service;
networkBackendService = binder.getService();
mBound = true;
}

@Override
public void onServiceDisconnected(ComponentName arg0) {
mBound = false;
}
};


/**
* Send a request to be queued for matchmaking
*
* @param view Context
*/
public void submit(View view) {

networkBackendService.sendMessageToServer("BMAKE");
}


/**
* Behavior when the server have found an opponent and started a game
* Parsing of the players info received by the server
*
* @param textReceived
*/
@Override
public void handleReception(String textReceived) {

Intent intent = new Intent(this, MainActivity.class);
boolean buttonState = accelerometerToggleButton.isChecked();

String own_player_info, opp_player_info;
String[] playersInfos = textReceived.split(","); // Parsing of the received informations
own_player_info = playersInfos[1];
opp_player_info = playersInfos[2];

if (MainMenuActivity.BRICKEST_DEBUG_MODE) {
Toast.makeText(this, "OWN :" + own_player_info, Toast.LENGTH_SHORT).show();
Toast.makeText(this, "OPP : " + opp_player_info, Toast.LENGTH_SHORT).show();
}

intent.putExtra(TAG_PLAYER_OWN_INFO, own_player_info);
intent.putExtra(TAG_PLAYER_OPP_INFO, opp_player_info);
intent.putExtra("SPELL_BLOCKS_NUMBER", this.spellsList.size());
intent.putExtra(SpellSelectionActivity.MATCHMAKING_SPELLS_LIST, this.spellsList);
intent.putExtra("BOOLEAN_CHECK", buttonState);
startActivity(intent);
}


/***
* The service is only unbound onDestroy, this allow the service to persist between activities
*/
@Override
protected void onDestroy() {
super.onDestroy();
unbindService(mConnection);
mBound = false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
* Created by Remi on 24/09/2017.
*/

import android.graphics.Rect;
import android.graphics.RectF;
import java.util.Random;

public class Boule {
public class Ball {

//The hitbox of the ball
private RectF rect;
Expand All @@ -26,11 +24,11 @@ public class Boule {
private float ballHeightMin = 3;

/**
* The method Boule() is setting the values of the object Boule, its hitbox and its speed
* The method Ball() is setting the values of the object Ball, its hitbox and its speed
* @param screenX is the length of the screen
* @param screenY is the height of the screen
*/
public Boule(int screenX, int screenY){
public Ball(int screenX, int screenY){

xSpeed = 100;
ySpeed = -400;
Expand Down Expand Up @@ -86,7 +84,7 @@ public void reset(int x, int y){
rect.bottom = y - 20 - ballHeight;
}

public void givePosition(Boule b1,Boule b2){
public void givePosition(Ball b1, Ball b2){
b1.rect.left = b2.rect.left;
b1.rect.right = b2.rect.right;
b1.rect.top = b2.rect.top;
Expand Down
Loading

0 comments on commit ac5674f

Please sign in to comment.