Coder Social home page Coder Social logo

snakejava's Introduction

贪吃蛇

1. 简要介绍

这是大一的时候 Java 选修课学习 Swing GUI 的时候心血来潮写的一个简单的图形界面程序。

这个程序实现的功能相当简单,就是一个贪吃蛇程序,没有四周的墙壁,吃掉一个豆子涨10分。再启动以后可以记录最高分,激励玩家继续前进。

2. 存在的问题

大一的时候技术不行(似乎现在也是。。。)有很多显然的 Bug 和可以改进的点。

  1. 最高分记录在关闭游戏后会再下次开启游戏后丢失。这是因为我们没有持久化存储最高分;如果想解决的话,可以将最高分写到一个文件里;
  2. 有可能在一格里同时进行 3 个操作,导致自己"吃了"自己的头,这是因为一帧的时间里键盘可能监听到我们的多个操作,我做了判定阻止一些"自杀"的操作,但还是有"自杀"的情况出现。这个 Bug 很难出现,我不太会解决;
  3. 因为效率的原因,生成的果实有可能生成在蛇身体的路径上。这个我初步想的是可以遍历,或者改一下地图的"块"的数据结构,比如改成 set;
  4. 有时候开局就会死掉(玩了可能有几百把只遇到一次);

3. 如何运行

首先,确保自己本机环境的 JDK 版本大于等于 1.8。

main 方法在 StartGames 类中,用 IDE 打开项目即可。

可以自己将其打包,理论上打包的 jar 文件可以在任何有 JDK 上的机器上运行,但是我在 Windows 上生成的 jar 在 Ubuntu 上无法运行。我也不知道为什么🤔

4. 最后

有问题就 issue,有大佬愿意 PR 就更好了。回首大学三年,自己做过一些什么有意义的事情。可能这算一小件🤔

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.