台球小游戏代码(急需基于eclipse的JAVA小游戏源代码!!!)

本文目录
急需基于eclipse的JAVA小游戏源代码!!!
单人版五子棋,不用导入,直接新建一个mywindow类就行,然后把一下代码粘贴就Ok了。或者,直接用dos就可以了。。
---------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class mypanel extends Panel implements MouseListener
{
int chess;
boolean Is_Black_True;
mypanel()
{
Is_Black_True = true;
for(int i = 0;i 《 11;i++)
{
for(int j = 0;j 《 11;j++)
{
chess = 0;
}
}
addMouseListener(this);
setBackground(Color.BLUE);
setBounds(0, 0, 360, 360);
setVisible(true);
}
public void mousePressed(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
if(x 《 25 || x 》 330 + 25 ||y 《 25 || y 》 330+25)
{
return;
}
if(chess != 0)
{
return;
}
if(Is_Black_True == true)
{
chess = 1;
Is_Black_True = false;
repaint();
Justisewiner();
return;
}
if(Is_Black_True == false)
{
chess = 2;
Is_Black_True = true;
repaint();
Justisewiner();
return;
}
}
void Drawline(Graphics g)
{
for(int i = 30;i 《= 330;i += 30)
{
for(int j = 30;j 《= 330; j+= 30)
{
g.setColor(Color.WHITE);
g.drawLine(i, j, i, 330);
}
}
for(int j = 30;j 《= 330;j += 30)
{
g.setColor(Color.WHITE);
g.drawLine(30, j, 330, j);
}
}
void Drawchess(Graphics g)
{
for(int i = 0;i 《 11;i++)
{
for(int j = 0;j 《 11;j++)
{
if(chess == 1)
{
g.setColor(Color.BLACK);
g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);
}
if(chess == 2)
{
g.setColor(Color.WHITE);
g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);
}
}
}
}
void Justisewiner()
{
int black_count = 0;
int white_count = 0;
int i = 0;
for(i = 0;i 《 11;i++)//横向判断
{
for(int j = 0;j 《 11;j++)
{
if(chess == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
for(i = 0;i 《 11;i++)//竖向判断
{
for(int j = 0;j 《 11;j++)
{
if(chess == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
for(i = 0;i 《 7;i++)//左向右斜判断
{
for(int j = 0;j 《 7;j++)
{
for(int k = 0;k 《 5;k++)
{
if(chess == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
}
for(i = 4;i 《 11;i++)//右向左斜判断
{
for(int j = 6;j 》= 0;j--)
{
for(int k = 0;k 《 5;k++)
{
if(chess == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
}
}
void Clear_Chess()
{
for(int i=0;i《11;i++)
{
for(int j=0;j《11;j++)
{
chess=0;
}
}
repaint();
}
public void paint(Graphics g)
{
Drawline(g);
Drawchess(g);
}
public void mouseExited(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
}
class myframe extends Frame implements WindowListener
{
mypanel panel;
myframe()
{
setLayout(null);
panel = new mypanel();
add(panel);
panel.setBounds(0,23, 360, 360);
setTitle("单人版五子棋");
setBounds(200, 200, 360, 383);
setVisible(true);
addWindowListener(this);
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowDeactivated(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
}
public class mywindow
{
public static void main(String argc )
{
myframe f = new myframe();
}
}
腾讯桌球延长线代码
没有代码。腾讯桌球是一款模拟现实桌球的手机休闲竞技游戏,游戏中的延长线属于破坏游戏平衡性的行为,所以是没有延长线的代码的。该游戏还原现实桌球玩法,简单流行的操作方式,绚丽的动画特效,配以真实的物理参数,精准的进球,激动人心的赛事让玩家有如身临其境。
小游戏程序设计代码内容
***隐藏网址***
黑白棋
#include《io.h》
#include《stdio.h》
#include《dos.h》
#include《string.h》
#include《math.h》
#include《bios.h》
#include《mem.h》
#include《fcntl.h》
#include《stdlib.h》
#include《conio.h》
#include 《graphics.h》
#define HH ’0’
#define N 6
int Q=0;
char key;
int fine=1;
int A=0,B=0;
char s;
void *ball;
int maxx;
unsigned int size;
loading()
{ int z=1;
while(z)
{ if(z》77)break;
printf("《");
delay(5000);
z++;
}
delay(2000);
cleardevice();
}
unsigned char Get_Ascii_Key(void)
{
if(bioskey(1))
return(bioskey(0));
else return(0);
}
int Test_Ascii_Key(int ascii)
{
if(Get_Ascii_Key()==ascii)
return(1);
else
return(0);
}
void tu(){
maxx=getmaxx();
size=imagesize(210,390,450,420);
ball=malloc(size);
setfillstyle(1,10);
bar(160,170,473,253);
setfillstyle(1,9);
bar(163,173,470,250);
setcolor(13);
outtextxy(200,200,"Welcome to BLACK & WHITE chess");
setcolor(14);
outtextxy(250,220,"Developer :Wu siyuan ");
outtextxy(290,240,"2002.8");
outtextxy(210,390,"Press any key to contunue...");
getimage(210,390,450,420,ball);
while(!kbhit()){
putimage(210,390,ball,XOR_PUT);
delay(30000);
}
cleardevice();
}
void sou(void){
}
void print()
{ int i=0,j=30;
setcolor(11);
outtextxy(35,20," 0 1 2 3 4 5");
outtextxy(14,50,"0");
outtextxy(14,100,"1");
outtextxy(14,150,"2");
outtextxy(14,200,"3");
outtextxy(14,250,"4");
outtextxy(14,300,"5");
setbkcolor(0);
setlinestyle(SOLID_LINE,0,2);
for(i=0;i《7;i++)
{ setcolor(GREEN);
line (j,30,j,330);
j+=50;
}
j=30;
for(i=0;i《7;i++)
{ setcolor(GREEN);
line(30,j,330,j);
j+=50;
}
for(i=0;i《6;i++)
for(j=0;j《6;j++)
{ if(s==’o’)
{
setcolor(WHITE);
circle(55+j*50,55+i*50,15);
}
else if(s==’x’)
{ setcolor(RED);
circle(55+j*50,55+i*50,15); }
}
}
int cal(char z)
{ int *p=0;
int num=0,i,j;
for(i=0;i《N;i++)
for(j=0;j《N;j++)
if(s==z)num++;
p=#
return(*p);
}
void save()
{int i,j;
for(i=0;i《N;i++)
for(j=0;j《N;j++)
m;
}
void load()
{ int i,j;
for(i=0;i《N;i++)
for(j=0;j《N;j++)
s;
}
snew(int x,int y,char z1,char z2)
{int i,j,a;int can;
if(s==z1&&(y-1)》=0)
{
i=0;
while(i《y)
{
if(s=1;break; }
i++;
}
}
if(s==z1)
{
i=y+2;
while(i《N)
{
if(s=1;break;}
i++;
}
}
if(s==z1&&(x-1)》=0)
{
i=0;
while(i《x)
{
if(s=1;break;}
i++;
}
}
if(s==z1)
{i=x+2;
while(i《N)
{
if(s=1;break;}
i++;
}
}
if(s==z1&&(x-1)》=0)
{i=2;
while(y+i《N&&(x-i》=0))
{if(s=1;break;}
i++;
}
}
if(s==z1&&(y-1)》=0)
{i=2;
while(i《N&&(y-i》=0))
{if(s==z2)
{can=1;break;}
i++;
}
}
if(s==z1&&(x-1)*(y-1)》=0)
{i=2;
while(x-i》=0&&y-i》=0)
{if(s==z2)
{can=1;
break;}
i++;
}
}
if(s==z1)
{i=2;
while(i+x《N)
{if(s==z2)
{can=1;
break;}
i++;
}
}
for(i=1,j=0;i《=8;i++)
if(can==0)j++;
if(j==8&&Q==1)
{printf("error!");
exit(1); }
else if(j!=8)s=z2;
if(can==1)
{ i=1;
while(s==z1)
{s=z2;
i++;
}
can=0;
}
if(can==1)
{i=1;
while(s==z1)
{s=z2;
i++;
}
can=0;
}
if(can==1)
{i=1;
while(s==z1)
{ s=z2;
i++;
}
can=0;
}
if(can==1)
{i=1;
while(s==z1)
{s=z2;
i++;
}
can=0;
}
if(can==1)
{i=1;
while(s==z1)
{s=z2;
i++;
}
can=0;
}
if(can==1)
{i=1;
while(s==z1)
{s=z2;
i++;
}
can=0;
}
if(can==1)
{i=1;
while(s==z1)
{s=z2;
i++;
}
can=0;
}
if(can==1)
{i=1;
while(s==z1)
{s=z2;
i++;
}
can=0;
}
} /* snew */
void one()
{ int a,b;char g=’o’;
load();
setcolor(15);
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\n To exit the Game press the ’q’ key.\n");
print();
printf("Please input x (0 to 5):");
while(1){
a=Get_Ascii_Key();
if(a==113||a==81){
printf("\nQuit?(y or n)");
while(1)
{
if(Test_Ascii_Key(89)||Test_Ascii_Key(121))
exit(0);
else if(Test_Ascii_Key(110)||Test_Ascii_Key(78))
{printf("\n\tWelcome to return the Game !\n");break; }
}}
if(a》=48&&a《=53){printf("\tGood! x has get!\n");
break;}
}
a=a-48;
printf("Please input y (0 to 5):");
while(1){
b=Get_Ascii_Key();
if(b==113||b==81)
{
printf("\nQuit?(y or Y)");
while(1)
{
if(Test_Ascii_Key(89)||Test_Ascii_Key(121))
exit(0);
else if(Test_Ascii_Key(110)||Test_Ascii_Key(78))
break;
}}
if(b》=48&&a《=53){printf("\tGood! y has get!");break;}
}
b=b-48;
Q=1;
snew(a,b,’x’,’o’);
Q=0;
save();
A=cal(g);
B=cal(’x’);
/* printf("\t\t\t\t\t\t\rA=%d,B=%d",A,B);*/
}/* one */
void search()
{
int i,j,r=0;
for(i=0;i《N;i++)
for(j=0;j《N;j++)
if(s==HH)
r++;
if(r==0)fine=0;
}
void two()
{ char h=’x’;int row;
int a=1,ii,j,t,t1,k;
load();
for(ii=0;ii《N;ii++)
for(j=0;j《N;j++)
if(s==HH)
{
row=ii;
col=j;
a++;
}
/* space right */
for(ii=1;ii《a;ii++)
{
load(); /*two*/
snew(row,’o’,’x’);
k=cal(h);
}
t=k;
ii--;
t1=ii;
while(ii)
{
if(t《=k)
{t=k;t1=ii;}
ii--;
}
a=t1;
A=cal(’o’);
B=t;
load();
snew(row,’o’,’x’);
save();
cleardevice();
printf("\n\n\t\t\t\t\t Computer located :%d,%d",row);
}
main()
{ int i,j;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"d:\\tc\\bgi");
setbkcolor(BLACK);
tu();
sou();
setbkcolor(0);
for(i=0;i《N;i++)
for(j=0;j《N;j++)
s=’0’;
s=’x’;
s=’o’;
save();
loading();
cleardevice();
while(fine)
{
print();
one();
two();
search();
if(key==113||key==81)
{
printf("\nQuit?(y or Y)");
while(!Test_Ascii_Key(89)&&!Test_Ascii_Key(121));
break;
}
}
if(A》B)outtextxy(400,200, " You win!");
else if(A《B)outtextxy(400,200," I win!");
else outtextxy(400,200," It’s a draw!");
printf("\n You:%d I:%d",A,B);
getch();
}
经典小游戏代码
ant 蚂蚁2. bagels 百吉饼另外贪吃蛇,吃豆子都是可以的,直接代码就可以玩。
Python包括随您的安装一起分发的大量标准库。标准库有一个称为Turtle的模块,这是一种向普通人介绍python编程的流行方法。今天介绍的所有游戏都是使用Python及其Turtle模块实现的。
每个游戏都完全独立于其他游戏,不试一试 您永远都不知道最喜欢哪种游戏。安装完之后我们可以使用"python -m freegames list"来查看所有的游戏
游戏简介
贪吃蛇 -经典街机游戏。使用箭头键导航并吃绿色食品。每次食用食物,蛇就会长出一段。避免自己进食或出界,吃豆子 –经典街机游戏。使用箭头键导航并吃掉所有白色食物。提防漫游迷宫的红色幽灵。Flappy-bird启发游戏。单击屏幕拍打翅膀。当您飞越屏幕时,请当心黑乌鸦。
大炮-射击运动。单击屏幕发射您的炮弹。炮弹在其路径中弹出蓝色气球。弹出所有气球,然后才能越过屏幕。
用java web小游戏源代码期末结课老师让做,急用,谢了
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
@SuppressWarnings("serial")
public class MainClass extends JFrame {
ControlSnake control;
Toolkit kit;
Dimension dimen;
public static void main(String args) {
new MainClass("my snake");
}
public MainClass(String s) {
super(s);
control = new ControlSnake();
control.setFocusable(true);
kit = Toolkit.getDefaultToolkit();
dimen = kit.getScreenSize();
add(control);
setLayout(new BorderLayout());
setLocation(dimen.width / 3, dimen.height / 3);// dimen.width/3,dimen.height/3
setSize(FWIDTH, FHEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
}
public static final int FWIDTH = 315;
public static final int FHEIGHT = 380;
}
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.Timer;
@SuppressWarnings("serial")
public class ControlSnake extends JPanel implements ActionListener {
Random rand;
ArrayList《Point》 list, listBody;
String str, str1;
static boolean key;
int x, y, dx, dy, fx, fy, flag;
int snakeBody;
int speed;
public ControlSnake() {
snakeBody = 1;
str = "上下左右方向键控制 P键暂停...";
str1 = "现在的长度为:" + snakeBody;
key = true;
flag = 1;
speed = 700;
rand = new Random();
list = new ArrayList《Point》();
listBody = new ArrayList《Point》();
x = 5;
y = 5;
list.add(new Point(x, y));
listBody.add(list.get(0));
dx = 10;
dy = 0;
fx = rand.nextInt(30) * 10 + 5;// 2
fy = rand.nextInt(30) * 10 + 5;// 2
setBackground(Color.BLACK);
setSize(new Dimension(318, 380));
final Timer time = new Timer(speed, this);
time.start();
addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == 37) {
dx = -10;
dy = 0;
} else if (e.getKeyCode() == 38) {
dx = 0;
dy = -10;
} else if (e.getKeyCode() == 39) {
dx = 10;
dy = 0;
} else if (e.getKeyCode() == 40) {
dx = 0;
dy = 10;
} else if (e.getKeyCode() == 80) {
if (flag % 2 == 1) {
time.stop();
}
if (flag % 2 == 0) {
time.start();
}
flag++;
}
}
});
}
public void paint(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(0, 0, 400, 400);
g.setColor(Color.DARK_GRAY);
g.drawLine(3, 3, 305, 3);
g.drawLine(3, 3, 3, 305);
g.drawLine(305, 3, 305, 305);
g.drawLine(3, 305, 305, 305);
g.setColor(Color.PINK);
for (int i = 0; i 《 listBody.size(); i++) {
g.fillRect(listBody.get(i).x, listBody.get(i).y, 9, 9);
}
g.fillRect(x, y, 9, 9);
g.setColor(Color.ORANGE);
g.fillRect(fx, fy, 9, 9);
g.setColor(Color.DARK_GRAY);
str1 = "现在的长度为:" + snakeBody;
g.drawString(str, 10, 320);
g.drawString(str1, 10, 335);
}
public void actionPerformed(ActionEvent e) {
x += dx;
y += dy;
if (makeOut() == false) {
JOptionPane.showMessageDialog(null, "重新开始......");
speed = 700;
snakeBody = 1;
x = 5;
y = 5;
list.clear();
list.add(new Point(x, y));
listBody.clear();
listBody.add(list.get(0));
dx = 10;
dy = 0;
}
addPoint(x, y);
if (x == fx && y == fy) {
speed = (int) (speed * 0.8);//速度增加参数
if (speed 《 200) {
speed = 100;
}
fx = rand.nextInt(30) * 10 + 5;// 2
fy = rand.nextInt(30) * 10 + 5;// 2
snakeBody++;// 2
} // 2
repaint();
}
public void addPoint(int xx, int yy) {
// 动态的记录最新发生的50步以内的移动过的坐标
// 并画出最新的snakeBody
if (list.size() 《 100) {//蛇身长度最长为100
list.add(new Point(xx, yy));
} else {
list.remove(0);
list.add(new Point(xx, yy));
}
if (snakeBody == 1) {
listBody.remove(0);
listBody.add(0, list.get(list.size() - 1));
} else {
listBody.clear();
if (list.size() 《 snakeBody) {
for (int i = list.size() - 1; i 》 0; i--) {
listBody.add(list.get(i));
}
} else {
for (int i = list.size() - 1; listBody.size() 《 snakeBody; i--) {
listBody.add(list.get(i));
}
}
}
}
public boolean makeOut() {
if ((x 《 3 || y 《 3) || (x 》 305 || y 》 305)) {
return false;
}
for (int i = 0; i 《 listBody.size() - 1; i++) {
for (int j = i + 1; j 《 listBody.size(); j++) {
if (listBody.get(i).equals(listBody.get(j))) {
return false;
}
}
}
return true;
}
}
/*贪吃蛇代码*/

更多文章:
即时战略游戏是什么意思(请问即时战略类游戏和策略类游戏的具体区别)
2026年9月24日 07:00
赛尔号魔灵仙女超进化(关于赛尔号的提问,被不要脸的百度删了话说我违什么规了别人卖号的都能发出去,我呢愚蠢的百度!!)
2026年9月24日 00:20








