Commit 005baca5 authored by kiana's avatar kiana

othelloProject

parents
Pipeline #4337 failed with stages
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
OthelloMap ground = new OthelloMap();
Scanner scanner = new Scanner(System.in);
Move players = new Move();
while (players.rules.checkEnd(ground.getNuts())) {
System.out.println("It's player1's turn, choose a place to put your nut");
if(!players.rules.pass( 2,ground.getNuts())){
int length=scanner.nextInt();
int width=(int)scanner.next().charAt(0)-'A'+1;
;
while(!players.rules.input(length,width, 2,ground.getNuts())){
System.out.println("wrong input");
length=scanner.nextInt();
width=(int)scanner.next().charAt(0)-'A'+1;
}
players.rules.setYes(0);
players.rules.setMojaz(0);
players.move( 2, length,width, ground.getNuts());
players.rules.setYes(0);
players.rules.setMojaz(0);
}
ground.map();
players.rules.score(ground.getNuts());
System.out.println("It's player2's turn, choose a place to put your nut");
if(!players.rules.pass( 1,ground.getNuts())) {
int length = scanner.nextInt();
int width = (int) scanner.next().charAt(0) - 'A' + 1;
while (!players.rules.input(length, width, 1, ground.getNuts())) {
System.out.println("wrong input");
length = scanner.nextInt();
width = (int) scanner.next().charAt(0) - 'A' + 1;
}
players.rules.setMojaz(0);
players.rules.setYes(0);
;
players.move(1, length, width, ground.getNuts());
}
players.rules.setMojaz(0);
players.rules.setYes(0);
ground.map();
players.rules.score(ground.getNuts());
players.rules.winner(ground.getNuts());
}
}
}
public class Move {
Rules rules = new Rules();
/**
* checks each direction to see if it can be placed there
* if yes then put the nut in the place
* and changes the nuts between to the right color
* @param turn
* @param x
* @param y
* @param map
*/
public void move(int turn, int x, int y, int[][] map) {
x--;
y--;
int i = 1;
//int[][] arr = map;
if (rules.ruleCheckRight(x, y,turn,map)) {
map[x][y]=turn;
while (map[x][y] != map[x + i][y]) {
if (turn == 1)
map[x + i][y] = 1;
else if (turn == 2)
map[x + i][y] = 2;
i++;
}
}
if (rules.ruleCheckLeft(x, y,turn,map)) {
map[x][y]=turn;
int i1 = 1;
while (map[x][y] != map[x - i1][y]) {
if (turn == 1)
map[x - i1][y] = 1;
else if (turn == 2)
map[x - i1][y] = 2;
i1++;
}
}
if (rules.ruleCheckUp(x, y,turn, map)) {
map[x][y]=turn;
int j = 1;
while (map[x][y] != map[x][y + j]) {
if (turn == 1)
map[x][y + j] = 1;
else if (turn == 2)
map[x][y + j] = 2;
j++;
}
}
if (rules.ruleCheckDown(x, y,turn, map)) {
map[x][y]=turn;
int j1 = 1;
while (map[x][y] != map[x][y - j1]) {
if (turn == 1)
map[x][y - j1] = 1;
else if (turn == 2)
map[x][y - j1] = 2;
j1++;
}
}
if (rules.ruleCheckUpRight(x, y,turn, map)) {
map[x][y]=turn;
int k = 1, z = 1;
while (map[x][y] != map[x + k][y + z]) {
if (turn == 1)
map[x + k][y + z] = 1;
else if (turn == 2)
map[x + k][y + z] = 2;
k++;
z++;
}
}
if (rules.ruleCheckUpLeft(x, y,turn, map)) {
map[x][y]=turn;
int k = 1, z = 1;
while (map[x][y] != map[x - k][y + z]) {
if (turn == 1)
map[x - k][y + z] = 1;
else if (turn == 2)
map[x - k][y + z] = 2;
k++;
z++;
}
}
if (rules.ruleCheckDownRight(x, y,turn, map)) {
map[x][y]=turn;
int k = 1, z = 1;
while (map[x][y] != map[x + k][y - z]) {
if (turn == 1)
map[x + k][y - z] = 1;
else if (turn == 2)
map[x + k][y - z] = 2;
k++;
z++;
}
}
if (rules.ruleCheckDownLeft(x, y,turn, map)) {
map[x][y]=turn;
int k = 1, z = 1;
while (map[x][y] != map[x - k][y - z]) {
if (turn == 1)
map[x - k][y - z] = 1;
else if (turn == 2)
map[x - k][y - z] = 2;
k++;
z++;
}
}
if(rules.getYes() == 1)
map[x][y] = turn;
//map(arr);
rules.setMojaz(0);
rules.setYes(0);
}
}
import java.io.*;
public class OthelloMap {
private int[][] nuts = new int[8][8];
public OthelloMap(){
meghdardehi();
map1();
}
private final String resetcolor = "\u001B[0m";
private final String color2 = "\u001B[38;5;27m";
private final String color3 = "\u001B[48;5;197m";
private final String color1 = "\u001B[48;5;243m";
private final String resetbg = "\u001B[49m";
public int[][] getNuts() {
return nuts;
}
public void setNuts(int[][] nuts) {
this.nuts = nuts;
}
public void meghdardehi(){
for(int i=0; i<8; i++) {
for (int j = 0; j < 8; j++) {
nuts[i][j] = 0;
}
}
nuts[3][3] = 1;
nuts[4][4] = 1;
nuts[3][4] = 2;
nuts[4][3] = 2;
}
/**
* prints the table alphabets
* prints the map
* prints the table numbers
*/
public void map(){
for(char alphabet= 'A'; alphabet<= 'H'; alphabet++){
System.out.print(" "+ alphabet +" ");
}
System.out.println(" ");
int number = 1;
System.out.print(" ");
for(int i=0; i<8; i++){
for(int j=0; j<8; j++){
// System.out.print(color1+color2+"----------"+resetcolor+resetbg);
System.out.print(color3+color2+" "+resetcolor+resetbg);
}
System.out.println(color3+" "+resetcolor);
System.out.print(" ");
for(int j=0; j<8; j++){
// System.out.print(color1+color2+"|"+resetcolor+resetbg);
System.out.print(color3+" "+resetbg);
if(nuts[i][j] == 0)
System.out.print(color1+" "+resetbg);
else if(nuts[i][j] == 1)
System.out.print(color1+" "+ "\u26AB " + " "+resetbg);
else if(nuts[i][j] == 2)
System.out.print( color1+" "+ "\u26AA " + " "+resetbg);
}
System.out.println(color3+" "+resetbg);
System.out.print(number++ + " ");
for(int j=0; j<9; j++){
// System.out.print(color1+color2+"|"+resetcolor+resetbg);
System.out.print(color3+" "+resetcolor);
if(j==8){
System.out.print(" ");
}
else{
System.out.print(color1+" "+resetbg);
}}
System.out.println(" ");
System.out.print(" ");
}
/**
* last line
*/
for(int j=0; j<8; j++){
// System.out.print(color1+color2 +"----------"+resetcolor+resetbg);
System.out.print(color3+color2 +" "+resetcolor+resetbg);
}
System.out.println(color3+" "+resetbg);
}
/**
* first map of the game
*/
public void map1(){
nuts[3][3] = 1;
nuts[4][4] = 1;
nuts[3][4] = 2;
nuts[4][3] = 2;
map();
}
}
This diff is collapsed.
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