Commit e367a058 authored by 9731301's avatar 9731301

add Othello class with suitable input and output_add name to user

parent e19b199d
......@@ -2,9 +2,10 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="7be08370-19a4-4528-ab9b-d4cb0ec736c4" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/User.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/MyOthello/Othello.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/MyOthello/Othello.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/MyOthello/User.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/MyOthello/User.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/User.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/User.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -62,7 +63,7 @@
<workItem from="1585656097487" duration="2378000" />
<workItem from="1585659438353" duration="9321000" />
<workItem from="1585687211713" duration="16102000" />
<workItem from="1585733466673" duration="521000" />
<workItem from="1585733466673" duration="3514000" />
</task>
<servers />
</component>
......@@ -70,26 +71,26 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state x="574" y="97" key="#com.intellij.ide.util.MemberChooser" timestamp="1585694421216">
<state x="574" y="97" key="#com.intellij.ide.util.MemberChooser" timestamp="1585736657332">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="574" y="97" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1585694421216" />
<state width="1493" height="201" key="GridCell.Tab.0.bottom" timestamp="1585703421720">
<state x="574" y="97" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1585736657332" />
<state width="1493" height="250" key="GridCell.Tab.0.bottom" timestamp="1585738348489">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1585703421720" />
<state width="1493" height="201" key="GridCell.Tab.0.center" timestamp="1585703421720">
<state width="1493" height="250" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1585738348489" />
<state width="1493" height="250" key="GridCell.Tab.0.center" timestamp="1585738348488">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1585703421720" />
<state width="1493" height="201" key="GridCell.Tab.0.left" timestamp="1585703421720">
<state width="1493" height="250" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1585738348488" />
<state width="1493" height="250" key="GridCell.Tab.0.left" timestamp="1585738348488">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1585703421720" />
<state width="1493" height="201" key="GridCell.Tab.0.right" timestamp="1585703421720">
<state width="1493" height="250" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1585738348488" />
<state width="1493" height="250" key="GridCell.Tab.0.right" timestamp="1585738348488">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1585703421720" />
<state width="1493" height="250" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1585738348488" />
<state width="1493" height="182" key="GridCell.Tab.1.bottom" timestamp="1585671521268">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
import java.util.ArrayList;
import java.util.Scanner;
public class Othello {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
ArrayList <Block> blocks = new ArrayList<Block>();
User user1 = new User();
User user2 = new User();
Character c = 'n';
int numberOfEmptyBlocksAtTheEnd = 0;
int row;
int column;
Block block;
Block chosenBlock = new Block();
chosenBlock.setColor('w');
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
block = new Block();
block.setRow(i);
block.setColumn(j);
blocks.add(block);
if ((i == 3 && j == 3) || (i == 4 && j==4))
block.setColor('b');
else if ((i == 4 && j == 3) || (i == 3 && j == 4))
block.setColor('w');
else
block.setColor('n');
}
}
System.out.println("plz enter user1 name");
user1.setName(sc.nextLine().trim());
while (!(c.equals('b') || c.equals('w'))) {
System.out.println("plz enter user1 color w or b");
c = sc.next().charAt(0);
user1.setColor(c);
}
System.out.println("plz enter user2 name");
user2.setName(sc.next());
if (user1.getColor().equals('w'))
user2.setColor('b');
else
user2.setColor('w');
System.out.println(user1.getName()+" color is "+user1.getColor()+" and "+user2.getName()+" color is "+user2.getColor());
System.out.println(" a b c d e f g h");
for (int i = 0 ; i < 8 ; i++){
System.out.print(i+1+" ");
for (int j = 0 ; j < 8 ; j++){
for (Block b : blocks){
if (b.getRow() == i && b.getColumn() == j){
System.out.print(b.getColor()+" ");
}
}
}
System.out.println();
}
while (true) {
System.out.println("plz enter your choice for example :3 a");
chosenBlock.changeColor();
System.out.println("turn is for : " + chosenBlock.getColor());
String input = sc.nextLine().trim();
String[] inputArray = input.split(" ");
System.out.println(inputArray[0]);
row = Integer.parseInt(inputArray[0])-1;
if (inputArray[1].toLowerCase().equals("a"))
column = 0;
else if (inputArray[1].toLowerCase().equals("b"))
column = 1;
else if (inputArray[1].toLowerCase().equals("c"))
column = 2;
else if (inputArray[1].toLowerCase().equals("d"))
column = 3;
else if (inputArray[1].toLowerCase().equals("e"))
column = 4;
else if (inputArray[1].toLowerCase().equals("f"))
column = 5;
else if (inputArray[1].toLowerCase().equals("g"))
column = 6;
else if (inputArray[1].toLowerCase().equals("h"))
column = 7;
else {
System.out.println("enter again correctly");
break;
}
chosenBlock.setRow(row);
chosenBlock.setColumn(column);
System.out.println(" a b c d e f g h ");
for (int i = 0 ; i < 8 ; i++){
System.out.print(i+1+" ");
for (int j = 0 ; j < 8 ; j++){
for (Block b : blocks){
if (b.getRow() == i && b.getColumn() == j){
System.out.print(b.getColor()+" ");
}
}
}
System.out.println();
}
for (Block b : blocks){
if (b.getColor().equals(user1.getColor())){
user1.addBlock(b);
}
else if (b.getColor().equals(user2.getColor())){
user2.addBlock(b);
}
else {
numberOfEmptyBlocksAtTheEnd ++;
}
if (user1.isAvailableBlockToPick(b,blocks)){
user1.addAvailableBlockToPick(b);
}
else {
user1.removeAvailableBlockToPick(b);
}
if (user2.isAvailableBlockToPick(b,blocks)){
user2.addAvailableBlockToPick(b);
}
else {
user2.removeAvailableBlockToPick(b);
}
}
}
}
}
import java.util.ArrayList;
public class User {
private String name;
private ArrayList<Block> userBlocks;
private ArrayList<Block> availableBlocksToPick;
private char color;
private Character color;
public User(){
userBlocks = new ArrayList<Block>();
......@@ -220,13 +221,22 @@ public class User {
availableBlocksToPick.remove(block);
}
public char getColor() {
public Character getColor() {
return color;
}
public void setColor(char color) {
public void setColor(Character color) {
this.color = color;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
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