Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int maxmatches=21, index, indexPc, counter;
- String str= "Push 1, 2 or 3 to take matches from the pile";
- boolean pc;
- void setup() {
- size(400, 200);
- }
- void draw() {
- background(255);
- drawMatches(25, 15, 40, 10, 15, 50);
- textSize(15);
- fill(0);
- text(str, 25, 20);
- if (pc==false) {
- myTurn();
- } else {
- PcTurn();
- }
- }
- //draw all remaining matches
- void drawMatches(int xPos, int space, int yPos, int w, int h, int hRect) {
- for (int i=0; i<maxmatches; i++) {
- fill(255, 0, 0);
- ellipseMode(CENTER);
- ellipse(xPos+i*space, yPos, w, h);
- fill(#C9C314);
- rect(xPos-w/2+i*space, yPos+h/4, w, hRect);
- }
- }
- void myTurn() {
- text("You turn:", 25, 120);
- if (key>='0'&& key<='9') {
- if (key<='3') {
- index = key-48;
- text(index + "(press enter to continue)", 100, 120);
- } else {
- text ("Only 1,2 or 3 allowed! Try again!", 100, 120);
- }
- }
- if (keyPressed) {
- if (key==ENTER && index>=0 && index<=3) {
- maxmatches-=index;
- index=5;
- pc=true;
- }
- }
- }
- void PcTurn() {
- counter++;
- text("PC turn:", 25, 120);
- if (counter==0) {
- indexPc=(int)random(1, 4);
- }
- if (counter>=120) {
- text(indexPc + "(press enter to continue)", 100, 120);
- if (keyPressed) {
- if (key==ENTER) {
- counter=0;
- maxmatches-=indexPc;
- pc=false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement