java - Trying to use Android internal storage for a high score array. -
using link http://developer.android.com/guide/topics/data/data-storage.html#filesinternal
i trying build high scores array app game. want store internally. have started , i'm getting errors can't figure out. wanted test make sure create file. using eclipse java code , andengine. please help!!
my errors are: method openfileoutput(string, int) undefined type gamescene syntax error on token "write", identifier expected after token
package com.example.game; import java.io.fileoutputstream; import java.util.timer; import org.andengine.engine.camera.camera; import org.andengine.engine.camera.hud.hud; import org.andengine.engine.handler.timer.itimercallback; import org.andengine.engine.handler.timer.timerhandler; import org.andengine.entity.entity; import org.andengine.entity.ientity; import org.andengine.entity.modifier.delaymodifier; import org.andengine.entity.primitive.rectangle; import org.andengine.entity.scene.ionscenetouchlistener; import org.andengine.entity.scene.scene; import org.andengine.entity.scene.background.background; import org.andengine.entity.scene.background.parallaxbackground; import org.andengine.entity.scene.background.parallaxbackground.parallaxentity; import org.andengine.entity.sprite.sprite; import org.andengine.entity.text.text; import org.andengine.extension.physics.box2d.fixedstepphysicsworld; import org.andengine.extension.physics.box2d.physicsfactory; import org.andengine.extension.physics.box2d.physicsworld; import org.andengine.extension.physics.box2d.util.vector2pool; import org.andengine.input.sensor.acceleration.accelerationdata; import org.andengine.input.sensor.acceleration.iaccelerationlistener; import org.andengine.input.sensor.orientation.iorientationlistener; import org.andengine.input.sensor.orientation.orientationsensoroptions; import org.andengine.input.touch.touchevent; import org.andengine.util.color.color; import android.content.context; import android.hardware.sensor; import android.hardware.sensorevent; import android.hardware.sensoreventlistener; import android.hardware.sensormanager; import com.badlogic.gdx.math.vector2; import com.badlogic.gdx.physics.box2d.fixturedef; import com.example.game.scenemanager.scenetype; public class gamescene extends basescene implements iaccelerationlistener { public iaccelerationlistener yo; public static physicsworld physicsworld; private float tiltspeedx; private float tiltspeedy; private int collisioncheck=0; private hud gamehud; private text scoretext; private text enemylife; float accelerometerspeedx; private int lives=3; private int captainlives=3; private player player; private captain captain; private crab crab; private bomb bomb; private princess princess; sprite explosion; sprite heart; sprite explosion2; int flag = 1; int flag2 = 1; int flag3 = 1; private void createhud() { gamehud = new hud(); engine.enableaccelerationsensor(activity, this); // create score text scoretext = new text(20, 420, resourcesmanager.font, "lives: 0123456789", vbom); scoretext.setskewcenter(0, 0); scoretext.settext("lives: "+ lives); gamehud.attachchild(scoretext); enemylife = new text(600, 20, resourcesmanager.font, "enemy: 0123456789", vbom); enemylife.setskewcenter(0, 0); enemylife.settext("score: "+ captainlives); gamehud.attachchild(enemylife); camera.sethud(gamehud); } private void subtractfromlives() { lives = lives -1; scoretext.settext("lives: "+ lives); if (lives ==0) { scenemanager.getinstance().loadlossscene(engine); int finalscore = captainlives; //saves score when run out of lives used in comparator high scores. } } private void subtractfromcaptainlives() { captainlives = captainlives +1; enemylife.settext("score: "+captainlives); if (captainlives ==0) { scenemanager.getinstance().loadwinscene(engine); } } private void createphysics() { physicsworld = new fixedstepphysicsworld(20, new vector2(0, -17), false); registerupdatehandler(physicsworld); } @override public void createscene() { resourcesmanager.gmusic.play(); //captainlives=3; lives = resourcesmanager.number_lives; captainlives = resourcesmanager.enemy_lives; createbackground(); createhud(); createphysics(); createplayer(); createcaptain(); createaetimehandler(2); } private void createplayer() { player = new player(400,300, vbom,camera, physicsworld) { @override public void ondie() { // todo auto-generated method stub } }; final long[] player_animate = new long[] { 100, 100, 100 }; player.animate(player_animate); this.attachchild(player); } private void createcaptain() { captain = new captain(480,150, vbom,camera, physicsworld) { @override public void ondie() { // todo auto-generated method stub } }; final long[] player_animate = new long[] { 100, 100, 100 }; captain.animate(player_animate); this.attachchild(captain); } private void createcrab() { int xpos = (int)(695*math.random()); crab = new crab(xpos,0, vbom,camera, physicsworld) { @override protected void onmanagedupdate(float psecondselapsed) { if (player.collideswith(this)) { subtractfromlives(); float x = player.getx(); float y = player.gety(); crab.detachself(); briefexplosion(x,y); collisioncheck=1; } } @override public void ondie() { // todo auto-generated method stub if(collisioncheck==0) { crab.detachself(); } } }; this.attachchild(crab); collisioncheck=0; } gamescene scene = this; private void briefexplosion(float x, float y) { explosion = new sprite(x, y, resourcesmanager.explosion_region, vbom); scene.attachchild(explosion); flag = 0; } private void briefexplosion2(float x, float y) { explosion2 = new sprite(x, y, resourcesmanager.explosion2_region, vbom); scene.attachchild(explosion2); flag3 = 0; } private void briefheart(float x, float y) { heart = new sprite(x, y, resourcesmanager.heart_region, vbom); scene.attachchild(heart); flag2 = 0; } private void createbomb() { int xpos = (int)(750*math.random()); bomb = new bomb(xpos,0, vbom,camera, physicsworld) { @override protected void onmanagedupdate(float psecondselapsed) { if (player.collideswith(this)) { subtractfromcaptainlives(); float x = captain.getx(); float y = captain.gety(); bomb.detachself(); briefexplosion2(x,y); collisioncheck=1; } } @override public void ondie() { if(collisioncheck==0) { subtractfromlives(); float x = (float) (math.random()*800); float y = 425; bomb.detachself(); briefexplosion2(x,y); } } }; this.attachchild(bomb); collisioncheck=0; } private void createprincess() { int xpos = (int)(730*math.random()); princess = new princess(xpos,0, vbom,camera, physicsworld) { @override protected void onmanagedupdate(float psecondselapsed) { if (player.collideswith(this)) { float x = player.getx(); float y = player.gety(); princess.detachself(); briefheart(x,y); collisioncheck=1; } } @override public void ondie() { if(collisioncheck==0) { subtractfromlives(); princess.detachself(); } } }; this.attachchild(princess); collisioncheck=0; } private void createbackground() { //setbackground(new background(color.blue)); parallaxbackground background = new parallaxbackground(0, 0, 0); background.attachparallaxentity(new parallaxentity(0, new sprite(0, 0, resourcesmanager.game_background_region, vbom))); setbackground(background); } @override public void onbackkeypressed() { scenemanager.getinstance().loadmenuscene(engine); } @override public scenetype getscenetype() { return scenetype.scene_game; } @override public void disposescene() { camera.sethud(null); camera.setcenter(400, 240); resourcesmanager.gmusic.stop(); // todo code responsible disposing scene // removing game scene objects. } @override public void onaccelerationaccuracychanged(accelerationdata paccelerationdata) { } @override public void onaccelerationchanged(accelerationdata paccelerationdata) { // todo auto-generated method stub player.setposition(player.getx() + paccelerationdata.getx()*2,300); if(player.getx() < 0) { player.setposition(0,300); } if(player.getx() > 550) { player.setposition(550,300); } } private boolean firsttouch = false; private void createaetimehandler(float meffectspawndelay) { timerhandler spritetimerhandler2; this.engine.registerupdatehandler(spritetimerhandler2 = new timerhandler(meffectspawndelay,true, new itimercallback() { @override public void ontimepassed(final timerhandler ptimerhandler) { int = (int)(math.random()*10); if( flag == 0) { explosion.detachself(); flag = 1; } if (flag2 == 0) { heart.detachself(); flag2 = 1; } if (flag3 == 0) { explosion2.detachself(); flag3 = 1; } if( < 3) { createprincess(); } else if(i>3 && i<7) { createbomb(); } else { createcrab(); } } })); } string filename = "high_scores"; string string = "arrggg"; fileoutputstream fos = openfileoutput(filename, context.mode_private); fos.write(string.getbytes()); fos.close(); }
openfileoutput function on context, , class not context. either pass 1 in, or open in way.
Comments
Post a Comment