java - Capturing the color in between? -
i need assignment java. assignment is:
create game where: there 2 playing pieces, black , white ones. when piece or line of pieces surrounded opponents on both left , right sides or both front , back, said captured , color changes color of pieces surrounded it. on turn, must capture @ least 1 of opponent’s piece. game ends when user has no more valid moves. , winner assigned player captured more pieces.
the board 6x6 , need display results in words, not actual game. know how create board using arrays. don't know how code actual game. appreciated!! know have use lot of "if" statements , loops don't know how it. have far:
boarda[0] = "a1"; boarda[1] = "a2"; boarda[2] = "a3"; boarda[3] = "a4"; boarda[4] = "a5"; boarda[5] = "a6"; boardb[0] = "b1"; boardb[1] = "b2"; boardb[2] = "b3"; boardb[3] = "b4"; boardb[4] = "b5"; boardb[5] = "b6"; boardc[0] = "c1"; boardc[1] = "c2"; boardc[2] = "c3"; boardc[3] = "c4"; boardc[4] = "c5"; boardc[5] = "c6"; boardd[0] = "d1"; boardd[1] = "d2"; boardd[2] = "d3"; boardd[3] = "d4"; boardd[4] = "d5"; boardd[5] = "d6"; boarde[0] = "e1"; boarde[1] = "e2"; boarde[2] = "e3"; boarde[3] = "e4"; boarde[4] = "e5"; boarde[5] = "e6"; boardf[0] = "f1"; boardf[1] = "f2"; boardf[2] = "f3"; boardf[3] = "f4"; boardf[4] = "f5"; boardf[5] = "f6"; scanner keyboard = new scanner(system.in); system.out.println("this how board looks like:" + "\n" + arrays.tostring(boarda) + "\n" + arrays.tostring(boardb)+ "\n" + arrays.tostring(boardc) +"\n"+ arrays.tostring(boardd) +"\n"+arrays.tostring(boarde) + "\n"+arrays.tostring(boardf)); system.out.println("the board has 6 blocks, starting 4 people in middle, 2 black , 2 white facing each other."); boardc[2] = "white"; boardc[3] = "black"; boardd[2] = "black"; boardd[3] = "white"; system.out.println("the board starts with: " + "\n" + arrays.tostring(boarda) + "\n" + arrays.tostring(boardb)+ "\n" + arrays.tostring(boardc) +"\n"+ arrays.tostring(boardd) +"\n"+arrays.tostring(boarde) + "\n"+arrays.tostring(boardf)); system.out.println("you white. want move?"); string input = keyboard.nextline();
you're asking for... lot. can't assignment you!
i believe should start writing stuff, little little. example, could:
- make work maybe 1 particular case @ first,
- then other,
- then see pattern , make generic...
i'll started, though.
think interaction user should that:
boolean gameended = false; boolean iswhitesturn = true; while(!gameended) { system.out.println("you are" + (iswhitesturn)?"white":"black" + ". want move?"); final string input = keyboard.nextline(); // process input here iswhitesturn = !iswhitesturn; // every time, toggle between players. } system.out.println("game over.");
now, in order process input, can first assume user input valid string
. is, coordinates of actual board case. later, you'll have check this , deal wrong inputs.
here have imput:
- translate
string
object
: e.g.:"e5"
should meanboarde[4]
. guess create methodsgetvalueat(final string coordinates)
,setvalueat(final string coordinates)
. check if there player @ coordinates (using
getvalueat()
).2.1 if there is, ask new input. 2.2 if there isn't, place player's colour @ right coordinates (using
setvalueat()
), execute algorithm changes colours of surrounded "players". know mean.- there must kind of condition stops game (e.g.: no more empty case on board). check it. if game supposed end, set
gameended = true;
since i'm @ it, suggest board more actual board, is... matrix.
for instance, use this:
private static final int board_width = 6; private static final int board_height = 6; final string[][] board = new string[board_width][board_height];
and initialize this:
for (int = 0; < board_height; i++) { final string letter = new character((char) ('a' + i)).tostring(); (int j = 0; j < board_width; j++) { this.board[i][j] = letter + string.valueof(j); } }
then print this:
for (int = 0; < board_height; i++) { (int j = 0; j < board_width; j++) { system.out.print(this.board[i][j] + "\t"); } system.out.println(); }
i hope started ;)
Comments
Post a Comment