當前位置:首頁 » 編程語言 » java小游戲開發

java小游戲開發

發布時間: 2023-08-01 13:39:16

『壹』 用java編一個小游戲或者其他程序

import java.util.Random;
import java.util.Scanner;

public class Game {

private static int win=0;
private static int fail=0;
private static int pi=0;
private static void check(int cpu,int pe){
int t=0;
if(pe-cpu==2) t= -1;
else if(pe-cpu==-2) t= 1;
else t=pe-cpu;
if(t>0) {System.out.println("你贏了!");win++;}
else if(t==0) {System.out.println("咱們平了!");pi++;}
else {System.out.println("你輸了!");fail++;}
}
public static void main(String[] args) {
String input="";
String cpuStr="";
Random rand=new Random();
int cpu=0;
int pe=0;
while(true){
System.out.println("*************************小游戲一個 輸e/E可以退出*****************");
System.out.println("請選擇你要出什麼?F--剪刀(forfex),S--石頭(stone),C--布(cloth)");
Scanner scan=new Scanner(System.in);
input=scan.nextLine();
cpu=rand.nextInt(3);
if(cpu==0)cpuStr="剪刀";
else if(cpu==1)cpuStr="石頭";
else cpuStr="布";

if(input.equals("F")||input.equals("f")){
pe=0;
System.out.println("你出的是,剪刀");
System.out.println("我出"+cpuStr);
check(cpu,pe);
}else if(input.equals("S")||input.equals("s")){
pe=1;
System.out.println("你出的是,石頭");
System.out.println("我出"+cpuStr);
check(cpu,pe);
}else if(input.equals("C")||input.equals("c")){
pe=2;
System.out.println("你出的是,布");
System.out.println("我出"+cpuStr);
check(cpu,pe);
}else if(input.equals("E")||input.equals("e")){
System.out.println("結束游戲。。");
System.out.println("結果統計:");
System.out.println("勝:"+win+"局");
System.out.println("負:"+fail+"局");
System.out.println("平:"+pi+"局");
System.exit(0);
}
}

}

}

以上回答參考:
http://..com/question/39899654.html

『貳』 用JAVA編寫一個小游戲

前天寫的猜數字游戲,yongi控制猜測次數,有詳細解析,用黑窗口可以直接運行,

我試驗過了,沒問題

import javax.swing.Icon;
import javax.swing.JOptionPane;
public class CaiShuZi4JOptionPane {
/**
* @param args
*/
public static void main(String[] args) {
Icon icon = null;
boolean bl = false;
int put = 0;
int c = (int) (((Math.random())*100)+1); //獲取一個1-100的隨機數
System.out.println("你獲取的隨機數是:"+c); //列印你的隨機數字

String str1 = (String) JOptionPane.showInputDialog(null,"請輸入你的猜測數字(1-100): ","猜數字游戲",JOptionPane.PLAIN_MESSAGE,icon,null,"在這輸入"); //第一次輸入你的猜測數字

if(str1==null){
JOptionPane.showMessageDialog(null, "你已經取消了本次游戲"); //如果你點取消那麼本次游戲結束
}else{
bl = num(str1); //判斷是輸入的是不是數字或者是整數
if(true==bl){ //如果是數字的話進入與隨機數比較的程序
System.out.println("你輸入的數字是:"+str1); //列印你輸入的數字
put = Integer.valueOf(str1);

for(int i = 4;i > 0;i--){ //i是你可以猜測的次數
if(put==c){
JOptionPane.showMessageDialog(null, "恭喜你猜對了,正確答案是:"+c+"。"); //如果你猜對了就直接結束循環
break;
}else if(put>c){ //如果輸大了就讓你再次從新輸入
str1 = (String) JOptionPane.showInputDialog(null,"你的輸入過大。你還有"+i+"次機會,請重新輸入: ","猜數字游戲",JOptionPane.PLAIN_MESSAGE,icon,null,"在這輸入");
if(str1==null){
JOptionPane.showMessageDialog(null, "你已經取消了本次輸入");
break;
}else{
bl =num(str1);
if(true==bl){
put = Integer.valueOf(str1);
}else{
JOptionPane.showMessageDialog(null, "你的輸入不正確,請重新輸入");
}
}
}else if(put<c){ //如果你輸小了也讓你從新輸入
str1 = (String) JOptionPane.showInputDialog(null,"你的輸入過小。你還有"+i+"次機會,請重新輸入: ","猜數字游戲",JOptionPane.PLAIN_MESSAGE,icon,null,"在這輸入");
if(str1==null){
JOptionPane.showMessageDialog(null, "你已經取消了本次輸入");
break;
}else{
bl =num(str1);
if(true==bl){
put = Integer.valueOf(str1);
}else{
JOptionPane.showMessageDialog(null, "你的輸入不正確,請重新輸入");
}
}
}
}


}else if(bl==false){ //這個 是你第一次如果填寫的不是數字的話也會結束本次游戲
JOptionPane.showMessageDialog(null, "請您下次按要求填寫。本次游戲結束");
}
if(true==bl && c!=put){ //如果你i次都沒猜對,那麼就直接告訴你這個數十什麼
JOptionPane.showMessageDialog(null, "很遺憾你沒能猜對,這個數字是:"+c+".");
}

}

}

public static boolean num(String value){ //一個靜態方法,判斷你輸入的是不是數字
try {
Integer.parseInt(value);
return true;
} catch (Exception e) {
return false;
}

}
}

『叄』 JAVA能寫游戲嗎

可以的哦,語言是工具,具體用這個工具做什麼,是看編寫者的想法,我們在使用的,以及零幾年的時候,手機游戲多數都回彈出一個JAVA+一杯茶的圖片, 那些游戲就是JAVA寫的

『肆』 java做一些小游戲需要學什麼

那就學游戲開發這個專業,畢竟java只是一門工具

『伍』 求一個簡單又有趣的JAVA小游戲代碼

具體如下:

連連看的小源碼

package Lianliankan;

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;//消除方法控制

代碼(code)是程序員用開發工具所支持的語言寫出來的源文件,是一組由字元、符號或信號碼元以離散形式表示信息的明確的規則體系。

對於字元和Unicode數據的位模式的定義,此模式代表特定字母、數字或符號(例如 0x20 代表一個空格,而 0x74 代表字元「t」)。一些數據類型每個字元使用一個位元組;每個位元組可以具有 256 個不同的位模式中的一個模式。

在計算機中,字元由不同的位模式(ON 或 OFF)表示。每個位元組有 8 位,這 8 位可以有 256 種不同的 ON 和 OFF 組合模式。對於使用 1 個位元組存儲每個字元的程序,通過給每個位模式指派字元可表示最多 256 個不同的字元。2 個位元組有 16 位,這 16 位可以有 65,536 種唯一的 ON 和 OFF 組合模式。使用 2 個位元組表示每個字元的程序可表示最多 65,536 個字元。

單位元組代碼頁是字元定義,這些字元映射到每個位元組可能有的 256 種位模式中的每一種。代碼頁定義大小寫字元、數字、符號以及 !、@、#、% 等特殊字元的位模式。每種歐洲語言(如德語和西班牙語)都有各自的單位元組代碼頁。

雖然用於表示 A 到 Z 拉丁字母表字元的位模式在所有的代碼頁中都相同,但用於表示重音字元(如"é"和"á")的位模式在不同的代碼頁中卻不同。如果在運行不同代碼頁的計算機間交換數據,必須將所有字元數據由發送計算機的代碼頁轉換為接收計算機的代碼頁。如果源數據中的擴展字元在接收計算機的代碼頁中未定義,那麼數據將丟失。

如果某個資料庫為來自許多不同國家的客戶端提供服務,則很難為該資料庫選擇這樣一種代碼頁,使其包括所有客戶端計算機所需的全部擴展字元。而且,在代碼頁間不停地轉換需要花費大量的處理時間。

『陸』 用java做一個小游戲

import java.awt.*;
public class TowerPoint
{
int x,y;
boolean 有盤子;
Disk 盤子=null;
HannoiTower con=null;
public TowerPoint(int x,int y,boolean boo)
{
this.x=x;
this.y=y;
有盤子=boo;
}
public boolean 是否有盤子()
{
return 有盤子;
}
public void set有盤子(boolean boo)
{
有盤子=boo;
}

public int getX()
{
return x;
}
public int getY()
{
return y;
}
public void 放置盤子(Disk 盤子,HannoiTower con)
{
this.con=con;
con.setLayout(null);
this.盤子=盤子;
con.add(盤子);
int w=盤子.getBounds().width;
int h=盤子.getBounds().height;
盤子.setBounds(x-w/2,y-h/2,w,h);
有盤子=true;
con.validate();
}
public Disk 獲取盤子()
{
return 盤子;
}
}

熱點內容
怎麼給物理機配置ip地址 發布:2025-02-07 08:01:37 瀏覽:138
三國志13未加密 發布:2025-02-07 07:54:37 瀏覽:925
馬斯克中國訪問 發布:2025-02-07 07:54:29 瀏覽:101
資料庫有表 發布:2025-02-07 07:50:49 瀏覽:28
基於nginx搭建圖片伺服器原理 發布:2025-02-07 07:44:18 瀏覽:448
java等待 發布:2025-02-07 07:28:24 瀏覽:612
vs編譯器會自己加空格嗎 發布:2025-02-07 07:23:05 瀏覽:175
光遇切換賬號安卓要輸入些什麼 發布:2025-02-07 07:10:20 瀏覽:501
多角線演算法 發布:2025-02-07 07:08:56 瀏覽:273
有效提高ftp傳輸速度 發布:2025-02-07 07:06:47 瀏覽:703