java小游戏-贪吃蛇

SnakeGame.java

package SnakeGame;

import javax.swing.*;
public class SnakeGame
{
public static void main( String[] args )
{
JDialog.setDefaultLookAndFeelDecorated( true );
GameFrame temp = new GameFrame();
}
}

Snake.java

package SnakeGame;

import java.awt.*;
import java.util.*;

class Snake extends LinkedList
{
public int snakeDirection = 2;
public int snakeReDirection = 4;
public Snake()
{
this.add( new Point( 3, 3 ) );
this.add( new Point( 4, 3 ) );
this.add( new Point( 5, 3 ) );
this.add( new Point( 6, 3 ) );
this.add( new Point( 7, 3 ) );
this.add( new Point( 8, 3 ) );
this.add( new Point( 9, 3 ) );
this.add( new Point( 10, 3 ) );
}
public void changeDirection( Point temp, int direction )
{
this.snakeDirection = direction;
switch( direction )
{
case 1://up
this.snakeReDirection = 3;
this.add( new Point( temp.x, temp.y - 1 ) );
break;
case 2://right
this.snakeReDirection = 4;
this.add( new Point( temp.x + 1, temp.y ) );
break;
case 3://down
this.snakeReDirection = 1;
this.add( new Point( temp.x, temp.y + 1 ) );
break;
case 4://left
this.snakeReDirection = 2;
this.add( new Point( temp.x - 1, temp.y ) );
break;
}
}
public boolean checkBeanIn( Point bean )
{
Point temp = (Point) this.getLast();
if( temp.equals( bean ) )
{
return true;
}
return false;
}

public void removeTail()
{
this.remove( 0 );
}

public void drawSnake( Graphics g, int singleWidthX, int singleHeightY, int cooPos )
{
g.setColor( ColorGroup.COLOR_SNAKE );
Iterator snakeSq = this.iterator();
while ( snakeSq.hasNext() )
{
Point tempPoint = (Point)snakeSq.next();
this.drawSnakePiece( g, tempPoint.x, tempPoint.y,
singleWidthX, singleHeightY, cooPos );
}
}

public void drawSnakePiece( Graphics g, int temp1, int temp2,
int singleWidthX, int singleHeightY, int cooPos )
{
g.fillRoundRect( singleWidthX * temp1 + 1,
singleHeightY * temp2 + 1,
singleWidthX - 2,
singleHeightY - 2,
cooPos,
cooPos );
}
public void clearEndSnakePiece( Graphics g, int temp1, int temp2,
int singleWidthX, int singleHeightY, int cooPos )
{
g.setColor( ColorGroup.COLOR_BACK );
g.fillRoundRect( singleWidthX * temp1 + 1,
singleHeightY * temp2 + 1,
singleWidthX - 2,
singleHeightY - 2,
cooPos,
cooPos );
}
}

GameFrame.java

package SnakeGame;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.geom.*;

class GameFrame extends JFrame
{
private Toolkit tempKit;
private int horizontalGrid, verticalGrid;
private int singleWidthX, singleHeightY;
private int cooPos;
private Snake mainSnake;
private LinkedList eatedBean;
{
eatedBean = new LinkedList();
}
private Iterator snakeSq;
public javax.swing.Timer snakeTimer;
private int direction = 2;
private int score;
private String info;
private Point bean, eatBean;
{
bean = new Point();
}
private boolean flag;
private JMenuBar infoMenu;
private JMenu[] tempMenu;
private JMenuItem[] tempMenuItem;
private JRadioButtonMenuItem[] levelMenuItem, versionMenuItem;
private JLabel scoreLabel;
{
scoreLabel = new JLabel();
}
private Graphics2D g;
private ImageIcon snakeHead;
{
snakeHead = new ImageIcon( "LOGO.gif" );
}
private ConfigMenu configMenu;
private boolean hasStoped = true;
public GameFrame()
{

this.tempKit = this.getToolkit();
this.setSize( tempKit.getScreenSize() );
this.setGrid( 60, 40, 5 );
this.getContentPane().setBackground( ColorGroup.COLOR_BACK );
this.setUndecorated( true );
this.setResizable( false );
this.addKeyListener( new KeyHandler() );
GameFrame.this.snakeTimer = new javax.swing.Timer( 80, new TimerHandler() );
this.getContentPane().add( scoreLabel, BorderLayout.SOUTH );
this.scoreLabel.setFont( new Font( "Fixedsys", Font.BOLD, 15 ) );
this.scoreLabel.setText( "Pause[SPACE] - Exit[ESC]" );
this.configMenu = new ConfigMenu( this );
this.setVisible( true );

}
public void setGrid( int temp1, int temp2, int temp3 )
{
this.horizontalGrid = temp1;
this.verticalGrid = temp2;
this.singleWidthX = this.getWidth() / temp1;
this.singleHeightY = this.getHeight() / temp2;
this.cooPos = temp3;
}

private class KeyHandler extends KeyAdapter
{
public void keyPressed( KeyEvent e )
{
if( e.getKeyCode() == 27 )
{
snakeTimer.stop();
if( JOptionPane.showConfirmDialog( null, "Are you sure to exit?" ) == 0 )
{
System.exit( 0 );
}
snakeTimer.start();
}
else if( e.getKeyCode() == 37 && mainSnake.snakeDirection != 2 )//left
{
direction = 4;
}
else if( e.getKeyCode() == 39 && mainSnake.snakeDirection != 4 )//right
{
direction = 2;
}
else if( e.getKeyCode() == 38 && mainSnake.snakeDirection != 3 )//up
{
direction = 1;
}
else if( e.getKeyCode() == 40 && mainSnake.snakeDirection != 1 )//down
{
direction = 3;
}
else if( e.getKeyCode() == 32 )
{
if( !hasStoped )
{
if( !flag )
{

snakeTimer.stop();
configMenu.setVisible( true );
configMenu.setMenuEnable( false );
flag = true;
}
else
{
snakeTimer.start();
configMenu.setVisible( false );
configMenu.setMenuEnable( true );
flag = false;
}
}
}
}
}

private class TimerHandler implements ActionListener
{
public synchronized void actionPerformed( ActionEvent e )
{
Point temp = (Point) mainSnake.getLast();
snakeSq = mainSnake.iterator();
while ( snakeSq.hasNext() )
{
Point tempPoint = (Point)snakeSq.next();
if( temp.equals( tempPoint ) && snakeSq.hasNext() != false )
{
snakeTimer.stop();
stopGame();
JOptionPane.showMessageDialog( null,
"Your Score is " + score + "\n\nYou Loss!" );
}
}
System.out.println( temp.x + " " + temp.y );
if( (temp.x == 0 && direction == 4) ||
(temp.x == horizontalGrid-1 && direction == 2) ||
(temp.y == 0 && direction == 1) ||
(temp.y == verticalGrid-1 && direction == 3) )
{
snakeTimer.stop();
stopGame();
JOptionPane.showMessageDialog( null,
"Your Score is " + score + "\n\nYou Loss!" );
}
if( direction != mainSnake.snakeReDirection )
{
moveSnake( direction );
}
mainSnake.drawSnake( getGraphics(), singleWidthX, singleHeightY, cooPos );
drawBeanAndEBean( getGraphics() );
}
}

public void stopGame()
{
this.hasStoped = true;
this.snakeTimer.stop();
Graphics2D g = (Graphics2D) GameFrame.this.getGraphics();
g.setColor( ColorGroup.COLOR_BACK );
super.paint( g );
configMenu.setVisible( true );
}

public void resetGame()
{
System.gc();
this.hasStoped = false;
Graphics2D g = (Graphics2D) GameFrame.this.getGraphics();
g.setColor( ColorGroup.COLOR_BACK );
super.paint( g );
this.mainSnake = new Snake();
this.createBean( bean );
this.eatedBean.clear();
mainSnake.drawSnake( getGraphics(), singleWidthX, singleHeightY, cooPos );
this.snakeTimer.start();
this.direction = 2;
this.score = 0;
this.scoreLabel.setText( "Pause[SPACE] - Exit[ESC]" );
}

private void moveSnake( int direction )
{
if( mainSnake.checkBeanIn( this.bean ) )
{
this.score += 100;
this.scoreLabel.setText( this.info + " Current Score:" + this.score );
this.eatedBean.add( new Point(this.bean) );
this.createBean( this.bean );
}
mainSnake.changeDirection( (Point) mainSnake.getLast(), direction );
Point temp = (Point) mainSnake.getFirst();
if( eatedBean.size() != 0 )
{
if( eatedBean.getFirst().equals( temp ) )
{
eatedBean.remove( 0 );
}
else
{
mainSnake.clearEndSnakePiece( getGraphics(), temp.x, temp.y,
singleWidthX, singleHeightY, cooPos );
mainSnake.removeTail();
}
}
else
{
mainSnake.clearEndSnakePiece( getGraphics(), temp.x, temp.y,
singleWidthX, singleHeightY, cooPos );
mainSnake.removeTail();
}
}

private void drawBeanAndEBean( Graphics g )
{
g.setColor( ColorGroup.COLOR_BEAN );
this.drawPiece( g, this.bean.x, this.bean.y );
g.setColor( ColorGroup.COLOR_EATEDBEAN );
snakeSq = eatedBean.iterator();
while ( snakeSq.hasNext() )
{
Point tempPoint = (Point)snakeSq.next();
this.drawPiece( g, tempPoint.x, tempPoint.y );
}
}

private void drawPiece( Graphics g, int x, int y )
{
g.fillRoundRect( this.singleWidthX * x + 1,
this.singleHeightY * y + 1,
this.singleWidthX - 2,
this.singleHeightY - 2,
this.cooPos,
this.cooPos );
}

private void createBean( Point temp )
{
LP:
while( true )
{
temp.x = (int) (Math.random() * this.horizontalGrid);
temp.y = (int) (Math.random() * this.verticalGrid);
snakeSq = mainSnake.iterator();
while ( snakeSq.hasNext() )
{
if( snakeSq.next().equals( new Point( temp.x, temp.y ) ) )
{
continue LP;
}
}
break;
}
}
}

ConfigMenu.java

package SnakeGame;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ConfigMenu extends JMenuBar
{

GameFrame owner;
JMenu[] menu;
JMenuItem[] menuItem;
JRadioButtonMenuItem[] speedItem, modelItem, standardItem;
private UIManager.LookAndFeelInfo looks[];
public ConfigMenu( GameFrame owner )
{
this.owner = owner;
owner.setJMenuBar( this );
String[] menu_name = {"Snake Game", "Game Configure", "Game Help"};
menu = new JMenu[menu_name.length];
for( int i = 0; i < menu_name.length; i++ )
{
menu[i] = new JMenu( menu_name[i] );
menu[i].setFont( new Font( "Courier", Font.PLAIN, 12 ) );
this.add( menu[i] );
}

String[] menuItem_name = {"Start Game", "Stop Game", "Exit Game",
"Game Color",
"About..."};
menuItem = new JMenuItem[menuItem_name.length];
for( int i = 0; i < menuItem_name.length; i++ )
{
menuItem[i] = new JMenuItem( menuItem_name[i] );
menuItem[i].setFont( new Font( "Courier", Font.PLAIN, 12 ) );
menuItem[i].addActionListener( new ActionHandler() );
}
menu[0].add( menuItem[0] );
menu[0].add( menuItem[1] );
menu[0].addSeparator();
menu[0].add( menuItem[2] );
menu[1].add( menuItem[3] );
menu[2].add( menuItem[4] );

String[] inner_menu_name = {"Game Speed", "Window Model", "Game Standard "};
JMenu[] inner_menu = new JMenu[inner_menu_name.length];
for( int i = 0; i < inner_menu_name.length; i++ )
{
inner_menu[i] = new JMenu( inner_menu_name[i] );
inner_menu[i].setFont( new Font( "Courier", Font.PLAIN, 12 ) );
menu[1].add( inner_menu[i] );
}

ButtonGroup temp1 = new ButtonGroup();
String[] speedItem_name = {"Speed-1", "Speed-2", "Speed-3", "Speed-4", "Speed-5"};
speedItem = new JRadioButtonMenuItem[speedItem_name.length];
for( int i = 0; i < speedItem_name.length; i++ )
{
speedItem[i] = new JRadioButtonMenuItem( speedItem_name[i] );
inner_menu[0].add( speedItem[i] );
speedItem[i].setFont( new Font( "Courier", Font.PLAIN, 12 ) );
speedItem[i].addItemListener( new ItemHandler() );
temp1.add( speedItem[i] );
}

ButtonGroup temp2 = new ButtonGroup();
String[] modelItem_name = { "Linux", "Mac", "Windows" };
modelItem = new JRadioButtonMenuItem[modelItem_name.length];
for( int i = 0; i < modelItem_name.length; i++ )
{
modelItem[i] = new JRadioButtonMenuItem( modelItem_name[i] );
inner_menu[1].add( modelItem[i] );
modelItem[i].setFont( new Font( "Courier", Font.PLAIN, 12 ) );
modelItem[i].addItemListener( new ItemHandler() );
temp2.add( modelItem[i] );
}

ButtonGroup temp3 = new ButtonGroup();
String[] standardItem_name = { "60 * 40", "45 * 30", "30 * 20" };
standardItem = new JRadioButtonMenuItem[standardItem_name.length];
for( int i = 0; i < standardItem_name.length; i++ )
{
standardItem[i] = new JRadioButtonMenuItem( standardItem_name[i] );
inner_menu[2].add( standardItem[i] );
standardItem[i].setFont( new Font( "Courier", Font.PLAIN, 12 ) );
standardItem[i].addItemListener( new ItemHandler() );
temp3.add( standardItem[i] );
}
looks = UIManager.getInstalledLookAndFeels();
}

private class ActionHandler implements ActionListener
{
public void actionPerformed( ActionEvent e )
{
if( e.getSource() == menuItem[0] )
{
owner.resetGame();
ConfigMenu.this.setVisible( false );
}
else if( e.getSource() == menuItem[1] )
{
owner.stopGame();
ConfigMenu.this.setVisible( true );
ConfigMenu.this.setMenuEnable( true );
}
else if( e.getSource() == menuItem[2] )
{
System.exit( 0 );
}
else if( e.getSource() == menuItem[3] )
{
ConfigDialog temp = new ConfigDialog( owner );
temp.setVisible( true );
}
else if( e.getSource() == menuItem[4] )
{
JOptionPane.showMessageDialog( null, "Sanke Game 2.0 Version!\n\n" +
"Author: FinalCore\n\n" );
}
}
}

private class ItemHandler implements ItemListener
{
public void itemStateChanged( ItemEvent e )
{
for( int i = 0; i < speedItem.length; i++ )
{
if( e.getSource() == speedItem[i] )
{
owner.snakeTimer.setDelay( 150 - 30 * i );
}
}
if( e.getSource() == standardItem[0] )
{
owner.setGrid( 60, 40, 5 );
}
else if( e.getSource() == standardItem[1] )
{
owner.setGrid( 45, 30, 10 );
}
else if( e.getSource() == standardItem[2] )
{
owner.setGrid( 30, 20, 15 );
}
for( int i = 0; i < modelItem.length; i++ )
{
if( e.getSource() == modelItem[i] )
{
try
{
UIManager.setLookAndFeel( looks[i].getClassName() );
}catch(Exception ex){}
}
}
}
}

public void setMenuEnable( boolean temp )
{
menu[1].setEnabled( temp );
}

}

ConfigDialog.java

package SnakeGame;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ConfigDialog extends JDialog
{
private Container c;
private JFrame owner;
private OwnPanel[] panel = new OwnPanel[4];
Box box1, box2;
private JButton commitButton, cancelButton;
Color[] color = new Color[4];
public ConfigDialog( Frame owner )
{
this.owner = (JFrame) owner;
this.setSize( 400, 200 );
this.setResizable( false );
this.setTitle( "Config Your Game" );
this.c = this.getContentPane();
this.c.setBackground( Color.WHITE );
this.c.setLayout( new FlowLayout() );
this.box1 = Box.createVerticalBox();
for( int i = 0; i < panel.length; i++ )
{
panel[i] = new OwnPanel();
panel[i].addActionListener( new ActionHandler() );
this.box1.add( panel[i] );
this.box1.add( Box.createVerticalStrut( 4 ) );
}
this.panel[0].setText( " Background" );
this.panel[1].setText( " Snake" );
this.panel[2].setText( " Bean" );
this.panel[3].setText( " EatedBean" );
this.panel[0].setBack( ColorGroup.COLOR_BACK );
this.panel[1].setBack( ColorGroup.COLOR_SNAKE );
this.panel[2].setBack( ColorGroup.COLOR_BEAN );
this.panel[3].setBack( ColorGroup.COLOR_EATEDBEAN );
this.box2 = Box.createHorizontalBox();
this.commitButton = new JButton( "确定" );
this.commitButton.setFont( Font.getFont( "Fixedsys" ) );
this.commitButton.addActionListener( new ActionHandler() );
this.cancelButton = new JButton( "取消" );
this.cancelButton.setFont( Font.getFont( "Fixedsys" ) );
this.cancelButton.addActionListener( new ActionHandler() );
this.box2.add( this.commitButton );
this.box2.add( Box.createHorizontalStrut( 20 ) );
this.box2.add( this.cancelButton );
this.box1.add( this.box2 );
this.c.add( this.box1, BorderLayout.NORTH );
this.setLocation( ( this.getToolkit().getScreenSize().width - this.getWidth() )/2,
( this.getToolkit().getScreenSize().height - this.getHeight() )/2 );
this.setVisible( true );
}
public void setOwnerColor( Color temp )
{
this.owner.getContentPane().setBackground( temp );
}
private class ActionHandler implements ActionListener
{
public void actionPerformed( ActionEvent e )
{
for( int i = 0; i < color.length; i++ )
{
if( e.getSource() == panel[i].reButton() )
{
color[i] = JColorChooser.showDialog( ConfigDialog.this,
"Choose BackGround Color",
Color.WHITE );
if( color[i] != null )
{
panel[i].setBack( color[i] );
}
}
}
if( e.getSource() == commitButton )
{
color[0] = (color[0]==null?ColorGroup.COLOR_BACK:color[0]);
color[1] = (color[1]==null?ColorGroup.COLOR_SNAKE:color[1]);
color[2] = (color[2]==null?ColorGroup.COLOR_BEAN:color[2]);
color[3] = (color[3]==null?ColorGroup.COLOR_EATEDBEAN:color[3]);
ConfigDialog.this.setVisible( false );
ColorGroup.setCOLOR_BACK( color[0] );
owner.getContentPane().setBackground( color[0] );
ColorGroup.setCOLOR_SNAKE( color[1] );
ColorGroup.setCOLOR_BEAN( color[2] );
ColorGroup.setCOLOR_EATEDBEAN( color[3] );
ConfigDialog.this.dispose();
}
else if( e.getSource() == cancelButton )
{
ConfigDialog.this.setVisible( false );
ConfigDialog.this.dispose();
}

}
}
}

class OwnPanel extends JPanel
{
private JLabel temp1;
private JTextField temp2;
private JButton temp3;
OwnPanel()
{
temp1 = new JLabel();
temp1.setFont( Font.getFont( "Fixedsys" ) );
temp2 = new JTextField();
temp3 = new JButton( "Change" );
temp3.setFont( Font.getFont( "Fixedsys" ) );
temp2.setEditable( false );
temp2.setColumns( 10 );
this.add( temp1 );
this.add( temp2 );
this.add( temp3 );
this.setLayout( new GridLayout( 1, 3 ) );
}
public void setButtonName( String temp )
{
temp3.setName( temp );
}
public void setBack( Color temp )
{
temp2.setBackground( temp );
}
public void setText( String temp )
{
temp1.setText( temp );
}
public Object reButton()
{
return temp3;
}
public void addActionListener( ActionListener ac )
{
temp3.addActionListener( ac );
}
}

Tools.java

package SnakeGame;

import java.awt.*;
import javax.swing.*;

class ColorGroup
{
static Color COLOR_BACK = Color.WHITE;
static Color COLOR_SNAKE = new Color( 43, 110, 187 );
static Color COLOR_BEAN = Color.BLUE;
static Color COLOR_EATEDBEAN = Color.CYAN;
static void setCOLOR_BACK( Color temp )
{
COLOR_BACK = temp;
}
static void setCOLOR_SNAKE( Color temp )
{
COLOR_SNAKE = temp;
}
static void setCOLOR_BEAN( Color temp )
{
COLOR_BEAN = temp;
}
static void setCOLOR_EATEDBEAN( Color temp )
{
COLOR_EATEDBEAN = temp;
}
}

final class MenuGet
{
public static JMenu getMenu( String temp )
{
JMenu reMenu = new JMenu( temp );
reMenu.setFont( Font.getFont( "Fixedsys" ) );
return reMenu;
}
}

final class MenuItemGet
{
public static JMenuItem getMenuItem( String temp )
{
JMenuItem reMenuItem = new JMenuItem( temp );
reMenuItem.setFont( Font.getFont( "Fixedsys" ) );
return reMenuItem;
}
}

时间: 2024-09-11 18:14:42

java小游戏-贪吃蛇的相关文章

AS3:小游戏“贪吃蛇”的实现

前几天在园子里看到有人用Silverlight做了一个"贪吃蛇",一时兴起也想用AS3.0做一个,虽然这个游戏已经被很多开发者做烂了,但是作为AS的初学者,重新做一遍也当是一种学习. 技术"难"点分析: 1.蛇身的构成可以用数组来存储一堆小球,将它们排列成连续的直线即可   2.蛇身的移动蛇头移动后,紧跟蛇头后的小球移动到蛇头原来的位置,然后...类推,后面的小球依次移动到前一个球的位置   3.碰撞检测蛇头移动时,如果超出舞台边界,则Game Over了:同样蛇头

怎样实现java小游戏的联机?

问题描述 怎样实现java小游戏的联机? 我们现在是要做一个java小游戏,已经写了各种界面还有行动的逻辑,现在需要实现联机,不太能理解怎样用socket实现联机以及各个组件的交互,求大神帮助! 解决方案 http://blog.csdn.net/u014174328/article/details/40866263http://blog.csdn.net/emilyRR/article/details/40596647 解决方案二: http://blog.csdn.net/a19881029

Android开发之经典游戏贪吃蛇_Android

前言 这款游戏实现的思路和源码参考了Google自带的Snake的例子,其中修改了一些个人认为还不够完善的地方,加入了一些新的功能,比如屏幕上的方向操作盘,暂停按钮,开始按钮,退出按钮.另外,为了稍微增加些用户体验,除了游戏的主界面,本人自己新增了5个界面,分别是登陆界面,菜单界面,背景音乐设置界面,难度设置界面,还有个关于游戏的介绍界面.个人觉得在新手阶段,参考现成的思路和实现方式是难以避免的.重要的是我们需要有自己的理解,读懂代码之后,需要思考代码背后的实现逻辑,形成自己的思维.这样在下次开

Android开发之经典游戏贪吃蛇

前言 这款游戏实现的思路和源码参考了Google自带的Snake的例子,其中修改了一些个人认为还不够完善的地方,加入了一些新的功能,比如屏幕上的方向操作盘,暂停按钮,开始按钮,退出按钮.另外,为了稍微增加些用户体验,除了游戏的主界面,本人自己新增了5个界面,分别是登陆界面,菜单界面,背景音乐设置界面,难度设置界面,还有个关于游戏的介绍界面.个人觉得在新手阶段,参考现成的思路和实现方式是难以避免的.重要的是我们需要有自己的理解,读懂代码之后,需要思考代码背后的实现逻辑,形成自己的思维.这样在下次开

初学者-java小游戏设计问题(有些冗长,麻烦耐心看完!)

问题描述 java小游戏设计问题(有些冗长,麻烦耐心看完!) 该小游戏是为了实现电脑随机出石头,剪刀,或布,然后玩家根据电脑的要求(赢电脑,输电脑,打平),大致思路是客户端发出指令开始游戏,服务器端接收后随机选择,然后发回给客户端,玩家选择后,服务器做出判断对错.现将游戏的服务器端与客户端贴出,现在的问题是当玩家输入自己的判断后,服务器返回的值一直是"回答错误",求解! 这是 服务器端 的程序 import java.io.*; import java.net.*; import ja

java游戏-Java小游戏npc碰撞后的随机方向设置

问题描述 Java小游戏npc碰撞后的随机方向设置 npc的随机方向设置和碰撞后方向随机怎样设置,就是NPC在地图中行走,碰到其他物体后随机一个方向继续行走 解决方案 首先npc有个活动范围,其次活动范围内可能有障碍物,那你npc在一个点时下一步上下左右四个方向哪些方向能走是能判断出来的, 然后把能走的方向放到数组里,用随机数,范围为数组长度,然后选择往哪里走,知道不能走后再继续判断改变方向.

java-如题比如我下了一个JAVA小游戏源代码照着写就能运行了吗

问题描述 如题比如我下了一个JAVA小游戏源代码照着写就能运行了吗 比如说俄罗斯方块,五子棋 等我该注意什么问题呢,大神们我知道我的问题对你们来说都是小问题,新手求科普 解决方案 看来你还没有做过游戏方面的东西吧.一般而言,游戏不止有代码,同样的还必须有图片资源,你想一下不然游戏的美工不就只有喝西北风了!!当然也有例外,比如你完全只是调用一些简单的几何图形函数就不会用到图片资源.但是这种游戏几乎没有!所以你要看代码中调用图片资源没有,如果有,还要找到图片资源,同时还要看用到其他的库没有,如果用到

java-新人,求助:Java小游戏代码改成安卓代码

问题描述 新人,求助:Java小游戏代码改成安卓代码 英雄难过棍子关的安卓代码 自己也是下载的源代码,想参考它写成安卓代码,但是一直没成功,求助. 解决方案 他们两者就是画图机制不一样,java paint Android canvas 解决方案二: http://download.csdn.net/download/u011040361/8310321

【求教】完成一个java小游戏

问题描述 用你所熟悉的语言(JAVA或C/C++)写一个如下的小游戏:屏幕窗口大小定为176*204,场景TILE的大小是8*8自定义一数据结构定义场景(场景要大于屏幕),场景TILE只需要有两种状态,一种是可通过,一种不可通过(墙)(比如你定义的场景为30*40个TILE大小,你可以用一个30*40的数组来表示场景,但数据不能直接写在程序中,要从外部数据资源中读取)要求游戏启动后,在游戏中能选择装载不同的场景,然后玩家能控制一个人(不能小于一个TILE大小)在场景中能左右上下移动,在遇到墙时则

Java小游戏该怎么做啊

问题描述 帮忙用javascript做一个简单的小游戏 解决方案 解决方案二:顶顶...解决方案三:帮忙印几张老人头给我吧.印的多的我再加分!解决方案四:自己动手写把···不会的具体问题再来问,会有比较多的人来回答你的···这么问···上网搜搜代码都会有现成的