Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int w=7, h=6, bs=100, player=1;
- int[][] board = new int [h][w];
- void setup() {
- size(700, 600);
- ellipseMode(CORNER);
- }
- int nextSpace (int x) {
- for(int y=h-1;y>=0;y--)
- if(board[y][x]==0)
- return y;
- return -1;
- }
- void mousePressed() {
- int x = mouseX/bs, y = nextSpace(x);
- if(y>=0){
- board[y][x]=player;
- player = player==1?2:1;
- }
- }
- void draw() {
- for (int j=0;j<h;j++){
- for (int i=0;i<w;i++){
- fill(255);
- rect(i*bs, j*bs,bs,bs);
- if(board[j][i]>0){
- fill(board[j][i]==1?255:0, board[j][i]==2?255:0,0);
- ellipse(i*bs,j*bs,bs,bs);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement