java贪吃蛇课程设计知乎_Java课程设计---贪吃蛇大作战
目錄
一、團隊課程設計博客鏈接
二、個人負責模塊和任務說明
1.負責實現闖關模式
2.負責實現挑戰模式
3.串聯GUI與信息代碼
4.實現排行榜功能
三、自己的代碼提交記錄截圖
四、自己負責模塊或任務詳細說明
這是挑戰模式的時間線程
this.thread = new Thread(() ->{while(start) {if (count == 0)
{break;
}if (!pause) {
count--;
initText();
}try{
Thread.sleep(SECOND);
}catch(InterruptedException e) {
e.printStackTrace();
}
}
count= 0;
});
游戲面板的重繪方法覆寫
public void paint(Graphics g) {
clearDraw(g);
if(ground != null&&snake!=null&&food!=null) {
ground.drawMe(g);
food.drawMe(g);
snake.drawMe(g);
}
if(snake!=null&& !snake.isLife()) {
recover(g);
}
}
啟動游戲
public void newGame() {
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
ground.clear();
ground.generateRocks();
food.newFood(ground.getPoint());
buttonPanel.getMapLevLabel().setText("");
buttonPanel.getMapLevLabel().setText(""+ground.getMapType());
snake.setSleepTime(100);
buttonPanel.setScore(0);
buttonPanel.repaint();
}
游戲結束核算成績的彈窗
public void calculate() {
String s ="您的成績為:最終關卡:"+ground.getMapType()+" 最終得分"+snake.getFoodCount();
SkipFrame2 skipFrame = new SkipFrame2();
skipFrame.getLabel().setBounds(100,50,600,40);
int flag=information.compare1(ground.getMapType(), snake.getFoodCount());
skipFrame.getLabel().setText(s);
if(flag>0) {
skipFrame.successful();
skipFrame.visible();
skipFrame.getButton().addActionListener(e -> {
String name=skipFrame.getNameText().getText();
skipFrame.shutdown();
information.addList1(flag, name, ground.getMapType(), snake.getFoodCount());
});
}else {
skipFrame.visible();
skipFrame.getButton().addActionListener(e -> skipFrame.shutdown());
}
}
五、課程設計感想
經過這次的課程設計,讓我對多線程以及面向對象編程有了更加深刻的理解,并且感受到了團隊合作的重要性,Java通常是要團隊分工進行的,所以一些命名的規范,接口之類的就變得非常重要了,此次課程設計也讓我對java編程有了更深一層的掌握,并且對游戲的創作有了一點了解。
總結
以上是生活随笔為你收集整理的java贪吃蛇课程设计知乎_Java课程设计---贪吃蛇大作战的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sip pbx_PBX免费CRM
- 下一篇: 集群环境下,谁偷走quartz配置的定时