/* 1: */ package com.tanke;
/* 2: */
/* 3: */ import java.awt.Color;
/* 4: */ import java.awt.Graphics;
/* 5: */ import java.awt.event.KeyEvent;
/* 6: */ import java.awt.event.KeyListener;
/* 7: */ import java.util.Vector;
/* 8: */ import javax.swing.JPanel;
/* 9: */
/* 10: */ class MyPanel
/* 11: */ extends JPanel
/* 12: */ implements KeyListener, Runnable
/* 13: */ {
/* 14: 39 */ int EnemyCount = (int)(Math.random() * 30.0D);
/* 15: 40 */ Hero hero = null;
/* 16: 41 */ MyTanke mt = null;
/* 17: */ Vector enemy;
/* 18: 44 */ Vector boms = new Vector();
/* 19: */
/* 20: */ public MyPanel(MyTanke mt)
/* 21: */ {
/* 22: 47 */ this.mt = mt;
/* 23: 48 */ this.hero = new Hero(100, 100);
/* 24: 49 */ this.hero.speed = 1;
/* 25: 50 */ this.enemy = new Vector();
/* 26: 52 */ for (int i = 0; i < this.EnemyCount; i++)
/* 27: */ {
/* 28: 54 */ Enemy temp = new Enemy((int)(Math.random() * 400.0D), (int)(Math.random() * 400.0D));
/* 29: 55 */ temp.setColor(1);
/* 30: 56 */ Thread t = new Thread(temp);
/* 31: 57 */ t.start();
/* 32: 58 */ this.enemy.add(temp);
/* 33: */ }
/* 34: */ }
/* 35: */
/* 36: */ public void hit(Enemy e, Hero h)
/* 37: */ {
/* 38: 66 */ if ((h.x < e.x + 30) && (h.x > e.x - 30) && (h.y > e.y - 30) && (h.y < e.y + 30))
/* 39: */ {
/* 40: 68 */ e.isLive = false;
/* 41: 69 */ Bom b = new Bom(e.x - 15, e.y - 15);
/* 42: 70 */ Thread t = new Thread(b);
/* 43: 71 */ this.boms.add(b);
/* 44: 72 */ t.start();
/* 45: 73 */ this.enemy.remove(e);
/* 46: */ }
/* 47: */ }
/* 48: */
/* 49: */ public void hitHero(Shot s, Hero e)
/* 50: */ {
/* 51: 78 */ if ((s.x > e.x - 15) && (s.x < e.x + 15) && (s.y < e.y + 15) && (s.y > e.y - 15))
/* 52: */ {
/* 53: 80 */ s.isLive = false;
/* 54: 81 */ e.isLive = false;
/* 55: 82 */ Bom b = new Bom(e.x - 15, e.y - 15);
/* 56: 83 */ Thread t = new Thread(b);
/* 57: 84 */ t.start();
/* 58: 85 */ this.boms.add(b);
/* 59: */ }
/* 60: */ }
/* 61: */
/* 62: */ public void hitTank(Shot s, Enemy e)
/* 63: */ {
/* 64: 91 */ if ((s.x > e.x - 15) && (s.x < e.x + 15) && (s.y < e.y + 15) && (s.y > e.y - 15))
/* 65: */ {
/* 66: 94 */ if (!this.hero.isSupper) {
/* 67: 95 */ s.isLive = false;
/* 68: */ }
/* 69: 96 */ e.isLive = false;
/* 70: 97 */ Bom b = new Bom(e.x - 15, e.y - 15);
/* 71: 98 */ Thread t = new Thread(b);
/* 72: 99 */ t.start();
/* 73:100 */ this.boms.add(b);
/* 74:101 */ this.enemy.remove(e);
/* 75: */ }
/* 76: */ }
/* 77: */
/* 78: */ public void paint(Graphics g)
/* 79: */ {
/* 80:107 */ super.paint(g);
/* 81:108 */ g.setColor(Color.black);
/* 82:109 */ g.fillRect(0, 0, 400, 400);
/* 83:110 */ g.setColor(Color.blue);
/* 84:111 */ if (this.hero.isLive)
/* 85: */ {
/* 86:112 */ drawTanke(this.hero.getX(), this.hero.getY(), g, this.hero.getDirect(), 0);
/* 87: */ }
/* 88: */ else
/* 89: */ {
/* 90:114 */ g.setColor(Color.yellow);
/* 91:115 */ this.mt.removeKeyListener(this);
/* 92:116 */ this.mt.addKeyListener(new Key());
/* 93:117 */ g.drawString("英雄死亡!(ESC退出游戏)", this.hero.x + 20, this.hero.y + 20);
/* 94: */ }
/* 95:119 */ if (this.enemy.size() == 0)
/* 96: */ {
/* 97:121 */ g.setColor(Color.yellow);
/* 98:122 */ this.mt.removeKeyListener(this);
/* 99:123 */ this.mt.addKeyListener(new Key());
/* 100:124 */ g.drawString("你赢了!游戏结束(ESC退出游戏)", this.hero.x + 20, this.hero.y + 20);
/* 101: */ }
/* 102:129 */ for (int i = 0; i < this.hero.ss.size(); i++)
/* 103: */ {
/* 104:131 */ Shot myShot = (Shot)this.hero.ss.get(i);
/* 105:132 */ if ((this.hero.s != null) && (this.hero.s.isLive)) {
/* 106:134 */ switch (myShot.direct)
/* 107: */ {
/* 108: */ case 0:
/* 109:137 */ g.fill3DRect(myShot.x - 2, myShot.y, 4, 4, false);
/* 110:138 */ break;
/* 111: */ case 1:
/* 112:140 */ g.fill3DRect(myShot.x, myShot.y - 2, 4, 4, false);
/* 113:141 */ break;
/* 114: */ case 2:
/* 115:143 */ g.fill3DRect(myShot.x - 2, myShot.y, 4, 4, false);
/* 116:144 */ break;
/* 117: */ case 3:
/* 118:146 */ g.fill3DRect(myShot.x, myShot.y - 2, 4, 4, false);
/* 119: */ }
/* 120: */ }
/* 121:150 */ if (!myShot.isLive) {
/* 122:152 */ this.hero.ss.remove(myShot);
/* 123: */ }
/* 124: */ }
/* 125:156 */ for (int i = 0; i < this.boms.size(); i++)
/* 126: */ {
/* 127:158 */ Bom b = (Bom)this.boms.get(i);
/* 128:159 */ switch (b.drawIndex)
/* 129: */ {
/* 130: */ case 1:
/* 131:162 */ g.drawImage(b.image1, b.x, b.y, 30, 30, this);
/* 132:163 */ break;
/* 133: */ case 2:
/* 134:165 */ g.drawImage(b.image2, b.x, b.y, 30, 30, this);
/* 135:166 */ break;
/* 136: */ case 3:
/* 137:168 */ g.drawImage(b.image3, b.x, b.y, 30, 30, this);
/* 138: */ }
/* 139: */ }
/* 140:172 */ for (int i = 0; i < this.boms.size(); i++)
/* 141: */ {
/* 142:174 */ Bom b = (Bom)this.boms.get(i);
/* 143:175 */ if (!b.isLive) {
/* 144:177 */ this.boms.remove(b);
/* 145: */ }
/* 146: */ }
/* 147:181 */ for (int i = 0; i < this.enemy.size(); i++)
/* 148: */ {
/* 149:183 */ Enemy temp = (Enemy)this.enemy.get(i);
/* 150:184 */ if (temp.isLive) {
/* 151:186 */ drawTanke(temp.getX(), temp.getY(), g, temp.direct, 1);
/* 152: */ }
/* 153:189 */ for (int j = 0; j < temp.ss.size(); j++)
/* 154: */ {
/* 155:191 */ Shot myShot = (Shot)temp.ss.get(j);
/* 156:192 */ if ((myShot != null) && (temp.isLive)) {
/* 157:194 */ switch (myShot.direct)
/* 158: */ {
/* 159: */ case 0:
/* 160:197 */ g.fill3DRect(myShot.x - 2, myShot.y, 4, 4, false);
/* 161:198 */ break;
/* 162: */ case 1:
/* 163:200 */ g.fill3DRect(myShot.x, myShot.y - 2, 4, 4, false);
/* 164:201 */ break;
/* 165: */ case 2:
/* 166:203 */ g.fill3DRect(myShot.x - 2, myShot.y, 4, 4, false);
/* 167:204 */ break;
/* 168: */ case 3:
/* 169:206 */ g.fill3DRect(myShot.x, myShot.y - 2, 4, 4, false);
/* 170: */ }
/* 171: */ }
/* 172:210 */ if (!myShot.isLive) {
/* 173:212 */ temp.ss.remove(myShot);
/* 174: */ }
/* 175: */ }
/* 176: */ }
/* 177:217 */ String str1 = "超级模式(√)";
/* 178:218 */ String str2 = "超级模式(×)";
/* 179:219 */ g.setColor(Color.yellow);
/* 180:220 */ if (this.hero.isSupper) {
/* 181:221 */ g.drawString("Bom:" + String.valueOf(this.boms.size()) +
/* 182:222 */ ", Hero.Shot:" + String.valueOf(this.hero.ss.size()) +
/* 183:223 */ ", Enemy:" + String.valueOf(this.enemy.size()) +
/* 184: */
/* 185:225 */ ", " + str1, 10, 10);
/* 186: */ } else {
/* 187:227 */ g.drawString("Bom:" + String.valueOf(this.boms.size()) +
/* 188:228 */ ", Hero.Shot:" + String.valueOf(this.hero.ss.size()) +
/* 189:229 */ ", Enemy:" + String.valueOf(this.enemy.size()) +
/* 190:230 */ ", " + str2, 10, 10);
/* 191: */ }
/* 192: */ }
/* 193: */
/* 194: */ public void drawTanke(int x, int y, Graphics g, int direct, int type)
/* 195: */ {
/* 196:236 */ switch (type)
/* 197: */ {
/* 198: */ case 0:
/* 199:239 */ g.setColor(Color.yellow);
/* 200:240 */ break;
/* 201: */ case 1:
/* 202:242 */ g.setColor(Color.blue);
/* 203: */ }
/* 204:245 */ switch (direct)
/* 205: */ {
/* 206: */ case 0:
/* 207:249 */ g.fill3DRect(x - 15, y - 15, 5, 30, false);
/* 208:250 */ g.fill3DRect(x + 10, y - 15, 5, 30, false);
/* 209:251 */ g.fill3DRect(x - 10, y - 10, 20, 20, false);
/* 210:252 */ g.fillOval(x - 5, y - 5, 10, 10);
/* 211:253 */ g.drawLine(x, y - 20, x, y);
/* 212: */
/* 213:255 */ break;
/* 214: */ case 1:
/* 215:257 */ g.fill3DRect(x - 15, y - 15, 30, 5, false);
/* 216:258 */ g.fill3DRect(x - 15, y + 10, 30, 5, false);
/* 217:259 */ g.fill3DRect(x - 10, y - 10, 20, 20, false);
/* 218:260 */ g.fillOval(x - 5, y - 5, 10, 10);
/* 219:261 */ g.drawLine(x, y, x + 20, y);
/* 220:262 */ break;
/* 221: */ case 2:
/* 222:264 */ g.fill3DRect(x - 15, y - 15, 5, 30, false);
/* 223:265 */ g.fill3DRect(x + 10, y - 15, 5, 30, false);
/* 224:266 */ g.fill3DRect(x - 10, y - 10, 20, 20, false);
/* 225:267 */ g.fillOval(x - 5, y - 5, 10, 10);
/* 226:268 */ g.drawLine(x, y, x, y + 20);
/* 227:269 */ break;
/* 228: */ case 3:
/* 229:271 */ g.fill3DRect(x - 15, y - 15, 30, 5, false);
/* 230:272 */ g.fill3DRect(x - 15, y + 10, 30, 5, false);
/* 231:273 */ g.fill3DRect(x - 10, y - 10, 20, 20, false);
/* 232:274 */ g.fillOval(x - 5, y - 5, 10, 10);
/* 233:275 */ g.drawLine(x - 20, y, x, y);
/* 234: */ }
/* 235:278 */ repaint();
/* 236: */ }
/* 237: */
/* 238: */ public void keyPressed(KeyEvent e)
/* 239: */ {
/* 240:283 */ if (e.getKeyCode() == 87)
/* 241: */ {
/* 242:285 */ this.hero.setDirect(0);
/* 243:286 */ this.hero.moveUp();
/* 244: */ }
/* 245:287 */ else if (e.getKeyCode() == 68)
/* 246: */ {
/* 247:289 */ this.hero.setDirect(1);
/* 248:290 */ this.hero.moveRight();
/* 249: */ }
/* 250:292 */ else if (e.getKeyCode() == 83)
/* 251: */ {
/* 252:294 */ this.hero.setDirect(2);
/* 253:295 */ this.hero.moveDown();
/* 254: */ }
/* 255:297 */ else if (e.getKeyCode() == 65)
/* 256: */ {
/* 257:299 */ this.hero.setDirect(3);
/* 258:300 */ this.hero.moveLeft();
/* 259: */ }
/* 260:302 */ else if (e.getKeyCode() == 81)
/* 261: */ {
/* 262:304 */ this.hero.isSupper = (!this.hero.isSupper);
/* 263: */ }
/* 264:306 */ else if (e.getKeyCode() == 27)
/* 265: */ {
/* 266:308 */ System.exit(0);
/* 267: */ }
/* 268:310 */ else if (e.getKeyCode() == 85)
/* 269: */ {
/* 270:312 */ if (this.hero.isSupper) {
/* 271:314 */ for (int i = 0; i < this.enemy.size(); i++)
/* 272: */ {
/* 273:316 */ Enemy en = (Enemy)this.enemy.get(i);
/* 274:317 */ Bom b = new Bom(en.x, en.y);
/* 275:318 */ Thread t = new Thread(b);
/* 276:319 */ t.start();
/* 277:320 */ this.boms.add(b);
/* 278:321 */ this.enemy.remove(en);
/* 279: */ }
/* 280: */ }
/* 281: */ }
/* 282:327 */ if (e.getKeyCode() == 74) {
/* 283:329 */ if (this.hero.isSupper) {
/* 284:330 */ this.hero.shotEnemy();
/* 285:332 */ } else if (this.hero.ss.size() < 5) {
/* 286:333 */ this.hero.shotEnemy();
/* 287: */ }
/* 288: */ }
/* 289:336 */ repaint();
/* 290: */ }
/* 291: */
/* 292: */ public void keyReleased(KeyEvent e) {}
/* 293: */
/* 294: */ public void keyTyped(KeyEvent e) {}
/* 295: */
/* 296: */ public void run()
/* 297: */ {
/* 298: */ for (;;)
/* 299: */ {
/* 300: */ try
/* 301: */ {
/* 302:355 */ Thread.sleep(100L);
/* 303: */ }
/* 304: */ catch (InterruptedException e)
/* 305: */ {
/* 306:358 */ e.printStackTrace();
/* 307: */ }
/* 308:362 */ for (int i = 0; i < this.hero.ss.size(); i++)
/* 309: */ {
/* 310:364 */ Shot myShot = (Shot)this.hero.ss.get(i);
/* 311:365 */ if (myShot.isLive) {
/* 312:367 */ for (int j = 0; j < this.enemy.size(); j++)
/* 313: */ {
/* 314:369 */ Enemy e = (Enemy)this.enemy.get(j);
/* 315:370 */ if (e.isLive) {
/* 316:372 */ hitTank(myShot, e);
/* 317: */ }
/* 318: */ }
/* 319: */ }
/* 320: */ }
/* 321:378 */ for (int i = 0; i < this.enemy.size(); i++)
/* 322: */ {
/* 323:380 */ Enemy e = (Enemy)this.enemy.get(i);
/* 324:381 */ for (int j = 0; j < e.ss.size(); j++)
/* 325: */ {
/* 326:383 */ Shot s = (Shot)e.ss.get(j);
/* 327:384 */ if (!this.hero.isSupper) {
/* 328:385 */ hitHero(s, this.hero);
/* 329: */ }
/* 330: */ }
/* 331: */ }
/* 332:388 */ if (this.hero.isSupper) {
/* 333:389 */ for (int i = 0; i < this.enemy.size(); i++)
/* 334: */ {
/* 335:391 */ Enemy e = (Enemy)this.enemy.get(i);
/* 336:392 */ hit(e, this.hero);
/* 337: */ }
/* 338: */ }
/* 339:394 */ repaint();
/* 340: */ }
/* 341: */ }
/* 342: */ }
/* Location: C:\Users\Cheese\Desktop\坦克大战\坦克大战.jar
* Qualified Name: com.tanke.MyPanel
* JD-Core Version: 0.7.0.1
*/
一键复制
编辑
Web IDE
原始数据
按行查看
历史