├── Cell.pde ├── LICENSE ├── README.md └── tictactoe.pde /Cell.pde: -------------------------------------------------------------------------------- 1 | class Cell { 2 | float x, y, w, h; 3 | float state; 4 | boolean player; 5 | 6 | Cell(float tempX, float tempY, float tempW, float tempH, float tempAngle) { 7 | x = tempX; 8 | y = tempY; 9 | w = tempW; 10 | h = tempH; 11 | state = 0; 12 | } 13 | 14 | void display() { 15 | line(100, 0, 100, height); 16 | line(200, 0, 200, height); 17 | line(0, 100, width, 100); 18 | line(0, 200, width, 200); 19 | 20 | noFill(); 21 | stroke(0); 22 | if (state == 0) { 23 | // Do nothing 24 | } 25 | if (state == 1) { 26 | ellipse(x+w/2, y+h/2, 100, 100); 27 | } 28 | if (state ==2) { 29 | line(x, y, x+w, y+h); 30 | line(x+w, y, x, y+h); 31 | } 32 | } 33 | 34 | void click(float mx, float my) { 35 | if (mx > x && mx < x + w && my > y && my < y +h) { 36 | state = (state + 1) % 3; 37 | println(state); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Michael Kolesidis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tictactoe-processing 2 | A simple Tic-Tac-Toe game created with Processing. 3 | -------------------------------------------------------------------------------- /tictactoe.pde: -------------------------------------------------------------------------------- 1 | int cols, rows; 2 | Cell[][] board; 3 | 4 | void setup() { 5 | size(300, 300); 6 | frameRate(60); 7 | strokeWeight(2); 8 | cols = 3; 9 | rows = 3; 10 | board = new Cell[cols][rows]; 11 | for (int i = 0; i < cols; i++) { 12 | for (int j =0; j < rows; j++) { 13 | board[i][j] = new Cell(i*100, j*100, 100, 100, i+j); 14 | } 15 | } 16 | } 17 | 18 | void draw() { 19 | background(255); 20 | for (int i = 0; i < cols; i++) { 21 | for (int j =0; j < rows; j++) { 22 | board[i][j].display(); 23 | } 24 | } 25 | } 26 | 27 | void mousePressed() { 28 | for (int i = 0; i < cols; i++) { 29 | for (int j =0; j < rows; j++) { 30 | board[i][j].click(mouseX, mouseY); 31 | } 32 | } 33 | } 34 | --------------------------------------------------------------------------------