java簡單小游戲
① 寫一個簡單的java小游戲
剛剛幫人改了一個小代碼游戲
地址是http://..com/question/160524457.html
是個互動小游戲,郵件就沒發了。
② 用JAVA編一個小游戲
我也想學
教教我吧
我是手游忠實的愛好者
有什麼游戲我也可以試玩哦
③ 用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編一個小游戲或者其他程序
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--剪刀(),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寫的簡單小游戲以及設計思路
建議去csdn查找裡面有源碼你可以敲一遍看看效果再理解
⑦ 用Java開發簡單的游戲
使用png格式的圖片,除去坦克以外部分鏤空,一來看起來好看點,二來能減少不少不必要的像素繪制。
另外就是圖片盡量小點,寧可作做放大處理,圖片資源越小,圖片紋理越小,載入到內存的過程越快。另外對於這種坦克、還有場景的一些固有的資源圖片,最好不要讓它自動從內存中釋放掉,打開游戲的時候自己做個預載入這些資源到內存中,整個程序結束的時候再從內存中釋放資源。java和objective-c都是有資源引用計數的,一開始你就給它們多添加一次引用就可以保證它們不會被自動釋放了(java我不怎麼用了,應該有現有的庫做這種事的吧,至少做android游戲開發內存預載入常要用的。)
⑧ 一個簡單的JAVA做的小游戲
我也不知道你要什麼樣的游戲
我隨便貼了一個
第一個Java文件:
import java.util.Scanner;
public class GameA_B {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
int area;
System.out.println("Game Start…………Please enter the area:(1-9)" +
'\n'+"1,2,3 means easy"+'\n'+"4,5,6 means middle"+'\n'+
"7,8,9 means hard"+'\n'+"Please choose:");
area=reader.nextInt();
switch((area-1)/3)
{
case 0:System.out.println("You choose easy! ");break;
case 1:System.out.println("You choose middle! ");break;
case 2:System.out.println("You choose hard! ");break;
}
System.out.println("Good Luck!");
GameProcess game1=new GameProcess(area);
game1.process();
}
}
第二個Java文件:
import java.util.Random;
import java.util.Scanner;
public class GameProcess {
int area,i,arrcount,right,midright,t;
int base[]=new int[arrcount],userNum[]=new int[area],sysNum[]=new int[area];
Random random=new Random();
Scanner reader=new Scanner(System.in);
GameProcess(int a)
{
area=a;
arrcount=10;
right=0;
midright=0;
t=0;
base=new int[arrcount];
userNum=new int[area];
sysNum=new int[area];
for(int i=0;i<arrcount;i++)
{
base[i]=i;
//System.out.println(base[i]);
}
}
void process()
{
rand();
while(right!=area)
{
scanf();
compare();
print();
check();
}
}
void rand()
{
for(i=0;i<area;i++)
{
t=random.nextInt(arrcount);
//System.out.println(t);
sysNum[i]=base[t];
System.out.println(base[t]);
delarr(t);
}
}
void delarr(int t)
{
for(int j=t;j<arrcount-1;j++)
base[j]=base[j+1];
arrcount--;
}
void scanf()
{
System.out.println("The system number has created!"+"\n"+"Please enter "+area+" Numbers");
for(int i=0;i<area;i++)
{
userNum[i]=reader.nextShort();
}
}
void check()
{
if(right==area)
System.out.println("You win…………!");
}
boolean check(int i)
{
return true;
}
void compare()
{
int i=0,j=0;
right=midright=0;
for(i=0;i<area;i++)
{
for(j=0;j<area;j++)
{
if(userNum[i]==sysNum[j])
{
if(i==j)
right++;
else
midright++;
}
}
}
}
void print()
{
System.out.println(" A "+right+" B "+midright);
}
}
希望能幫到你
忘點贊