id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
a62de0b4-59ba-4fc6-8359-f6b3c2263608 | public boolean isNotMine(int column, int row) { //vrati true, pokud je zadane policko prazdne nebo je na nem souperova figurka
if(isEnemy(player,column, row) || isFree(column, row)) {
return true;
}
else {
return false;
}
} |
e9460f3c-5caf-4cf5-b437-87f21baa43d9 | public boolean castling(boolean type) { //vrati false, pokud rosada type nebyla mozna;type = true pro kratkou
//int ij = 0;
if(player){
if(type){
if(board[4][0] != null && board[4][0] instanceof King && !board[4][0].moved && board[7][0] != null && board[7][0] instanceof Rook && !board[7][0].moved && isFree(5,0) && isFree(6,0)){
for(int i=0;i<=3;i++) {
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
//ij++;
//System.out.println("sem tu?" + ij);
//System.out.println("sem tu?" + ij + " " + i);
if ((this.board[_column][_row] != null) && (this.board[_column][_row].getPlayer() != this.player)) {
boolean a = this.board[_column][_row].inRange(i+4, 0);
if(a) {
//System.out.println("vracim flase");
return false;
}
}
}
}
}
this.board[6][0] = new King(this,true,6,0,true);
this.board[5][0] = new Rook(this,true,5,0,true);
this.board[4][0] = null;
this.board[7][0] = null;
}
else {
return false;
}
}
else{
if(board[4][0] != null && board[4][0] instanceof King && !board[4][0].moved && board[0][0] != null && board[0][0] instanceof Rook && !board[0][0].moved && isFree(1,0) && isFree(2,0) && isFree(3,0)){
for(int i=0;i<=4;i++) {
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
//ij++;
//System.out.println("sem tu?" + ij + " " + i);
if ((this.board[_column][_row] != null) && (this.board[_column][_row].getPlayer() != this.player)) {
boolean a = this.board[_column][_row].inRange(i, 0);
if(a) {
//System.out.println("vracim flase");
return false;
}
}
}
}
}
this.board[2][0] = new King(this,true,2,0,true);
this.board[3][0] = new Rook(this,true,3,0,true);
this.board[4][0] = null;
this.board[0][0] = null;
}
else {
return false;
}
}
}
else {
if(type){
if(board[4][7] != null && board[4][7] instanceof King && !board[4][7].moved && board[7][7] != null && board[7][7] instanceof Rook && !board[7][7].moved && isFree(5,7) && isFree(6,7)){
for(int i=0;i<=3;i++) {
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
//ij++;
//System.out.println("sem tu?" + ij);
//System.out.println("sem tu?" + ij + " " + i);
if ((this.board[_column][_row] != null) && (this.board[_column][_row].getPlayer() != this.player)) {
boolean a = this.board[_column][_row].inRange(i+4, 7);
//System.out.println("muze " + this.board[_column][_row].toString() + " Z " + _column + " " + _row + " na " + (i+4) + " 7?? - " + a);
if(a) {
//System.out.println("vracim flase");
return false;
}
}
}
}
}
this.board[6][7] = new King(this,true,6,7,true);
this.board[5][7] = new Rook(this,true,5,7,true);
this.board[4][7] = null;
this.board[7][7] = null;
}
else {
return false;
}
}
else{
if(board[4][7] != null && board[4][7] instanceof King && !board[4][7].moved && board[0][7] != null && board[0][7] instanceof Rook && !board[0][7].moved && isFree(1,7) && isFree(2,7) && isFree(3,7)){
for(int i=0;i<=4;i++) {
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
//ij++;
//System.out.println("sem tu?" + ij);
//System.out.println("sem tu?" + ij + " " + i);
if ((this.board[_column][_row] != null) && (this.board[_column][_row].getPlayer() != this.player)) {
boolean a = this.board[_column][_row].inRange(i, 7);
if(a) {
//System.out.println("vracim flase");
return false;
}
}
}
}
}
this.board[2][7] = new King(this,true,2,7,true);
this.board[3][7] = new Rook(this,true,3,7,true);
this.board[4][7] = null;
this.board[0][7] = null;
}
else {
return false;
}
}
}
//System.out.println("vracim nic nez pravdu");
return true;
} |
02779de3-b424-4148-b2b3-10f3df46a98a | public boolean command() { //nacte prikaz z klavesnice a pokud je mozny, provede ho a vrati true
Scanner inp = new Scanner(System.in);
if(player) {
System.out.println("Hraje bily.");
}
else {
System.out.println("Hraje cerny.");
}
System.out.println("Zadej prikaz:");
String rawCommand = inp.nextLine();//save, load, new,0-0,0-0-0
switch(rawCommand) {
case "quit":
System.exit(1); // prikaz quit
case "save":
this.save(); //prikaz save
return false;
case "load":
this.load(); //prikaz load
return true;
case "new":
return false; //nova hra
case "0-0":
boolean b = this.castling(true); //prikaz rosada (strana krale)
if(!b) {
System.out.println("Rosadu nelze provest.");
}
return b;
case "0-0-0":
boolean c = this.castling(false); //prikaz rosada (strana kralovny)
if(!c) {
System.out.println("Rosadu nelze provest.");
}
return c;
default:
rawCommand = rawCommand.replaceAll(" ",""); //blok default odstrani mezery, zjisti, zda-li je prikaz ve spravnem formatu a vrati odpovidajici prikaz (prip. error)
if(rawCommand.length() == 4) { //validni prikaz ma po vypusteni mezer presne 4 znaky
boolean checker = true;
int oldColumn, oldRow, newColumn, newRow;
for (int i = 0;i < 4;i++){
if (!Character.isDigit(rawCommand.charAt(i))) {
rawCommand = rawCommand.replace(rawCommand.charAt(i), letterToNumber((rawCommand.charAt(i)))); //nahrazeni pismen sloupcu za cislice
}
if ((Character.getNumericValue(rawCommand.charAt(i)) > 8) || (Character.getNumericValue(rawCommand.charAt(i)) < 1)){ //policka jsou od 1,1 do 8,8
checker = false;
}
}
oldColumn = Character.getNumericValue(rawCommand.charAt(0)) - 1;
oldRow = Character.getNumericValue(rawCommand.charAt(1)) - 1;
newColumn = Character.getNumericValue(rawCommand.charAt(2)) - 1;
newRow = Character.getNumericValue(rawCommand.charAt(3)) - 1;
if (checker && (board[oldColumn][oldRow] != null) && (board[oldColumn][oldRow].getPlayer() == player)) { //pokud je prikaz validni, preda se dal
boolean a = this.board[oldColumn][oldRow].move(true,newColumn, newRow);
if(!a) {
System.out.println("Nemozny tah.");
}
return a;
}
else {
System.out.println("Chybny prikaz.");
return false; //jinak je predana chyba
}
}
else
{
System.out.println("Prikaz neni ve spravnem formatu.");
return false; //jinak je predana chyba
}
}
} |
73aa0618-7381-4923-a50e-80591494ec93 | private char letterToNumber(char _letter) { //prevede pismena a-h na cislice 1-8
char[] lettersLC = {'a','b','c','d','e','f','g','h'};
char[] lettersUC = {'A','B','C','D','E','F','G','H'};
char[] numbers = {'1','2','3','4','5','6','7','8'};
for (int i = 0; i < 8; i++){
if(_letter == lettersLC[i]) {
return numbers[i];
}
if(_letter == lettersUC[i]) {
return numbers[i];
}
}
return '9';
} |
4f84e561-beed-416d-8e33-7b838b64ae58 | private void save() { //zapise do souboru, kdo je na tahu a pozice vsech figurek
try{
Scanner inp = new Scanner(System.in);
System.out.println("Zadej jmeno souboru:");
FileWriter fstream = new FileWriter(inp.nextLine() + ".save");
BufferedWriter out = new BufferedWriter(fstream);
out.write(getPlayer());
out.newLine();
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
if(this.board[_column][_row] != null){
String write = this.board[_column][_row].toString()+this.board[_column][_row].getColumn()+this.board[_column][_row].getRow();
if(this.board[_column][_row].getMoved()){
write += "T";
}
else {
write += "F";
}
out.write(write);
out.newLine();
}
}
}
out.close();
}
catch (Exception e){
System.err.println("Error: " + e.getMessage());
System.exit(0);
}
} |
2e17bd88-e0ca-4804-8e59-1a6235fe6c09 | private void load() { //nacte hru ze souboru
Scanner inp = new Scanner(System.in);
System.out.println("Zadej jmeno souboru:");
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
this.board[_row][_column] = null;
}
}
BufferedReader br = null;
try {
String object;
br = new BufferedReader(new FileReader(inp.nextLine() + ".save"));
while ((object = br.readLine()) != null) {
if(object.length() == 4 && !"true".equals(object)) {
loadPiece(object);
}
else if("true".equals(object)) {
player = false;
}
else if("false".equals(object)){
player = true;
}
else {
System.out.println("Chyba souboru.");
System.exit(0);
}
}
}
catch (IOException e) {
}
finally {
try {
if (br != null) {
br.close();
}
}
catch (IOException ex) {
}
}
} |
edc4c7a6-85a1-40eb-ac2d-96daa56661f4 | private void loadPiece(String com) { //vytvori na sachovnici instanci dane figurky
int column = Character.getNumericValue(com.charAt(1));
int row = Character.getNumericValue(com.charAt(2));
boolean moved;
if(com.charAt(3) == 'T') {
moved = true;
}
else {
moved = false;
}
switch(com.charAt(0)) {
case 'p':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new Pawn(this, false, column, row, moved);
break;
case 'P':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new Pawn(this, true, column, row, moved);
break;
case 'k':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new Knight(this, false, column, row, moved);
break;
case 'K':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new Knight(this, true, column, row, moved);
break;
case 'b':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new Bishop(this, false, column, row, moved);
break;
case 'B':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new Bishop(this, true, column, row, moved);
break;
case 'r':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new Rook(this, false, column, row, moved);
break;
case 'R':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new Rook(this, true, column, row, moved);
break;
case 'q':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new Queen(this, false, column, row, moved);
break;
case 'Q':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new Queen(this, true, column, row, moved);
break;
case 'x':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new King(this, false, column, row, moved);
break;
case 'X':
//System.out.println(com.charAt(0) + "@ " + column + " " + row);
this.board[column][row] = new King(this, true, column, row, moved);
break;
default:
System.out.println("Chyba souboru.");
System.exit(0);
}
} |
89021073-ccac-40d4-aef6-d5e8dc5d433d | public void newGame() { //zahaji novou hru
this.player = false;
fillBoardColor();
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
this.board[_row][_column] = null;
}
}
this.board[0][0] = new Rook(this,true,0,0,false);
this.board[1][0] = new Knight(this,true,1,0,false);
this.board[2][0] = new Bishop(this,true,2,0,false);
this.board[3][0] = new Queen(this,true,3,0,false);
this.board[4][0] = new King(this,true,4,0,false);
this.board[5][0] = new Bishop(this,true,5,0,false);
this.board[6][0] = new Knight(this,true,6,0,false);
this.board[7][0] = new Rook(this,true,7,0,false);
for(int i = 0; i < 8;i++){
this.board[i][1] = new Pawn(this,true,i,1,false);
}
this.board[0][7] = new Rook(this,false,0,7,false);
this.board[1][7] = new Knight(this,false,1,7,false);
this.board[2][7] = new Bishop(this,false,2,7,false);
this.board[3][7] = new Queen(this,false,3,7,false);
this.board[4][7] = new King(this,false,4,7,false);
this.board[5][7] = new Bishop(this,false,5,7,false);
this.board[6][7] = new Knight(this,false,6,7,false);
this.board[7][7] = new Rook(this,false,7,7,false);
for(int i = 0; i < 8;i++){
this.board[i][6] = new Pawn(this,false,i,6,false);
}
} |
cd73e82c-722a-43b4-8193-ad43ff19d08c | public void print() { //vytiskne sachovnici a figurky do konzole
for(int row = 7; row >= 0; row--) {
System.out.print(row+1 + " ");
for(int column = 0;column < 8;column++) {
System.out.print(fields[column][row]);
if(board[column][row] != null) {
System.out.print(board[column][row]);
}
else {
System.out.print("-");
}
System.out.print(" ");
}
System.out.print("\n");
}
System.out.println(" a b c d e f g h");
} |
cbdcca16-0134-43ba-a099-5c5c007777d8 | private void fillBoardColor() { //naplni pole barev jednotlivych policek na sachovnici
boolean switching = false; //na stridani barev v radku
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
if (switching == true) {
fields[_column][_row] = 'B'; //...a priradi barvu
}
else {
fields[_column][_row] = 'C';
}
switching = !switching; //dalsi barva v radku bude odlisna
}
switching = !switching; //dalsi barva ve sloupci bude odlisna
}
} |
b68012a4-8d97-4720-85d6-2d7d225ed562 | public boolean stillPlaying() {
return this.stillPlaying;
} |
9b2b7673-8334-45cd-9827-fe3ede971611 | public void changePlayer() { //zmeni hrace
this.player = !this.player;
} |
267d8065-bda1-4fb9-b577-bf984dd06f45 | public boolean isEndGame(Chessman king) { //otestuje, zda-li neni dana situace remiza pripadne mat
boolean draw = !isChecked();
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
if(this.board[_column][_row] != null && this.board[_column][_row].getPlayer() == player) {
for (int __row = 0; __row < 8; __row++) { //projde celou sachovnici...
for (int __column = 0; __column < 8; __column++) {
//System.out.println("Ptam se "+this.board[_column][_row].toString()+" na pozici ["+_column+"]["+_row+"], jestli by mohl jit na ["+__column+"]["+__row+"] tak, aby pak nebyl sach.");
if(this.board[_column][_row].move(false,__column,__row)) {
//System.out.println("alespon jeden mozny tah tu je");
return false;
}
else {
//System.out.println("tohle zrovna ne");
}
}
}
}
}
}
stillPlaying = false;
if(draw) {
System.out.println("Remiza.");
return true;
}
else {
if(player) {
System.out.println("Zvitezil cerny!");
}
else{
System.out.println("Zvitezil bily!");
}
return true;
}
} |
3a5c1c3a-942a-4ae9-99aa-4714818fa2a3 | public boolean isChecked() { //zkontroluje, zda-li neni kral hrace, ktery je prave na tahu, v sachu
int columnKing = -1, rowKing = -1;
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
if ((this.board[_column][_row] instanceof King) && (this.board[_column][_row].color == this.player)) {
columnKing = _column;
rowKing = _row;
break;
}
if (columnKing != -1){
break;
}
}
}
if (columnKing != -1 && rowKing != -1) {
if(this.player) {
whiteKing = this.board[columnKing][rowKing];
}
else {
blackKing = this.board[columnKing][rowKing];
}
//System.out.println("neni tenhle " +this.board[columnKing][rowKing]+"[" + columnKing + "," + rowKing + "] moula v sachu?");
for (int _row = 0; _row < 8; _row++) { //projde celou sachovnici...
for (int _column = 0; _column < 8; _column++) {
if ((this.board[_column][_row] != null) && (this.board[_column][_row].getPlayer() != this.player)) {
boolean a = this.board[_column][_row].inRange(columnKing, rowKing);
//System.out.println("Ptam se " + this.board[_column][_row] + " na pozici " + _column+ " " + _row + " jestli muzou na krale@" + columnKing + " " + rowKing + "tedy: " + a);
if (a) {
//System.out.println("a muze tam!");
return true;
}
}
}
}
}
return false;
} |
47aa7427-fb81-4d7c-b63a-2ffcc03f850e | private String getPlayer(){
if(player) {
return "true";
}
else{
return "false";
}
} |
730dce69-2f61-40a0-aa7b-e511488b8084 | public Chessman getKing() {
if(player == true) {
return whiteKing;
}
else {
return blackKing;
}
} |
c2a8a969-20ad-41a8-9a96-5729d7477d59 | Rook(ChessBoard boardRef,boolean color, int row, int column,boolean moved) {//konstruktor pro nacteni nove hry/hry ze souboru
super(boardRef, color, row, column,moved);
} |
17941392-4ab6-400d-933e-9a5c2c816ff8 | Rook(Chessman copy, int column, int row) {//konstruktor k presouvani po sachovnici
super();
this.color = copy.color;
this.row = row;
this.column = column;
this.ref = copy.ref;
this.moved = true;
System.out.println(this.moved);
} |
7a196059-4dd6-4aff-abac-a5a644ea98b2 | @Override public boolean inRange(int column, int row) { //vrati true, pokud je pole [row][column] v dosahu figury
if(column == this.column) {
if(row > this.row) {
for(int i = 1;i < row-this.row; i++) {
if(!ref.isFree(this.column, this.row+i)) {
return false;
}
}
return true;
}
if(row < this.row) {
for(int i = 1;i < this.row-row; i++) {
if(!ref.isFree(this.column, this.row-i)) {
return false;
}
}
return true;
}
}
if(row == this.row) {
if(column > this.column) {
for(int i = 1;i < column-this.column; i++) {
if(!ref.isFree(this.column+1, this.row)) {
return false;
}
}
return true;
}
if(column < this.column) {
for(int i = 1;i < this.column-column; i++) {
if(!ref.isFree(this.column-1, this.row)) {
return false;
}
}
return true;
}
}
return false;
} |
3b40fd52-b8e2-43b2-91c3-1f086f8b097d | @Override public boolean move(boolean really,int column, int row){//vrati true, pokud je tah na pole [column][row] mozny. pokud je navic argument really = true, tah se i provede
if(inRange(column, row)&& ref.isNotMine(column, row)){
Rook backUp;
Chessman ten;
backUp = this;
ten = ref.board[column][row];
ref.board[column][row] = new Rook(this,column,row);
ref.board[this.column][this.row] = null;
//ref.print();
boolean b = ref.isChecked();
if(really) {
if(b) {
ref.board[backUp.column][backUp.row] = backUp;
ref.board[column][row] = ten;
//System.out.println("vracim false tudyma");
return false;
}
else {
//System.out.println("ok, vracim true");
ref.board[column][row].moved = true;
return true;
}
}
else{
ref.board[backUp.column][backUp.row] = backUp;
ref.board[column][row] = ten;
return !b;
}
}
else {
//System.out.println("vracim false");
return false;
}
} |
7d96cbe8-f7d4-4a07-97fc-75611c3d90a7 | @Override public String toString() {
if (this.color == true) {
return "R";
}
else {
return "r";
}
} |
5fb66f71-577d-4592-b61f-8b3dbea78910 | public static void main(String[] args) { //hlavni trida s jednoduchou smyckou
ChessBoard a = new ChessBoard();
a.newGame();
a.changePlayer();
while(a.stillPlaying()) {
a.print();
if(a.command()){
a.changePlayer();
//System.out.println("endgame");
a.isEndGame(a.getKing());
}
}
} |
d3c3221a-90cc-4870-9798-82451118cbb2 | King(ChessBoard boardRef,boolean color, int row, int column, boolean moved) {//konstruktor pro nacteni nove hry/hry ze souboru
super(boardRef, color, row, column, moved);
} |
0634a594-3baa-427a-8c65-94ea95e8e5f1 | King(Chessman copy, int column, int row) {//konstruktor k presouvani po sachovnici
super();
this.color = copy.color;
this.row = row;
this.column = column;
this.ref = copy.ref;
this.moved = true;
System.out.println(this.moved);
} |
ff4bdc3f-3d84-48b0-b613-25835b6e043b | @Override public boolean move(boolean really,int column, int row){//vrati true, pokud je tah na pole [column][row] mozny. pokud je navic argument really = true, tah se i provede
if(inRange(column, row)&& ref.isNotMine(column, row)){
King backUp;
Chessman ten;
backUp = this;
ten = ref.board[column][row];
ref.board[column][row] = new King(this,column,row);
ref.board[this.column][this.row] = null;
//ref.print();
boolean b = ref.isChecked();
if(really) {
if(b) {
ref.board[backUp.column][backUp.row] = backUp;
ref.board[column][row] = ten;
//System.out.println("vracim false tudyma");
return false;
}
else {
//System.out.println("ok, vracim true");
ref.board[column][row].moved = true;
return true;
}
}
else{
ref.board[backUp.column][backUp.row] = backUp;
ref.board[column][row] = ten;
return !b;
}
}
else {
//System.out.println("vracim false");
return false;
}
} |
72966875-e544-4a87-a32e-743107454a26 | @Override public boolean inRange(int column, int row) { //vrati true, pokud je pole [row][column] v dosahu figury
if((Math.abs(column - this.column) <= 1) && (Math.abs(row - this.row) <= 1)) {
if(ref.isFree(column, row) || ref.isEnemy(this.color,column,row)) {
return true;
}
}
return false;
} |
2f43c989-1cff-4e7a-9f7f-8cc2403fe70a | @Override public String toString() {
if (this.color == true) {
return "X";
}
else {
return "x";
}
} |
104c508b-926c-49da-ae15-e3af9093c83b | Chessman(ChessBoard boardRef,boolean color, int column, int row, boolean moved) { //konstruktor
this.color = color;
this.column = column;
this.row = row;
this.ref = boardRef;
this.moved = moved;
} |
6ea75f3e-14a3-4591-85c9-bd2f3841af34 | Chessman() { //defaultni konstruktor
super();
} |
9a9e4dcc-5da1-4d53-9d05-c38e6082ab23 | public boolean isDraw() {
return false;
} |
1424bd54-d6f9-4259-961c-8c1b61d99d04 | public boolean isCheckmate() {
return false;
} |
de988a1e-0234-46d7-8f64-dcfa05f83a13 | public abstract boolean move(boolean really,int column, int row); //provede tah na policko [column,row], nebo vrati false, pokud tah neni mozny, pokud je really = false, tah se neprovede, pozue se zjisti, zda-li je mozny |
3d085371-c3e8-4e7d-888f-ffd3760c60e5 | public abstract boolean inRange(int column, int row); |
69f5f9f5-bb1b-4373-a1ba-fec6a6bea335 | @Override public abstract String toString(); |
01d2123d-0382-403d-a67b-dd1840cdae64 | public int getColumn() {
return this.column;
} |
91e330b1-def9-4418-83af-c4d40803ef93 | public int getRow() {
return this.row;
} |
4f20d5f5-0c52-44f2-b130-0285ebf735a1 | public boolean getPlayer() {
return this.color;
} |
4315cd9d-1ce7-42f5-8075-d1c81e95f34b | public boolean getMoved(){
return this.moved;
} |
1de84dd7-0e57-4ac7-badd-d1daf600fef6 | Bishop(ChessBoard boardRef,boolean color, int row, int column,boolean moved) {//konstruktor pro nacteni nove hry/hry ze souboru
super(boardRef, color, row, column,moved);
} |
ae2d27d9-e513-476e-a27f-9f8ac636521e | Bishop(Chessman copy, int column, int row) {//konstruktor k presouvani po sachovnici
super();
this.color = copy.color;
this.row = row;
this.column = column;
this.ref = copy.ref;
} |
3a8831de-86ac-43d7-b5ed-df6c2a9e6ab5 | @Override public boolean move(boolean really,int column, int row){//vrati true, pokud je tah na pole [column][row] mozny. pokud je navic argument really = true, tah se i provede
if(inRange(column, row)&& ref.isNotMine(column, row)){
Bishop backUp;
Chessman ten;
backUp = this;
ten = ref.board[column][row];
ref.board[column][row] = new Bishop(this,column,row);
ref.board[this.column][this.row] = null;
//ref.print();
boolean b = ref.isChecked();
if(really) {
if(b) {
ref.board[backUp.column][backUp.row] = backUp;
ref.board[column][row] = ten;
//System.out.println("vracim false tudyma");
return false;
}
else {
//System.out.println("ok, vracim true");
ref.board[column][row].moved = true;
return true;
}
}
else{
ref.board[backUp.column][backUp.row] = backUp;
ref.board[column][row] = ten;
return !b;
}
}
else {
//System.out.println("vracim false");
return false;
}
} |
fa30c6fb-8be6-4a1b-a9be-3cad81493b11 | @Override public boolean inRange(int column, int row) { //vrati true, pokud je pole [row][column] v dosahu figury
if(Math.abs(this.column - column) == Math.abs(this.row - row)) {
//System.out.println("ok");
if(this.column < column && this.row < row) {
for(int i = 1; i < (column - this.column);i++) {
//System.out.println(i);
if(!ref.isFree(this.column+i, this.row+i)) {
return false;
}
}
return true;
}
if(this.column > column && this.row > row) {
for(int i = 1; i < (this.column - column);i++) {
//System.out.println(i);
if(!ref.isFree(this.column-i, this.row-i)) {
return false;
}
}
return true;
}
if(this.column < column && this.row > row) {
for(int i = 1; i < (column - this.column);i++) {
//System.out.println(i);
if(!ref.isFree(this.column+i, this.row-i)) {
return false;
}
}
return true;
}
if(this.column > column && this.row < row) {
for(int i = 1; i < (this.column - column);i++) {
//System.out.println(i);
if(!ref.isFree(this.column-i, this.row+i)) {
return false;
}
}
return true;
}
}
return false;
} |
15ef6f39-ff9c-4665-be52-98a63adc0ddb | @Override public String toString() {
if (this.color == true) {
return "B";
}
else {
return "b";
}
} |
bd36633d-f319-4125-bdd9-82583bf4e120 | Knight(ChessBoard boardRef,boolean color, int row, int column,boolean moved) { //konstruktor pro nacteni nove hry/hry ze souboru
super(boardRef, color, row, column, moved);
} |
128bc039-952b-4579-ae9a-4d92f94978b6 | Knight(Chessman copy, int column, int row) { //konstruktor k presouvani po sachovnici
super();
this.color = copy.color;
this.row = row;
this.column = column;
this.ref = copy.ref;
} |
acf16991-6e64-432d-91b8-ce547520e085 | @Override public boolean inRange(int column, int row) { //vrati true, pokud je pole [row][column] v dosahu figury
if (Math.abs(column - this.column) == 2 && Math.abs(row - this.row) == 1) {
return true;
}
if (Math.abs(row - this.row) == 2 && Math.abs(column - this.column) == 1) {
return true;
}
return false;
} |
83e0a355-9c6c-493d-b285-49d483c33d8f | @Override public boolean move(boolean really,int column, int row){ //vrati true, pokud je tah na pole [column][row] mozny. pokud je navic argument really = true, tah se i provede
if(inRange(column, row)&& ref.isNotMine(column, row)){
Knight backUp;
Chessman ten;
backUp = this;
ten = ref.board[column][row];
ref.board[column][row] = new Knight(this,column,row);
ref.board[this.column][this.row] = null;
//ref.print();
boolean b = ref.isChecked();
if(really) {
if(b) {
ref.board[backUp.column][backUp.row] = backUp;
ref.board[column][row] = ten;
//System.out.println("vracim false tudyma");
return false;
}
else {
//System.out.println("ok, vracim true");
ref.board[column][row].moved = true;
return true;
}
}
else{
ref.board[backUp.column][backUp.row] = backUp;
ref.board[column][row] = ten;
return !b;
}
}
else {
//System.out.println("vracim false");
return false;
}
} |
a1470f7e-25c6-412a-bca2-8b0eb9bbe2b9 | @Override public String toString() {
if (this.color == true) {
return "K";
}
else {
return "k";
}
} |
d3e5a8bc-08ec-43ed-9f09-d37dd88b7755 | @GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
} |
5056e364-26b3-4ccf-9480-2ca4a71c5a73 | @GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
} |
a59cbc8b-94da-4a90-b981-202f8d2a6649 | @GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
} |
74ba5670-e53e-443e-8361-099546fd2f77 | @GET
@Produces(MediaType.APPLICATION_JSON)
public String sayJsonHello() {
return "{\"respuesta\": \"Hello Jersey\"}";
} |
8e1e660f-2ad5-4bb4-8f1e-bd4efd1e4e3e | @GET
@Produces(MediaType.TEXT_XML)
public List<Todo> getTodosBrowser() {
List<Todo> todos = new ArrayList<Todo>();
todos.addAll(TodoDao.instance.getModel().values());
return todos;
} |
04717776-f09c-4500-b926-31de821e8347 | @GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<Todo> getTodos() {
List<Todo> todos = new ArrayList<Todo>();
todos.addAll(TodoDao.instance.getModel().values());
return todos;
} |
9b97194a-6571-4392-9704-e4e5128ae682 | @GET
@Path("count")
@Produces(MediaType.TEXT_PLAIN)
public String getCount() {
int count = TodoDao.instance.getModel().size();
return String.valueOf(count);
} |
dc6d2a74-da16-4441-b47a-dfa853c01054 | @POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newTodo(@FormParam("id") String id,
@FormParam("summary") String summary,
@FormParam("description") String description,
@Context HttpServletResponse servletResponse) throws IOException {
Todo todo = new Todo(id, summary);
if (description != null) {
todo.setDescription(description);
}
TodoDao.instance.getModel().put(id, todo);
servletResponse.sendRedirect("../create_todo.html");
} |
adbd7b20-1095-4511-82e5-5a253034a007 | @GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Todo getTodo() {
Todo todo = TodoDao.instance.getModel().get(id);
if (todo == null)
throw new RuntimeException("Get: Todo with " + id + " not found");
return todo;
} |
a71cecde-99f4-42a0-a82f-e5ea9204ca51 | @GET
@Produces(MediaType.TEXT_XML)
public Todo getTodoHTML() {
Todo todo = TodoDao.instance.getModel().get(id);
if (todo == null)
throw new RuntimeException("Get: Todo with " + id + " not found");
return todo;
} |
f36a4947-581d-4e95-880d-f0e781dbdc9e | @PUT
@Consumes(MediaType.APPLICATION_XML)
public Response putTodo(JAXBElement<Todo> todo) {
Todo c = todo.getValue();
return putAndGetResponse(c);
} |
1fdd30e3-ac8a-48b6-9b2b-e83d27ec11fe | @DELETE
public void deleteTodo() {
Todo c = TodoDao.instance.getModel().remove(id);
if (c == null)
throw new RuntimeException("Delete: Todo with " + id + " not found");
} |
f01d6d6b-197e-433d-876e-83bc863deb4f | private Response putAndGetResponse(Todo todo) {
Response res;
if (TodoDao.instance.getModel().containsKey(todo.getId())) {
res = Response.noContent().build();
} else {
res = Response.created(uriInfo.getAbsolutePath()).build();
}
TodoDao.instance.getModel().put(todo.getId(), todo);
return res;
} |
45389d0f-be16-4895-ab0a-2a3d49c4c528 | public static void main(String[] args) {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
// Fluent interfaces
System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_PLAIN).get(ClientResponse.class).toString());
// Get plain text
System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_PLAIN).get(String.class));
// Get XML
System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_XML).get(String.class));
// The HTML
System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_HTML).get(String.class));
//The JSON
System.out.println(service.path("rest").path("hello").accept(MediaType.APPLICATION_JSON).get(String.class));
// Get XML
System.out.println(service.path("rest").path("todo").accept(MediaType.TEXT_XML).get(String.class));
// Get XML for application
System.out.println(service.path("rest").path("todo").accept(MediaType.APPLICATION_JSON).get(String.class));
// Get JSON for application
System.out.println(service.path("rest").path("todo").accept(MediaType.APPLICATION_XML).get(String.class));
} |
52310863-5421-475f-84c9-a7af177bb33f | private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost:8080/hellorest").build();
} |
c1d8d351-7d0f-49cc-bd21-e3ed1156e358 | private TodoDao() {
Todo todo = new Todo("1", "Learn REST");
todo.setDescription("Read http://www.vogella.com/articles/REST/article.html");
contentProvider.put("1", todo);
todo = new Todo("2", "Do something");
todo.setDescription("Read complete http://www.vogella.com");
contentProvider.put("2", todo);
} |
6755fcb6-181d-43ab-b936-0cde42be8e41 | public Map<String, Todo> getModel() {
return contentProvider;
} |
8ec0dbc5-176d-4a88-97b8-04645f78d68d | public Todo() {
} |
cc4d6f1b-f42b-44e3-8621-b99b2131ddd5 | public Todo(String id, String summary) {
this.id = id;
this.summary = summary;
} |
41e5c4be-3ee5-43ee-bddd-59cbf4b22fe9 | public String getId() {
return id;
} |
2a65f48b-8c6d-442f-a248-6a3d61c81267 | public void setId(String id) {
this.id = id;
} |
108ddc3f-69dd-415a-af1f-d29cb814eac7 | public String getSummary() {
return summary;
} |
7c08d41e-97dd-4b28-9bd3-d0fc47b8342a | public void setSummary(String summary) {
this.summary = summary;
} |
609480df-caa9-4f8f-842c-190a3185eddd | public String getDescription() {
return description;
} |
0c8f0908-21ed-4b38-a508-15877ca8f126 | public void setDescription(String description) {
this.description = description;
} |
346a418a-30cc-410b-bc3a-af85ff38b2fb | public abstract int getHealth(); |
e551cd94-f027-47e9-8812-f3f52e80ab6e | public abstract int getStrength(); |
eb2e5f10-ad45-410b-b775-9954ccb5c1f8 | public abstract int getDexterity(); |
716f1235-b45f-4299-ada5-648591f939e9 | public abstract int getIntelligence(); |
0b3f5267-904f-4353-af37-9483f6f143de | public abstract int attack(); // probably take some arguments from weapon to increase damage.... |
afa1d9b1-1463-428c-be2b-1618d3d59cdf | public Light(){
} |
05d43d1d-714a-40ca-bf72-5d9393e7cbfe | @Override
public int getHealth() {
// TODO Auto-generated method stub
return hp;
} |
a1ebc41b-b23a-4ecd-93da-0fd698f047ac | @Override
public int getStrength() {
// TODO Auto-generated method stub
return muscle;
} |
ed862f25-e69c-49d8-8f2b-007f7ebd6f49 | @Override
public int getDexterity() {
// TODO Auto-generated method stub
return dex;
} |
358f1790-5bb4-4e99-b3ff-e2200277b125 | @Override
public int getIntelligence() {
// TODO Auto-generated method stub
return intel;
} |
d78fd2f9-f2e4-4428-bdad-5ab62e58718f | @Override
public int attack() {
// TODO Auto-generated method stub
return 0;
} |
4906f691-6b1c-463e-9c3e-2e28a8ff1253 | public Medium(){
} |
eb4534b8-d61f-40a5-b716-186ada410159 | @Override
public int getHealth() {
// TODO Auto-generated method stub
return hp;
} |
f38bbec2-e2f8-4094-b0d9-4f4587c8723c | @Override
public int getStrength() {
// TODO Auto-generated method stub
return muscle;
} |
07cc68c5-a872-4e9f-8ef2-f693f123789a | @Override
public int getDexterity() {
// TODO Auto-generated method stub
return dex;
} |
2547e1de-7a10-474a-a625-0208b91212e1 | @Override
public int getIntelligence() {
// TODO Auto-generated method stub
return intel;
} |
78c8232f-ec39-40e6-97ee-e0011adde762 | @Override
public int attack() {
// TODO Auto-generated method stub
return 0;
} |
29f731d2-2b64-4fbb-b0e2-9a63f2ceae61 | public Heavy() {
} |
54d23548-ba32-45f2-9ffb-c5ae0fcbbd4c | @Override
public int getHealth() {
// TODO Auto-generated method stub
return hp;
} |
0ec5b2f1-4245-4a2b-8e8c-6df7f4dd69c5 | @Override
public int getStrength() {
// TODO Auto-generated method stub
return muscle;
} |
68bb9df5-9d82-4be0-aeb9-d314e4be769a | @Override
public int getDexterity() {
// TODO Auto-generated method stub
return dex;
} |
e54a894c-f0fc-42ad-89fd-308f04fafb76 | @Override
public int getIntelligence() {
// TODO Auto-generated method stub
return intel;
} |
caf9706a-cb44-4ec1-a316-7882d2d1254e | @Override
public int attack() {
// TODO Auto-generated method stub
return 0;
} |
3edf60bb-9d13-427a-ac93-4f13957ee778 | public Wizard() {
} |
fbeb3eac-ad18-4308-bac4-6ea4b9283a85 | @Override
public int getHealth() {
return hp;
} |
d4fd7aa5-d406-4d5b-a02a-f057305e76f4 | @Override
public void setHealth(int health) {
hp = hp + health;
} |
27313c0e-6028-4135-b101-25ff475d0faa | @Override
public int getStrength() {
return muscle;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.