Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package io.hexlet.xo.controllers;
- import io.hexlet.xo.model.Field;
- import io.hexlet.xo.model.Point;
- public class WinnerController {
- public String getWinner(final Field field) {
- final Point p1 = new Point();
- final Point p2 = new Point();
- final Point p3 = new Point();
- for (int i = 0; i < field.getSize(); i++) {
- p1.x = 0;
- p2.x = 1;
- p3.x = 2;
- p1.y = i;
- p2.y = i;
- p3.y = i;
- if (field.getFigure(p1) != null && field.getFigure(p2) != null && field.getFigure(p3) != null && field.getFigure(p1).equals(field.getFigure(p2)) && field.getFigure(p1).equals(field.getFigure(p3))) {
- return field.getFigure(p1);
- }
- }
- for (int j = 0; j < field.getSize(); j++) {
- p1.x = j;
- p2.x = j;
- p3.x = j;
- p1.y = 0;
- p2.y = 1;
- p3.y = 2;
- if (field.getFigure(p1) != null && field.getFigure(p2) != null && field.getFigure(p3) != null && field.getFigure(p1).equals(field.getFigure(p2)) && field.getFigure(p1).equals(field.getFigure(p3))) {
- return field.getFigure(p1);
- }
- }
- p1.x = 0;
- p2.x = 1;
- p3.x = 2;
- p1.y = 0;
- p2.y = 1;
- p3.y = 2;
- if (field.getFigure(p1) != null && field.getFigure(p2) != null && field.getFigure(p3) != null && field.getFigure(p1).equals(field.getFigure(p2)) && field.getFigure(p1).equals(field.getFigure(p3))) {
- return field.getFigure(p1);
- }
- p1.x = 0;
- p2.x = 1;
- p3.x = 2;
- p1.y = 2;
- p2.y = 1;
- p3.y = 0;
- if (field.getFigure(p1) != null && field.getFigure(p2) != null && field.getFigure(p3) != null && field.getFigure(p1).equals(field.getFigure(p2)) && field.getFigure(p1).equals(field.getFigure(p3))) {
- return field.getFigure(p1);
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement