Commit e5eb7e39 authored by 9731301's avatar 9731301

Add java doc and add some changes about choosing winner

parent 1fad4f87
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavadocGenerationManager">
<option name="OUTPUT_DIRECTORY" value="$PROJECT_DIR$/javadoc" />
<option name="OPTION_SCOPE" value="package" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="true" project-jdk-name="10" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
......
......@@ -3,7 +3,6 @@
<component name="ChangeListManager">
<list default="true" id="63729159-695b-4499-ba7f-f31e81a0234c" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/MyPentago/Pentago.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/MyPentago/Pentago.class" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -63,7 +62,8 @@
<workItem from="1586174700430" duration="9185000" />
<workItem from="1586246845885" duration="2399000" />
<workItem from="1586261785897" duration="27125000" />
<workItem from="1586330745810" duration="2315000" />
<workItem from="1586330745810" duration="2884000" />
<workItem from="1586529900164" duration="20946000" />
</task>
<servers />
</component>
......@@ -71,46 +71,54 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state width="1493" height="50" key="GridCell.Tab.0.bottom" timestamp="1586351258387">
<state x="259" y="75" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1" timestamp="1586554028945">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="50" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586351258387" />
<state width="1493" height="50" key="GridCell.Tab.0.center" timestamp="1586351258387">
<state x="259" y="75" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1/0.0.1536.824@0.0.1536.824" timestamp="1586554028945" />
<state x="292" y="97" key="FileChooserDialogImpl" timestamp="1586553985712">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="50" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1586351258387" />
<state width="1493" height="50" key="GridCell.Tab.0.left" timestamp="1586351258387">
<state x="292" y="97" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1586553985712" />
<state width="964" height="37" key="GridCell.Tab.0.bottom" timestamp="1586554029065">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="50" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1586351258387" />
<state width="1493" height="50" key="GridCell.Tab.0.right" timestamp="1586351258387">
<state width="964" height="37" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586554029065" />
<state width="964" height="37" key="GridCell.Tab.0.center" timestamp="1586554029065">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="50" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1586351258387" />
<state width="1493" height="194" key="GridCell.Tab.1.bottom" timestamp="1586290133992">
<state width="964" height="37" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1586554029065" />
<state width="964" height="37" key="GridCell.Tab.0.left" timestamp="1586554029064">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="194" key="GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586290133992" />
<state width="1493" height="194" key="GridCell.Tab.1.center" timestamp="1586290133992">
<state width="964" height="37" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1586554029064" />
<state width="964" height="37" key="GridCell.Tab.0.right" timestamp="1586554029065">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="194" key="GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824" timestamp="1586290133992" />
<state width="1493" height="194" key="GridCell.Tab.1.left" timestamp="1586290133992">
<state width="964" height="37" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1586554029065" />
<state width="1493" height="16" key="GridCell.Tab.1.bottom" timestamp="1586542893581">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="194" key="GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824" timestamp="1586290133992" />
<state width="1493" height="194" key="GridCell.Tab.1.right" timestamp="1586290133992">
<state width="1493" height="16" key="GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586542893581" />
<state width="1493" height="16" key="GridCell.Tab.1.center" timestamp="1586542893581">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="194" key="GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824" timestamp="1586290133992" />
<state x="281" y="271" key="com.intellij.ide.util.TipDialog" timestamp="1586330747078">
<state width="1493" height="16" key="GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824" timestamp="1586542893581" />
<state width="1493" height="16" key="GridCell.Tab.1.left" timestamp="1586542893580">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="281" y="271" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1586330747078" />
<state x="25" y="67" key="new project wizard" timestamp="1586105483065">
<state width="1493" height="16" key="GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824" timestamp="1586542893580" />
<state width="1493" height="16" key="GridCell.Tab.1.right" timestamp="1586542893581">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="25" y="67" key="new project wizard/0.0.1536.824@0.0.1536.824" timestamp="1586105483065" />
<state width="1493" height="16" key="GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824" timestamp="1586542893581" />
<state x="281" y="271" key="com.intellij.ide.util.TipDialog" timestamp="1586529909931">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="281" y="271" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1586529909931" />
<state x="25" y="67" key="new project wizard" timestamp="1586352295911">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="25" y="67" key="new project wizard/0.0.1536.824@0.0.1536.824" timestamp="1586352295911" />
<state x="425" y="187" key="run.anything.popup" timestamp="1586180125854">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
/**
* Block Class represents a block with it cells and number
*
* @author zahra_fatehi
* @version 0.0
*/
import java.util.ArrayList;
public class Block {
private ArrayList<Cell> allCells;
private int number;
private String turn;
/**
*create a list of cells for the block
*/
public Block(){
allCells = new ArrayList<>();
}
/**
* @return number of a block
*/
public int getNumber() {
return number;
}
/**
* @param number is the number of block
*/
public void setNumber(int number) {
this.number = number;
}
/**
* create 9 cells for a block
*/
public void createCells(){
for (int i = 0 ; i < 9 ; i++ ){
Cell cell = new Cell();
cell.setNumber(i);;
cell.setColor('O');
allCells.add(cell);
}
}
/**
* @param turn is the field that shows how to change the position
*/
public void changePositionOfBlock(String turn){
Cell transporterCell;
if ( turn.equals("right")){
......@@ -71,6 +91,9 @@ public class Block {
}
}
/**
* @return all cells in a block
*/
public ArrayList<Cell> getAllCells() {
return allCells;
}
......
/**
*Cell Class represents a cell that has color
* this class this class has some methods to set color and checks that cell is available to take
*/
public class Cell {
private Character color ;
private int number ;
public Cell(){
color = 'O';
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
/**
* get color of a cell
* @return color field
*/
public Character getColor() {
return color;
}
/**
* @param color is the color of cell
*/
public void setColor(Character color) {
this.color = color;
}
/**
* checks that cell is available to take
* @return true if it is available to take and false if it is not
*/
public boolean cellIsAvailableToTake( ){
if (color.equals('O')){
return true;
}
else {
return false;
}
}
}
......@@ -66,9 +66,18 @@ public class Pentago {
System.out.println("***********************************");
blockNumber = bot.setBlock() ;
cellNumber = bot.setCell(blocks , blockNumber) ;
if (chosenUser.cellIsAvailableToTake(blocks.get(blockNumber).getAllCells().get(cellNumber))) {
if (blocks.get(blockNumber).getAllCells().get(cellNumber).cellIsAvailableToTake()) {
blocks.get(blockNumber).getAllCells().get(cellNumber).setColor(chosenUser.getColor());
}
else {
if (chosenUser.equals(user1)){
chosenUser = user2;
}
else {
chosenUser = user1;
}
continue;
}
printBlocks(blocks);
if (user1.isWinner(blocks)){
......@@ -91,9 +100,19 @@ public class Pentago {
blockNumber = scanner.nextInt() - 1;
System.out.println("plz enter a cell number");
cellNumber = scanner.nextInt() - 1;
if (chosenUser.cellIsAvailableToTake(blocks.get(blockNumber).getAllCells().get(cellNumber))) {
if (blocks.get(blockNumber).getAllCells().get(cellNumber).cellIsAvailableToTake()) {
blocks.get(blockNumber).getAllCells().get(cellNumber).setColor(chosenUser.getColor());
}
else {
if (chosenUser.equals(user1)){
chosenUser = user2;
}
else {
chosenUser = user1;
}
System.out.println("u can't take this block");
continue;
}
printBlocks(blocks);
if (user1.isWinner(blocks)){
......
/**
* User Class represents a User with its color and there is some methods to choose winner
* @author zahra_fatehi
* @version 0.0
*/
import java.util.ArrayList;
public class User {
private ArrayList<Cell> takenCells;
private Character color;
/**
* create a User with taken cells
*/
public User(){
takenCells = new ArrayList<Cell>();
}
public boolean cellIsAvailableToTake( Cell cellToChoose ){
if (cellToChoose.getColor().equals('O')){
return true;
}
else {
return false;
}
}
/**
* @return color field
*/
public Character getColor() {
return color;
}
/**
*
* @param color is the color of a user
*/
public void setColor(Character color) {
this.color = color;
}
/**
* this method checks that this user is winner or not
* @param blocks
* @return
*/
public boolean isWinner(ArrayList<Block> blocks){
//choose the winner
// checking horizontal
int counter = 0 ;
for( int cellIndex = 0 , blockIndex = 0; counter < 12 ; ){// checking horizental
for( int cellIndex = 0 , blockIndex = 0; counter < 6 ; ){
if ( blocks.get(blockIndex).getAllCells().get(cellIndex).getColor().equals(color)
&& blocks.get(blockIndex).getAllCells().get(cellIndex + 1).getColor().equals(color)
&& blocks.get(blockIndex).getAllCells().get(cellIndex + 2).getColor().equals(color)
......@@ -36,17 +49,32 @@ public class User {
&& blocks.get(blockIndex + 1).getAllCells().get(cellIndex + 1).getColor().equals(color)){
return true;
}
cellIndex+=3;
counter ++ ;
if (counter == 3 || counter == 9){
if (counter == 3 ){
blockIndex = 2;
cellIndex = 0 ;
}
if ( counter == 6){
}
counter = 0 ;
for( int cellIndex = 1 , blockIndex = 0; counter < 6 ; ){
if ( blocks.get(blockIndex).getAllCells().get(cellIndex).getColor().equals(color)
&& blocks.get(blockIndex).getAllCells().get(cellIndex + 1).getColor().equals(color)
&& blocks.get(blockIndex + 1).getAllCells().get(cellIndex -1).getColor().equals(color)
&& blocks.get(blockIndex + 1).getAllCells().get(cellIndex ).getColor().equals(color)
&& blocks.get(blockIndex + 1).getAllCells().get(cellIndex + 1).getColor().equals(color)){
return true;
}
cellIndex+=3;
counter ++ ;
if (counter == 3 ){
blockIndex = 2;
cellIndex = 1 ;
blockIndex = 0 ;
}
}
// checking vertical
counter = 0 ;
for( int cellIndex = 0 , blockIndex = 0; counter < 12 ; ){// checking vertical
for( int cellIndex = 0 , blockIndex = 0; counter < 6 ; ){
if ( blocks.get(blockIndex).getAllCells().get(cellIndex).getColor().equals(color)
&& blocks.get(blockIndex).getAllCells().get(cellIndex + 3).getColor().equals(color)
&& blocks.get(blockIndex).getAllCells().get(cellIndex + 6).getColor().equals(color)
......@@ -55,12 +83,29 @@ public class User {
return true;
}
counter ++ ;
if ( counter == 3 || counter == 9){
cellIndex++;
if ( counter == 3){
cellIndex = 0 ;
blockIndex = 1 ;
}
if (counter == 6){
blockIndex = 0 ;
cellIndex = 1 ;
}
counter = 0 ;
for( int cellIndex = 3 , blockIndex = 0; counter < 6 ; ){
if ( blocks.get(blockIndex).getAllCells().get(cellIndex).getColor().equals(color)
&& blocks.get(blockIndex).getAllCells().get(cellIndex + 3).getColor().equals(color)
&& blocks.get(blockIndex + 2).getAllCells().get(cellIndex - 3).getColor().equals(color)
&& blocks.get(blockIndex + 2).getAllCells().get(cellIndex ).getColor().equals(color)
&& blocks.get(blockIndex + 2).getAllCells().get(cellIndex + 3).getColor().equals(color)){
return true;
}
counter ++ ;
cellIndex++;
if ( counter == 3){
cellIndex = 3 ;
blockIndex = 1 ;
}
}
//check diagonal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment