Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. [aron@aron-desktop hw6]$ cat TicTacToe.java
  2. import java.util.ArrayList;
  3. import fang2.core.*;
  4. import fang2.sprites.*;
  5.  
  6. public class TicTacToe extends Game{
  7.  
  8. private int width = 3;
  9. private int height = 3;
  10. private ArrayList<GameTile> gameBoard = new ArrayList<GameTile>(width*height);
  11.  
  12. public TicTacToe(){
  13. super();
  14. setNumberOfPlayers(2);
  15. }
  16.  
  17. public static void main(String[] argv){
  18. new TicTacToe().runAsApplication();
  19. new TicTacToe().runAsApplication();
  20. }
  21.  
  22. @Override
  23. public void setup(){
  24. setupGameBoard();
  25. }
  26.  
  27. @Override
  28. public void advance(double dT){
  29.  
  30. }
  31.  
  32. private GameTile getGameTile(int x, int y){
  33. return gameBoard.get(x + y*width);
  34. }
  35.  
  36. private void setupGameBoard(){
  37. //initilize the gameboard array
  38. for(int n = 0; n < gameBoard.size(); n++){
  39. gameBoard.add(new GameTile());
  40. }
  41.  
  42. for(int y = 0; y < height; y++){
  43. for(int x = 0; x < width; x++){
  44. GameTile tempTile = getGameTile(x,y);
  45. tempTile.setScale(0.3);
  46. tempTile.setLocation(x / width + 0.17, y / height + 0.17);
  47. }
  48. }
  49.  
  50.  
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement