Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions core/src/ru/dvimer/lesson/Figurs/Bishop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

package ru.dvimer.lesson.Figurs;

/**
* Created by Алексей on 23.01.2016.
*/
public class Bishop extends Figure {

public Bishop(int x, int y) {
super(x, y);
}



@Override
public boolean proverka(int x, int y) {
if (y - this.y == x - this.x || -(y - this.y) == (x - this.x)){
return true;
}
return false;
}

@Override
public void setPosition(int x, int y) {
if (y - this.y == x - this.x || -(y - this.y) == (x - this.x)) {
this.y = y;
this.x = x;
}
}


}
37 changes: 27 additions & 10 deletions core/src/ru/dvimer/lesson/Figurs/Figure.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package ru.dvimer.lesson.Figurs;

import java.util.ArrayList;

/**
* Created by Алексей on 23.01.2016.
*/
public abstract class Figure {
protected int x;
protected int y;


protected ArrayList<Integer> keyX = new ArrayList<Integer>();
protected ArrayList<Integer> keyY = new ArrayList<Integer>();

public Figure() {
}
Expand All @@ -17,6 +20,13 @@ public Figure(int x, int y) {
this.y = y;
}

public ArrayList<Integer> getKeyX() {
return keyX;
}

public ArrayList<Integer> getKeyY() {
return keyY;
}


public int getX() {
Expand All @@ -35,18 +45,25 @@ public void setY(int y) {
this.y = y;
}


// public void setPosition(int x, int y) {
// if (y - this.y == 1 && x-this.x == 1) {
// this.y = y++;
// this.x = x++;
// }
// }
//

public void light() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (proverka(i, j)) {
keyX.add(i);
keyY.add(j);
}
}
}
}


public void resetLight() {
keyX.clear();
keyY.clear();
}

public abstract void setPosition(int x, int y);

public abstract boolean proverka(int x, int y);

}
26 changes: 0 additions & 26 deletions core/src/ru/dvimer/lesson/Figurs/Horse.java

This file was deleted.

33 changes: 33 additions & 0 deletions core/src/ru/dvimer/lesson/Figurs/King.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ru.dvimer.lesson.Figurs;

/**
* Created by Алексей on 23.01.2016.
*/
public class King extends Figure {


public King(int x, int y) {
super(x, y);

}


@Override
public boolean proverka(int x, int y) {
if (Math.abs(y-this.y) == 1&& Math.abs(x - this.x) == 0|| Math.abs(y-this.y) == 0&& Math.abs(x - this.x) == 1||Math.abs(y-this.y) == 1 && Math.abs(x - this.x) == 1){
return true;
}
return false;
}

@Override
public void setPosition(int x, int y) {
if (Math.abs(y-this.y) == 1&& Math.abs(x - this.x) == 0|| Math.abs(y-this.y) == 0&& Math.abs(x - this.x) == 1||Math.abs(y-this.y) == 1 && Math.abs(x - this.x) == 1){
this.y = y;
this.x = x;
}
}



}
30 changes: 30 additions & 0 deletions core/src/ru/dvimer/lesson/Figurs/Knight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

package ru.dvimer.lesson.Figurs;
/**
* Created by Алексей on 23.01.2016.
*/
public class Knight extends Figure {

public Knight(int x, int y) {
super(x, y);
}


@Override
public boolean proverka(int x, int y) {
if (Math.abs(y-this.y) == 2&& Math.abs(x - this.x) == 1|| Math.abs(y-this.y) == 1&& Math.abs(x - this.x) == 2){
return true;
}
return false;
}

@Override
public void setPosition(int x, int y) {
if (Math.abs(y-this.y) == 2&& Math.abs(x - this.x) == 1|| Math.abs(y-this.y) == 1&& Math.abs(x - this.x) == 2){
this.y = y;
this.x = x;
}
}


}
30 changes: 30 additions & 0 deletions core/src/ru/dvimer/lesson/Figurs/Pawn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.dvimer.lesson.Figurs;

/**
* Created by Алексей on 23.01.2016.
*/
public class Pawn extends Figure {

public Pawn(int x, int y) {
super(x, y);
}


@Override
public boolean proverka(int x, int y) {
if (y - this.y == 1 && x - this.x == 0 || y - this.y == 2 && x - this.x == 0 && this.y < 1){
return true;
}
return false;
}

@Override
public void setPosition(int x, int y) {
if (y - this.y == 1 && x - this.x == 0 || y - this.y == 2 && x - this.x == 0 && this.y < 1) {

this.y = y;
}
}


}
31 changes: 31 additions & 0 deletions core/src/ru/dvimer/lesson/Figurs/Queen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

package ru.dvimer.lesson.Figurs;
/**
* Created by Алексей on 23.01.2016.
*/
public class Queen extends Figure {

public Queen(int x, int y) {
super(x, y);
}


@Override
public boolean proverka(int x, int y) {
if (Math.abs(y-this.y) <=8&& x - this.x == 0|| y-this.y == 0&& Math.abs(x - this.x) <=8 ||y - this.y == x - this.x || -(y - this.y) == (x - this.x)){
return true;
}
return false;
}

@Override
public void setPosition(int x, int y) {
if (Math.abs(y-this.y) <=8&& x - this.x == 0|| y-this.y == 0&& Math.abs(x - this.x) <=8 ||y - this.y == x - this.x || -(y - this.y) == (x - this.x) ){
this.y = y;
this.x = x;
}

}


}
13 changes: 11 additions & 2 deletions core/src/ru/dvimer/lesson/Figurs/Rook.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
package ru.dvimer.lesson.Figurs;

import java.util.ArrayList;

/**
* Created by Алексей on 23.01.2016.
*/
public class Rook extends Figure {



public Rook(int x, int y) {
super(x, y);

}

@Override
public boolean proverka(int x, int y) {
if (Math.abs(y-this.y) <= 8&& x - this.x == 0|| y-this.y == 0&& Math.abs(x - this.x) <=8 ){
return true;
}
return false;
}

@Override
public void setPosition(int x, int y) {
if (y - this.y == x - this.x || -(y - this.y) == (x - this.x)) {
if (Math.abs(y-this.y) <= 8&& x - this.x == 0|| y-this.y == 0&& Math.abs(x - this.x) <=8 ){
this.y = y;
this.x = x;
}
Expand Down
34 changes: 23 additions & 11 deletions core/src/ru/dvimer/lesson/GameClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import ru.dvimer.lesson.Figurs.Figure;
import ru.dvimer.lesson.Figurs.Rook;
import ru.dvimer.lesson.Figurs.*;

public class GameClass extends ApplicationAdapter {
SpriteBatch batch;
Texture pole;
Texture smile;
Texture smileEnd;
Texture lightField;



Figure[] white = new Figure[8];
Figure[] white = new Figure[6];


int mouseX;
Expand All @@ -35,10 +35,18 @@ public void create() {
pole = new Texture("pole.png");
smile = new Texture("smile.png");
smileEnd = new Texture("smileEnd.png");

for (int i = 0; i < 8; i++) {
white[i] = new Rook(i, 0);
}
lightField = new Texture("allocation.png");
//
// for (int i = 0; i < 8; i++) {
// white[i] = new Queen(i, 0);
// }

white[0] = new King(1,0);
white[1] = new Queen(2,0);
white[2] = new Rook(3,0);
white[3] = new Knight(4,0);
white[4] = new Bishop(5,0);
white[5] = new Pawn(6,0);
}

@Override
Expand All @@ -56,19 +64,21 @@ public void render() {
}
}
}
for (int i = 0; i < 8; i++) {
for (int i = 0; i < white.length; i++) {
if (i == selectIndex) continue;
batch.draw(smile, white[i].getX() * 60, white[i].getY() * 60);
}

if (selectIndex > -1) {
//batch.draw(smileEnd, white[selectIndex].getX() * 60, white[selectIndex].getY() * 60);
for (int i = 0; i < white[selectIndex].getKeyX().size() ; i++) {
batch.draw(lightField, white[selectIndex].getKeyX().get(i) * 60, white[selectIndex].getKeyY().get(i)* 60);
}
batch.draw(smileEnd, white[selectIndex].getX() * 60, white[selectIndex].getY() * 60);
batch.draw(smile, mouseX - 30, mouseY - 30);
}
batch.end();
}


public void update() {
mouseX = Gdx.input.getX();
mouseY = 480 - Gdx.input.getY();
Expand All @@ -78,8 +88,9 @@ public void update() {


if (selectIndex == -1) {
for (int i = 0; i < 8; i++) {
for (int i = 0; i < white.length; i++) {
if (white[i].getX() == mouseCellX && white[i].getY() == mouseCellY && Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
white[i].light();
selectIndex = i;
break;
}
Expand All @@ -88,6 +99,7 @@ public void update() {

if (!Gdx.input.isButtonPressed(Input.Buttons.LEFT) && selectIndex > -1) {
white[selectIndex].setPosition(mouseCellX, mouseCellY);
white[selectIndex].resetLight();
selectIndex = -1;
}
}
Expand Down