@@ 两人重合时
A 玩家1
B 玩家2
◎ 幸运轮盘
★ 地雷
■ 暂停
〓 时空隧道
∷ 普通格 0
地图样式
∷∷∷∷∷★¤∷∷■∷∷∷★∷∷∷★∷∷〓∷∷¤∷〓∷■∷∷∷
∷
∷
★
∷
∷★〓∷∷■∷∷∷∷∷∷∷∷∷★∷∷∷∷〓∷∷∷∷¤∷★∷∷∷
∷
∷
∷
¤∷∷〓∷∷∷∷∷∷∷★∷∷¤∷∷∷∷〓∷〓∷∷■★∷∷∷∷∷
int [ ] map = new int [ 100 ] ;
int [ ] luckyTurn = { 6 , 23 , 40 , 55 , 69 , 83 } ;
int [ ] landMine = { 5 , 13 , 17 , 33 , 38 , 50 , 64 , 80 , 94 } ;
int [ ] pause = { 9 , 27 , 60 , 93 } ;
int [ ] timeTunnel = { 20 , 25 , 45 , 63 , 72 , 88 , 90 } ;
第一行 31 0 - 30
右竖列 31 - 34
第二行 35 - 65
左竖列 66 - 68
第三行 69 - 99
规则:
游戏从玩家1 先扔骰子开始,走出相应步数,然后玩家2 扔骰子,重复过程。当任意一个玩家走到地图结束位置则游戏结束。
判定规则:
1. 当玩家重合时,被踩中的玩家退回到起点。
2. 当玩家遇到幸运轮盘时,可以再掷一次骰子。1 - 6 之间的数
3. 当玩家遇到地雷时,随机后退1 - 6 步。
4. 当玩家遇到暂停时,下次回合中玩家不能掷骰子。
5. 当玩家遇到时空隧道时,穿越到下一个时空隧道,但是如果下一个时空隧道不存在,退回到第一个时空隧道。
编写游戏时需要的属性
玩家1 和玩家2 的昵称
玩家1 的位置
玩家2 的位置
玩家1 和玩家2 是否暂停的标识
游戏的过程:
当任意一个玩家走到地图结束位置则游戏结束
游戏从玩家1 先仍骰子开始,走完当前地图,然后玩家扔骰子
扔完骰子后计算玩家当前在声明位置
package flygame;
import java. util. Random;
public class Player {
private String name;
private int point;
private boolean isPause= false ;
public Player ( ) {
}
public Player ( String name, int point, boolean isPause) {
super ( ) ;
this . name = name;
this . point = point;
this . isPause = isPause;
}
public String getName ( ) {
return name;
}
public void setName ( String name) {
this . name = name;
}
public int getPoint ( ) {
return point;
}
public void setPoint ( int point) {
this . point = point;
}
public boolean isPause ( ) {
return isPause;
}
public void setPause ( boolean isPause) {
this . isPause = isPause;
}
public int play ( ) {
Random m= new Random ( ) ;
int num= m. nextInt ( 6 ) + 1 ;
return num;
}
}
package flygame;
public class Map {
int [ ] map = new int [ 100 ] ;
public void init ( ) {
int [ ] luckyTurn = { 6 , 23 , 40 , 55 , 69 , 83 } ;
int [ ] landMine = { 5 , 13 , 17 , 33 , 38 , 50 , 64 , 80 , 94 } ;
int [ ] pause = { 9 , 27 , 60 , 93 } ;
int [ ] timeTunnel = { 20 , 25 , 45 , 63 , 72 , 88 , 90 } ;
for ( int i= 0 ; i< luckyTurn. length; i++ ) {
int index = luckyTurn[ i] ;
map[ index] = 1 ;
}
for ( int i= 0 ; i< landMine. length; i++ ) {
int index = landMine[ i] ;
map[ index] = 2 ;
}
for ( int i= 0 ; i< pause. length; i++ ) {
int index= pause[ i] ;
map[ index] = 3 ;
}
for ( int i= 0 ; i< timeTunnel. length; i++ ) {
int index= timeTunnel[ i] ;
map[ index] = 4 ;
}
showMap ( 0 , 0 ) ;
}
public void drawLine ( int begin, int end) {
for ( int i= begin; i<= end; i++ ) {
System. out. print ( getGraphics ( map[ i] ) ) ;
}
System. out. println ( ) ;
}
public void drawLine ( int begin, int end, int aPos, int bPos) {
for ( int i= begin; i<= end; i++ ) {
System. out. print ( getGraphics ( map[ i] , i, aPos, bPos) ) ;
}
System. out. println ( ) ;
}
public void drawRight ( int begin, int end) {
for ( int i= begin; i<= end; i++ ) {
for ( int j= 1 ; j<= 53 ; j++ ) { System. out. print ( " " ) ; }
System. out. println ( getGraphics ( map[ i] ) ) ;
}
}
public void drawRight ( int begin, int end, int aPos, int bPos) {
for ( int i= begin; i<= end; i++ ) {
for ( int j= 1 ; j<= 53 ; j++ ) { System. out. print ( " " ) ; }
System. out. println ( getGraphics ( map[ i] , i, aPos, bPos) ) ;
}
}
public void drawMiddleLine ( int begin, int end) {
for ( int i= end; i>= begin; i-- ) {
System. out. print ( getGraphics ( map[ i] ) ) ;
}
System. out. println ( ) ;
}
public void drawMiddleLine ( int begin, int end, int aPos, int bPos) {
for ( int i= end; i>= begin; i-- ) {
System. out. print ( getGraphics ( map[ i] , i, aPos, bPos) ) ;
}
System. out. println ( ) ;
}
public void drawLeft ( int begin, int end) {
for ( int i= begin; i<= end; i++ ) {
System. out. println ( getGraphics ( map[ i] ) ) ;
}
}
public void drawLeft ( int begin, int end, int aPos, int bPos) {
for ( int i= begin; i<= end; i++ ) {
System. out. println ( getGraphics ( map[ i] , i, aPos, bPos) ) ;
}
}
public void showMap ( int aPos, int bPos) {
drawLine ( 0 , 30 , aPos, bPos) ;
drawRight ( 31 , 34 , aPos, bPos) ;
drawMiddleLine ( 35 , 65 , aPos, bPos) ;
drawLeft ( 66 , 69 , aPos, bPos) ;
drawLine ( 70 , 99 , aPos, bPos) ;
}
public String getGraphics ( int flag) {
String icon= null;
if ( flag== 0 ) { icon= "∷" ; }
else if ( flag== 1 ) { icon= "◎" ; }
else if ( flag== 2 ) { icon= "★" ; }
else if ( flag== 3 ) { icon= "■" ; }
else { return icon= "〓" ; }
return icon;
}
public String getGraphics ( int flag, int index, int aPos, int bPos) {
String icon= null;
if ( index== aPos&& index== bPos) {
icon= "@@" ;
} else if ( index== aPos) {
icon= "A" ;
} else if ( index== bPos) {
icon= "B" ;
} else {
icon= getGraphics ( flag) ;
}
return icon;
}
}
package flygame;
import java. util. Random;
import java. util. Scanner;
public class Game {
Player[ ] player = new Player [ 2 ] ;
Map map;
public void init ( ) {
Scanner in = new Scanner ( System. in) ;
for ( int i= 0 ; i< player. length; i++ ) {
System. out. println ( "请玩家1选择角色:1.吴煜鑫; 2.陆小涛; 3.王帅:" ) ;
int choose= in. nextInt ( ) ;
player[ i] = new Player ( ) ;
player[ i] . setName ( getName ( choose) ) ;
}
map= new Map ( ) ;
map. init ( ) ;
start ( ) ;
}
public String getName ( int choose) {
String name= null;
switch ( choose) {
case 1 :
name= "吴煜鑫" ;
break ;
case 2 :
name= "陆小涛" ;
break ;
case 3 :
name= "王帅" ;
break ;
}
return name;
}
public void start ( ) {
Scanner in = new Scanner ( System. in) ;
while ( player[ 0 ] . getPoint ( ) < 99 && player[ 1 ] . getPoint ( ) < 99 ) {
for ( int i= 0 ; i< player. length; i++ ) {
if ( player[ i] . isPause ( ) ) {
System. out. println ( player[ i] . getName ( ) + "暂停一轮" ) ;
player[ i] . setPause ( false ) ;
continue ;
}
System. out. print ( "请玩家" + player[ i] . getName ( ) + "掷骰子:" ) ;
in. nextLine ( ) ;
int n= player[ i] . play ( ) ;
System. out. println ( "点数为:" + n) ;
if ( player[ i] . getPoint ( ) + n>= 99 ) {
System. out. println ( player[ i] . getName ( ) + "获胜" ) ;
return ;
}
player[ i] . setPoint ( player[ i] . getPoint ( ) + n) ;
int pos= player[ i] . getPoint ( ) ;
int flag= map. map[ pos] ;
switch ( flag) {
case 0 :
common ( i) ;
break ;
case 1 :
i-- ; map. showMap ( player[ 0 ] . getPoint ( ) , player[ 1 ] . getPoint ( ) ) ;
System. out. println ( "恭喜你幸运轮盘,继续扔骰子!" ) ;
continue ;
case 2 :
landMine ( i) ;
break ;
case 3 :
pause ( i) ;
break ;
case 4 :
timeTunnel ( i) ;
}
map. showMap ( player[ 0 ] . getPoint ( ) , player[ 1 ] . getPoint ( ) ) ;
}
}
}
public void common ( int i) {
if ( player[ 0 ] . getPoint ( ) == player[ 1 ] . getPoint ( ) ) {
if ( i== 0 ) { System. out. println ( player[ 1 ] . getName ( ) + "被踢回原点" ) ; player[ 1 ] . setPoint ( 0 ) ; }
else { System. out. println ( player[ 0 ] . getName ( ) + "被踢回原点" ) ; player[ 0 ] . setPoint ( 0 ) ; }
}
}
public void landMine ( int i) {
Random ran = new Random ( ) ;
int xx = ran. nextInt ( 6 ) + 1 ;
System. out. println ( player[ i] . getName ( ) + "踩到地雷,后退" + xx+ "步" ) ;
if ( player[ i] . getPoint ( ) < xx)
{ player[ i] . setPoint ( 0 ) ; }
else
{ player[ i] . setPoint ( player[ i] . getPoint ( ) - xx) ; }
}
public void pause ( int i) {
player[ i] . setPause ( true ) ;
}
public void timeTunnel ( int i) {
if ( player[ i] . getPoint ( ) <= 88 ) {
System. out. println ( player[ i] . getName ( ) + "进入时空隧道,到达下一个时空" ) ;
switch ( player[ i] . getPoint ( ) ) {
case 20 : player[ i] . setPoint ( 25 ) ; break ;
case 25 : player[ i] . setPoint ( 45 ) ; break ;
case 45 : player[ i] . setPoint ( 63 ) ; break ;
case 63 : player[ i] . setPoint ( 72 ) ; break ;
case 72 : player[ i] . setPoint ( 88 ) ; break ;
case 88 : player[ i] . setPoint ( 90 ) ; break ;
}
} else {
System. out. println ( "由于您在最后一个时空,穿越到第一个时空" ) ;
player[ i] . setPoint ( 20 ) ;
}
}
}
package flygame;
public class test {
public static void main ( String[ ] args) {
Game game= new Game ( ) ;
game. init ( ) ;
}
}