-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStac.java
More file actions
143 lines (109 loc) · 2.22 KB
/
Stac.java
File metadata and controls
143 lines (109 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import java.awt.event.KeyEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyListener;
import java.util.*;
@SuppressWarnings({ "serial", "unused" })
class Stac extends JFrame{
static int cntr=0;
JLabel t1;
Block blk = new Block();
Block nblk = new Block();
Stac()
{ super("StackItUp!!!");
addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
//nblk.keyReleased(e);
}
@Override
public void keyPressed(KeyEvent e) {
blk.keyPressed(e);
nblk.nextrect();
cntr++;
System.out.println(cntr);
t1.setText("SCORE : "+cntr);
//if(blk.cntr>=1)
//{nblk.keyPressed(e);
//}
}
});
t1 = new JLabel() ;
t1.setBounds(30,30,100,30) ;
setFocusable(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(0,0,720,720);
setBackground(Color.darkGray);
setResizable(false);
setVisible(true);
add(t1);
}
public void move() {
blk.moverect();
nblk.moverect();
}
@Override
public void paint(Graphics g) {
super.paint(g);
blk.paint(g);
nblk.paint(g);
}
public static void main(String[]args)throws InterruptedException {
{
Stac rect=new Stac();
while(true)
{
rect.move();
rect.repaint();
Thread.sleep(15);
}
}
}
}
@SuppressWarnings("serial")
class Block extends JFrame{
double vel=2.0;
int x=0,w=250,h=50,y=600;
Block(){
double vel=2.0;
this.x=x;
this.y=y;
this.w=w;
this.h= h;
this.vel=vel;
}
public void moverect()
{
if(x+vel<720 && x+vel>0)
{x+=vel;
}
if(x+vel>=720-w)
{vel=vel*(-1);
x+=vel;
}
if(x+vel==0)
{vel=vel*(-1);
x+=vel;
}
}
public void nextrect()
{
y-=h;
x=0;
}
@Override
public void paint(Graphics g)
{
g.setColor(Color.RED);
g.fillRect(x,y,w,h);
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_ENTER)
{
vel = 0;
}
}
}