其次,如果不是手机本身的原因,那就可能是游戏本身的原因,由于每次更新,会增加很多新内容,所以游戏变得越来越大,而游戏的服务器负担过重,于是卡顿就更明显了,这个问题的解决办法,就只有等官方自己去解决,优化游戏环境啦。//package main;
import javaawtColor;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaawteventKeyEvent;
import javaawteventKeyListener;
import javaawteventWindowAdapter;
import javaawteventWindowEvent;
import javaioBufferedReader;
import javaioFileInputStream;
import javaioFileOutputStream;
import javaioInputStreamReader;
import javaxswingImageIcon;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJMenu;
import javaxswingJMenuBar;
import javaxswingJMenuItem;
import javaxswingJOptionPane;
import javaxswingJPanel;
public class TanChiShe implements KeyListener,ActionListener{
/
@param args
/
int max = 300;//蛇长最大值
final int JianJu = 15; //设定蛇的运动网格间距(窗口最大3228格)
byte fangXiang = 4; //控制蛇的运动方向,初始为右
int time = 500; //蛇的运动间隔时间
int jianTime = 2;//吃一个减少的时间
int x,y;//蛇的运动坐标,按网格来算
int x2,y2;//暂存蛇头的坐标
int jiFenQi = 0;//积分器
boolean isRuned = false;//没运行才可设级别
boolean out = false;//没开始运行
boolean run = false;//暂停运行
String JiBie = "中级";
JFrame f = new JFrame("贪吃蛇 V10");
JPanel show = new JPanel();
JLabel Message = new JLabel("级别:中级 蛇长:5 时间500ms 分数:00");
// JButton play = new JButton("开始");
JLabel sheTou;
JLabel shiWu;
JLabel sheWei[] = new JLabel[max];
static int diJi = 4; //第几个下标的蛇尾要被加上
ImageIcon shang = new ImageIcon("tuPian\\isSheTouUppng");//产生四个上下左右的蛇头图案
ImageIcon xia = new ImageIcon("tuPian\\isSheTouDownpng");
ImageIcon zhuo = new ImageIcon("tuPian\\isSheTouLeftpng");
ImageIcon you = new ImageIcon("tuPian\\isSheTouRightpng");
JMenuBar JMB = new JMenuBar();
JMenu file = new JMenu("开始游戏");
JMenuItem play = new JMenuItem(" 开始游戏 ");
JMenuItem pause = new JMenuItem(" 暂停游戏 ");
JMenu hard = new JMenu("游戏难度");
JMenuItem gao = new JMenuItem("高级");
JMenuItem zhong = new JMenuItem("中级");
JMenuItem di = new JMenuItem("低级");
JMenu about = new JMenu(" 关于 ");
JMenuItem GF = new JMenuItem("※高分榜");
JMenuItem ZZ = new JMenuItem("关于作者");
JMenuItem YX = new JMenuItem("关于游戏");
JMenuItem QK = new JMenuItem("清空记录");
static TanChiShe tcs = new TanChiShe();
public static void main(String[] args) {
// TanChiShe tcs = new TanChiShe();
tcsf();
}
public void f(){
fsetBounds(250,100,515,530);
fsetLayout(null);
fsetAlwaysOnTop(true);//窗口始终保持最前面
fsetBackground(new Color(0,0,0));
fsetDefaultCloseOperation(0);
fsetResizable(false);
fsetVisible(true);
// fgetContentPane()setBackground(ColorBLACK);
faddWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
Systemexit(0);//退出程序
}
});
fsetJMenuBar(JMB);
JMBadd(file);
fileadd(play);
fileadd(pause);
JMBadd(hard);
hardadd(gao);
hardadd(zhong);
hardadd(di);
JMBadd(about);
aboutadd(GF);
GFsetForeground(Colorblue);
aboutadd(ZZ);
aboutadd(YX);
aboutadd(QK);
QKsetForeground(Colorred);
fadd(show);
showsetBounds(0,fgetHeight()-92,fgetWidth(),35);
// showsetBackground(Colorgreen);
// fadd(play);
// playsetBounds(240,240,80,25);
playaddActionListener(this);
pauseaddActionListener(this);
gaoaddActionListener(this);
zhongaddActionListener(this);
diaddActionListener(this);
GFaddActionListener(this);
ZZaddActionListener(this);
YXaddActionListener(this);
QKaddActionListener(this);
showadd(Message);
MessagesetForeground(Colorblue);
faddKeyListener(this);
// showaddKeyListener(this);
playaddKeyListener(this);
sheChuShi();
}
public void sheChuShi(){//蛇初始化
sheTou = new JLabel(you);//用向右的图来初始蛇头
fadd(sheTou);
sheTousetBounds(JianJu0,JianJu0,JianJu,JianJu);
// Systemoutprintln("ishere");
shiWu = new JLabel("■");
fadd(shiWu);
shiWusetBounds(10JianJu,10JianJu,JianJu,JianJu);
for(int i=0;i<=diJi;i++) {
sheWei[i] = new JLabel("■");
fadd(sheWei[i]);
sheWei[i]setBounds(-1JianJu,0JianJu,JianJu,JianJu);
}
while(true){
if(out == true){
yunXing();
break;
}
try{
Threadsleep(200);
}catch(Exception ex){
exprintStackTrace();
}
}
}
public void sheJiaChang(){//蛇的长度增加
if(diJi < max){
sheWei[++diJi] = new JLabel(new ImageIcon("tuPian\\isSheWeijpg"));
fadd(sheWei[diJi]);
sheWei[diJi]setBounds(sheWei[diJi-1]getX(),sheWei[diJi-1]getY(),JianJu,JianJu);
// Systemoutprintln("diJi "+diJi);
}
}
public void pengZhuanJianCe(){//检测蛇的碰撞情况
if(sheTougetX()<0 || sheTougetY()<0 ||
sheTougetX()>fgetWidth()-15 || sheTougetY()>fgetHeight()-105 ){
gameOver();
// Systemoutprintln("GameOVER");
}
if(sheTougetX() == shiWugetX() && sheTougetY() == shiWugetY()){
out: while(true){
shiWusetLocation((int)(Mathrandom()32)JianJu,(int)(Mathrandom()28)JianJu);
for(int i=0;i<=diJi;i++){
if(shiWugetX()!= sheWei[i]getX() && shiWugetY()!=sheWei[i]getY()
&& sheTougetX()!=shiWugetX() && sheTougetY()!= shiWugetY()){//如果食物不在蛇身上则退出循环,产生食物成功
break out;
}
}
}
sheJiaChang();
// Systemoutprintln("吃了一个");
if(time>100 ){
time -= jianTime;
}
else{}
MessagesetText("级别:"+JiBie+" 蛇长:"+(diJi+2)+" 时间:"+time+"ms 分数:"+(jiFenQi+=10)+"");
}
for(int i=0;i<=diJi;i++){
if(sheTougetX() == sheWei[i]getX() && sheTougetY() == sheWei[i]getY()){
gameOver();
// Systemoutprintln("吃到尾巴了");
}
}
}
public void yunXing(){
while(true){
while(run){
if(fangXiang == 1){//上
y-=1;
}
if(fangXiang == 2){//下
y+=1;
}
if(fangXiang == 3){//左
x-=1;
}
if(fangXiang == 4){//右
x+=1;
}
x2 = sheTougetX();
y2 = sheTougetY();
sheTousetLocation(xJianJu,yJianJu); //设置蛇头的坐标 网格数间隔
for(int i=diJi;i>=0;i--){
if(i==0){
sheWei[i]setLocation(x2,y2);
// Systemoutprintln(i+" "+sheTougetX()+" "+sheTougetY());
}
else{
sheWei[i]setLocation(sheWei[i-1]getX(),sheWei[i-1]getY());
// Systemoutprintln(i+" "+sheWei[i]getX()+" "+sheWei[i]getY());
}
}
pengZhuanJianCe();
try{
Threadsleep(time);
}catch(Exception e){
eprintStackTrace();
}
}
MessagesetText("级别:"+JiBie+" 蛇长:"+(diJi+2)+" 时间:"+time+"ms 分数:"+(jiFenQi+=10)+"");
try{
Threadsleep(200);
}catch(Exception e){
eprintStackTrace();
}
}
}
public void gameOver(){//游戏结束时处理
int in = JOptionPaneshowConfirmDialog(f,"游戏已经结束!\n是否要保存分数","提示",JOptionPaneYES_NO_OPTION);
if(in == JOptionPaneYES_OPTION){
// Systemoutprintln("YES");
String s = JOptionPaneshowInputDialog(f,"输入你的名字:");
try{
FileInputStream fis = new FileInputStream("GaoFenini");//先把以前的数据读出来加到写的数据前
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
String s2,setOut = "";
while((s2=brreadLine())!= null){
setOut =setOut+s2+"\n";
}
FileOutputStream fos = new FileOutputStream("GaoFenini");//输出到文件流
s = setOut+s+":"+jiFenQi+"\n";
foswrite(sgetBytes());
}catch(Exception e){}
}
Systemexit(0);
}
public void keyTyped(KeyEvent arg0) {
// TODO 自动生成方法存根
}
public void keyPressed(KeyEvent arg0) {
// Systemoutprintln(arg0getSource());
if(arg0getKeyCode() == KeyEventVK_UP){//按上下时方向的值相应改变
if(fangXiang != 2){
fangXiang = 1;
// sheTousetIcon(shang);//设置蛇的方向
}
// Systemoutprintln("UP");
}
if(arg0getKeyCode() == KeyEventVK_DOWN){
if(fangXiang != 1){
fangXiang = 2;
// sheTousetIcon(xia);
}
// Systemoutprintln("DOWN");
}
if(arg0getKeyCode() == KeyEventVK_LEFT){//按左右时方向的值相应改变
if(fangXiang != 4){
fangXiang = 3;
// sheTousetIcon(zhuo);
}
// Systemoutprintln("LEFT");
}
if(arg0getKeyCode() == KeyEventVK_RIGHT){
if(fangXiang != 3){
fangXiang = 4;
// sheTousetIcon(you);
}
// Systemoutprintln("RIGHT");
}
}
public void keyReleased(KeyEvent arg0) {
// TODO 自动生成方法存根
}
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
JMenuItem JI = (JMenuItem)arg0getSource();
if(JI == play){
out = true;
run = true;
isRuned = true;
gaosetEnabled(false);
zhongsetEnabled(false);
disetEnabled(false);
}
if(JI == pause){
run = false;
}
if(isRuned == false){//如果游戏还没运行,才可以设置级别
if(JI == gao){
time = 200;
jianTime = 1;
JiBie = "高级";
MessagesetText("级别:"+JiBie+" 蛇长:"+(diJi+2)+" 时间:"+time+"ms 分数:"+jiFenQi);
}
if(JI == zhong){
time = 400;
jianTime = 2;
JiBie = "中级";
MessagesetText("级别:"+JiBie+" 蛇长:"+(diJi+2)+" 时间:"+time+"ms 分数:"+jiFenQi);
}
if(JI == di){
time = 500;
jianTime = 3;
JiBie = "低级";
MessagesetText("级别:"+JiBie+" 蛇长:"+(diJi+2)+" 时间:"+time+"ms 分数:"+jiFenQi);
}
}
if(JI == GF){
try{
FileInputStream fis = new FileInputStream("GaoFenini");
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
String s,setOut = "";
while((s=brreadLine())!= null){
setOut =setOut+s+"\n";
}
if(setOutequals("")){
JOptionPaneshowMessageDialog(f,"暂无保存记录!","高分榜",JOptionPaneINFORMATION_MESSAGE);
}
else{
JOptionPaneshowMessageDialog(f,setOut);
}
}catch(Exception e){
eprintStackTrace();
}
}
if(JI == ZZ){//关于作者
JOptionPaneshowMessageDialog(f,"软件作者:申志飞\n地址:四川省绵阳市\nQQ:898513806\nE-mail:shenzhifeiok@126com","关于作者",JOptionPaneINFORMATION_MESSAGE);
}
if(JI == YX){//关于游戏
JOptionPaneshowMessageDialog(f,"贪吃蛇游戏\n游戏版本 V10","关于游戏",JOptionPaneINFORMATION_MESSAGE);
}
if(JI == QK){
try{
int select = JOptionPaneshowConfirmDialog(f,"确实要清空记录吗?","清空记录",JOptionPaneYES_OPTION);
if(select == JOptionPaneYES_OPTION){
String setOut = "";
FileOutputStream fos = new FileOutputStream("GaoFenini");//输出到文件流
foswrite(setOutgetBytes());
}
}catch(Exception ex){}
}
}
}
//是我自己写的,本来里面有的,但无法上传,所以把去掉了,里面的ImageIcon等语句可以去掉。能正常运行。1、游戏正在维护中,这种情况下是登陆不上游戏的,建议大家可以关注最新的官网维护资讯。
2、自身网络问题,请检查一下自己的网络状态是否良好。
3、目前服务器过于拥挤,如果服务器爆满可能就挤不进去了,建议大家换个时段或者登录方式重试。
4、安装包错误,旧版本的安装包没有更新会出现这个问题,可以下载最新版疯狂贪吃蛇
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)