java游戏课程设计
❶ java课程设计——猜数字游戏
代码如下:
importjava.util.Scanner;
publicclassRandomT{
intsum=0;
publicstaticvoidmain(String[]args){
intnumber=(int)(Math.random()*100+1);
inttemp=number;
System.out.println("请猜一个100以内的数:");
RandomTrt=newRandomT();
intin=rt.Sn();
Booleanyn=rt.Compare(temp,in);
while(!yn){
System.out.println("请重新输入:");
intin1=rt.Sn();
yn=rt.Compare(temp,in1);
}
System.out.println("正确数字是:"+number);
}
publicBooleanCompare(inttemp,intnumber){
Booleanyesno=null;
if(temp==number){
if(sum==1){
System.out.println("Beautiful");
}elseif(2<=sum||sum<=4){
System.out.println("还是不错的!");
}else{
System.out.println("唉,总算对了!");
}
yesno=true;
}elseif(number<temp){
System.out.println("猜小了");
yesno=false;
}elseif(number>temp){
System.out.println("猜大了");
yesno=false;
}
returnyesno;
}
publicintSn(){
Scannersc=newScanner(System.in);
intin=sc.nextInt();
sum+=1;
returnin;
}
}
如果满意请采纳!
❷ 课程设计java制作的石头剪子布游戏源码
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Test extends JApplet{
private static final long serialVersionUID = 1L;
JButton btnStone = new JButton("石头");
JButton btnForfex = new JButton("剪刀");
JButton btnCloth = new JButton("布");
JLabel jl = new JLabel();
JPanel jpl = new JPanel();
public void init(){
jpl.add(jl,BorderLayout.NORTH);
jpl.add(btnStone,BorderLayout.SOUTH);
jpl.add(btnForfex,BorderLayout.SOUTH);
jpl.add(btnCloth,BorderLayout.SOUTH);
this.getContentPane().add(jpl);
btnForfex.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
doSFC();
if(doSFC()==1){
jl.setText("石头");
JOptionPane.showMessageDialog(null, "平手");
}
if(doSFC()==2){
jl.setText("剪刀");
JOptionPane.showMessageDialog(null, "你赢了");
}
if(doSFC()==3){
jl.setText("布");
JOptionPane.showMessageDialog(null, "你输了");
}
}
});
btnStone.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
doSFC();
if(doSFC()==1){
jl.setText("石头");
JOptionPane.showMessageDialog(null, "你赢了");
}
if(doSFC()==2){
jl.setText("剪刀");
JOptionPane.showMessageDialog(null, "你输了");
}
if(doSFC()==3){
jl.setText("布");
JOptionPane.showMessageDialog(null, "平手");
}
}
});
btnCloth.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
doSFC();
if(doSFC()==1){
jl.setText("石头");
JOptionPane.showMessageDialog(null, "你输了");
}
if(doSFC()==2){
jl.setText("剪刀");
JOptionPane.showMessageDialog(null, "平手");
}
if(doSFC()==3){
jl.setText("布");
JOptionPane.showMessageDialog(null, "你赢了");
}
}
});
}
public int doSFC(){//随机生成1、2、3
int n = 0 ;
//
return n;
}
}
❸ JAVA课程设计,求个能用eclipse实现小游戏或小程序的源代码。感激不尽
你自己去下载吧,这里面都有 http://www.oschina.net/project/java
❹ 求Java课程设计—小游戏(含源代码)
http://hi..com/srxboys/item/8ce4743da1adc991c2cf29c4
Tank——坦克大战(简洁版)源代码-------(此文档是自己在韩顺平教程总结而来)
*功能:1.防止敌人的坦克重叠运动
*(决定把判断是否碰撞的函数写到EnemyTank类)
*2.可以分关
*2.1(做一个开始的Panel,它是一个空的)
*2.2开始字体闪烁
*3.可以在玩游戏的时候,暂停和继续
*3.1当用户点击暂停时,子弹的速度和坦克速度设为0,并让坦克的方向
*不要发生变化。
*4.可以记录玩家的成绩
*4.1用文件流的方式(小游戏)[大游戏是用的数据库<cs,bs>结构,三国]
*4.2单写一个记录类,完成对玩家的记录
*4.3先完成保存共击毁了多少辆敌人坦克的功能
*4.4存盘退出游戏,可以记录当时的敌人的坦克坐标,并可以恢复
*5.java如何操作声音文件
*/
❺ java课程设计程序-猜数游戏
Newload()
{
jf1=new JFrame("猜数游戏");
jf2=new JFrame("猜数游戏");
jf3=new JFrame("猜数游戏");
jf1_title=new JLabel("猜数游戏-欢迎进入");
jf1_title.setFont(new Font("仿宋体",Font.BOLD,40));//设置字体大小,及文字字体
jf1_title.setHorizontalAlignment(JLabel.CENTER);
JLabel jf2title=new JLabel("猜数游戏");
jf2title.setFont(new Font("仿宋体",Font.BOLD,40));//设置字体大小,及文字字体
jf2title.setHorizontalAlignment(JLabel.CENTER);
jf1_username=new JLabel("用户名");
jf1_userpass=new JLabel("密码");
jf2_question=new JLabel("There is question which needs you to guess!");
jf2_question.setFont(new Font("仿宋体",Font.BOLD,20));//设置字体大小,及文字字体
jf2_question.setHorizontalAlignment(JLabel.CENTER);
jf2_rightface=new JLabel(iron1);
jf2_wrongface=new JLabel(iron2);
jf2_rightface.setVisible(false);
jf2_wrongface.setVisible(false);
jf2_reelresult=new JLabel();
jf3_pinyu=new JLabel("your result is");
jf1_usernameT=new JTextField(6);
jf2_anwser=new JTextField(6);
jf2_anwser.addActionListener(this);
jf1_password=new JPasswordField(6);
jf1_password.addActionListener(this);
jf1_ok=new JButton("确定");
jf1_ok.addActionListener(this);
jf1_quit=new JButton("退出");
jf1_quit.addActionListener(this);
jf2_newgame=new JButton("新游戏(k)");
jf2_newgame.setMnemonic(KeyEvent.VK_K);
jf2_newgame.addActionListener(this);
jf2_ok=new JButton("确定");
jf2_ok.addActionListener(this);
jf1.setLayout(new BorderLayout());
jf2.setLayout(new BorderLayout());
JPanel jf1p1=new JPanel(),jf2p1=new JPanel(),jf2p2=new JPanel(),jf2p3=new JPanel();
jf2p1.setLayout(new BorderLayout());
jf1p1.setLayout(new FlowLayout());
jf2p2.setLayout(new FlowLayout());
jf2p3.setLayout(new FlowLayout());
jf1.add(jf1_title,"Center");
jf1p1.add(jf1_username);jf1p1.add(jf1_usernameT);
jf1p1.add(jf1_userpass);jf1p1.add(jf1_password);
jf1p1.add(jf1_ok);jf1p1.add(jf1_quit);
jf1.add(jf1p1,"South");
jf2p2.add(jf2_rightface);
jf2p2.add(jf2_wrongface);
jf2p2.add(jf2_reelresult);
jf2p1.add(jf2p2,"South");
jf2p1.add(jf2_question);
jf2.add(jf2title,"North");
jf2.add(jf2p1,"Center");
jf2p3.add(jf2_ans);jf2p3.add(jf2_anwser);jf2p3.add(jf2_ok);jf2p3.add(jf2_newgame);
jf2.add(jf2p3,"South");
jf3.add(jf3_pinyu);
jf1.setSize(700,400);
jf2.setSize(700,400);
jf3.setSize(700,400);
jf1.setLocation(300,150);
jf2.setLocation(300,150);
jf3.setLocation(300,150);
jf1.setVisible(true);
jf2.setVisible(false);
jf3.setVisible(false);
jf1.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
jf2.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jf1_ok||e.getSource()==jf1_password)
{char[] a=jf1_password.getPassword();String paas="";
for(int i=0;i<a.length;i++)//JPasswordField是一种特殊的类只能得到char数组,将其转成String
paas=paas+a[i];
if(jf1_usernameT.getText().equals("user")&&paas.equals("pass"))
{jf2.setVisible(true);jf1.setVisible(false);
number=returnquestion();
jf2_anwser.requestFocus();
}
else
JOptionPane.showMessageDialog(null,"用户名不正确或密码错误!");
}
if(e.getSource()==jf1_quit)
{
System.exit(0);
}
if(e.getSource()==jf2_ok||e.getSource()==jf2_anwser)
{
if(times<=5){
if(Integer.parseInt(jf2_anwser.getText())==number)
{
jf2_rightface.setVisible(true);
jf2_wrongface.setVisible(false);
jf2_reelresult.setText("you are right! and your have used "+times+" times!"
+((times<=3)?"very good!":"pleas do more work for it"));
}
else
if(Integer.parseInt(jf2_anwser.getText())>number)
{times++;
jf2_wrongface.setVisible(true);
jf2_rightface.setVisible(false);
jf2_reelresult.setText("your answer is bigger than the one proced by computer!"
+"and your have used "+times+" times!");
}
else
if(Integer.parseInt(jf2_anwser.getText())<number)
{times++;
jf2_wrongface.setVisible(true);
jf2_rightface.setVisible(false);
jf2_reelresult.setText("your answer is smaller than the one proced by computer!"
+"and your have used "+times+" times!");
}
}
else
{JOptionPane.showMessageDialog(null,"你已经超过六次了,请重新开始吧!");}
jf2_anwser.requestFocus();
jf2_anwser.setText("");
}
if(e.getSource()==jf2_newgame)
{
number=returnquestion();
times=0;
jf2_rightface.setVisible(false);
jf2_wrongface.setVisible(false);
jf2_anwser.setText("");
jf2_reelresult.setText("");
jf2_anwser.requestFocus();
}
}
public static void main(String args[])
{
new Newload();
}
int returnquestion()
{
double db=Math.random()*100;
return (int)db;
}
}
❻ !高分跪求帮忙写一个简单小程序的JAVA课程设计报告(内详!!)
连连看java源代码
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener
{
JFrame mainFrame; //主面板
Container thisContainer;
JPanel centerPanel,southPanel,northPanel; //子面板
JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组
JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮
JLabel fractionLable=new JLabel("0"); //分数标签
JButton firstButton,secondButton; //分别记录两次被选中的按钮
int grid[][] = new int[8][7];//储存游戏按钮位置
static boolean pressInformation=false; //判断是否有按钮被选中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标
int i,j,k,n;//消除方法控制
public void init(){
mainFrame=new JFrame("JKJ连连看");
thisContainer = mainFrame.getContentPane();
thisContainer.setLayout(new BorderLayout());
centerPanel=new JPanel();
southPanel=new JPanel();
northPanel=new JPanel();
thisContainer.add(centerPanel,"Center");
thisContainer.add(southPanel,"South");
thisContainer.add(northPanel,"North");
centerPanel.setLayout(new GridLayout(6,5));
for(int cols = 0;cols < 6;cols++){
for(int rows = 0;rows < 5;rows++ ){
diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));
diamondsButton[cols][rows].addActionListener(this);
centerPanel.add(diamondsButton[cols][rows]);
}
}
exitButton=new JButton("退出");
exitButton.addActionListener(this);
resetButton=new JButton("重列");
resetButton.addActionListener(this);
newlyButton=new JButton("再来一局");
newlyButton.addActionListener(this);
southPanel.add(exitButton);
southPanel.add(resetButton);
southPanel.add(newlyButton);
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));
northPanel.add(fractionLable);
mainFrame.setBounds(280,100,500,450);
mainFrame.setVisible(true);
}
public void randomBuild() {
int randoms,cols,rows;
for(int twins=1;twins<=15;twins++) {
randoms=(int)(Math.random()*25+1);
for(int alike=1;alike<=2;alike++) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
}
this.grid[cols][rows]=randoms;
}
}
}
public void fraction(){
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));
}
public void reload() {
int save[] = new int[30];
int n=0,cols,rows;
int grid[][]= new int[8][7];
for(int i=0;i<=6;i++) {
for(int j=0;j<=5;j++) {
if(this.grid[i][j]!=0) {
save[n]=this.grid[i][j];
n++;
}
}
}
n=n-1;
this.grid=grid;
while(n>=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
}
this.grid[cols][rows]=save[n];
n--;
}
mainFrame.setVisible(false);
pressInformation=false; //这里一定要将按钮点击信息归为初始
init();
for(int i = 0;i < 6;i++){
for(int j = 0;j < 5;j++ ){
if(grid[i+1][j+1]==0)
diamondsButton[i][j].setVisible(false);
}
}
}
public void estimateEven(int placeX,int placeY,JButton bz) {
if(pressInformation==false) {
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
pressInformation=true;
}
else {
x0=x;
y0=y;
fristMsg=secondMsg;
firstButton=secondButton;
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
if(fristMsg==secondMsg && secondButton!=firstButton){
xiao();
}
}
}
public void xiao() { //相同的情况下能不能消去。仔细分析,不一条条注释
if((x0==x &&(y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)&&(y0==y))){ //判断是否相邻
remove();
}
else{
for (j=0;j<7;j++ ) {
if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空
if (y>j) { //如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边
for (i=y-1;i>=j;i-- ){ //判断第二按钮左侧直到第一按钮中间有没有按钮
if (grid[x][i]!=0) {
k=0;
break;
}
else{ k=1; } //K=1说明通过了第一次验证
}
if (k==1) {
linePassOne();
}
}
if (y<j){ //如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边
for (i=y+1;i<=j ;i++ ){ //判断第二按钮左侧直到第一按钮中间有没有按钮
if (grid[x][i]!=0){
k=0;
break;
}
else { k=1; }
}
if (k==1){
linePassOne();
}
}
if (y==j ) {
linePassOne();
}
}
if (k==2) {
if (x0==x) {
remove();
}
if (x0<x) {
for (n=x0;n<=x-1;n++ ) {
if (grid[n][j]!=0) {
k=0;
break;
}
if(grid[n][j]==0 && n==x-1) {
remove();
}
}
}
if (x0>x) {
for (n=x0;n>=x+1 ;n-- ) {
if (grid[n][j]!=0) {
k=0;
break;
}
if(grid[n][j]==0 && n==x+1) {
remove();
}
}
}
}
}
for (i=0;i<8;i++ ) { //列
if (grid[i][y0]==0) {
if (x>i) {
for (j=x-1;j>=i ;j-- ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (x<i) {
for (j=x+1;j<=i;j++ ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (x==i) {
rowPassOne();
}
}
if (k==2){
if (y0==y) {
remove();
}
if (y0<y) {
for (n=y0;n<=y-1 ;n++ ) {
if (grid[i][n]!=0) {
k=0;
break;
}
if(grid[i][n]==0 && n==y-1) {
remove();
}
}
}
if (y0>y) {
for (n=y0;n>=y+1 ;n--) {
if (grid[i][n]!=0) {
k=0;
break;
}
if(grid[i][n]==0 && n==y+1) {
remove();
}
}
}
}
}
}
}
public void linePassOne(){
if (y0>j){ //第一按钮同行空按钮在左边
for (i=y0-1;i>=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮
if (grid[x0][i]!=0) {
k=0;
break;
}
else { k=2; } //K=2说明通过了第二次验证
}
}
if (y0<j){ //第一按钮同行空按钮在与第二按钮之间
for (i=y0+1;i<=j ;i++){
if (grid[x0][i]!=0) {
k=0;
break;
}
else{ k=2; }
}
}
}
public void rowPassOne(){
if (x0>i) {
for (j=x0-1;j>=i ;j-- ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
if (x0<i) {
for (j=x0+1;j<=i ;j++ ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
}
public void remove(){
firstButton.setVisible(false);
secondButton.setVisible(false);
fraction();
pressInformation=false;
k=0;
grid[x0][y0]=0;
grid[x][y]=0;
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==newlyButton){
int grid[][] = new int[8][7];
this.grid = grid;
randomBuild();
mainFrame.setVisible(false);
pressInformation=false;
init();
}
if(e.getSource()==exitButton)
System.exit(0);
if(e.getSource()==resetButton)
reload();
for(int cols = 0;cols < 6;cols++){
for(int rows = 0;rows < 5;rows++ ){
if(e.getSource()==diamondsButton[cols][rows])
estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);
}
}
}
public static void main(String[] args) {
lianliankan llk = new lianliankan();
llk.randomBuild();
llk.init();
}
}
//old 998 lines
//new 318 lines
参考资料:http://..com/question/36439800.html?fr=qrl3