java控制台制作海战棋

本文介绍了如何在Java控制台中开发一款简单的海战棋游戏,涵盖了游戏规则、界面交互和逻辑实现等关键内容。
摘要由CSDN通过智能技术生成

控制台上简易的海战棋:

在这里插入代码片
import java.util.Scanner;

public class Battleship {
   
	
	public static int pB = 7;
	public static int pC = 9;
	public static int pP = 5;
	public static int cB = 7;
	public static int cC = 9;
	public static int cP = 5;
	

	public static String[][] drawBoard(int width, int height) {
   
		String[][] board = new String[width][height];
		for (int i = 0; i < width; i++) {
   
			for (int j = 0; j < height; j++) {
   
				board[i][j] = "_";
			}
		}
		//draw the battleship
		int finishBattleship = 1; 
		while(finishBattleship > 0) {
     
			int x = (int)(Math.random() * (height - 1)); 
			int y = (int)(Math.random() * (width - 4)); 
		    board[x + 1][y] = "B";
			board[x + 1][y + 1] = "B";
			board[x + 1][y + 2] = "B";
			board[x + 1][y + 3] = "B";
			board[x + 1][y + 4] = "B";
			board[x][y + 1] = "B";
			board[x][y + 2] = "B";
			finishBattleship--;
			
		}
		
		
		//draw the chasers
		int finishChaser = 3;
		
		while (finishChaser > 0) {
   
			int x = (int)(Math.random() * (width - 3));
			int y = (int)(Math.random() * height);
			if (board[x][y] == "_" && board[x + 1][y] == "_" && board[x 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值