From 6eb04fc2d5fc9236bdf155ee26f5996b6fea6f1d Mon Sep 17 00:00:00 2001 From: Artemii_Khokhlov Date: Wed, 19 Jun 2024 23:46:47 +0600 Subject: [PATCH 1/3] init project --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8562103f..33469f3b 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,5 @@ build/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store +/.idea/ From 4d90fbaa8515412155e55274ffd4e041d7ff607e Mon Sep 17 00:00:00 2001 From: Artemii_Khokhlov Date: Thu, 20 Jun 2024 23:20:58 +0600 Subject: [PATCH 2/3] add main.css, index.jsp and create LogicServlet --- pom.xml | 20 +++++++++++----- src/main/java/com/tictactoe/LogicServlet.java | 24 +++++++++++++++++++ src/main/webapp/index.jsp | 18 ++++++++++++++ src/main/webapp/static/main.css | 11 +++++++++ 4 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/tictactoe/LogicServlet.java diff --git a/pom.xml b/pom.xml index cb226e88..aeb8c0eb 100644 --- a/pom.xml +++ b/pom.xml @@ -18,16 +18,24 @@ - javax.servlet - javax.servlet-api - 4.0.1 + jakarta.servlet + jakarta.servlet-api + 6.1.0 provided + - javax.servlet - jstl - 1.2 + jakarta.servlet.jsp.jstl + jakarta.servlet.jsp.jstl-api + 3.0.0 + + + + + + + diff --git a/src/main/java/com/tictactoe/LogicServlet.java b/src/main/java/com/tictactoe/LogicServlet.java new file mode 100644 index 00000000..7623274d --- /dev/null +++ b/src/main/java/com/tictactoe/LogicServlet.java @@ -0,0 +1,24 @@ +package com.tictactoe; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; + +@WebServlet(name = "LogicServlet", value = "/logic") +public class LogicServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + int index = getSelectedIndex(req); + resp.sendRedirect("/index.jsp"); + } + + private int getSelectedIndex(HttpServletRequest request) { + String click = request.getParameter("click"); + boolean isNumeric = click.chars().allMatch(Character::isDigit); + return isNumeric ? Integer.parseInt(click) : 0; + } +} diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 964cc071..17ab59b7 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -3,11 +3,29 @@ + Tic-Tac-Toe

Tic-Tac-Toe

+ + + + + + + + + + + + + + + + +
012
345
678
Tic-Tac-Toe @@ -11,25 +13,53 @@ - - - + + + - - - + + + - - - + + +
012${data.get(0).getSign()}${data.get(1).getSign()}${data.get(2).getSign()}
345${data.get(3).getSign()}${data.get(4).getSign()}${data.get(5).getSign()}
678${data.get(6).getSign()}${data.get(7).getSign()}${data.get(8).getSign()}
- + +

CROSSES WIN!

+ +
+ +

NOUGHTS WIN!

+ +
+ +

IT'S A DRAW

+
+ +
+ + \ No newline at end of file