Commit 1fad4f87 authored by 9731301's avatar 9731301

add some changes and add single player option

parent 04b7356e
......@@ -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/Block.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/MyPentago/Block.class" 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" />
......@@ -63,7 +62,8 @@
<workItem from="1586162373379" duration="6530000" />
<workItem from="1586174700430" duration="9185000" />
<workItem from="1586246845885" duration="2399000" />
<workItem from="1586261785897" duration="13320000" />
<workItem from="1586261785897" duration="27125000" />
<workItem from="1586330745810" duration="2315000" />
</task>
<servers />
</component>
......@@ -71,42 +71,42 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state width="1493" height="564" key="GridCell.Tab.0.bottom" timestamp="1586275386382">
<state width="1493" height="50" key="GridCell.Tab.0.bottom" timestamp="1586351258387">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="564" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586275386382" />
<state width="1493" height="564" key="GridCell.Tab.0.center" timestamp="1586275386382">
<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">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="564" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1586275386382" />
<state width="1493" height="564" key="GridCell.Tab.0.left" timestamp="1586275386382">
<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">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="564" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1586275386382" />
<state width="1493" height="564" key="GridCell.Tab.0.right" timestamp="1586275386382">
<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">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="564" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1586275386382" />
<state width="1493" height="194" key="GridCell.Tab.1.bottom" timestamp="1586274892633">
<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">
<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="1586274892633" />
<state width="1493" height="194" key="GridCell.Tab.1.center" timestamp="1586274892633">
<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">
<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="1586274892633" />
<state width="1493" height="194" key="GridCell.Tab.1.left" timestamp="1586274892633">
<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">
<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="1586274892633" />
<state width="1493" height="194" key="GridCell.Tab.1.right" timestamp="1586274892633">
<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">
<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="1586274892633" />
<state x="281" y="271" key="com.intellij.ide.util.TipDialog" timestamp="1586261829792">
<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">
<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="1586261829792" />
<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">
<screen x="0" y="0" width="1536" height="824" />
</state>
......@@ -116,18 +116,4 @@
</state>
<state x="425" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1586180125854" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-method">
<url>file://$PROJECT_DIR$/src/User.java</url>
<line>27</line>
<properties class="User" method="isWinner">
<option name="EMULATED" value="true" />
</properties>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
\ No newline at end of file
......@@ -5,6 +5,7 @@ public class Pentago {
public static void main(String [] args){
ArrayList<Block> blocks = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
SinglePlay bot = new SinglePlay();
User user1 = new User();
User user2 = new User();
User chosenUser = new User();
......@@ -17,6 +18,13 @@ public class Pentago {
int i ;
boolean ans = false;
String turn;
String singlePlay;
System.out.println("Do you want single play?yes/no");
singlePlay = scanner.next().toLowerCase().trim();
if (singlePlay.equals("yes")){
user2 = bot; ;
bot.setColor('0');
}
for ( i = 0 ; i < 4 ; i++ ){
Block block = new Block();
block.createCells();
......@@ -26,11 +34,14 @@ public class Pentago {
printBlocks(blocks);
while (true) {
if (chosenUser.isWinner(blocks)){
System.out.println(chosenUser.getColor() + " is winner");
if (user1.isWinner(blocks)){
System.out.println(user1.getColor() + " is winner");
break;
}
if (user2.isWinner(blocks)){
System.out.println(user2.getColor() + " is winner");
break;
}
//pass the turn if there is not any cell to choose for player
if (chosenUser.equals(user1)){
chosenUser = user2;
......@@ -51,22 +62,57 @@ public class Pentago {
System.out.println("pass");
continue;
}
System.out.println("\nplz enter a block number");
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))) {
blocks.get(blockNumber).getAllCells().get(cellNumber).setColor(chosenUser.getColor());
if (chosenUser.equals(bot)) {
System.out.println("***********************************");
blockNumber = bot.setBlock() ;
cellNumber = bot.setCell(blocks , blockNumber) ;
if (chosenUser.cellIsAvailableToTake(blocks.get(blockNumber).getAllCells().get(cellNumber))) {
blocks.get(blockNumber).getAllCells().get(cellNumber).setColor(chosenUser.getColor());
}
printBlocks(blocks);
if (user1.isWinner(blocks)){
System.out.println(user1.getColor() + " is winner");
break;
}
if (user2.isWinner(blocks)){
System.out.println(user2.getColor() + " is winner");
break;
}
System.out.println();
blockNumberToTurn = bot.setBlock() ;
turn = bot.setRightAndLeft();
blocks.get(blockNumberToTurn).changePositionOfBlock(turn);
printBlocks(blocks);
System.out.println("***********************************");
}
else {
System.out.println("\nplz enter a block number");
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))) {
blocks.get(blockNumber).getAllCells().get(cellNumber).setColor(chosenUser.getColor());
}
printBlocks(blocks);
System.out.println();
System.out.println("plz enter the number of block you wanna turn");
blockNumberToTurn =scanner.nextInt() - 1 ;
System.out.println("plz enter how change position? right/left");
turn = scanner.next().trim();
blocks.get(blockNumberToTurn).changePositionOfBlock(turn);
printBlocks(blocks);
printBlocks(blocks);
if (user1.isWinner(blocks)){
System.out.println(user1.getColor() + " is winner");
break;
}
if (user2.isWinner(blocks)){
System.out.println(user2.getColor() + " is winner");
break;
}
System.out.println();
System.out.println("plz enter the number of block you wanna turn");
blockNumberToTurn = scanner.nextInt() - 1;
System.out.println("plz enter how change position? right/left");
turn = scanner.next().trim();
blocks.get(blockNumberToTurn).changePositionOfBlock(turn);
printBlocks(blocks);
System.out.println();
}
}
}
public static void printBlocks( ArrayList<Block> blocks){
......@@ -100,5 +146,6 @@ public class Pentago {
System.out.println();
}
}
System.out.println();
}
}
import java.util.ArrayList;
import java.util.Random;
public class SinglePlay extends User{
private Random random = new Random();
public int setCell(ArrayList<Block> blocks , int blockNumber){
while (true) {
int x =random.nextInt(9);
for (Block b : blocks){
if (b.getNumber() == blockNumber) {
if (b.getAllCells().get(x).getColor().equals('O')){
return x;
}
}
}
}
}
public int setBlock(){
return random.nextInt(4);
}
public String setRightAndLeft(){
int r = random.nextInt(2);
if ( r == 0)
return "right";
else
return "left";
}
}
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