/** * Called when the start/stop wall button is pressed or when the proximity sensor detects * something */ public void createWall() { if (!isAlive) return; // Is the player currently creating a wall if (!creatingWall) { // Start creating a wall creatingWall = true; // The player is now creating a wall // Create the wall object Wall wall = new Wall( "W" + GameSettings.generateUniqueId(), GameSettings.getPlayerId(), GameSettings.getWallColor(), context); wallId = wall.getId(); // Store the wall id map.addMapItem(wall); // Add the wall to the map // Tell the other devices that a new wall has been created gameUpdateHandler.sendCreateWall( GameSettings.getPlayerId(), wallId, new ArrayList<LatLng>(), GameSettings.getWallColor()); // Show the "creating wall" notification showNotification(getString(R.string.wall_on_notification), Toast.LENGTH_SHORT); } // The wall is never turned off // else { // // Stop creating the wall // creatingWall = false; // The player is no longer creating a wall // wallId = null; // Forget about the current wall // // // Show the "stopped creating wall" notification // showNotification(getString(R.string.wall_off_notification), Toast.LENGTH_SHORT); // } }
public void breakWall(View view) { // This should never be true ! if (!isAlive) return; if (travelledDistance >= WALL_BREAKER_COST) { addScore(-WALL_BREAKER_COST); // Break the wall ArrayList<Wall> originalWalls = new ArrayList<>(map.getWalls()); for (Wall wall : originalWalls) { ArrayList<Wall> newWalls = wall.splitWall(snappedGpsLoc, holeSize); if (newWalls != null) { map.removeMapItem(wall.getId()); // The wall has to be split for (int i = 0; i < newWalls.size(); i++) { Wall newWall = newWalls.get(i); // Add the new wall to the game map.addMapItem(newWall); gameUpdateHandler.sendCreateWall( newWall.getOwnerId(), newWall.getId(), newWall.getPoints(), newWall.getColor()); } } } showNotification(getString(R.string.wall_breaker_notification), Toast.LENGTH_SHORT); } else { showNotification(getString(R.string.no_wall_breaker_notification), Toast.LENGTH_SHORT); } }
// region Initialization // --------------------------------------------------------------------------------------------- @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { // If the application closed accidentally the player is set to spectator mode // At this point the game is corrupt and a lot of problems will arise // If this happens to the host it is extremely problematic // TODO make the host end the game if his game is corrupt GameSettings.loadFromBundle(savedInstanceState); GameSettings.setSpectate(true); Toast.makeText(this, getString(R.string.game_activity_closed), Toast.LENGTH_SHORT).show(); } // Content of Activity // ----------------------------------------------------------------------------------------- setContentView(R.layout.activity_game); // Sensor tracking // ----------------------------------------------------------------------------------------- // Initialize sensorDataObservable and proximityObserver acceleration = 0; accelerationCount = 0; turns = 0; sensorDataObservable = new SensorDataObservable(this); isBellRinging = false; // Location tracking // ----------------------------------------------------------------------------------------- // Initialize the stored locations to 0,0 snappedGpsLoc = new LatLng(0, 0); gpsLoc = new LatLng(0, 0); if (savedInstanceState != null) travelledDistance = savedInstanceState.getDouble("travelledDistance", 0.0); else travelledDistance = 0.0; // Initialize location listener locationListener = new CustomLocationListener( this, // The activity that builds the google api this, // The LocationObserver 1500, // Normal update frequency of the location 500, // Fastest update frequency of the location LocationRequest.PRIORITY_HIGH_ACCURACY // Accuracy of the location ); // Create the context used by the google api (just stores the google key) context = new GeoApiContext().setApiKey(getString(R.string.google_maps_key_server)); // Permissions // ----------------------------------------------------------------------------------------- // Request permissions before doing anything else (after initializing the location listener!) requestPermissions(); // Map Object // ----------------------------------------------------------------------------------------- // Create the map object MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); map = new Map(mapFragment); // Player objects // ----------------------------------------------------------------------------------------- // Create the player map.addMapItem( new Player(GameSettings.getPlayerId(), GameSettings.getPlayerName(), new LatLng(0.0, 0.0))); // Networking // ----------------------------------------------------------------------------------------- // Create the gameUpdateHandler object connection = new SocketIoConnection("testA1", String.valueOf(GameSettings.getGameId())); gameUpdateHandler = new GameUpdateHandler(this, connection, map, context); gameEventHandler = new GameEventHandler(connection, this); if (savedInstanceState != null) // When the game is corrupt, you are considered dead. gameUpdateHandler.sendDeathMessage("//", "A corrupted game"); // Create the data server dataServer = new HttpConnector(getString(R.string.dataserver_url)); // Setup the game ui if (!GameSettings.isOwner()) { Button startButton = (Button) findViewById(R.id.start_game_button); startButton.setVisibility(View.GONE); } Button wallBreaker = (Button) findViewById(R.id.breakWallButton); wallBreaker.setVisibility(View.GONE); LinearLayout travelledDistanceContainer = (LinearLayout) findViewById(R.id.travelledDistanceContainer); travelledDistanceContainer.setVisibility(View.GONE); TextView travelledDistance = (TextView) findViewById(R.id.travelledDistance); travelledDistance.setVisibility(View.GONE); TextView travelledDistanceHead = (TextView) findViewById(R.id.travelledDistanceHead); travelledDistanceHead.setVisibility(View.GONE); findViewById(R.id.eventContainer).setVisibility(View.GONE); findViewById(R.id.countdown).setVisibility(View.GONE); }