Advertisement
Guest User

ghelp

a guest
Oct 26th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. int w=7, h=6, bs=100, player=1;
  2. int[][] board = new int [h][w];
  3.  
  4. void setup() {
  5. size(700, 600);
  6. ellipseMode(CORNER);
  7. }
  8.  
  9. int nextSpace (int x) {
  10. for(int y=h-1;y>=0;y--)
  11. if(board[y][x]==0)
  12. return y;
  13. return -1;
  14. }
  15.  
  16.  
  17.  
  18. void mousePressed() {
  19. int x = mouseX/bs, y = nextSpace(x);
  20. if(y>=0){
  21. board[y][x]=player;
  22. player = player==1?2:1;
  23. }
  24. }
  25.  
  26. void draw() {
  27. for (int j=0;j<h;j++){
  28. for (int i=0;i<w;i++){
  29. fill(255);
  30. rect(i*bs, j*bs,bs,bs);
  31. if(board[j][i]>0){
  32. fill(board[j][i]==1?255:0, board[j][i]==2?255:0,0);
  33. ellipse(i*bs,j*bs,bs,bs);
  34. }
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement