Skip to content

Commit

Permalink
main screen, with a button that starts the game
Browse files Browse the repository at this point in the history
  • Loading branch information
bart9h committed Sep 28, 2011
1 parent ae9d7b6 commit ce60ed9
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 36 deletions.
7 changes: 7 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Game"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.ALTERNATIVE" />
</intent-filter>
</activity>
</application>
</manifest>
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
TARGET=bin/AngryPipes-debug.apk

SRCS=\
AndroidManifest.xml \
src/org/ninehells/angrypipes/AngryPipes.java \
src/org/ninehells/angrypipes/Board.java \
src/org/ninehells/angrypipes/Game.java \
src/org/ninehells/angrypipes/View.java \

$(TARGET): $(SRCS)
ant debug

clean:
rm -rf bin/ gen/

install: install-emulator

install-emulator: $(TARGET)
Expand Down
19 changes: 18 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AngryPipes</string>
<string name="app_name">
AngryPipes
</string>
<string name="intro">
The pipes are angry.\n\n
Someone bad has scrambled them,\n
and now they\'re all disconnected.\n\n
Connect them again to make them happy!\n\n\n
</string>
<string name="play">
PLAY
</string>
<string name="settings">
Settings
</string>
<string name="about">
About
</string>
</resources>
67 changes: 32 additions & 35 deletions src/org/ninehells/angrypipes/AngryPipes.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.ninehells.angrypipes;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.Intent;
import android.os.Bundle;
import android.widget.HorizontalScrollView;
import android.widget.ScrollView;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Button;
import android.widget.TextView;

import org.ninehells.angrypipes.Board;
import org.ninehells.angrypipes.View;
import org.ninehells.angrypipes.Game;

public class AngryPipes extends Activity
{
Expand All @@ -16,37 +18,32 @@ public void onCreate(Bundle state)
{
super.onCreate(state);

mPreferences = getPreferences(MODE_PRIVATE);
mBoard = new Board(
mPreferences.getInt("width", 100),
mPreferences.getInt("height", 100),
mPreferences.getString("board", "").getBytes()
);

View view = new View(this);
view.setBoard(mBoard);

ScrollView verticalScroll = new ScrollView(this);
HorizontalScrollView horizontalScroll = new HorizontalScrollView(this);
horizontalScroll.addView(view);
verticalScroll.addView(horizontalScroll);
setContentView(verticalScroll);
TextView text = new TextView(this);
text.setText(R.string.intro);

Button play = new Button(this);
play.setText(R.string.play);
play.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(AngryPipes.this, Game.class));
}
});

Button settings = new Button(this);
settings.setText(R.string.settings);

Button about = new Button(this);
about.setText(R.string.about);

LinearLayout group = new LinearLayout(this);
group.setOrientation(LinearLayout.VERTICAL);
group.setGravity(Gravity.CENTER);
group.addView(text);
group.addView(play);
group.addView(settings);
group.addView(about);
setContentView(group);
}

@Override
public void onPause()
{
super.onPause();

SharedPreferences.Editor ed = mPreferences.edit();
ed.putInt("width", mBoard.width());
ed.putInt("height", mBoard.height());
ed.putString("board", new String(mBoard.serialize()));
ed.commit();
}

private Board mBoard;
private SharedPreferences mPreferences;
}

// vim600:fdm=syntax:fdn=2:nu:
52 changes: 52 additions & 0 deletions src/org/ninehells/angrypipes/Game.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.ninehells.angrypipes;

import android.app.Activity;
import android.os.Bundle;
import android.content.SharedPreferences;
import android.widget.HorizontalScrollView;
import android.widget.ScrollView;

import org.ninehells.angrypipes.Board;
import org.ninehells.angrypipes.View;

public class Game extends Activity
{
@Override
public void onCreate(Bundle state)
{
super.onCreate(state);

mPreferences = getPreferences(MODE_PRIVATE);
mBoard = new Board(
mPreferences.getInt("width", 20),
mPreferences.getInt("height", 30),
mPreferences.getString("board", "").getBytes()
);

View view = new View(this);
view.setBoard(mBoard);

ScrollView verticalScroll = new ScrollView(this);
HorizontalScrollView horizontalScroll = new HorizontalScrollView(this);
horizontalScroll.addView(view);
verticalScroll.addView(horizontalScroll);
setContentView(verticalScroll);
}

@Override
public void onPause()
{
super.onPause();

SharedPreferences.Editor ed = mPreferences.edit();
ed.putInt("width", mBoard.width());
ed.putInt("height", mBoard.height());
ed.putString("board", new String(mBoard.serialize()));
ed.commit();
}

private Board mBoard;
private SharedPreferences mPreferences;
}

// vim600:fdm=syntax:fdn=2:nu:

0 comments on commit ce60ed9

Please sign in to comment.