private string MakeForm(ITicTacToeBoxClass.ITicTacToeBox ticTacToeBox)
        {
            var formPage = new StringBuilder();

            formPage.Append(@"<form action=""/"" method=""post"">");
            formPage.Append(@"<table style=""width: 100 % "">");
            for (var i = 0; i < ticTacToeBox.cellCount(); i += 3)
            {
                formPage.Append("<tr>");
                for (var k = 0; k < ticTacToeBox.victoryCellCount(); k++)
                {
                    formPage.Append(
                        @"<td><button name=box type=""submit"" value=""" +
                        WebUtility.HtmlEncode(ticTacToeBox.getGlyphAtLocation(i + k))
                        + @""">" +
                        $"{WebUtility.HtmlEncode(ticTacToeBox.getGlyphAtLocation(i + k))}" +
                        "</button></td>");
                }
                formPage.Append("</tr>");
            }
            formPage.Append(@"</table>");
            for (var i = 0; i < ticTacToeBox.cellCount(); i++)
            {
                formPage.Append(@"<input type=""hidden"" name=""pos" + i + @""" value=""" +
                                ticTacToeBox.getGlyphAtLocation(i) + @"""><br>");
            }
            formPage.Append(@"</form>");

            return(formPage.ToString());
        }
        private string Form(ITicTacToeBoxClass.ITicTacToeBox ticTacToeBox,
                            TicTacToeGame game, int errorMesageCode, ServerProperties serverProperties)
        {
            var form = MakeForm(ticTacToeBox);

            form = RemoveButton(game.Setting.playerGlyph, form);
            form = RemoveButton(game.Setting.aIGlyph, form);
            var errorMessage = errorMesageCode != Translate.Blank
                ? "<p>" +
                               Translator.translator(Translator.language.english,
                                                     errorMesageCode) + "</p>"
                : "";

            form = errorMessage += form;
            if (!game.CheckForWinner((TicTacToeBoxClass.TicTacToeBox)ticTacToeBox))
            {
                return(form);
            }
            form = "<p>Game Over</p>"
                   + @"<a href=""http://127.0.0.1:"
                   + serverProperties.Port
                   + @"""><button>Another Game?</button></a>"
                   + form;
            for (var i = 0; i < ticTacToeBox.cellCount(); i++)
            {
                form = RemoveButton("-" + (i + 1) + "-", form);
            }
            return(form);
        }
Ejemplo n.º 3
0
        public string SerializeTicTacToeBox
            (ITicTacToeBoxClass.ITicTacToeBox ticTacToeBox)
        {
            var jSonTicTacToeBox = @"{ ""board"" : [";

            for (var i = 0; i < ticTacToeBox.cellCount(); i++)
            {
                jSonTicTacToeBox += "\""
                                    + ticTacToeBox
                                    .getGlyphAtLocation(i)
                                    + "\", ";
            }
            jSonTicTacToeBox = jSonTicTacToeBox
                               .Substring(0, jSonTicTacToeBox.Length - 2)
                               + @"], ""gameOver"" : ""false""}";
            return(jSonTicTacToeBox);
        }