import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferStrategy;
import java.util.Random;
import javax.swing.JFrame;
public abstract class Viniati implements MouseListener
{
public static int a;
public static int score;
public static char mouse_c;
/************************************************************************
* Our main code!
***********************************************************************/
public static void main(String[] args){
int line_1_xe = 200; // line 1 pos X end
int line_1_ye = 200; // line 1 pos Y end
int delay = 100;
float radius=75;
int[] trix = {100,50,150};
int[] triy =
{
100, // point a
156, // point b
156 // point c
};
int[] trix1 = {100,50,150};
int[] triy1 =
{
100, // point a
48, // point b
40 // point c
};
int random_place = 0;
int sslr = 0; // Score since count since last random number genirated
int color_c;
JFrame jf = new JFrame("Viniati v1.0");
jf.setIgnoreRepaint( true );
jf.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
jf.setResizable(false);
Canvas canvas = new Canvas();
canvas.setIgnoreRepaint(true);
canvas.setSize(200, 200);
jf.add(canvas);
jf.pack();
jf.setVisible(true);
//
// Okay, now let's make a back buffer...
//
canvas.createBufferStrategy(2);
BufferStrategy buffer = canvas.getBufferStrategy();
//
// Okay, now let's do some "active rendering" !
//
Graphics graphics = null;
graphics = buffer.getDrawGraphics();
//
// Now, let's also init mouse code...
//
canvas.addMouseListener(new MouseListener()
{
public void mouseClicked(MouseEvent clicke)
{
mouse_c=1;
}
public void mouseEntered(MouseEvent arg0) {}
public void mouseExited(MouseEvent arg0) {}
public void mousePressed(MouseEvent arg0) {}
public void mouseReleased(MouseEvent arg0) {}
//public void mouseDragged(MouseEvent e) {}
//public void mouseMoved(MouseEvent e) {}
});
//
// Last of all, let's init the random code fuction.
//
Random rand = new Random();
while(true)
{
/*
* Lets clear our new buffer
*/
graphics.setColor(Color.black);
graphics.fillRect(0, 0, 200, 200);
/*
* Create game board
*/
graphics.setColor(Color.gray);
graphics.fillOval(20,20,155,155);
graphics.setColor(Color.red);
graphics.fillPolygon(trix, triy, 3);
graphics.fillOval(52,138,95,36);
graphics.setColor(Color.yellow);
graphics.fillPolygon(trix1, triy1, 3);
graphics.fillOval(47,22,100,40);
graphics.drawOval(20,20,155,155);
/*
*
*/
if(mouse_c == 1)
{
if(random_place==1)
{
if(a==4)
{
score++;
delay--;
sslr++;
}
else
{
if(a==5)
{
score++;
delay--;
sslr++;
}
else
{
score=0;
delay=100;
sslr=0;
}
}
}
else
{
if(a==2)
{
score++;
delay--;
sslr++;
}
else
if(a==3)
{
score++;
delay--;
sslr++;
}
else
{
score=0;
delay=100;
sslr=0;
}
}
}
mouse_c =0;
/*
* delay exicution for a short time...
*/
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
break; // I don't really care if we don't sucseed at sleeping...
}
if(a==6)
a=0;
else
a++;
/*
* p
*/
line_1_xe = (int) (100 + radius * java.lang.Math.cos(a));
line_1_ye = (int) (100 + radius * java.lang.Math.sin(a));
/*
* And now draw our line...
*/
graphics.setColor(Color.green);
graphics.drawLine(100, 100, line_1_xe, line_1_ye);
/*
* Right the score on the board
*/
graphics.setColor(Color.white);
graphics.drawString("Score: " + score, 1, 10);
/**************************************************************
* Check if Score Since Last Random generation == 4, if so
* genorate a new number to select what zone to hit.
*************************************************************/
if(sslr==4)
{
random_place= rand.nextInt(3);
sslr=0;
}
/**************************************************************
* If the number genorated it 1 then do zone yellow.
*************************************************************/
if(random_place==1)
{
if(score>=15)
{
color_c = rand.nextInt(2);
if(color_c==1)
graphics.setColor(Color.red);
else
graphics.setColor(Color.yellow);
}
else
graphics.setColor(Color.yellow);
graphics.drawString("yellow zone", 134, 190);
}
/**************************************************************
* If the number genorated is anything else do zone red...
*************************************************************/
else
{
if(score>=15)
{
color_c = rand.nextInt(2);
if(color_c==1)
graphics.setColor(Color.yellow);
else
graphics.setColor(Color.red);
}
else
graphics.setColor(Color.red);
graphics.drawString("red zone", 134, 190);
}
/**************************************************************
* Last of all update the screen buffer...
*************************************************************/
if( !buffer.contentsLost() )
buffer.show();
}
}
}