In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to write the code for Java to achieve backgammon Mini Game", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how to write the code for Java to achieve backgammon Mini Game.
The operation of the game is shown in the figure:
Principle:
Two-dimensional array mainly with the help of 3x3
Achieve:
1. Main- main program
Public class Main {public static void main (String [] args) {Player player=new Player (); / / player Game game=new Game (player); / / one cycle represents a game while (true) {game.Init (); / / initialize game.play (); / / start the game game.destory (); / / release boolean q=player.queryContinue () / / after a game is over, ask the user whether to start the next game if (! Q) {System.out.println ("Welcome to continue the game next time!") ; break;}}
2. AI- computer
Import java.util.Random;// returns the falling child position of the AI object / / an array represents the row and column starting from 0 / so the valid range is [0Power2] public class AI {private final Random random=new Random (); public int [] getPosition () {int r=random.nextInt (3); / / generate the random integer [012 int c=random.nextInt (3); return new int [] {rcot c};}}
3. Player- players
Import java.util.Scanner;// returns the player's drop position / / indicates the row and column with an array starting from 0 / so the valid range is [0L2] public class Player {private final Scanner sc=new Scanner (System.in); public int [] getPosition () {System.out.println ("Please enter the position of the falling child, the valid range of rows and rows is [0L2]"); System.out.print ("> >") Int rtraining c; while (true) {System.out.print (">"); r=sc.nextInt (); c=sc.nextInt (); if (r > = 0&&r=0&&c)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.