“CP_Midterm_OOP_HW” by chris pro
https://openprocessing.org/sketch/96384
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution ShareAlike
CP_Midterm_OOP_HW
pro
xxxxxxxxxx
//Chris Pro Midterm
//Tic Tac Toe
//Mouse click on a space to go and press any key to reset the board
//Declare Classes
GameBoard game;
Buttons button;
void setup() {
//window setup and game board
size(300, 300);
background(255);
game = new GameBoard();
button = new Buttons();
game.reset();
}
void draw() {
if (mousePressed) {
//1st button (space 1,0)
button.buttonOne();
//2nd button (space 1,2)
button.buttonTwo();
//3rd button (space 1,3)
button.buttonThree();
//4th button (space 2,1)
button.buttonFour();
//5th button (space 2,2)
button.buttonFive();
//6th button (space 2,3)
button.buttonSix();
//7th button (space 3,1)
button.buttonSeven();
//8th button (space 3,2)
button.buttonEight();
//9th button (space 3,3)
button.buttonNine();
}
//Pressing any key will reset the game board
if (keyPressed) {
game.reset();
}
}
class Buttons{
//Data Variables
int xOne;
int xTwo;
int xThree;
int yOne;
int yTwo;
int yThree;
//Initialize data variables
Buttons(){
xOne = 100;
xTwo = 200;
xThree = 300;
yOne = 100;
yTwo = 200;
yThree = 300;
}
//Functions for buttons (9 total)
void buttonOne(){
if (mouseX > 0 && mouseX < xOne && mouseY > 0 && mouseY < yOne) {
ellipseMode(CORNER);
ellipse(0, 0, 100, 100);
}}
void buttonTwo(){
if (mouseX > xOne && mouseX < xTwo && mouseY > 0 && mouseY < yOne) {
line(100, 0, 200, 100);
line(100, 100, 200, 0);
}}
void buttonThree(){
if (mouseX > xTwo && mouseX < xThree && mouseY > 0 && mouseY < yOne) {
ellipseMode(CORNER);
ellipse(200, 0, 100, 100);
}}
void buttonFour(){
if (mouseX > 0 && mouseX < xOne && mouseY > yOne && mouseY < yTwo) {
line(0, 100, 100, 200);
line(100, 100, 0, 200);
}}
void buttonFive(){
if (mouseX > xOne && mouseX < xTwo && mouseY > yOne && mouseY < yTwo) {
ellipseMode(CORNER);
ellipse(100, 100, 100, 100);
}}
void buttonSix(){
if (mouseX > xTwo && mouseX < xThree && mouseY > yOne && mouseY < yTwo) {
line(200, 100, 300, 200);
line(200, 200, 300, 100);
}}
void buttonSeven(){
if (mouseX > 0 && mouseX < xOne && mouseY > yTwo && mouseY < yThree) {
ellipseMode(CORNER);
ellipse(0, 200, 100, 100);
}}
void buttonEight(){
if (mouseX > xOne && mouseX < xTwo && mouseY > yTwo && mouseY < yThree) {
line(100, 200, 200, 300);
line(200, 200, 100, 300);
}}
void buttonNine(){
if (mouseX > xTwo && mouseX < xThree && mouseY > yTwo && mouseY < yThree) {
ellipseMode(CORNER);
ellipse(200, 200, 100, 100);
}}
}
class GameBoard{
//Data Variables
int rectH;
int rectW;
//Initialize data variables
GameBoard(){
rectH = 100;
rectW = 100;
}
//Functions for a blank game board
void reset(){
rect(0, 0, rectW, rectH);
rect(0, 100, rectW, rectH);
rect(0, 200, rectW, rectH);
rect(100, 0, rectW, rectH);
rect(100, 100, rectW, rectH);
rect(100, 200, rectW, rectH);
rect(200, 0, rectW, rectH);
rect(200, 100, rectW, rectH);
rect(200, 200, rectW, rectH);
}
}
See More Shortcuts