I tried to build the game tic tac toe in the last few weeks and am now trying to challenge myself and my skills.
I finished tic tac toe in the sense, that two people can play it when on the same computer, but in my opinion a good game needs a singleplayer modus. So with that in mind I have a few questions.
As you can see I haven't started the computer yet. My problem is that I don't want to start and after that notice that I did way too much work.
I thought about making the computer finish a line if it has already two of its own in there.
if ((grid[0] + grid[1]) == -2 && turn == 0){
image(op,50,450);
grid[2] = -1;
turn = 1;
}
As you can see my try is not really efficient as I had to code the same thing for every possible combination of two. My question now is, if there is an easier way to do the whole thing.
Okay I want to learn Processing and Java in general and therefore pushed myself into coding a little game. I have a few problems, that I don't know a fix for and I would be very thankful if someone could help me. I'm very unexperienced though and therefore it would be nice if you could explain what you did and use the easiest way possible. Thanks for any help.
Code:
float x;
float y;
float a;
float b;
int px;
int score;
float addlimit;
int start;
float multi;
PFont arial;
float speedlimit;
String gamemode;
int status;
int crazy;
float rand;
void setup(){
size(600,600);
smooth();
x = random(10,590);
y = random(10,100);
a = 2;
b = 3;
px = 0;
multi = 1.25;
addlimit = 10;
score = 0;
arial = createFont("Arial",32);
textFont(arial,15);
speedlimit = 10;
start = 1;
crazy = 0;
status = 0;
}
void draw(){
if (start == 1){
background(0);
textFont(arial,15);
text("Commands: 'R' - Resets the game",100,100);
text("'S' - Pauses the game",189,115);
text("'P' - Unpauses the game",189,130);
text("'N' or '1' - Sets the gamemode to Normal",189,145);
text("'U' or '2' - Sets the gamemode to Ultra",189,160);
text("'X' or '3' - Sets the gamemode to Random",189,175);
text("'C' or '4' - Sets the gamemode to Crazy",189,190);
text("'H' or '5' - Sets the gamemode to Hardcore",189,205);
text("'M' - Returns to this menu",189,220);
textFont(arial,25);
text("Press 'P' or Leftclick to start the game",85,500);
if (x < (px + 25) && x > (px - 25) && y > 495 && y < 505){
b = b*(-1);
score = score + 1;
}
if (score == speedlimit){
a = a*multi;
b = b*multi;
speedlimit = speedlimit + addlimit;
}
if (score == 50){
textFont(arial,50);
text("YOU WIN!",height/2 -110,width/2-25);
textFont(arial,35);
text("Left click to continue in Free Mode",35,width -20);
noLoop();
}
if (score < 0){
score = 0;
}
}
}
void mousePressed() {
loop();
if (score == 50){
score = score + 1;
}
}
void keyPressed(){
if (key == 'r' || key == 'n' || key == '1'){
crazy = 0;
x = random(10,590);
y = random(10,100);
a = 2;
b = 3;
px = 0;
multi = 1.25;
addlimit = 10;
score = 0;
speedlimit = 10;
status = 0;
}
if (key == 'u' || key == '2'){
crazy = 0;
x = random(10,590);
y = random(10,100);
a = 2;
b = 3;
score = 0;
addlimit = 5;
multi = 1.25;
speedlimit = 5;
status = 1;
}
if (key == 's'){
noLoop();
}
if (key == 'p'){
loop();
}
if (key == 'x' || key == '3'){
crazy = 0;
score = 0;
speedlimit = random(20);
multi = (random(10,15)/10);
addlimit = random(20);
x = random(10,590);
y = random(10,100);
a = random(1,6);
b = random(1,6);
status = 2;
}
if (key == 'm'){
start = 1;
}
if (key == 'c' || key == '4'){
x = random(10,590);
y = random(10,100);
a = 2;
b = 3;
multi = 1.15;
addlimit = 10;
score = 0;
speedlimit = 10;
crazy = 1;
status = 3;
}
if (key == 'h' || key == '5'){
x = random(10,590);
y = random(10,100);
a = 2;
b = 3;
addlimit = 5;
multi = 1.35;
speedlimit = 5;
score = 0;
crazy = 1;
status = 4;
}
}
Description:
This program is as many of you probably know called the ball pad game. The ball is bouncing of the pad and all walls, but the one under the pad, that only moves on the x-axis. There is a score system involved that adds one if the ball hits the pad and substracts one if the ball hits the wall it doesn't bounce off of. I created a few gamemode to challenge myself and the player since the original game may get boring.
Problems:
1. If you play and you lose points the speed keeps being the same. I have not a clue how to fix that problem although I tried different stuff.
2. When the ball hits the side of the Pad there is a chance that the Ball keeps bouncing of the inside of the Pad without getting out. I know that you could just inverse the speed of the ball and it would bounce off, but that would result in the ball always bouncing back and not off, which is not wanted.