Game tic tac toe. Extra methods removed.
public class Field { public String[][] figures = new String[3][3]; public String getFigure(final Point point) { return figures[point.x][point.y]; } } public class Point { public int x; public int y; } Now you need to make a check for matches on verticals, horizontals and diagonals. Letting go of all the subtleties regarding whose course, how many pieces on the field, and so on.
public class A { public String getWinner(final Field field) { Point point1 = new Point(); point1.x = 0; point1.y = 0; Point point2 = new Point(); point1.x = 0; point1.y = 1; Point point3 = new Point(); point1.x = 0; point1.y = 2; if (field.getFigure(point1) != null && field.getFigure(point2) != null && field.getFigure(point3) != null && field.getFigure(point1).equals(field.getFigure(point2)) && field.getFigure(point2).equals(field.getFigure(point3))) { return field.getFigure(point1); } return "no winners"; } } - I understand what needs to be done through the cycle, but I don’t quite understand how. I can stupidly "lick", but I want to understand.
- If we have a fixed number of cells, is it possible to implement this through SWITCH?
- If I fill all 9 cells of the array String, am "X" or "O", I still get an exception that I can not understand - Exception in thread "main" java.lang.NoSuchMethodException:
XOgame.model.A.main ([Ljava.lang.String;) at java.lang.Class.getMethod (Class.java:1786) at com.intellij.rt.execution.application.AppMain.main (AppMain.java: 125) - I study a similar subject Java. Arrays We need a method that checks the winner in tic-tac-toe
Point(int, int)? - vp_arth