Commit cc77ce89 authored by kiana's avatar kiana

pentago project

parents
Pipeline #4335 failed with stages
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
boolean isEnd = false;
Scanner scanner = new Scanner(System.in);
PentagoMap ground = new PentagoMap();
Move play = new Move();
ground.first();
ground.map();
int i = 1;
System.out.println("First write x then y of the place you wanna put your nut in " +
"then select a ground to rotate and then write if you want to rotate it to right or left by " +
"typing 'L' or 'R' ");
/**
* while no one hasnt won :
* gets x and y of the place
* then gets the play ground it wants to rotate and which direction to rotate if L or R
* checks if the inputs are valid
* put the nut and rotate the play ground
* same thing happens to the other player
* prints the map after each turn
*/
while(!(play.end(ground.getNuts(), 1) || play.end(ground.getNuts(), 2))) {
i--;
int y1 = scanner.nextInt();
int x1 = scanner.nextInt();
while (!play.check(y1,x1,ground.getNuts())){
System.out.println("invalid input");
y1 = scanner.nextInt();
x1 = scanner.nextInt();
}
y1--;
x1--;
play.move(y1, x1, ground.getNuts(), 1);
play.rotation(scanner.nextInt(), scanner.next().charAt(0), ground.getNuts());
ground.map();
if(play.end(ground.getNuts(),1))
{
System.out.println("winner is white");
return;
}
if(play.end(ground.getNuts(),2))
{
System.out.println("winner is black");
return;
}
int y2 = scanner.nextInt();
int x2 = scanner.nextInt();
while (!play.check(y2,x2,ground.getNuts())){
System.out.println("invalid input");
y2 = scanner.nextInt();
x2 = scanner.nextInt();
}
y2--;
x2--;
play.move(y2, x2, ground.getNuts(), 2);
play.rotation(scanner.nextInt(), scanner.next().charAt(0), ground.getNuts());
ground.map();
if(play.end(ground.getNuts(),1))
{
System.out.println("winner is white");
isEnd = true;
}
if(play.end(ground.getNuts(),2))
{
System.out.println("winner is black");
isEnd = true;
}
if(isEnd)
return;
}
}
}
This diff is collapsed.
import java.util.ArrayList;
public class PentagoMap {
private int[][] nuts = new int[6][6];
/**
* make the array 0 at first
*/
public void first(){
for (int i=0; i<6; i++){
for (int j=0; j<6; j++){
nuts[i][j] = 0;
}
}
}
/**
* sets the nuts
* @param nuts
*/
public void setNuts(int[][] nuts) {
this.nuts = nuts;
}
/**
* gets the nuts
* @return
*/
public int[][] getNuts() {
return nuts;
}
/**
* prints the map
*/
public void map() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (nuts[i][j] == 0)
System.out.print("\u2B55 ");
else if(nuts[i][j] == 1)
System.out.print("\u26AA ");
else if(nuts[i][j] == 2)
System.out.print("\u26AB ");
}
System.out.print("| ");
for (int k = 3; k < 6; k++) {
if (nuts[i][k] == 0)
System.out.print("\u2B55 ");
else if(nuts[i][k] == 1)
System.out.print("\u26AA ");
else if(nuts[i][k] == 2)
System.out.print("\u26AB ");
}
System.out.println();
}
//System.out.print("-");
for (int z=0; z<6; z++)
System.out.print("--- ");
System.out.println();
for (int i = 3; i < 6; i++) {
for (int j = 0; j < 3; j++) {
if (nuts[i][j] == 0)
System.out.print("\u2B55 ");
else if(nuts[i][j] == 1)
System.out.print("\u26AA ");
else if(nuts[i][j] == 2)
System.out.print("\u26AB ");
}
System.out.print("| ");
for (int k = 3; k < 6; k++) {
if (nuts[i][k] == 0)
System.out.print("\u2B55 ");
else if(nuts[i][k] == 1)
System.out.print("\u26AA ");
else if(nuts[i][k] == 2)
System.out.print("\u26AB ");
}
System.out.println();
}
System.out.println(" ");
System.out.println(" ");
}
}
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