收藏 分享(赏)

俄罗斯方块.doc

上传人:kpmy5893 文档编号:9197234 上传时间:2019-07-29 格式:DOC 页数:19 大小:108.50KB
下载 相关 举报
俄罗斯方块.doc_第1页
第1页 / 共19页
俄罗斯方块.doc_第2页
第2页 / 共19页
俄罗斯方块.doc_第3页
第3页 / 共19页
俄罗斯方块.doc_第4页
第4页 / 共19页
俄罗斯方块.doc_第5页
第5页 / 共19页
点击查看更多>>
资源描述

1、1 俄罗斯方块2 package org.loon.game.test; 3 import java.awt.Graphics2D; 4 import java.awt.Image; 5 /* 6 * 7 * Copyright 2008 - 2009 8 * 9 * Licensed under the Apache License, Version 2.0 (the “License“); you may not 10 * use this file except in compliance with the License. You may obtain a copy of 11 * t

2、he License at 12 * 13 * http:/www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an “AS IS“ BASIS, WITHOUT 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

3、 18 * License for the specific language governing permissions and limitations under 19 * the License. 20 * 21 * project loonframework 22 * author chenpeng 23 * email: 24 * version 0.1 25 */ 26 public class TetrisField 27 private Block stoneCurrent; 28 private Block stoneNext; 29 private int stonePos

4、ition; 30 private int gameFieldStones; 31 private int curLines = 0, curLevel = 1, curPoints = 0, row, col; 32 private boolean gameOver = false; 33 public TetrisField(int row, int col) 34 int i = 0; 35 int j = 0; 36 this.row = row; 37 this.col = col; 38 stonePosition = new int42; 39 gameFieldStones =

5、 new introwcol; 40 for (i = 0; i 3) 89 canStart = 1; 90 91 92 if (canStart = 1 | isThread) 93 for (i = 0; i 3) 113 canStart = 1; 114 115 116 if (canStart = 1) 117 for (i = 0; i 3) 134 canStart = 1; 135 136 137 if (canStart = 1) 138 for (i = 0; i 0) 198 int TempGameField = new introwcol; 199 int sum

6、= 0; 200 curLines += Quantity; 201 curLevel = Math.round(curLines / row) + 1; 202 /最大等级为 20 203 if (curLevel 20) 204 curLevel = 20; 205 206 curPoints += Math.pow(row * curLevel), Quantity); 207 for (i = col - 1; i 3; i-) 208 for (j = 0; j row; j+) 209 isLine = true; 210 if (gameFieldStonesji = 0) 21

7、1 isLine = false; 212 break; 213 214 215 if (isLine = false) 216 for (j = 0; j row; j+) 217 TempGameFieldji + sum = gameFieldStonesji; 218 219 else 220 sum+; 221 222 223 for (i = 0; i 4; i+) 224 for (j = 0; j row; j+) 225 TempGameFieldji = gameFieldStonesji; 226 227 228 gameFieldStones = TempGameFie

8、ld; 229 return true; 230 else 231 return false; 232 233 234 public int getStonePosition() 235 return gameFieldStones; 236 237 public void draw(Graphics2D g, Image stones) 238 int nextStone = getNextStone(); 239 switch (nextStone) 240 case 1: 241 g.drawImage(stones1, 240, 60, null); 242 g.drawImage(s

9、tones1, 260, 60, null); 243 g.drawImage(stones1, 240, 80, null); 244 g.drawImage(stones1, 260, 80, null); 245 break; 246 case 2: 247 g.drawImage(stones2, 220, 70, null); 248 g.drawImage(stones2, 240, 70, null); 249 g.drawImage(stones2, 260, 70, null); 250 g.drawImage(stones2, 280, 70, null); 251 bre

10、ak; 252 case 3: 253 g.drawImage(stones3, 250, 60, null); 254 g.drawImage(stones3, 230, 80, null); 255 g.drawImage(stones3, 250, 80, null); 256 g.drawImage(stones3, 270, 80, null); 257 break; 258 case 4: 259 g.drawImage(stones4, 270, 60, null); 260 g.drawImage(stones4, 230, 80, null); 261 g.drawImage

11、(stones4, 250, 80, null); 262 g.drawImage(stones4, 270, 80, null); 263 break; 264 case 5: 265 g.drawImage(stones5, 230, 60, null); 266 g.drawImage(stones5, 230, 80, null); 267 g.drawImage(stones5, 250, 80, null); 268 g.drawImage(stones5, 270, 80, null); 269 break; 270 case 6: 271 g.drawImage(stones6

12、, 230, 60, null); 272 g.drawImage(stones6, 250, 60, null); 273 g.drawImage(stones6, 250, 80, null); 274 g.drawImage(stones6, 270, 80, null); 275 break; 276 case 7: 277 g.drawImage(stones7, 250, 60, null); 278 g.drawImage(stones7, 270, 60, null); 279 g.drawImage(stones7, 230, 80, null); 280 g.drawIma

13、ge(stones7, 250, 80, null); 281 break; 282 283 284 public int getNextStone() 285 if (stoneNext = null) 286 stoneNext = new Block(int) Math.round(Math.random() * 6) + 1); 287 288 return stoneNext.getBlockID(); 289 290 public int getLines() 291 return curLines; 292 293 public int getLevel() 294 return

14、 curLevel; 295 296 public int getPoints() 297 return curPoints; 298 299 public boolean isGameOver() 300 return gameOver; 301 302 class Block 303 private int blockID; 304 private int startPosition = new int42; 305 private int rotatePosition = 0; 306 public Block(int blockID) 307 setBlockID(blockID);

15、308 createStone(); 309 310 private void createStone() 311 switch (blockID) 312 case 1: 313 startPosition00 = 4; 314 startPosition01 = 2; 315 startPosition10 = 5; 316 startPosition11 = 2; 317 startPosition20 = 4; 318 startPosition21 = 3; 319 startPosition30 = 5; 320 startPosition31 = 3; 321 break; 32

16、2 case 2: 323 startPosition00 = 5; 324 startPosition01 = 0; 325 startPosition10 = 5; 326 startPosition11 = 1; 327 startPosition20 = 5; 328 startPosition21 = 2; 329 startPosition30 = 5; 330 startPosition31 = 3; 331 break; 332 case 3: 333 startPosition00 = 5; 334 startPosition01 = 2; 335 startPosition

17、10 = 4; 336 startPosition11 = 3; 337 startPosition20 = 5; 338 startPosition21 = 3; 339 startPosition30 = 6; 340 startPosition31 = 3; 341 break; 342 case 4: 343 startPosition00 = 4; 344 startPosition01 = 1; 345 startPosition10 = 4; 346 startPosition11 = 2; 347 startPosition20 = 4; 348 startPosition21

18、 = 3; 349 startPosition30 = 5; 350 startPosition31 = 3; 351 break; 352 case 5: 353 startPosition00 = 5; 354 startPosition01 = 1; 355 startPosition10 = 5; 356 startPosition11 = 2; 357 startPosition20 = 5; 358 startPosition21 = 3; 359 startPosition30 = 4; 360 startPosition31 = 3; 361 break; 362 case 6

19、: 363 startPosition00 = 5; 364 startPosition01 = 1; 365 startPosition10 = 4; 366 startPosition11 = 2; 367 startPosition20 = 5; 368 startPosition21 = 2; 369 startPosition30 = 4; 370 startPosition31 = 3; 371 break; 372 case 7: 373 startPosition00 = 4; 374 startPosition01 = 1; 375 startPosition10 = 4;

20、376 startPosition11 = 2; 377 startPosition20 = 5; 378 startPosition21 = 2; 379 startPosition30 = 5; 380 startPosition31 = 3; 381 break; 382 383 384 public int rotateStone(int currentPosition) 385 int newPosition = new int42; 386 int x, y; 387 switch (blockID) 388 case 2: 389 if (rotatePosition = 0)

21、390 x = currentPosition30; 391 y = currentPosition31; 392 newPosition00 = x - 3; 393 newPosition01 = y; 394 newPosition10 = x - 2; 395 newPosition11 = y; 396 newPosition20 = x - 1; 397 newPosition21 = y; 398 newPosition30 = x; 399 newPosition31 = y; 400 rotatePosition = 1; 401 else 402 x = currentPo

22、sition30; 403 y = currentPosition31; 404 newPosition00 = x; 405 newPosition01 = y - 3; 406 newPosition10 = x; 407 newPosition11 = y - 2; 408 newPosition20 = x; 409 newPosition21 = y - 1; 410 newPosition30 = x; 411 newPosition31 = y; 412 rotatePosition = 0; 413 414 return newPosition; 415 case 3: 416

23、 if (rotatePosition = 0) 417 x = currentPosition20; 418 y = currentPosition21; 419 newPosition00 = x; 420 newPosition01 = y - 1; 421 newPosition10 = x; 422 newPosition11 = y + 1; 423 newPosition20 = x; 424 newPosition21 = y; 425 newPosition30 = x + 1; 426 newPosition31 = y; 427 rotatePosition = 1; 4

24、28 else if (rotatePosition = 1) 429 x = currentPosition20; 430 y = currentPosition21; 431 newPosition00 = x; 432 newPosition01 = y + 1; 433 newPosition10 = x - 1; 434 newPosition11 = y; 435 newPosition20 = x; 436 newPosition21 = y; 437 newPosition30 = x + 1; 438 newPosition31 = y; 439 rotatePosition

25、 = 2; 440 else if (rotatePosition = 2) 441 x = currentPosition20; 442 y = currentPosition21; 443 newPosition00 = x; 444 newPosition01 = y - 1; 445 newPosition10 = x - 1; 446 newPosition11 = y; 447 newPosition20 = x; 448 newPosition21 = y; 449 newPosition30 = x; 450 newPosition31 = y + 1; 451 rotateP

26、osition = 3; 452 else if (rotatePosition = 3) 453 x = currentPosition20; 454 y = currentPosition21; 455 newPosition00 = x - 1; 456 newPosition01 = y; 457 newPosition10 = x + 1; 458 newPosition11 = y; 459 newPosition20 = x; 460 newPosition21 = y; 461 newPosition30 = x; 462 newPosition31 = y - 1; 463

27、rotatePosition = 0; 464 465 return newPosition; 466 case 4: 467 if (rotatePosition = 0) 468 x = currentPosition20; 469 y = currentPosition21; 470 newPosition00 = x; 471 newPosition01 = y; 472 newPosition10 = x + 1; 473 newPosition11 = y; 474 newPosition20 = x + 2; 475 newPosition21 = y; 476 newPosit

28、ion30 = x + 2; 477 newPosition31 = y - 1; 478 rotatePosition = 1; 479 else if (rotatePosition = 1) 480 x = currentPosition20; 481 y = currentPosition21; 482 newPosition00 = x - 1; 483 newPosition01 = y - 2; 484 newPosition10 = x; 485 newPosition11 = y - 2; 486 newPosition20 = x; 487 newPosition21 =

29、y - 1; 488 newPosition30 = x; 489 newPosition31 = y; 490 rotatePosition = 2; 491 else if (rotatePosition = 2) 492 x = currentPosition10; 493 y = currentPosition11; 494 newPosition00 = x - 2; 495 newPosition01 = y + 1; 496 newPosition10 = x - 2; 497 newPosition11 = y; 498 newPosition20 = x - 1; 499 n

30、ewPosition21 = y; 500 newPosition30 = x; 501 newPosition31 = y; 502 rotatePosition = 3; 503 else if (rotatePosition = 3) 504 x = currentPosition10; 505 y = currentPosition11; 506 newPosition00 = x; 507 newPosition01 = y; 508 newPosition10 = x; 509 newPosition11 = y + 1; 510 newPosition20 = x; 511 ne

31、wPosition21 = y + 2; 512 newPosition30 = x + 1; 513 newPosition31 = y + 2; 514 rotatePosition = 0; 515 516 return newPosition; 517 case 5: 518 if (rotatePosition = 0) 519 x = currentPosition10; 520 y = currentPosition11; 521 newPosition00 = x - 2; 522 newPosition01 = y - 1; 523 newPosition10 = x - 1

32、; 524 newPosition11 = y - 1; 525 newPosition20 = x; 526 newPosition21 = y - 1; 527 newPosition30 = x; 528 newPosition31 = y; 529 rotatePosition = 1; 530 else if (rotatePosition = 1) 531 x = currentPosition00; 532 y = currentPosition01; 533 newPosition00 = x; 534 newPosition01 = y; 535 newPosition10

33、= x + 1; 536 newPosition11 = y; 537 newPosition20 = x; 538 newPosition21 = y + 1; 539 newPosition30 = x; 540 newPosition31 = y + 2; 541 rotatePosition = 2; 542 else if (rotatePosition = 2) 543 x = currentPosition20; 544 y = currentPosition21; 545 newPosition00 = x; 546 newPosition01 = y; 547 newPosi

34、tion10 = x; 548 newPosition11 = y + 1; 549 newPosition20 = x + 1; 550 newPosition21 = y + 1; 551 newPosition30 = x + 2; 552 newPosition31 = y + 1; 553 rotatePosition = 3; 554 else if (rotatePosition = 3) 555 x = currentPosition20; 556 y = currentPosition21; 557 newPosition00 = x; 558 newPosition01 = y; 559 newPosition10 = x + 1; 560 newPosition11 = y; 561 newPosition20 = x + 1; 562 newPosition21 = y - 1; 563 newPosition30 = x + 1; 564 newPosition31 = y - 2; 565 rotatePosition = 0

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报