1. 求java小游戲源代碼
[最佳答案] 連連看java源代碼 import javax.swing.*; import java.awt.*; import java.awt.event.*; pu... int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戲按鈕的位...
2. 我在網路上下載了一些java游戲源碼,擴展名是jar格式,請問怎麼打開
你把它直接扔到手機里就行了。
第一步:於手機的數據線連接(讀卡器也行)
第二補:把JAVA游戲扔到手機里
第三步:打開手機,安裝,
第四步:你可以玩了
3. 跪求游戲java源代碼
給你一個俄羅斯方塊的把!!
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
import javax.swing.Timer;
public class Tetris extends JFrame {
public Tetris() {
Tetrisblok a = new Tetrisblok();
addKeyListener(a);
add(a);
}
public static void main(String[] args) {
Tetris frame = new Tetris();
JMenuBar menu = new JMenuBar();
frame.setJMenuBar(menu);
JMenu game = new JMenu("游戲");
JMenuItem newgame = game.add("新游戲");
JMenuItem pause = game.add("暫停");
JMenuItem goon = game.add("繼續");
JMenuItem exit = game.add("退出");
JMenu help = new JMenu("幫助");
JMenuItem about = help.add("關於");
menu.add(game);
menu.add(help);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(220, 275);
frame.setTitle("Tetris內測版");
// frame.setUndecorated(true);
frame.setVisible(true);
frame.setResizable(false);
}
}
// 創建一個俄羅斯方塊類
class Tetrisblok extends JPanel implements KeyListener {
// blockType 代表方塊類型
// turnState代表方塊狀態
private int blockType;
private int score = 0;
private int turnState;
private int x;
private int y;
private int i = 0;
int j = 0;
int flag = 0;
// 定義已經放下的方塊x=0-11,y=0-21;
int[][] map = new int[13][23];
// 方塊的形狀 第一組代表方塊類型有S、Z、L、J、I、O、T 7種 第二組 代表旋轉幾次 第三四組為 方塊矩陣
private final int shapes[][][] = new int[][][] {
// i
{ { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0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} },
// l
{ { 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
// t
{ { 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 } } };
// 生成新方塊的方法
public void newblock() {
blockType = (int) (Math.random() * 1000) % 7;
turnState = (int) (Math.random() * 1000) % 4;
x = 4;
y = 0;
if (gameover(x, y) == 1) {
newmap();
drawwall();
score = 0;
JOptionPane.showMessageDialog(null, "GAME OVER");
}
}
// 畫圍牆
public void drawwall() {
for (i = 0; i < 12; i++) {
map[i][21] = 2;
}
for (j = 0; j < 22; j++) {
map[11][j] = 2;
map[0][j] = 2;
}
}
// 初始化地圖
public void newmap() {
for (i = 0; i < 12; i++) {
for (j = 0; j < 22; j++) {
map[i][j] = 0;
}
}
}
// 初始化構造方法
Tetrisblok() {
newblock();
newmap();
drawwall();
Timer timer = new Timer(1000, new TimerListener());
timer.start();
}
// 旋轉的方法
public void turn() {
int tempturnState = turnState;
turnState = (turnState + 1) % 4;
if (blow(x, y, blockType, turnState) == 1) {
}
if (blow(x, y, blockType, turnState) == 0) {
turnState = tempturnState;
}
repaint();
}
// 左移的方法
public void left() {
if (blow(x - 1, y, blockType, turnState) == 1) {
x = x - 1;
}
;
repaint();
}
// 右移的方法
public void right() {
if (blow(x + 1, y, blockType, turnState) == 1) {
x = x + 1;
}
;
repaint();
}
// 下落的方法
public void down() {
if (blow(x, y + 1, blockType, turnState) == 1) {
y = y + 1;
delline();
}
;
if (blow(x, y + 1, blockType, turnState) == 0) {
add(x, y, blockType, turnState);
newblock();
delline();
}
;
repaint();
}
// 是否合法的方法
public int blow(int x, int y, int blockType, int turnState) {
for (int a = 0; a < 4; a++) {
for (int b = 0; b < 4; b++) {
if (((shapes[blockType][turnState][a * 4 + b] == 1) && (map[x
+ b + 1][y + a] == 1))
|| ((shapes[blockType][turnState][a * 4 + b] == 1) && (map[x
+ b + 1][y + a] == 2))) {
return 0;
}
}
}
return 1;
}
// 消行的方法
public void delline() {
int c = 0;
for (int b = 0; b < 22; b++) {
for (int a = 0; a < 12; a++) {
if (map[a][b] == 1) {
c = c + 1;
if (c == 10) {
score += 10;
for (int d = b; d > 0; d--) {
for (int e = 0; e < 11; e++) {
map[e][d] = map[e][d - 1];
}
}
}
}
}
c = 0;
}
}
// 判斷你掛的方法
public int gameover(int x, int y) {
if (blow(x, y, blockType, turnState) == 0) {
return 1;
}
return 0;
}
// 把當前添加map
public void add(int x, int y, int blockType, int turnState) {
int j = 0;
for (int a = 0; a < 4; a++) {
for (int b = 0; b < 4; b++) {
if (map[x + b + 1][y + a] == 0) {
map[x + b + 1][y + a] = shapes[blockType][turnState][j];
}
;
j++;
}
}
}
// 畫方塊的的方法
public void paintComponent(Graphics g) {
super.paintComponent(g);
// 畫當前方塊
for (j = 0; j < 16; j++) {
if (shapes[blockType][turnState][j] == 1) {
g.fillRect((j % 4 + x + 1) * 10, (j / 4 + y) * 10, 10, 10);
}
}
// 畫已經固定的方塊
for (j = 0; j < 22; j++) {
for (i = 0; i < 12; i++) {
if (map[i][j] == 1) {
g.fillRect(i * 10, j * 10, 10, 10);
}
if (map[i][j] == 2) {
g.drawRect(i * 10, j * 10, 10, 10);
}
}
}
g.drawString("score=" + score, 125, 10);
g.drawString("抵制不良游戲,", 125, 50);
g.drawString("拒絕盜版游戲。", 125, 70);
g.drawString("注意自我保護,", 125, 90);
g.drawString("謹防受騙上當。", 125, 110);
g.drawString("適度游戲益腦,", 125, 130);
g.drawString("沉迷游戲傷身。", 125, 150);
g.drawString("合理安排時間,", 125, 170);
g.drawString("享受健康生活。", 125, 190);
}
// 鍵盤監聽
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_DOWN:
down();
break;
case KeyEvent.VK_UP:
turn();
break;
case KeyEvent.VK_RIGHT:
right();
break;
case KeyEvent.VK_LEFT:
left();
break;
}
}
// 無用
public void keyReleased(KeyEvent e) {
}
// 無用
public void keyTyped(KeyEvent e) {
}
// 定時器監聽
class TimerListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
repaint();
if (blow(x, y + 1, blockType, turnState) == 1) {
y = y + 1;
delline();
}
;
if (blow(x, y + 1, blockType, turnState) == 0) {
if (flag == 1) {
add(x, y, blockType, turnState);
delline();
newblock();
flag = 0;
}
flag = 1;
}
;
}
}
}
4. 求一個簡單RPG游戲的代碼,JAva編寫的
packagecom.lxi;
importjava.io.BufferedReader;
importjava.io.InputStreamReader;
publicclassRpg{
@SuppressWarnings("unchecked")
publicstaticvoidmain(String[]args)throwsException{
System.out.println("在這里輸入兩個人物進行PK,以英文逗號分隔:[BM,DH,MK]");
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
Class<Person>c1;
Class<Person>c2;
try{
Stringtemp=br.readLine();
String[]str=temp.split(",");
if(str.length!=2){
thrownewException("輸入格式有誤,按默認PK");
}
c1=(Class<Person>)Class.forName("com.lxi."
+str[0].toUpperCase());
c2=(Class<Person>)Class.forName("com.lxi."
+str[1].toUpperCase());
}catch(Exceptione){
//TODOAuto-generatedcatchblock
c1=(Class<Person>)Class.forName("com.lxi.BM");
c2=(Class<Person>)Class.forName("com.lxi.DH");
}
try{
Personp1=c1.newInstance();
Personp2=c2.newInstance();
longtime=System.currentTimeMillis();
longnextTime1=(long)(time+p1.coldTime*1000);//
longnextTime2=(long)(time+p2.coldTime*1000);//發動攻擊的時間
System.out.println("---游戲開始---");
while(true){
longcurrenTime=System.currentTimeMillis();
if(nextTime1<currenTime){//時間到則發動攻擊
p1.hit(p2);
nextTime1+=p1.coldTime*1000+p1.waitTime*1000;//下次攻擊時間=冷卻時間+被暈眩時間
p1.waitTime=0;//回合結束,重置被暈眩時間為0
}
if(nextTime2<currenTime){
p2.hit(p1);
nextTime2+=p2.coldTime*1000+p2.waitTime*1000;
p2.waitTime=0;
}
}
}catch(ClassCastExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(InstantiationExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(IllegalAccessExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(Exceptione){
e.printStackTrace();
}
}
}
packagecom.lxi;
importjava.util.Random;
classBMextendsPerson{
publicBM(){
val=650;
coldTime=1.5;
fight=40;
chanceHit=3;
chanceDefense=3;
waitTime=0;
}
intcount=0;//防禦技能發動的次數
inttemp=40;//攻擊力,值同fight
booleanhitFlag=false;
booleandefenseFlag=false;
Randomrand=newRandom();
publicvoidhit(Personp){
if(rand.nextInt(10)<chanceHit){
fight=fight*2;//發動雙倍攻擊
hitFlag=true;
}
inthurt=p.defense(this);
p.val=p.val-hurt;
fight=temp;//還原為單倍攻擊
if(p.val<=0){
System.out.println(this.getClass().getSimpleName()+"勝出!");
System.exit(0);
}
System.out.println(this.getClass().getSimpleName()+"攻擊"
+p.getClass().getSimpleName()+","
+this.getClass().getSimpleName()
+(this.hitFlag?"發動攻擊技能":"未發動攻擊技能")
+p.getClass().getSimpleName()
+(this.defenseFlag?"發動防禦技能":"未發動防禦技能")
+this.getClass().getSimpleName()+":"+this.val+","
+p.getClass().getSimpleName()+":"+p.val);
hitFlag=false;
defenseFlag=false;
}
publicintdefense(Personp){
if(rand.nextInt(10)<chanceDefense){
if(count!=0){
p.val=p.val-p.fight;
count++;
defenseFlag=true;
if(p.val<=0){
System.out.println(this.getClass().getSimpleName()+"勝出!");
System.exit(0);
}
}
}
returnp.fight;
}
}
classMKextendsPerson{
publicMK(){
val=700;
coldTime=2.5;
fight=50;
chanceDefense=6;
chanceHit=3;
waitTime=0;
}
booleanhitFlag=false;
booleandefenseFlag=false;
Randomrand=newRandom();
publicvoidhit(Personp){
if(rand.nextInt(10)<chanceHit){
p.waitTime=3;//使對方暈眩3s
hitFlag=true;
}
inthurt=p.defense(this);
p.val=p.val-hurt;
if(p.val<=0){
System.out.println(this.getClass().getSimpleName()+"勝出!");
System.exit(0);
}
System.out.println(this.getClass().getSimpleName()+"攻擊"
+p.getClass().getSimpleName()+","
+this.getClass().getSimpleName()
+(this.hitFlag?"發動攻擊技能":"未發動攻擊技能")
+p.getClass().getSimpleName()
+(this.defenseFlag?"發動防禦技能":"未發動防禦技能")
+this.getClass().getSimpleName()+":"+this.val+","
+p.getClass().getSimpleName()+":"+p.val);
hitFlag=false;
defenseFlag=false;
}
publicintdefense(Personp){
if(rand.nextInt(10)<chanceDefense){
defenseFlag=true;
returnp.fight/2;//防禦技能發動,傷害減半
}
returnp.fight;
}
}
packagecom.lxi;
importjava.io.BufferedReader;
importjava.io.InputStreamReader;
importjava.util.Random;
//三個人物的基類
abstractclassPerson{
intval;//生命值
doublecoldTime;//冷卻時間
intwaitTime;//暈眩時間
intfight;//攻擊力
intchanceHit;//發起主動技能的概率
intchanceDefense;//發起防禦技能的概率
abstractvoidhit(Personp);//攻擊技能
abstractintdefense(Personp);//防禦技能,返回被傷害點數
}
classDHextendsPerson{
publicDH(){
val=600;
coldTime=1.0;
fight=30;
chanceHit=3;//表示30%的概率
chanceDefense=3;
waitTime=0;
}
Randomrand=newRandom();
booleanhitFlag=false;//主動技能發動的標識
booleandefenseFlag=false;//防禦技能發動的標識
publicvoidhit(Personp){
if(rand.nextInt(10)<chanceHit){//發動主動技能
inthurt=p.defense(this);
p.val=p.val-hurt;
if(p.val<=0){
System.out.println(this.getClass().getSimpleName()+"勝出!");
System.exit(0);
}
val=val+hurt;
if(val>600)
val=600;
hitFlag=true;//標記主動技能已經發動
}else{//進行普通攻擊
inthurt=p.defense(this);
p.val=p.val-hurt;
if(p.val<=0){
System.out.println(this.getClass().getSimpleName()+"勝出!");
System.exit(0);
}
}
System.out.println(this.getClass().getSimpleName()+"攻擊"
+p.getClass().getSimpleName()+","
+this.getClass().getSimpleName()
+(this.hitFlag?"發動攻擊技能":"未發動攻擊技能")
+p.getClass().getSimpleName()
+(this.defenseFlag?"發動防禦技能":"未發動防禦技能")
+this.getClass().getSimpleName()+":"+this.val+","
+p.getClass().getSimpleName()+":"+p.val);
hitFlag=false;//
defenseFlag=false;//重置標記,下次重用
}
publicintdefense(Personp){
if(rand.nextInt(10)<chanceDefense){
defenseFlag=true;//標記防禦技能已經發動
return0;
}else{
returnp.fight;
}
}
}
5. java游戲源碼怎麼用
這要看你要寫什麼手機程序,是android還是j2me。android和j2me的話就用eclipse就可以了,IDE中集成了一些插件,比較方便。格式的話都不一樣,android的是APK格式的,j2me是PNG的。先在pc上開發出來程序,裝一個虛擬設備,調試成功後,將你的程序打包,網上有很多教程,這里就不說了,打包完成後就可以放入手機中了。寫了這么多,請採納
6. 求一個簡單又有趣的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 拉丁字母表字元的位模式在所有的代碼頁中都相同,但用於表示重音字元(如"é"和"á")的位模式在不同的代碼頁中卻不同。如果在運行不同代碼頁的計算機間交換數據,必須將所有字元數據由發送計算機的代碼頁轉換為接收計算機的代碼頁。如果源數據中的擴展字元在接收計算機的代碼頁中未定義,那麼數據將丟失。
如果某個資料庫為來自許多不同國家的客戶端提供服務,則很難為該資料庫選擇這樣一種代碼頁,使其包括所有客戶端計算機所需的全部擴展字元。而且,在代碼頁間不停地轉換需要花費大量的處理時間。
7. 如何用java語言做一個rpg類游戲
首先要學會游戲邏輯一般的游戲開發教程上都有其次是界面如果是2d的swing就可以不過建議還是找游戲專用的框架
8. java網路游戲源代碼下載
這是游戲公司的最高度機密。。。哪可能有啊。。
而且只用JAVA是做不出網路游戲的。。
要是代碼被知道的話,黑客直接進游戲哪東西,都不用知道別人賬號密碼