mirror of
https://github.com/RustyRaptor/Baddleship.git
synced 2026-12-03 16:05:19 -07:00
working on use input board size.
This commit is contained in:
1 parent
ae0a606ddc
commit
2316a27541
1 file changed
+10
-9
+10
-9
@@ -4,10 +4,11 @@ import std.range : iota;
|
||||
import std.random;
|
||||
import std.datetime;
|
||||
import std.datetime.timezone : LocalTime;
|
||||
import core.simd;
|
||||
|
||||
|
||||
/// Prints the board
|
||||
void printBoard(int[5][5] board){
|
||||
void printBoard(int[][] board){
|
||||
/// TODO: print neatly
|
||||
foreach(row; board) {
|
||||
writeln(row);
|
||||
@@ -20,31 +21,31 @@ void printWelcome(){
|
||||
}
|
||||
|
||||
/// returns a random row on the game board
|
||||
int randomRow(){
|
||||
int randomRow(int[][] board){
|
||||
|
||||
|
||||
auto rnd = Random();
|
||||
/// TODO: range based on length of board
|
||||
const int i = uniform(0, 4, rnd);
|
||||
const int i = uniform(0, board.length, rnd);
|
||||
assert(i >= 0 && i < 4);
|
||||
return(i);
|
||||
}
|
||||
|
||||
/// returns a random column on the game board
|
||||
int randomCol(){
|
||||
int randomCol(int[][] board){
|
||||
auto rnd = Random(22);
|
||||
|
||||
/// TODO: range based on length of board
|
||||
const int i = uniform(0, 4, rnd);
|
||||
const int i = uniform(0, board.length, rnd);
|
||||
assert(i >= 0 && i < 4);
|
||||
return(i);
|
||||
}
|
||||
|
||||
void main(){
|
||||
|
||||
const int a = 5;
|
||||
|
||||
/// Initialize the board
|
||||
/// TODO: User inputs size of board
|
||||
int[5][5] board;
|
||||
foreach(row; board) {
|
||||
foreach(item; row){
|
||||
item = 0;
|
||||
@@ -53,8 +54,8 @@ void main(){
|
||||
SysTime today = Clock.currTime();
|
||||
writeln(((today.second)));
|
||||
/// place a ship on a random tile
|
||||
const int shipRow = randomRow();
|
||||
const int shipCol = randomCol();
|
||||
const int shipRow = randomRow(board);
|
||||
const int shipCol = randomCol(board);
|
||||
printWelcome();
|
||||
printBoard(board);
|
||||
// writeln(board[shipRow]);
|
||||
|
||||
Reference in new issue
Block a user