Java中9个随机卷的骰子游戏 [英] Game of Dice with 9 Random Rolls in Java

查看:110
本文介绍了Java中9个随机卷的骰子游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要实现  A 游戏  GameOfDice 到 是 打 由 二 玩家 每个 播放&NBSP ;获取 至 辊  A 死 的 播放 谁 镇压NBSP;的 最高 胜 也就是说 轮  A 播放 具有 到 赢得 三 轮 到 赢 的 游戏  A 游戏 可以 具有  AT 最  9 镇压NBSP;为 每个 播放 后 的 第九 卷, 如果 不 一个 胜 的 游戏 两端 和 这是  A 平局 提示: 您 可以 生成  9 随机 镇压NBSP;为 每个 播放器,用于 示例: 随机数 用于 播放器1 是  345612312,  然后    first 移动                  on  on         Player2]。



实施方法:



game_on()  -  接受 两个玩家 对象



get_move()  -  获得 的 移动 为  A 播放器 为 的 与 圆形



你 可 使用 附加 方法 至 产生 所述 移动 



样品 输出: 



Player1 移动:  4 



Player2 移动:  3 



播放器1 移动:  2 



Player2 移动:  1 



Player1 移动:  1 



Player2 移动:  2 



Player1 移动:  2 



Player2 移动:  3 



Player1 移动:  6 



Player2 移动:  2 



获胜者   Player1 



到目前为止,我已尝试生成骰子但我需要9个随机掷骰(从1到6),前3场比赛的选手将获胜,如果是9场比赛。我在上述方法中遇到了麻烦,其中创建了玩家并且滚动被解析为单独移动。



Hi everyone,

I need to implement a game GameOfDice to be played by two players. Each player gets to roll a  die. The player who rolls the highest wins that round. A player has to win three rounds to  win the game. A game can have at most nine rolls for each player. After the ninth roll, if no  one wins, the game ends and it’s a draw. [Hint: You may generate nine random rolls for each  player, for example: Random number for Player1 is 345612312, and then the first  move of Player1 is 3, next is 4 and so on. The same follows for Player2].

Implement methods:

game_on() – accepts two player objects

get_move() – get the move for a player for the corresponding round.

You may use additional method to generate the moves. 

Sample Output: 

Player1's Move: 4 

Player2's Move: 3 

Player1's Move: 2 

Player2's Move: 1 

Player1's Move: 1 

Player2's Move: 2 

Player1's Move: 2 

Player2's Move: 3 

Player1's Move: 6 

Player2's Move: 2 

Winner is Player1 

So far, I have tried to generate the dice but I need 9 random rolls from (anywhere 1 through 6) and player with the first 3 games wins, if 9 draw. I'm having trouble with the aforementioned methods where the players are created and the rolls are parsed as individual moves.

import java.util.*;
    public class Dice {
     
    	// Creating an object from the class "Random" to be able to use the "Random Number" generator.
    	Random generator = new Random();
     
    	// Public instance variable called "thro" to store in it the randomly numbers.
    	public int thro;
     
    	// Data member "Length", of type "Integer". To get the length of the dice.
    	private int length;
     
    	// get method to get the vd

推荐答案

参见 http://docs.oracle.com/javase/7/docs/api/java/util/Random.html [ ^ ],请为自己做更多功课。
See http://docs.oracle.com/javase/7/docs/api/java/util/Random.html[^], and please make more of an effort to do your homework for yourself.


这篇关于Java中9个随机卷的骰子游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆