Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
|
||
} | ||
} |