📄 game_main.java
字号:
package rich_Game;
import java.awt.Event;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
import com.sun.org.apache.xpath.internal.operations.Equals;
public class Game_main {
private final static int MENU = 0;// 菜单
private final static int GAMEING = 1;// 游戏进行时
private final static int EXIT = 2;// 游戏退出
private static int gamestate = MENU;
public static Map map = new Map();
public static Big_map bmap = new Big_map();
public static boolean isP = true;// 判断 谁是当前玩家
public static Player p = new Player("钱贝贝", 50000, "男");
public static Player c = new Player("电脑", 50000);
public static Player temp;
public static void Init() {
bmap.Init();
}
/**
* 玩家事件
*/
public static void enevts(Player people) {
String s;
int[] map1 = bmap.getPos(people.position);
// int map_type[i][j].type=0;
switch (bmap.map_type[map1[0]][map1[1]].type) {
case 11:// 商店
System.out.println(people.getName() + "到达商店");
break;
case 12:// 公园
System.out.println(people.getName() + "到达公园");
break;
case 13:// 监狱
System.out.println(people.getName() + "到达监狱");
break;
case 14:// 赌场
System.out.println(temp.getName() + "到达赌场");
break;
case 2:// 空地
System.out.println("是否买地 Y买 N不买");
s = input(true);
if (s.equals("Y")) {
System.out.println("当前地属于" + people.getName());
people.setMoney(people.getMoney() - 1000);
System.out.println(people.getName() + "买下此地,现有总金钱为:" + people.getMoney());
// map.Updata();
if(people.getName().equals(p.getName()))
bmap.map_type[map1[0]][map1[1]].type=3;
else bmap.map_type[map1[0]][map1[1]].type=4;
} else if (s.equals("N")) {
System.out.println("不买了! Y 继续");
}
break;
}
}
private static void updata() {
System.out.println("请输入Y 继续:");
String str = input(true);
temp = new Player();
if (str.equals("Y")) {
}
if (isP = true) {
temp = p;
} else if (isP = false)
temp = c;
}
private static int random(int min, int max) {
int rand = 0;
Random random = new Random();
rand = Math.abs(random.nextInt() % max - min + 1) + min;// 取1-6的数
return rand;
}
public static byte previous() {
System.out.println("轮到 " + temp.getName() + "摇色子");
byte tempNum = (byte) random(1, 6);
return tempNum;// 骰子点数
}
public static void main(String[] args) {
// int tempNum=0;
boolean bool = true;
Init();
while (bool) {
switch (gamestate) {
case MENU:
System.out.println("大富翁游戏");
// System.out.println(map.showstr);
System.out.println("游戏开始,请输入大写字母(Y 开始 /N 退出)");
String str = input(true);
if (str.equals("Y")) {
System.out.println("现在电脑和玩家都在同一个起点位置.游戏开始后,谁的钱输完就认输.祝好运!");
p.diaplay();
c.diaplay();
gamestate = GAMEING;
} else if (str.equals("N")) {
gamestate = EXIT;
}
break;
//
// System.out.println(p);
case GAMEING:
while (true) {
updata();
byte num = previous();
System.out.println("现在由" + temp.getName() + "摇出的骰子点数是"
+ num + "点");
System.out
.println("现在" + temp.getName() + "移动" + num + "步");
enevts(temp);
bmap.Render();
// map.display(true);
updata();
System.out.println("现在由" + c.getName() + "摇出的骰子点数是" + num
+ "点");
System.out.println("现在" + c.getName() + "移动" + num + "步");
bmap.setMap(num, temp);
enevts(temp);
bmap.Render();
gamestate = 0;
}
case EXIT:
bool = false;
break;
default:
break;
}
}
}
/**
* 获取用户的输入 input函数
*/
public static String input(boolean inputstate) {
String num1 = null;
InputStreamReader isr = new InputStreamReader(System.in);
// 声明一个isr的缓冲区
BufferedReader br = new BufferedReader(isr);
try {
// 从命令行读入一行字
num1 = br.readLine();
if (inputstate) {
if (!num1.equals("Y") && !num1.equals("N"))
throw new IOException();
}
} catch (IOException ex) {
// 程序IO异常处理
System.out.println("对不起,您输入的格式不正确。输入大写Y/N");
// System.exit(0);
}
return num1;
}
/** 判断输赢 */
public static void win(boolean isEnd) {
if (isEnd = false) {
System.out.println(Game_main.p.getPlayer() == 0);
System.out.println(p.getName() + "金钱已经输光了!");
System.out.println(p.getName() + "输!!!");
System.out.println("GAME OVER!");
} else {
gamestate = EXIT;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -