Skip to content

Commit

Permalink
created a board and some players
Browse files Browse the repository at this point in the history
  • Loading branch information
guodman committed Feb 16, 2012
1 parent 851a807 commit ba4ca7d
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
3 changes: 1 addition & 2 deletions res/layout/main.xml
Expand Up @@ -58,7 +58,6 @@
android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

</LinearLayout>
</LinearLayout>

</LinearLayout>
7 changes: 4 additions & 3 deletions src/com/mortalpowers/android/barcard/BarcardActivity.java
Expand Up @@ -25,15 +25,16 @@ public void onCreate(Bundle savedInstanceState) {

Button scan = (Button) findViewById(R.id.button1);
scan.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
scanSomething();

}
});
Toast.makeText(this, "OnCreate", Toast.LENGTH_SHORT).show();


LinearLayout l = (LinearLayout) findViewById(R.id.linearLayout1);
GameBoard gb = new GameBoard(this);
l.addView(gb);
}

public void scanSomething() {
Expand Down
71 changes: 71 additions & 0 deletions src/com/mortalpowers/android/barcard/GameBoard.java
@@ -0,0 +1,71 @@
package com.mortalpowers.android.barcard;

import java.util.ArrayList;

import android.content.Context;
import android.widget.GridLayout;
import android.widget.TextView;

public class GameBoard extends GridLayout {
private final int width = 10;
private final int height = 10;
private ArrayList<ArrayList<TextView>> data;
private ArrayList<Player> players;


public GameBoard(Context context) {
super(context);
setRowCount(height);
setColumnCount(width);

data = new ArrayList<ArrayList<TextView>>();

players = new ArrayList<Player>();
players.add(new Player("1"));
Player p2 = new Player("2");
p2.x = 3;
p2.y = 6;
players.add(p2);

for (int i = 0; i < width; i++) {
ArrayList<TextView> row = new ArrayList<TextView>();
data.add(row);
for (int j = 0; j < height; j++) {
TextView tv = new TextView(context);
tv.setText(" " + i + "x" + j + " ");
row.add(tv);
addView(tv);
}
}

updateBoard();
}

public void updateBoard() {
String[][] buffer = new String[width][height];
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
buffer[i][j] = "";
}
}

for (Player p : players) {
buffer[p.x][p.y] = buffer[p.x][p.y] + " " + p.name + " ";
}

for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
TextView t = data.get(i).get(j);
t.setText("[" + buffer[i][j] + "]");
}
}
}

public void setGridValue(int x, int y, String value) {
data.get(x).get(y).setText(value);
}

public String getGridValue(int x, int y) {
return (String) data.get(x).get(y).getText();
}
}
15 changes: 15 additions & 0 deletions src/com/mortalpowers/android/barcard/Player.java
@@ -0,0 +1,15 @@
package com.mortalpowers.android.barcard;

public class Player {
int x = 0;
int y = 0;
String name = "Unnamed";

public Player(String name) {
this.name = name;
}

public void move(int toX, int toY) {

}
}

0 comments on commit ba4ca7d

Please sign in to comment.