//Reakcja na klikniecie pola gry - dopasowuje klikniecie, wybiera pole i robi ruch. Jesli ruch konczyl ture, to zmienia ture. public int SelectField(int x, int y, Classes.ClientMove clientmove) { if (turn == player.color) { int move = board.TrytoSelectField(player, playermove, x, y, clientmove); if (move >= 2) { turn = 1 - turn; if (move == 4) { turn = 2; startdices[0] = 0; startdices[1] = 0; } } return(move); } return(0); }
//Sprawdza w jakie pole kliknal gracz i czy istnieje ruch idpowiadajacy temu zaznaczeniu public int TrytoSelectField(Player player, Move move, int x, int y, Classes.ClientMove clientmove) { int matched = -1; if (y < 300) { if (x > 580) { matched = 27; } if (matched < 0) { for (int i = 0; i < 6; i++) { if (x > 540 - i * 40) { matched = i; break; } } } if (x > 290 && matched < 0) { matched = 24; } if (matched < 0) { for (int i = 6; i < 12; i++) { if (x > 250 - (i - 6) * 40) { matched = i; break; } } } } else { if (y > 400) { if (x > 580) { matched = 26; } if (matched < 0) { for (int i = 0; i < 6; i++) { if (x > 540 - i * 40) { matched = 23 - i; break; } } } if (x > 290 && matched < 0) { matched = 25; } if (matched < 0) { for (int i = 6; i < 12; i++) { if (x > 250 - (i - 6) * 40) { matched = 23 - i; break; } } } } } if (CanSelect(player.color, matched)) { if (matched >= 0 && selected >= 0) { if (selected != matched) { int movemade = Move(player, move, selected, matched); if (movemade > 0) { clientmove.from = selected; clientmove.to = matched; clientmove.endturn = movemade - 1; //Koniec gry if (clientmove.endturn == 4) { movemade = 4; } else { //Brak mozliwych ruchow if (clientmove.endturn == 0 && !isAnyPossibleMove(move)) { clientmove.endturn = 1; movemade = 3; } } selected = -1; PossibleMoves(selected, move, possiblemoves); return(movemade); } } } } else { matched = -1; } selected = Select(player.color, selected, matched); PossibleMoves(selected, move, possiblemoves); return(0); }