java学习一个月了,没有什么进展,期间又是复习Linux,又是看Android,瞻前顾后,感觉自己真的是贪得无厌,
学习的东西广而不精,所以写出的文章也就只能泛泛而谈。五一小长假,哪里都没有去,也不想去,刚刚无聊刷新了下
朋友圈,朋友们不是在玩,就是在吃,突然一下子感觉自己老了许多。岁月真是把杀猪刀,夺走了我们的青春,但却无
法夺走我们的激情。
好好复习了!
在老师引领下,算是把人生中的第一个Java项目敲完了,感觉对于学习OOP的朋友,应该有所帮助,先做个笔记吧
等后期有时间再添些自己的Feature。
package com.manue1.tetris; import javax.swing.JFrame; /** * 游戏窗口 * @author Manue1 * @version 1.0 * */ public class GameFrame extends JFrame{ private static final long serialVersionUID = 1L; private Tetris tetris; public GameFrame(){ tetris =new Tetris(); add(tetris); setSize(530,580); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); } public static void main(String[] args){ GameFrame frame =new GameFrame(); frame.setVisible(true); frame.tetris.action(); //创建4个格子 } }
1 package com.manue1.tetris; 2 3 import java.awt.image.BufferedImage; 4 5 /** 6 * 定义格子 7 * @author Manue1 8 */ 9 public class Cell extends Object{ 10 private int row; int col; 11 private BufferedImage image; 12 13 public Cell(int row, int col, BufferedImage image) { 14 super(); 15 this.row = row; 16 this.col = col; 17 this.image = image; 18 } 19 20 public int getRow() { 21 return row; 22 } 23 24 public void setRow(int row) { 25 this.row = row; 26 } 27 28 public int getCol() { 29 return col; 30 } 31 32 public void setCol(int col) { 33 this.col = col; 34 } 35 36 public BufferedImage getImage() { 37 return image; 38 } 39 40 public void setImage(BufferedImage image) { 41 this.image = image; 42 } 43 44 @Override 45 public String toString() { 46 return "Cell [col=" + col + ", image=" + image + ", row=" + row + "]"; 47 } 48 49 50 public void moveLeft(){ 51 col--; 52 } 53 public void moveRight(){ 54 col++; 55 } 56 public void moveDrop(){ 57 row++; 58 } 59 60 61 }