国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務器之家 - 編程語言 - Java教程 - java實現Flappy Bird游戲源代碼

java實現Flappy Bird游戲源代碼

2021-06-24 10:11Koma_Wong Java教程

這篇文章主要為大家詳細介紹了java實現Flappy Bird游戲源代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java實現flappy bird游戲的具體代碼,供大家參考,具體內容如下

?
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
2017/7/23
*/
 
import java.awt.graphics;
//import java.util.timer;
import java.awt.event.actionevent;
import java.awt.event.actionlistener;
import java.awt.event.mouselistener;
import java.awt.event.mouseevent;
import java.awt.event.keylistener;
import java.awt.event.keyevent;
import java.awt.rectangle;
import java.awt.*;
 
import java.util.*;
 
import javax.swing.jframe;
import javax.swing.timer;
import javax.swing.*;
 
 
import javax.swing.jpanel;
 
class renderer extends jpanel
{
 
 private static final long serialversionuid = 1l;
 
 protected void paintcomponent(graphics g)
 {
 super.paintcomponent(g);
 
 flappybird.flappybird.repaint(g);
 }
 
}
public class flappybird implements actionlistener, mouselistener, keylistener
{
 public static flappybird flappybird;
 
 public final int width = 900, height = 800;
 
 public renderer renderer;
 
 public rectangle bird;
 
 public arraylist<rectangle> columns;
 
 public int ticks, ymotion, score;
 
 public boolean gameover, started;
 
 public random rand;
 
 public flappybird()
 {
 jframe jframe = new jframe();
 timer timer = new timer(20,this);
 
 renderer = new renderer();
 rand = new random();
 
 jframe.add(renderer);
 jframe.settitle("flappy bird");
 jframe.setdefaultcloseoperation(jframe.exit_on_close);
 jframe.setsize(width,height);
 jframe.addmouselistener(this);
 jframe.addkeylistener(this);
 jframe.setresizable(false);
 jframe.setvisible(true);
 
 bird = new rectangle(width / 2 - 10, height / 2 - 10, 20, 20);
 
 columns = new arraylist<rectangle>();
 
 addcolumn(true);
 addcolumn(true);
 addcolumn(true);
 addcolumn(true);
 
 timer.start();
 }
 
 public void addcolumn(boolean start)
 {
 int space = 300;
 int width = 100;
 int height = 50 + rand.nextint(300);
 
 if(start)
 {
 columns.add(new rectangle(width + width + columns.size() * 300, height - height - 120, width, height));
 columns.add(new rectangle(width + width + (columns.size()-1)*300, 0, width, height - height - space));
 }
 else
 {
 columns.add(new rectangle(columns.get(columns.size() - 1).x + 600, height - height - 120, width, height));
 columns.add(new rectangle(columns.get(columns.size() - 1).x , 0, width, height - height - space));
 }
 
 }
 
 public void paintcolumn(graphics g, rectangle column)
 {
 g.setcolor(color.green.darker());
 g.fillrect(column.x, column.y, column.width, column.height);
 }
 
 public void jump()
 {
 if (gameover)
 {
 bird = new rectangle(width / 2 - 10, height / 2 - 10, 20, 20);
 
 columns.clear();
 
 ymotion = 0;
 score = 0;
 
 addcolumn(true);
 addcolumn(true);
 addcolumn(true);
 addcolumn(true);
 
 gameover = false;
 }
 
 if(!started)
 {
 started = true;
 }
 else if(!gameover)
 {
 if(ymotion > 0)
 {
 ymotion = 0;
 }
 
 ymotion -= 10;
 }
 }
 
 public void actionperformed(actionevent e)
 {
 
 int speed = 10;
 
 ticks++;
 
 if(started )
 {
 for( int i = 0; i < columns.size(); i++)
 {
 rectangle column = columns.get(i);
 
 column.x -= speed;
 }
 
 if(ticks % 2 ==0 && ymotion < 15)
 {
 ymotion += 2;
 }
 
 for (int i = 0; i < columns.size(); i++)
 {
 rectangle column = columns.get(i);
 
 if (column.x + column.width < 0)
 {
  columns.remove(column);
  if(column.y ==0)
  {
  addcolumn(false);
  }
 }
 }
 
 bird.y += ymotion;
 
 for(rectangle column : columns)
 {
 if(bird.x + bird.width / 2 > column.x + column.width / 2 - 5
 && bird.x + bird.width / 2 < column.x + column.width / 2 + 5
 && column.y == 0)
 {
  score++;
 }
 
 if(column.intersects(bird))
 {
  gameover = true;
 
  if(bird.x <= column.x)
  {
  bird.x = column.x - bird.width;
  }
  else
  {
  if(column.y != 0)
  {
  bird.y = column.y - bird.height;
  }
  else if(bird.y < column.height)
  {
  bird.y = column.height;
  }
  }
 }
 }
 
 if(bird.y > height - 120 || bird.y < 0 )
 {
 gameover = true;
 }
 
 if(bird.y + ymotion >= height -120)//(gameover)
 {
 bird.y = height -120 - bird.height;
 }
 }
 renderer.repaint();
 }
 
 public void repaint(graphics g)
 {
 //system.out.println("hello");
 g.setcolor(color.cyan);
 g.fillrect(0,0,width,height);
 
 g.setcolor(color.orange);
 g.fillrect(0, height - 120, width, 150);
 
 g.setcolor(color.green);
 g.fillrect(0, height - 120, width, 20);
 
 g.setcolor(color.red);
 g.fillrect(bird.x, bird.y, bird.width, bird.height);
 
 for ( rectangle column : columns )
 {
 paintcolumn(g,column);
 }
 
 g.setcolor(color.white);
 g.setfont(new font("arial",1,70));
 
 if(!started)
 {
 g.drawstring("click to start!",90,height / 2-50);
 }
 
 if(gameover)
 {
 g.drawstring("game over! you suck!",40,height / 2-50);
 }
 
 if(!gameover && started)
 {
 g.drawstring(string.valueof(score), width / 2, 100);
 }
 }
 
 public static void main(string[]args)
 {
 flappybird = new flappybird();
 }
 
 public void mouseclicked(mouseevent e)
 {
 jump();
 }
 public void mousepressed(mouseevent e){}
 public void mousereleased(mouseevent e){}
 public void mouseentered(mouseevent e){}
 public void mouseexited(mouseevent e){}
 
 public void keypressed(keyevent e){}
 public void keytyped(keyevent e){}
 public void keyreleased(keyevent e)
 {
 if(e.getkeycode() == keyevent.vk_space)
 {
 jump();
 }
 }
 
}

效果圖:

java實現Flappy Bird游戲源代碼

java實現Flappy Bird游戲源代碼

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/Rong_Toa/article/details/78118064

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久丁香视频 | 精品国产一区二区在线 | 在线观看中文字幕亚洲 | 国产高清精品在线 | 久久综合九九 | 日韩美女乱淫aaa高清视频 | 久热免费在线观看 | 国产精品二区一区二区aⅴ污介绍 | 香蕉影院在线观看 | 亚洲第十页 | 久久国产精品二区 | 最近免费中文字幕大全免费版视频 | 日韩欧美一区二区三 | 国产韩国精品一区二区三区 | 国产成人精品一区二区三区福利 | 精品国产一区二区在线 | 狠狠久久综合 | 色中色av| 欧美黄网站 | 在线视频 中文字幕 | 亚洲二区在线 | 青青久视频 | 日韩中文字幕在线观看 | 免费成人在线观看 | 成人高清视频在线观看 | 久久av综合 | 国产精品欧美一区二区三区 | 亚洲精品一区二区三区蜜桃久 | 色播久久| 国产成人自拍视频在线观看 | 99色综合 | 国产在线资源 | 欧美日韩视频在线 | 欧美国产日韩在线 | 欧美激情亚洲 | 这里只有精品在线视频观看 | 欧美日韩国产高清 | 日韩精品久久久 | 久久亚 | 国产高清免费视频 | 成人av入口 |