From 6f8fa1a258e573f38e49d5ac53ebde4c20b576b0 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 08:53:21 +1100 Subject: [PATCH 01/26] updated --- Crossword/App/UI/DrawCreditsLabel.cs | 2 +- Crossword/App/UI/DrawCrossword.cs | 4 +- Crossword/App/UI/UpdateCrosswordScore.cs | 21 ++---- Crossword/App/handlers/MouseHandlers.cs | 14 ++-- Crossword/App/hint/GetUserHint.cs | 14 +--- Crossword/App/hint/QuickSolver.cs | 11 ++- Crossword/App/init/InitClueAnswers.cs | 4 +- Crossword/App/init/InitControls.cs | 12 +--- Crossword/App/init/InitData.cs | 20 +----- Crossword/App/init/InitDirtySquares.cs | 20 ++---- Crossword/ClueAnswerMap/CheckHint.cs | 14 +--- Crossword/ClueAnswerMap/CheckWord.cs | 11 +-- Crossword/ClueAnswerMap/HighlightSquares.cs | 26 ++----- Crossword/Constants/GameConstants.cs | 7 +- Crossword/Constants/UIConstants.cs | 4 +- Crossword/Crossword.csproj | 1 - Crossword/EventHandlers/ListBoxHandlers.cs | 75 -------------------- Crossword/FetchData/CallDataApiAsync.cs | 5 -- Crossword/FetchData/GetCrosswordDataAsync.cs | 8 +-- Crossword/Parsers/GetAnswers.cs | 5 -- Crossword/PuzzleSquares/CreateSquare.cs | 4 +- Crossword/PuzzleSquares/SetHighlighted.cs | 2 +- Crossword/PuzzleSquares/SetLetter.cs | 1 + Crossword/PuzzleSquares/Square.cs | 4 +- 24 files changed, 51 insertions(+), 238 deletions(-) delete mode 100644 Crossword/EventHandlers/ListBoxHandlers.cs diff --git a/Crossword/App/UI/DrawCreditsLabel.cs b/Crossword/App/UI/DrawCreditsLabel.cs index 1363df3..dc54c85 100644 --- a/Crossword/App/UI/DrawCreditsLabel.cs +++ b/Crossword/App/UI/DrawCreditsLabel.cs @@ -21,7 +21,7 @@ private void DrawCreditsLabel() _creditsLabel.TextColor = UIConstants.CreditsColor; _creditsLabel.Left = rectCrossWord.Left; _creditsLabel.Font = _fntCredits; - _creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + UIConstants.SquareHeight/2; + _creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + (UIConstants.SquareHeight/2); _mainPanel.Widgets.Add(_creditsLabel); } diff --git a/Crossword/App/UI/DrawCrossword.cs b/Crossword/App/UI/DrawCrossword.cs index d34073b..cb9cead 100644 --- a/Crossword/App/UI/DrawCrossword.cs +++ b/Crossword/App/UI/DrawCrossword.cs @@ -34,8 +34,8 @@ private void DrawCrossword() //Main puzzle squares array //Draw crossword with squares with spaces _puzzleSquares[i, j] = new Rectangle( - sqPuzzleSquares[i, j]!.XCoord + i * ((int)UIConstants.SquareSpacer), - sqPuzzleSquares[i, j]!.YCoord + j * ((int) UIConstants.SquareSpacer), + sqPuzzleSquares[i, j]!.xCoord + i * ((int)UIConstants.SquareSpacer), + sqPuzzleSquares[i, j]!.yCoord + j * ((int) UIConstants.SquareSpacer), UIConstants.SquareWidth, UIConstants.SquareHeight); diff --git a/Crossword/App/UI/UpdateCrosswordScore.cs b/Crossword/App/UI/UpdateCrosswordScore.cs index ac01e89..85781ce 100644 --- a/Crossword/App/UI/UpdateCrosswordScore.cs +++ b/Crossword/App/UI/UpdateCrosswordScore.cs @@ -18,23 +18,16 @@ private void UpdateCrosswordScore() { logger.LogInformation("Start UpdateCrosswordScore()"); - // Parallel.For(0, NumQuestions, i => - // { - // if (caPuzzleClueAnswers[i].IsCorrect()) - // { - // Interlocked.Increment(ref CrosswordScore); - // } - // - // caPuzzleClueAnswers[i].CheckWord(); - // }); - - - for (var i=0;i { - CrosswordScore++; + if (caPuzzleClueAnswers[i].IsCorrect()) + { + Interlocked.Increment(ref CrosswordScore); + } caPuzzleClueAnswers[i].CheckWord(); - } + }); + if (CrosswordScore == NumQuestions) { diff --git a/Crossword/App/handlers/MouseHandlers.cs b/Crossword/App/handlers/MouseHandlers.cs index cf9188d..6b51059 100644 --- a/Crossword/App/handlers/MouseHandlers.cs +++ b/Crossword/App/handlers/MouseHandlers.cs @@ -163,18 +163,12 @@ private int FindClueAnswerIdx(Square? sqSelSquare) var tmpClueAnswer = sqSelSquare?.GetClueAnswerRef(IsAcross); var clueAnswerIdx = 0; - // Parallel.For(0, NumQuestions, (k, loopState) => - // { - // if (tmpClueAnswer == caPuzzleClueAnswers[k]) loopState.Stop(); - // clueAnswerIdx = k; - // loopState.Stop(); - // }); - - for (var k=0;k { - if (tmpClueAnswer == caPuzzleClueAnswers[k]) break; + if (tmpClueAnswer == caPuzzleClueAnswers[k]) loopState.Stop(); clueAnswerIdx = k; - } + loopState.Stop(); + }); return clueAnswerIdx; } diff --git a/Crossword/App/hint/GetUserHint.cs b/Crossword/App/hint/GetUserHint.cs index 9ee925c..82818b4 100644 --- a/Crossword/App/hint/GetUserHint.cs +++ b/Crossword/App/hint/GetUserHint.cs @@ -27,24 +27,14 @@ private void GetHintLetters(int count) _szTmpGetLetters = _szTmpGetLetters[1..]; //loop over hint letters - // Parallel.For(0, NumQuestions, i => - // { - // var bTmpResult = caPuzzleClueAnswers[i].CheckHint(chHintLetter); - // if (bTmpResult) - // { - // hintSupplied = true; - // } - // }); - - for (var i=0;i { var bTmpResult = caPuzzleClueAnswers[i].CheckHint(chHintLetter); if (bTmpResult) { hintSupplied = true; } - } - + }); count++; if (_szGetLetters is not null && count == _szGetLetters.Length) allHintLettersChecked = true; diff --git a/Crossword/App/hint/QuickSolver.cs b/Crossword/App/hint/QuickSolver.cs index 82d0537..fc24c72 100644 --- a/Crossword/App/hint/QuickSolver.cs +++ b/Crossword/App/hint/QuickSolver.cs @@ -38,15 +38,12 @@ public void QuickSolver() //Increment the score if the answer is correct UpdateCrosswordScore(); - for (var i = 0; i < NumQuestions; i++) + // for (var i = 0; i < NumQuestions; i++) + // caPuzzleClueAnswers[i].CheckWord(); + Parallel.For(0, NumQuestions, i => { caPuzzleClueAnswers[i].CheckWord(); - } - - // Parallel.For(0, NumQuestions, i => - // { - // caPuzzleClueAnswers[i].CheckWord(); - // }); + }); //If the crossword score == the number of questions, then it is the end of the game if (CrosswordScore == NumQuestions) diff --git a/Crossword/App/init/InitClueAnswers.cs b/Crossword/App/init/InitClueAnswers.cs index 962fad4..ade95cb 100644 --- a/Crossword/App/init/InitClueAnswers.cs +++ b/Crossword/App/init/InitClueAnswers.cs @@ -34,7 +34,7 @@ private void InitClueAnswers() sqPuzzleSquares[_puzzleDataset[i].CoordDown + j, _puzzleDataset[i].CoordAcross]; if (j == 0) LstClueAcross.Items.Add(new ListItem( - $"{_puzzleDataset[i].QuestionNum}. {_puzzleDataset[i].Clue}", + _puzzleDataset[i].QuestionNum + ". " + _puzzleDataset[i].Clue, Color.White)); } else @@ -43,7 +43,7 @@ private void InitClueAnswers() sqPuzzleSquares[_puzzleDataset[i].CoordDown, _puzzleDataset[i].CoordAcross + j]; if (j == 0) LstClueDown.Items.Add(new ListItem( - $"{_puzzleDataset[i].QuestionNum}. {_puzzleDataset[i].Clue}", + _puzzleDataset[i].QuestionNum + ". " + _puzzleDataset[i].Clue, Color.White)); } } diff --git a/Crossword/App/init/InitControls.cs b/Crossword/App/init/InitControls.cs index 3eae218..4a5fb85 100644 --- a/Crossword/App/init/InitControls.cs +++ b/Crossword/App/init/InitControls.cs @@ -27,17 +27,11 @@ private void InitControls() //Dimension array for crossword data _puzzleDataset = new CrosswordState[NumQuestions]; - // Parallel.For(0, NumQuestions, i => - // { - // _puzzleDataset[i] = new CrosswordState(_rowRef[i], _colRef[i], _szAnswers[i], _szClues[i], _bDataIsAcross[i], - // _quesNum[i]); - // }); - - for (var i=0;i { _puzzleDataset[i] = new CrosswordState(_rowRef[i], _colRef[i], _szAnswers[i], _szClues[i], _bDataIsAcross[i], - _quesNum[i]); - } + _quesNum[i]); + }); // init labels _currentScoreLabel = new Label(); diff --git a/Crossword/App/init/InitData.cs b/Crossword/App/init/InitData.cs index 1336614..fe9352a 100644 --- a/Crossword/App/init/InitData.cs +++ b/Crossword/App/init/InitData.cs @@ -113,23 +113,7 @@ private void InitDataArrays() { logger.LogInformation("Start InitDataArrays()"); - // Parallel.For(0, NumQuestions, i => - // { - // if (_mrParserData?.ColRef is not null) _colRef[i] = _mrParserData.ColRef[i]; - // if (_mrParserData?.RowRef is not null) _rowRef[i] = _mrParserData.RowRef[i]; - // if (_mrParserData?.IsAcross is not null) - // _bDataIsAcross[i] = _mrParserData.IsAcross[i] switch - // { - // 1 => true, - // 2 => false, - // _ => _bDataIsAcross[i] - // }; - // if (_mrParserData?.QuesNum is not null) _quesNum[i] = _mrParserData.QuesNum[i]; - // if (_mrParserData?.Clues is not null) _szClues[i] = _mrParserData.Clues[i]; - // if (_mrParserData?.Answers is not null) _szAnswers[i] = _mrParserData.Answers[i]; - // }); - - for (var i=0;i { if (_mrParserData?.ColRef is not null) _colRef[i] = _mrParserData.ColRef[i]; if (_mrParserData?.RowRef is not null) _rowRef[i] = _mrParserData.RowRef[i]; @@ -143,7 +127,7 @@ private void InitDataArrays() if (_mrParserData?.QuesNum is not null) _quesNum[i] = _mrParserData.QuesNum[i]; if (_mrParserData?.Clues is not null) _szClues[i] = _mrParserData.Clues[i]; if (_mrParserData?.Answers is not null) _szAnswers[i] = _mrParserData.Answers[i]; - } + }); } catch (Exception ex) diff --git a/Crossword/App/init/InitDirtySquares.cs b/Crossword/App/init/InitDirtySquares.cs index c42f6e7..9c45ee1 100644 --- a/Crossword/App/init/InitDirtySquares.cs +++ b/Crossword/App/init/InitDirtySquares.cs @@ -20,25 +20,13 @@ private void InitDirtySquares() logger.LogInformation("Start ForceDirtySquares()"); //Forces dirty squares - //Parallel.For(0, _NumRows, i => - //_logger.LogInformation("Start ForceDirtySquares()"); - - for (var i = 0; i < _NumRows; i++) + Parallel.For(0, _NumRows, i => { - for (var j = 0; j < _NumCols; j++) + Parallel.For(0, _NumCols, j => { sqPuzzleSquares[i, j]!.IsDirty = true; - } - } - - //Forces dirty squares - // Parallel.For(0, _NumRows, i => - // { - // Parallel.For(0, _NumCols, j => - // { - // sqPuzzleSquares[i, j]!.IsDirty = true; - // }); - // }); + }); + }); } catch (Exception ex) { diff --git a/Crossword/ClueAnswerMap/CheckHint.cs b/Crossword/ClueAnswerMap/CheckHint.cs index ecd8cfb..c29c373 100644 --- a/Crossword/ClueAnswerMap/CheckHint.cs +++ b/Crossword/ClueAnswerMap/CheckHint.cs @@ -23,21 +23,13 @@ public bool CheckHint(char hintLetter) var szAnswerLength = Answer.Length; //Parallel for loop - // Parallel.For(0, szAnswerLength, i => - // { - // if (SqAnswerSquares is null || Answer[i] != hintLetter || - // SqAnswerSquares[i]!.Letter == hintLetter) return; - // SqAnswerSquares[i]?.SetLetter(hintLetter, IsAcross); - // foundResult = true; - // }); - - for (var i=0;i { if (SqAnswerSquares is null || Answer[i] != hintLetter || - SqAnswerSquares[i]!.Letter == hintLetter) break; + SqAnswerSquares[i]!.Letter == hintLetter) return; SqAnswerSquares[i]?.SetLetter(hintLetter, IsAcross); foundResult = true; - } + }); return foundResult; } diff --git a/Crossword/ClueAnswerMap/CheckWord.cs b/Crossword/ClueAnswerMap/CheckWord.cs index 9e9c413..bff52ac 100644 --- a/Crossword/ClueAnswerMap/CheckWord.cs +++ b/Crossword/ClueAnswerMap/CheckWord.cs @@ -17,17 +17,10 @@ public void CheckWord() // SqAnswerSquares?[i]?.CheckLetter(Answer[i]); // } - //Parallel.For(0, Answer.Length, i => - for (var i = 0; i < Answer.Length; i++) + Parallel.For(0, Answer.Length, i => { SqAnswerSquares?[i]?.CheckLetter(Answer[i]); - } - - - // Parallel.For(0, Answer.Length, i => - // { - // SqAnswerSquares?[i]?.CheckLetter(Answer[i]); - // }); + }); } #endregion diff --git a/Crossword/ClueAnswerMap/HighlightSquares.cs b/Crossword/ClueAnswerMap/HighlightSquares.cs index 0ef150f..1e3031e 100644 --- a/Crossword/ClueAnswerMap/HighlightSquares.cs +++ b/Crossword/ClueAnswerMap/HighlightSquares.cs @@ -32,34 +32,18 @@ public void HighlightSquares(Square? sq, bool setHighLighted) // } // } - //Parallel.For(0, Answer.Length, i => - for (var i = 0; i < Answer.Length; i++) + Parallel.For(0, Answer.Length, i => { if (!setHighLighted) SqAnswerSquares?[i]?.SetHighlighted(UIConstants.CurrentNone); else { SqAnswerSquares?[i] - ?.SetHighlighted(SqAnswerSquares?[i] == sq - ? UIConstants.CurrentLetter - : UIConstants.CurrentWord); + ?.SetHighlighted(SqAnswerSquares?[i] == sq + ? UIConstants.CurrentLetter + : UIConstants.CurrentWord); } - } - - - - // Parallel.For(0, Answer.Length, i => - // { - // if (!setHighLighted) - // SqAnswerSquares?[i]?.SetHighlighted(UIConstants.CurrentNone); - // else - // { - // SqAnswerSquares?[i] - // ?.SetHighlighted(SqAnswerSquares?[i] == sq - // ? UIConstants.CurrentLetter - // : UIConstants.CurrentWord); - // } - // }); + }); } #endregion diff --git a/Crossword/Constants/GameConstants.cs b/Crossword/Constants/GameConstants.cs index 4dcf222..808bee3 100644 --- a/Crossword/Constants/GameConstants.cs +++ b/Crossword/Constants/GameConstants.cs @@ -30,12 +30,7 @@ public sealed class GameConstants "Dedicated to Neil Reading (neilski) RIP."; //game title string - public const string GameTitle = "CyberPuzzles Crossword v1.0.2" + - "Original Authors: Bryan Richards & Aaron Saikovski\n" + - "Original date: 24th March 1997\n" + - "Description: A Monogame and .Net 8 Core port of the original OzEmail Cyberpuzzles Java based crossword Applet.\n" + - "Dedicated to Neil Reading (neilski) RIP."; - + public const string GameTitle = "CyberPuzzles Crossword v1.0.2"; } diff --git a/Crossword/Constants/UIConstants.cs b/Crossword/Constants/UIConstants.cs index d4cccd9..e363e17 100644 --- a/Crossword/Constants/UIConstants.cs +++ b/Crossword/Constants/UIConstants.cs @@ -79,8 +79,8 @@ public sealed class UIConstants public static Color CreditsColor = Color.Black; //Button colours - //public static Color ButtonTextColor = Color.White; - //public static Color ButtonHoverTextColor = Color.Yellow; + public static Color ButtonTextColor = Color.White; + public static Color ButtonHoverTextColor = Color.Yellow; //Listbox text colors diff --git a/Crossword/Crossword.csproj b/Crossword/Crossword.csproj index 02c40cc..b74c5e9 100644 --- a/Crossword/Crossword.csproj +++ b/Crossword/Crossword.csproj @@ -66,7 +66,6 @@ - diff --git a/Crossword/EventHandlers/ListBoxHandlers.cs b/Crossword/EventHandlers/ListBoxHandlers.cs deleted file mode 100644 index b2cad6e..0000000 --- a/Crossword/EventHandlers/ListBoxHandlers.cs +++ /dev/null @@ -1,75 +0,0 @@ - -namespace Crossword.EventHandlers; - -public sealed partial class CrosswordMain -{ - #region SelChangeListClueAcross - - // Event handler for the Across listbox - // private void SelChangeListClueAcross(object sender, EventArgs args) - // { - // try - // { - // SqCurrentSquare.GetClueAnswerRef(IsAcross)?.HighlightSquares(SqCurrentSquare, false); - // - // if (LstClueAcross.SelectedIndex is not null) - // { - // if (!IsAcross) - // { - // IsAcross = true; - // LstClueDown.SelectedIndex = -1; - // } - // SqCurrentSquare = caPuzzleClueAnswers[(int)LstClueAcross.SelectedIndex].GetSquare(); - // caPuzzleClueAnswers[(int)LstClueAcross.SelectedIndex].HighlightSquares(SqCurrentSquare, true); - // } - // } - // catch (Exception e) - // { - // - // //Catch the exception - // Console.WriteLine($"Exception {e} occurred in method SelChangeListClueAcross"); - // } - // - // } - - #endregion - - #region SelChangeListClueDown - - //Event handler for the Down listbox - // private void SelChangeListClueDown(object sender, EventArgs args) - // { - // try - // { - // //causing an exception - // //sqCurrentSquare.getClueAnswerRef(bIsAcross).HighlightSquares(sqCurrentSquare, false); - // - // if (LstClueDown.SelectedIndex is not null) - // { - // SqCurrentSquare.GetClueAnswerRef(IsAcross)?.HighlightSquares(SqCurrentSquare, false); - // - // if (IsAcross) - // { - // IsAcross = false; - // LstClueAcross.SelectedIndex = -1; - // } - // - // SqCurrentSquare = caPuzzleClueAnswers[LstClueAcross.Items.Count + (int)LstClueDown.SelectedIndex] - // .GetSquare(); - // caPuzzleClueAnswers[LstClueAcross.Items.Count + (int)LstClueDown.SelectedIndex] - // .HighlightSquares(SqCurrentSquare, true); - // } - // } - // catch (Exception e) - // { - // - // //Catch the exception - // Console.WriteLine($"Exception {e} occurred in method SelChangeListClueDown"); - // } - // - // - // } - - #endregion - -} \ No newline at end of file diff --git a/Crossword/FetchData/CallDataApiAsync.cs b/Crossword/FetchData/CallDataApiAsync.cs index f444370..71f6356 100644 --- a/Crossword/FetchData/CallDataApiAsync.cs +++ b/Crossword/FetchData/CallDataApiAsync.cs @@ -4,7 +4,6 @@ using Crossword.Shared.Config; using Crossword.Shared.Logger; using Crossword.Shared.Constants; - namespace Crossword.FetchData; /// @@ -36,7 +35,6 @@ public partial class FetchCrosswordData //pass in the API key to the header client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Add(ApiConstants.ApiKeyName, apiKey); - //client.DefaultRequestHeaders.Add(APIConstants.ApiKeyName, apiKey); //catch inner HttpRequestException try @@ -52,8 +50,6 @@ public partial class FetchCrosswordData else { throw new Exception($"Failed to call the API. Status code: {response.StatusCode}"); - //Console.WriteLine($"Failed to call the API. Status code: {response.StatusCode}"); - return string.Empty; } } @@ -64,7 +60,6 @@ public partial class FetchCrosswordData throw; } } - catch (Exception ex) { logger.LogError(ex, ex.Message); diff --git a/Crossword/FetchData/GetCrosswordDataAsync.cs b/Crossword/FetchData/GetCrosswordDataAsync.cs index 3e6491e..78d6426 100644 --- a/Crossword/FetchData/GetCrosswordDataAsync.cs +++ b/Crossword/FetchData/GetCrosswordDataAsync.cs @@ -25,11 +25,6 @@ public partial class FetchCrosswordData { logger.LogInformation("Start GetCrosswordDataAsync()"); - // //Call the API to get the puzzledata....otherwise use default values - // try - // { - //logger.LogInformation("Start GetCrosswordDataAsync()"); - //call the API var apiResponse = await CallDataApiAsync(); @@ -43,8 +38,7 @@ public partial class FetchCrosswordData } finally { - - logger.Dispose(); + logger.Dispose(); } } diff --git a/Crossword/Parsers/GetAnswers.cs b/Crossword/Parsers/GetAnswers.cs index 5e59e9f..053c766 100644 --- a/Crossword/Parsers/GetAnswers.cs +++ b/Crossword/Parsers/GetAnswers.cs @@ -13,12 +13,7 @@ private void GetAnswers(IReadOnlyList strData) { var puzzletempstr = strData[5]; var answertemp = puzzletempstr.Split("#"); - //string[] answertemp; - - // var puzzletempstr = strData[5]; - // answertemp = puzzletempstr.Split("#"); if (_crosswordData == null) return; - _crosswordData.Answers = new string[_crosswordData.NumQuestions]; for (var k = 0; k < _crosswordData.NumQuestions; k++) { diff --git a/Crossword/PuzzleSquares/CreateSquare.cs b/Crossword/PuzzleSquares/CreateSquare.cs index e4a3e38..54b5d0a 100644 --- a/Crossword/PuzzleSquares/CreateSquare.cs +++ b/Crossword/PuzzleSquares/CreateSquare.cs @@ -11,8 +11,8 @@ public sealed partial class Square /// public void CreateSquare(int xCoord, int yCoord) { - this.XCoord = xCoord; - this.YCoord = yCoord; + this.xCoord = xCoord; + this.yCoord = yCoord; } #endregion diff --git a/Crossword/PuzzleSquares/SetHighlighted.cs b/Crossword/PuzzleSquares/SetHighlighted.cs index afb623a..ac11b41 100644 --- a/Crossword/PuzzleSquares/SetHighlighted.cs +++ b/Crossword/PuzzleSquares/SetHighlighted.cs @@ -42,7 +42,7 @@ public void SetHighlighted(int highlightType) default: //Something went wrong.... if (BackColour.Equals(UIConstants.SquareHighlightErr)) { - //Console.WriteLine($"Bogus color: {highlightType}"); + Console.WriteLine($"Bogus color: {highlightType}"); BackColour = UIConstants.SquareHighlightErr; IsDirty = true; } diff --git a/Crossword/PuzzleSquares/SetLetter.cs b/Crossword/PuzzleSquares/SetLetter.cs index 0c33700..7c32709 100644 --- a/Crossword/PuzzleSquares/SetLetter.cs +++ b/Crossword/PuzzleSquares/SetLetter.cs @@ -17,5 +17,6 @@ public void SetLetter(char letter, bool isAcross) IsDirty = true; ForeColour = UIConstants.SquareHighlightDefault; } + #endregion } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/Square.cs b/Crossword/PuzzleSquares/Square.cs index 5169903..6423547 100644 --- a/Crossword/PuzzleSquares/Square.cs +++ b/Crossword/PuzzleSquares/Square.cs @@ -18,8 +18,8 @@ public sealed partial class Square { #region getters_setters - public int XCoord { get; set; } - public int YCoord { get; set; } + public int xCoord { get; set; } + public int yCoord { get; set; } public char Letter { get; set; } From 43db78938d143fdb111e2259fa239d8b0386b0bf Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 08:55:13 +1100 Subject: [PATCH 02/26] updated solution name --- .idea/.idea.CyberPuzzles/.idea/.gitignore | 13 ------------- .idea/.idea.CyberPuzzles/.idea/encodings.xml | 4 ---- .idea/.idea.CyberPuzzles/.idea/indexLayout.xml | 10 ---------- .idea/.idea.CyberPuzzles/.idea/vcs.xml | 6 ------ CyberPuzzles.sln => Crossword.Net.sln | 0 5 files changed, 33 deletions(-) delete mode 100644 .idea/.idea.CyberPuzzles/.idea/.gitignore delete mode 100644 .idea/.idea.CyberPuzzles/.idea/encodings.xml delete mode 100644 .idea/.idea.CyberPuzzles/.idea/indexLayout.xml delete mode 100644 .idea/.idea.CyberPuzzles/.idea/vcs.xml rename CyberPuzzles.sln => Crossword.Net.sln (100%) diff --git a/.idea/.idea.CyberPuzzles/.idea/.gitignore b/.idea/.idea.CyberPuzzles/.idea/.gitignore deleted file mode 100644 index 39ae96d..0000000 --- a/.idea/.idea.CyberPuzzles/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/contentModel.xml -/projectSettingsUpdater.xml -/.idea.CyberPuzzles.iml -/modules.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/.idea.CyberPuzzles/.idea/encodings.xml b/.idea/.idea.CyberPuzzles/.idea/encodings.xml deleted file mode 100644 index df87cf9..0000000 --- a/.idea/.idea.CyberPuzzles/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/.idea.CyberPuzzles/.idea/indexLayout.xml b/.idea/.idea.CyberPuzzles/.idea/indexLayout.xml deleted file mode 100644 index c53fc5c..0000000 --- a/.idea/.idea.CyberPuzzles/.idea/indexLayout.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - datafiles - - - - - \ No newline at end of file diff --git a/.idea/.idea.CyberPuzzles/.idea/vcs.xml b/.idea/.idea.CyberPuzzles/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/.idea.CyberPuzzles/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CyberPuzzles.sln b/Crossword.Net.sln similarity index 100% rename from CyberPuzzles.sln rename to Crossword.Net.sln From 03869e7b10740f6f664a8d1d9ba699e89f4bdf33 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 09:00:51 +1100 Subject: [PATCH 03/26] added parser and entities project --- .../Crosssword.Entities.csproj | 9 ++ Crosssword.Entities/CrosswordData.cs | 43 ++++++++++ Crosssword.Entities/CrosswordState.cs | 27 ++++++ Crossword.Net.sln | 12 +++ Crossword.Parser/Crossword.Parser.csproj | 14 ++++ Crossword.Parser/GetAnswers.cs | 24 ++++++ Crossword.Parser/GetBlurb.cs | 15 ++++ Crossword.Parser/GetClues.cs | 32 ++++++++ Crossword.Parser/GetColsAndRows.cs | 18 ++++ Crossword.Parser/GetCybersilver.cs | 21 +++++ Crossword.Parser/GetGridPositions.cs | 52 ++++++++++++ Crossword.Parser/GetHintLetters.cs | 15 ++++ Crossword.Parser/GetNumBytes.cs | 15 ++++ Crossword.Parser/GetPuzzleIdAndType.cs | 18 ++++ Crossword.Parser/ParseCrosswordData.cs | 82 +++++++++++++++++++ 15 files changed, 397 insertions(+) create mode 100644 Crosssword.Entities/Crosssword.Entities.csproj create mode 100644 Crosssword.Entities/CrosswordData.cs create mode 100644 Crosssword.Entities/CrosswordState.cs create mode 100644 Crossword.Parser/Crossword.Parser.csproj create mode 100644 Crossword.Parser/GetAnswers.cs create mode 100644 Crossword.Parser/GetBlurb.cs create mode 100644 Crossword.Parser/GetClues.cs create mode 100644 Crossword.Parser/GetColsAndRows.cs create mode 100644 Crossword.Parser/GetCybersilver.cs create mode 100644 Crossword.Parser/GetGridPositions.cs create mode 100644 Crossword.Parser/GetHintLetters.cs create mode 100644 Crossword.Parser/GetNumBytes.cs create mode 100644 Crossword.Parser/GetPuzzleIdAndType.cs create mode 100644 Crossword.Parser/ParseCrosswordData.cs diff --git a/Crosssword.Entities/Crosssword.Entities.csproj b/Crosssword.Entities/Crosssword.Entities.csproj new file mode 100644 index 0000000..3a63532 --- /dev/null +++ b/Crosssword.Entities/Crosssword.Entities.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/Crosssword.Entities/CrosswordData.cs b/Crosssword.Entities/CrosswordData.cs new file mode 100644 index 0000000..9424248 --- /dev/null +++ b/Crosssword.Entities/CrosswordData.cs @@ -0,0 +1,43 @@ +////////////////////////////////////////////////////////////////////////////// +// // +// Module: CrosswordData.cs // +// Authors: Aaron Saikovski & Bryan Richards // +// Date: 23/01/97 // +// Version: 1.0 // +// Purpose: Utilizes a String Tokenizer to parse the crossword // +// puzzle components from a data set string. // +// // +////////////////////////////////////////////////////////////////////////////// + + +namespace Crossword.Entities; + +public sealed class CrosswordData +{ + #region Fields + + //Instance variables for holding parsed QuickCrossword data + public string? PuzzleType { get; set; } + public int NumCols { get; set; } + public int NumRows { get; set; } + public int NumAcross { get; set; } + public int NumDown { get; set; } + public int PuzzleId { get; set; } + public int[]? ColRef { get; set; } + public int[]? RowRef { get; set; } + public int[]? IsAcross { get; set; } + public int[]? QuesNum { get; set; } + public string[]? Clues { get; set; } + public string[]? Answers { get; set; } + + public int[]? Costs { get; set; } + + public string? GetLetters { get; set; } + public string? Blurb { get; set; } + public int NumQuestions { get; set; } + + public int NumBytes { get; set; } + + #endregion + +} \ No newline at end of file diff --git a/Crosssword.Entities/CrosswordState.cs b/Crosssword.Entities/CrosswordState.cs new file mode 100644 index 0000000..206e638 --- /dev/null +++ b/Crosssword.Entities/CrosswordState.cs @@ -0,0 +1,27 @@ +namespace Crossword.Entities; + +/// +/// CrosswordMain dataset to map clues to answers. +/// +/// +/// constructor +/// +/// +/// +/// +/// +/// +/// +public sealed class CrosswordState(int coordAcross, int coordDown, string answer, string clue, bool isAcross, int questionNum) +{ + #region getters_setters + + public int CoordAcross { get;} = coordAcross; + public int CoordDown { get; } = coordDown; + public string Answer { get; } = answer; + public string Clue { get; } = clue; + public bool IsAcross { get; } = isAcross; + public int QuestionNum { get; } = questionNum; + + #endregion +} \ No newline at end of file diff --git a/Crossword.Net.sln b/Crossword.Net.sln index 944e235..3004560 100644 --- a/Crossword.Net.sln +++ b/Crossword.Net.sln @@ -6,6 +6,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword", "Crossword\Cros EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Shared", "Crossword.Shared\Crossword.Shared.csproj", "{8061C3BE-083E-415C-B678-394F8EBCCFC6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Parser", "Crossword.Parser\Crossword.Parser.csproj", "{2FE9007A-7C46-48AD-86A5-FCADA1AA2D34}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crosssword.Entities", "Crosssword.Entities\Crosssword.Entities.csproj", "{629F5D51-C8E0-4C64-BE84-48C5DB565FA8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +28,13 @@ Global {8061C3BE-083E-415C-B678-394F8EBCCFC6}.Debug|Any CPU.Build.0 = Debug|Any CPU {8061C3BE-083E-415C-B678-394F8EBCCFC6}.Release|Any CPU.ActiveCfg = Release|Any CPU {8061C3BE-083E-415C-B678-394F8EBCCFC6}.Release|Any CPU.Build.0 = Release|Any CPU + {2FE9007A-7C46-48AD-86A5-FCADA1AA2D34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2FE9007A-7C46-48AD-86A5-FCADA1AA2D34}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2FE9007A-7C46-48AD-86A5-FCADA1AA2D34}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2FE9007A-7C46-48AD-86A5-FCADA1AA2D34}.Release|Any CPU.Build.0 = Release|Any CPU + {629F5D51-C8E0-4C64-BE84-48C5DB565FA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {629F5D51-C8E0-4C64-BE84-48C5DB565FA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {629F5D51-C8E0-4C64-BE84-48C5DB565FA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {629F5D51-C8E0-4C64-BE84-48C5DB565FA8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Crossword.Parser/Crossword.Parser.csproj b/Crossword.Parser/Crossword.Parser.csproj new file mode 100644 index 0000000..4ccddcc --- /dev/null +++ b/Crossword.Parser/Crossword.Parser.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/Crossword.Parser/GetAnswers.cs b/Crossword.Parser/GetAnswers.cs new file mode 100644 index 0000000..06cd402 --- /dev/null +++ b/Crossword.Parser/GetAnswers.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; + +namespace Crossword.Parser; + +public sealed partial class CrosswordParser +{ + #region + /// + /// GetAnswers + /// + /// + private void GetAnswers(IReadOnlyList strData) + { + var puzzletempstr = strData[5]; + var answertemp = puzzletempstr.Split("#"); + if (_crosswordData == null) return; + _crosswordData.Answers = new string[_crosswordData.NumQuestions]; + for (var k = 0; k < _crosswordData.NumQuestions; k++) + { + _crosswordData.Answers[k] = answertemp[k]; + } + } + #endregion +} \ No newline at end of file diff --git a/Crossword.Parser/GetBlurb.cs b/Crossword.Parser/GetBlurb.cs new file mode 100644 index 0000000..227fd0d --- /dev/null +++ b/Crossword.Parser/GetBlurb.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace Crossword.Parser; + +public sealed partial class CrosswordParser +{ + /// + /// GetBlurb + /// + /// + private void GetBlurb(IReadOnlyList strData) + { + if (_crosswordData != null) _crosswordData.Blurb = strData[8]; + } +} \ No newline at end of file diff --git a/Crossword.Parser/GetClues.cs b/Crossword.Parser/GetClues.cs new file mode 100644 index 0000000..7a46ada --- /dev/null +++ b/Crossword.Parser/GetClues.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; + +namespace Crossword.Parser; + +public sealed partial class CrosswordParser +{ + /// + /// GetClues + /// + /// + private void GetClues(IReadOnlyList strData) + { + var puzzletempstr = strData[4]; + string[] cluetemp = puzzletempstr.Split("#"); + if (_crosswordData == null) return; + _crosswordData.Clues = new string[_crosswordData.NumQuestions]; + for (var j = 0; j < _crosswordData.NumQuestions; j++) + { + _crosswordData.Clues[j] = cluetemp[j]; + } + + // string[] cluetemp; + // var puzzletempstr = strData[4]; + // cluetemp = puzzletempstr.Split("#"); + // if (_crosswordData == null) return; + // _crosswordData.Clues = new string[_crosswordData.NumQuestions]; + // for (var j = 0; j < _crosswordData.NumQuestions; j++) + // { + // _crosswordData.Clues[j] = cluetemp[j]; + // } + } +} \ No newline at end of file diff --git a/Crossword.Parser/GetColsAndRows.cs b/Crossword.Parser/GetColsAndRows.cs new file mode 100644 index 0000000..5b56406 --- /dev/null +++ b/Crossword.Parser/GetColsAndRows.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Crossword.Parser; + +public sealed partial class CrosswordParser +{ + /// + /// GetColsAndRows + /// + /// + private void GetColsAndRows(IReadOnlyList strData) + { + var puzzleTempStr = strData[2]; + if (_crosswordData == null) return; + _crosswordData.NumCols = int.Parse(puzzleTempStr[..2]); + _crosswordData.NumRows = int.Parse(puzzleTempStr[2..]); + } +} \ No newline at end of file diff --git a/Crossword.Parser/GetCybersilver.cs b/Crossword.Parser/GetCybersilver.cs new file mode 100644 index 0000000..5fbebb6 --- /dev/null +++ b/Crossword.Parser/GetCybersilver.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; + +namespace Crossword.Parser; + +public sealed partial class CrosswordParser +{ + /// + /// GetCybersilver + /// + /// + private void GetCybersilver(IReadOnlyList strData) + { + var puzzletempstr = strData[7]; + var costTemp = puzzletempstr.Split(" "); + + for (var loopIdx = 0; loopIdx < 6; loopIdx++) + { + if (_crosswordData is { Costs: not null }) _crosswordData.Costs[loopIdx] = int.Parse(costTemp[loopIdx]); + } + } +} \ No newline at end of file diff --git a/Crossword.Parser/GetGridPositions.cs b/Crossword.Parser/GetGridPositions.cs new file mode 100644 index 0000000..b4ab262 --- /dev/null +++ b/Crossword.Parser/GetGridPositions.cs @@ -0,0 +1,52 @@ + + +using System.Collections.Generic; +using Crossword.Shared.ParserUtils; + +namespace Crossword.Parser; + +public sealed partial class CrosswordParser +{ + /// + /// GetGridPositions + /// + /// + private void GetGridPositions(IReadOnlyList strData) + { + var puzzleTempStr = strData[3]; + if (_crosswordData == null) return; + _crosswordData.NumQuestions = ParserHelper.CountOccurrences(puzzleTempStr, '#'); + _crosswordData.ColRef = new int[_crosswordData.NumQuestions]; + _crosswordData.RowRef = new int[_crosswordData.NumQuestions]; + _crosswordData.IsAcross = new int[_crosswordData.NumQuestions]; + _crosswordData.QuesNum = new int[_crosswordData.NumQuestions]; + + //split string + var gridPosTmp = puzzleTempStr.Split('#'); + + for (var tokIdx = 0; tokIdx < _crosswordData.NumQuestions; tokIdx++) + { + var subGridDataTemp = gridPosTmp[tokIdx].Split(" "); + + for (var i = 0; i < 4; i++) + { + switch (i) + { + case 0: + _crosswordData.ColRef[tokIdx] = int.Parse(subGridDataTemp[0]); + break; + + case 1: + _crosswordData.RowRef[tokIdx] = int.Parse(subGridDataTemp[1]); + break; + case 2: + _crosswordData.IsAcross[tokIdx] = int.Parse(subGridDataTemp[2]); + break; + case 3: + _crosswordData.QuesNum[tokIdx] = int.Parse(subGridDataTemp[3]); + break; + } + } + } + } +} \ No newline at end of file diff --git a/Crossword.Parser/GetHintLetters.cs b/Crossword.Parser/GetHintLetters.cs new file mode 100644 index 0000000..406f1ca --- /dev/null +++ b/Crossword.Parser/GetHintLetters.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace Crossword.Parser; + +public sealed partial class CrosswordParser +{ + /// + /// GetHintLetters + /// + /// + private void GetHintLetters(IReadOnlyList strData) + { + if (_crosswordData != null) _crosswordData.GetLetters = strData[6]; + } +} \ No newline at end of file diff --git a/Crossword.Parser/GetNumBytes.cs b/Crossword.Parser/GetNumBytes.cs new file mode 100644 index 0000000..30d8041 --- /dev/null +++ b/Crossword.Parser/GetNumBytes.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace Crossword.Parser; + +public sealed partial class CrosswordParser +{ + /// + /// GetNumBytes + /// + /// + private void GetNumBytes(IReadOnlyList strData) + { + if (_crosswordData != null) _crosswordData.NumBytes = int.Parse(strData[0]); + } +} \ No newline at end of file diff --git a/Crossword.Parser/GetPuzzleIdAndType.cs b/Crossword.Parser/GetPuzzleIdAndType.cs new file mode 100644 index 0000000..b6c7b65 --- /dev/null +++ b/Crossword.Parser/GetPuzzleIdAndType.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Crossword.Parser; + +public sealed partial class CrosswordParser +{ + /// + /// GetPuzzleIdAndType + /// + /// + private void GetPuzzleIdAndType(IReadOnlyList strData) + { + var puzzletempstr = strData[1]; + if (_crosswordData == null) return; + _crosswordData.PuzzleId = int.Parse(puzzletempstr[2..]); + _crosswordData.PuzzleType = puzzletempstr[..2]; + } +} \ No newline at end of file diff --git a/Crossword.Parser/ParseCrosswordData.cs b/Crossword.Parser/ParseCrosswordData.cs new file mode 100644 index 0000000..daa4615 --- /dev/null +++ b/Crossword.Parser/ParseCrosswordData.cs @@ -0,0 +1,82 @@ +using System; +using Crossword.Entities; +namespace Crossword.Parser; + +public sealed partial class CrosswordParser +{ + //init the crossword data class + private CrosswordData? _crosswordData; + + /// + /// // Main - used to parse QuickCrossword data set from string + /// // Pre : szParseData is NOT null + /// // Post : Returns true if data has been successfully parsed from String and false otherwise + /// + /// + /// + public CrosswordData? ParsePuzzleData(string puzzleData) + { + ArgumentNullException.ThrowIfNull(puzzleData); + + //init the CrosswordData object + _crosswordData = new CrosswordData(); + + //local vars + var strData = puzzleData.Split("*"); + + //Loop over for each of the tokens + for (var tokenIdx = 0; tokenIdx < strData.Length; tokenIdx++) + { + switch (tokenIdx) + { + //Eat the first String - number of bytes in data set - eg. "1075" + case 0: + GetNumBytes(strData); + break; + + //Puzzle ID - eg. "QXW000000" + case 1: + GetPuzzleIdAndType(strData); + break; + + //Number of Columns and Rows - eg. "0909" + case 2: + GetColsAndRows(strData); + break; + + //Grid positions and Data for across and down numbers - eg. "0 0 1 1#6 0 1 4#3 2 1 6#0 3 1 8#3 5 1 11#0 6 1 13#0 8 1 15#4 8 1 16#1 0 2 2#4 0 2 3#6 0 2 4#8 0 2 5#3 2 2 6#5 2 2 7#7 4 2 9#0 5 2 10#4 5 2 12#2 6 2 14" + case 3: + GetGridPositions(strData); + break; + + //Clues - eg. "Bread maker#Skill#Receive#Calm#Real#Taunts#Apple _ _ _#Midday meal#Irritate#Wealthy#Queen,King,__ __ __#Ballet skirt#Book of maps#100 make a dollar#Conjuring#Cease#Prison room#Length of life" + case 4: + GetClues(strData); + break; + + //Answers - eg BAKER#ART#ACCEPT#SOOTHE#ACTUAL#TEASES#PIE#LUNCH#ANNOY#RICH#ACE#TUTU#ATLAS#CENTS#MAGIC#STOP#CELL#AGE + case 5: + GetAnswers(strData); + break; + + //Hint letters - eg "ABCEGHIKLMNOPRSTUY" + case 6: + GetHintLetters(strData); + break; + + //CyberSilver level costs & bonuses - eg. "30 1 1 0 1 5" + case 7: + GetCybersilver(strData); + break; + + //Jim's crappy blurb - eg. "Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!" + case 8: + GetBlurb(strData); + break; + } + } + + //return the crossword data object + return _crosswordData; + } +} \ No newline at end of file From e0497acd61fcf15286886a8fb4a4233698bf132d Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 09:04:37 +1100 Subject: [PATCH 04/26] updated constants --- .../src/Constants/GameConstants.cs | 37 ++++ Crossword.Shared/src/Constants/UIConstants.cs | 99 +++++++++ Crossword/App/UI/DrawCreditsLabel.cs | 2 +- Crossword/App/UI/DrawCrossword.cs | 2 +- Crossword/App/UI/DrawCrosswordScore.cs | 2 +- Crossword/App/UI/DrawGetNextPuzzleButton.cs | 2 +- Crossword/App/UI/DrawHintButton.cs | 2 +- Crossword/App/UI/LoadAssets.cs | 2 +- Crossword/App/handlers/MouseHandlers.cs | 2 +- Crossword/App/init/InitArrays.cs | 2 +- Crossword/App/init/InitData.cs | 2 +- Crossword/App/init/InitListBoxes.cs | 2 +- Crossword/App/main/CrosswordMain.cs | 2 +- Crossword/App/monogame/Monogame.cs | 2 +- Crossword/ClueAnswerMap/HighlightSquares.cs | 2 +- Crossword/Constants/GameConstants.cs | 74 +++---- Crossword/Constants/UIConstants.cs | 198 +++++++++--------- Crossword/FetchData/GetCrosswordDataAsync.cs | 2 +- Crossword/PuzzleSquares/CheckLetter.cs | 2 +- Crossword/PuzzleSquares/SetHighlighted.cs | 2 +- Crossword/PuzzleSquares/SetLetter.cs | 2 +- Crossword/PuzzleSquares/SetObjectRef.cs | 2 +- 22 files changed, 290 insertions(+), 154 deletions(-) create mode 100644 Crossword.Shared/src/Constants/GameConstants.cs create mode 100644 Crossword.Shared/src/Constants/UIConstants.cs diff --git a/Crossword.Shared/src/Constants/GameConstants.cs b/Crossword.Shared/src/Constants/GameConstants.cs new file mode 100644 index 0000000..69d29db --- /dev/null +++ b/Crossword.Shared/src/Constants/GameConstants.cs @@ -0,0 +1,37 @@ + +//////////////////////////////////////////////////////////////////////////// +// // +// Module: GameConstants.cs // +// Authors: Aaron Saikovski // +// Date: 31/10/202 // +// Version: 1.0 // +// Purpose: Global constants. // +// // +//////////////////////////////////////////////////////////////////////////// + + +namespace Crossword.Shared.Constants; + +/// +/// Game Constants +/// +public sealed class GameConstants +{ + //default puzzledata for testing + //public const string DefaultPuzzleData = "505*JX000000*0707*0 0 1 1#0 2 1 4#0 3 1 7#4 3 1 8#1 4 1 10#0 6 1 11#0 0 2 1#2 0 2 2#5 0 2 3#1 2 2 5#4 2 2 6#6 3 2 9*Try#Writing surface#Night bird#Truck#Opposite of male#Nearest#Car#Piece of furniture#Part of a flower#Terrible#Avoid#Unscramble XNET*ATTEMPT#TABLET#OWL#VAN#FEMALE#CLOSEST#AUTO#TABLE#PETAL#AWFUL#EVADE#NEXT*ABCDEFLMNOPSTUVWX*30 1 1 0 1 5*Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!"; + public const string? DefaultPuzzleData = "761*QX000001*0909*0 0 1 1#4 1 1 6#0 2 1 7#2 3 1 9#0 5 1 11#4 6 1 16#0 7 1 17#4 8 1 18#0 0 2 1#2 0 2 2#4 0 2 3#6 0 2 4#8 0 2 5#3 2 2 8#5 3 2 10#0 5 2 11#2 5 2 12#4 5 2 13#6 5 2 14#8 5 2 15*Forward#Strictly accurate#Australian marsupial#Moving to avoid#Not accepted conduct#Astonish greatly#Provide meals#Occurrence#Pretend#Public way#Beer froth#Full-length dress#Adult male deer#Crazy#Metric unit of mass#Skin irritation#Friend#Uncommon#Inland body of water#Bench*FORTH#EXACT#KOALA#DODGING#IMMORAL#AMAZE#CATER#EVENT#FAKE#ROAD#HEAD#MAXI#STAG#LOCO#GRAM#ITCH#MATE#RARE#LAKE#SEAT*ZCDEFGHIKLMNORSTVXA*30 1 1 0 1 5*Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!"; + + + //Credits string + public const string? CreditsText = "**CREDITS**\n" + + "Original Authors: Bryan Richards & Aaron Saikovski\n" + + "Original date: 24th March 1997\n" + + "Description: A Monogame and .Net 8 Core port of the original OzEmail Cyberpuzzles Java based crossword Applet.\n" + + "Dedicated to Neil Reading (neilski) RIP."; + + //game title string + public const string GameTitle = "CyberPuzzles Crossword v1.0.2"; +} + + + diff --git a/Crossword.Shared/src/Constants/UIConstants.cs b/Crossword.Shared/src/Constants/UIConstants.cs new file mode 100644 index 0000000..1559fde --- /dev/null +++ b/Crossword.Shared/src/Constants/UIConstants.cs @@ -0,0 +1,99 @@ + + +using Color = Microsoft.Xna.Framework.Color; + +namespace Crossword.Shared.Constants; + +/// +/// UI Constants +/// +public sealed class UIConstants +{ + + //Crossword dimension constants + public const int CrosswordWindowHeight = 600; + public const int CrosswordWindowWidth = 800; + + //Square width and height constants + public const int SquareWidth = 40; + public const int SquareHeight = 40; + public const float SquareSpacer = 1.5f; + + //Highlight Constants + public const int CurrentLetter = 1; + public const int CurrentWord = 2; + public const int CurrentNone = 3; + + + //Font sizes + public const int FntSml = 9; + public const int FntMed = 15; + public const int FntLge = 20; + public const int FntCredits = 13; + + + + //main game offsets + public const int MainOffsetX = 30; + public const int MainOffsetY = 30; + + + //Small number offset + public const float SmlNumOffsetX = 1.8f; + public const float SmlNumOffsetY = 1.7f; + + + //Square char offset + public const float SqCharOffsetX = 12.5f; + public const float SqCharOffsetY = 12f; + + //ClueList offsets/sizes + public const int ClLabelHeight = 20; + public const int ClListboxHeight = 180; + public const int ClListSpacer = 5; + + //Colors for square letters + public static Color SqCorrect = Color.Green; + public static Color SqError = Color.Black; + + //Puzzle tile images + public const string BlackSquare = "images/tile_black"; + public const string HighliteSquare = "images/tile_yellow"; + public const string SquareWord = "images/tile_orange"; + public const string NormalSquare = "images/tile_grey"; + + //Link Buttons + public const string HintButtonImage = "images/btn_get_hint"; + public const string NextPuzzleButtonImage = "images/btn_next_puzzle"; + + + //Fonts + public const string HelveticaBold = "content/fonts/Helvetica-Bold.ttf"; + public const string HelveticaPlain = "content/fonts/Helvetica.ttf"; + + + //Score color + public static Color ScoreColor = Color.Red; + + //Credits Colo + public static Color CreditsColor = Color.Black; + + //Button colours + public static Color ButtonTextColor = Color.White; + public static Color ButtonHoverTextColor = Color.Yellow; + + + //Listbox text colors + public static Color ListBoxTextColor = Color.Black; + + //Square highlight colors + public static Color SquareHighlightCurrent = Color.Cyan; + public static Color SquareHighlightWord = Color.Yellow; + public static Color SquareHighlightNone = Color.White; + public static Color SquareHighlightErr = Color.Red; + public static Color SquareHighlightDefault = Color.Black; + + //Font colors + public static Color SmallFontColor = Color.Black; + +} \ No newline at end of file diff --git a/Crossword/App/UI/DrawCreditsLabel.cs b/Crossword/App/UI/DrawCreditsLabel.cs index dc54c85..58f9e35 100644 --- a/Crossword/App/UI/DrawCreditsLabel.cs +++ b/Crossword/App/UI/DrawCreditsLabel.cs @@ -1,6 +1,6 @@ using System; -using Crossword.Constants; +using Crossword.Shared.Constants; namespace Crossword.App; public sealed partial class CrosswordMain diff --git a/Crossword/App/UI/DrawCrossword.cs b/Crossword/App/UI/DrawCrossword.cs index cb9cead..fb80ab8 100644 --- a/Crossword/App/UI/DrawCrossword.cs +++ b/Crossword/App/UI/DrawCrossword.cs @@ -1,5 +1,5 @@ using System; -using Crossword.Constants; +using Crossword.Shared.Constants; using FontStashSharp; using Microsoft.Xna.Framework; diff --git a/Crossword/App/UI/DrawCrosswordScore.cs b/Crossword/App/UI/DrawCrosswordScore.cs index 1105a14..4c5a2c5 100644 --- a/Crossword/App/UI/DrawCrosswordScore.cs +++ b/Crossword/App/UI/DrawCrosswordScore.cs @@ -1,6 +1,6 @@ using System; -using Crossword.Constants; +using Crossword.Shared.Constants; namespace Crossword.App; diff --git a/Crossword/App/UI/DrawGetNextPuzzleButton.cs b/Crossword/App/UI/DrawGetNextPuzzleButton.cs index 466d14d..dc2ee70 100644 --- a/Crossword/App/UI/DrawGetNextPuzzleButton.cs +++ b/Crossword/App/UI/DrawGetNextPuzzleButton.cs @@ -1,5 +1,5 @@ using System; -using Crossword.Constants; +using Crossword.Shared.Constants; using Microsoft.Xna.Framework; diff --git a/Crossword/App/UI/DrawHintButton.cs b/Crossword/App/UI/DrawHintButton.cs index aba7b0e..de58e40 100644 --- a/Crossword/App/UI/DrawHintButton.cs +++ b/Crossword/App/UI/DrawHintButton.cs @@ -1,5 +1,5 @@ using System; -using Crossword.Constants; +using Crossword.Shared.Constants; using Microsoft.Xna.Framework; namespace Crossword.App; diff --git a/Crossword/App/UI/LoadAssets.cs b/Crossword/App/UI/LoadAssets.cs index 7eba338..1f93472 100644 --- a/Crossword/App/UI/LoadAssets.cs +++ b/Crossword/App/UI/LoadAssets.cs @@ -1,6 +1,6 @@ using System; using System.IO; -using Crossword.Constants; +using Crossword.Shared.Constants; using FontStashSharp; using Microsoft.Xna.Framework.Graphics; diff --git a/Crossword/App/handlers/MouseHandlers.cs b/Crossword/App/handlers/MouseHandlers.cs index 6b51059..e088397 100644 --- a/Crossword/App/handlers/MouseHandlers.cs +++ b/Crossword/App/handlers/MouseHandlers.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using Crossword.PuzzleSquares; -using Crossword.Constants; +using Crossword.Shared.Constants; namespace Crossword.App; diff --git a/Crossword/App/init/InitArrays.cs b/Crossword/App/init/InitArrays.cs index 5c46e60..1ae8404 100644 --- a/Crossword/App/init/InitArrays.cs +++ b/Crossword/App/init/InitArrays.cs @@ -1,6 +1,6 @@ using System; using Crossword.PuzzleSquares; -using Crossword.Constants; +using Crossword.Shared.Constants; namespace Crossword.App; diff --git a/Crossword/App/init/InitData.cs b/Crossword/App/init/InitData.cs index fe9352a..917e190 100644 --- a/Crossword/App/init/InitData.cs +++ b/Crossword/App/init/InitData.cs @@ -1,6 +1,6 @@ using System; using System.Threading.Tasks; -using Crossword.Constants; +using Crossword.Shared.Constants; namespace Crossword.App; diff --git a/Crossword/App/init/InitListBoxes.cs b/Crossword/App/init/InitListBoxes.cs index 9c4e54a..04cde20 100644 --- a/Crossword/App/init/InitListBoxes.cs +++ b/Crossword/App/init/InitListBoxes.cs @@ -1,5 +1,5 @@ using System; -using Crossword.Constants; +using Crossword.Shared.Constants; using Myra.Graphics2D.UI; diff --git a/Crossword/App/main/CrosswordMain.cs b/Crossword/App/main/CrosswordMain.cs index 8250a13..e6ef298 100644 --- a/Crossword/App/main/CrosswordMain.cs +++ b/Crossword/App/main/CrosswordMain.cs @@ -1,6 +1,6 @@ using System; using Crossword.ClueAnswerMap; -using Crossword.Constants; +using Crossword.Shared.Constants; using Crossword.EventHandlers; using Crossword.PuzzleSquares; using Crossword.Entities; diff --git a/Crossword/App/monogame/Monogame.cs b/Crossword/App/monogame/Monogame.cs index a0cf562..1615e06 100644 --- a/Crossword/App/monogame/Monogame.cs +++ b/Crossword/App/monogame/Monogame.cs @@ -1,5 +1,5 @@ using System; -using Crossword.Constants; +using Crossword.Shared.Constants; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; diff --git a/Crossword/ClueAnswerMap/HighlightSquares.cs b/Crossword/ClueAnswerMap/HighlightSquares.cs index 1e3031e..4ba4b62 100644 --- a/Crossword/ClueAnswerMap/HighlightSquares.cs +++ b/Crossword/ClueAnswerMap/HighlightSquares.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using Crossword.PuzzleSquares; -using Crossword.Constants; +using Crossword.Shared.Constants; namespace Crossword.ClueAnswerMap; diff --git a/Crossword/Constants/GameConstants.cs b/Crossword/Constants/GameConstants.cs index 808bee3..7030354 100644 --- a/Crossword/Constants/GameConstants.cs +++ b/Crossword/Constants/GameConstants.cs @@ -1,37 +1,37 @@ - -//////////////////////////////////////////////////////////////////////////// -// // -// Module: GameConstants.cs // -// Authors: Aaron Saikovski // -// Date: 31/10/202 // -// Version: 1.0 // -// Purpose: Global constants. // -// // -//////////////////////////////////////////////////////////////////////////// - - -namespace Crossword.Constants; - -/// -/// Game Constants -/// -public sealed class GameConstants -{ - //default puzzledata for testing - //public const string DefaultPuzzleData = "505*JX000000*0707*0 0 1 1#0 2 1 4#0 3 1 7#4 3 1 8#1 4 1 10#0 6 1 11#0 0 2 1#2 0 2 2#5 0 2 3#1 2 2 5#4 2 2 6#6 3 2 9*Try#Writing surface#Night bird#Truck#Opposite of male#Nearest#Car#Piece of furniture#Part of a flower#Terrible#Avoid#Unscramble XNET*ATTEMPT#TABLET#OWL#VAN#FEMALE#CLOSEST#AUTO#TABLE#PETAL#AWFUL#EVADE#NEXT*ABCDEFLMNOPSTUVWX*30 1 1 0 1 5*Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!"; - public const string? DefaultPuzzleData = "761*QX000001*0909*0 0 1 1#4 1 1 6#0 2 1 7#2 3 1 9#0 5 1 11#4 6 1 16#0 7 1 17#4 8 1 18#0 0 2 1#2 0 2 2#4 0 2 3#6 0 2 4#8 0 2 5#3 2 2 8#5 3 2 10#0 5 2 11#2 5 2 12#4 5 2 13#6 5 2 14#8 5 2 15*Forward#Strictly accurate#Australian marsupial#Moving to avoid#Not accepted conduct#Astonish greatly#Provide meals#Occurrence#Pretend#Public way#Beer froth#Full-length dress#Adult male deer#Crazy#Metric unit of mass#Skin irritation#Friend#Uncommon#Inland body of water#Bench*FORTH#EXACT#KOALA#DODGING#IMMORAL#AMAZE#CATER#EVENT#FAKE#ROAD#HEAD#MAXI#STAG#LOCO#GRAM#ITCH#MATE#RARE#LAKE#SEAT*ZCDEFGHIKLMNORSTVXA*30 1 1 0 1 5*Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!"; - - - //Credits string - public const string? CreditsText = "**CREDITS**\n" + - "Original Authors: Bryan Richards & Aaron Saikovski\n" + - "Original date: 24th March 1997\n" + - "Description: A Monogame and .Net 8 Core port of the original OzEmail Cyberpuzzles Java based crossword Applet.\n" + - "Dedicated to Neil Reading (neilski) RIP."; - - //game title string - public const string GameTitle = "CyberPuzzles Crossword v1.0.2"; -} - - - +// +// //////////////////////////////////////////////////////////////////////////// +// // // +// // Module: GameConstants.cs // +// // Authors: Aaron Saikovski // +// // Date: 31/10/202 // +// // Version: 1.0 // +// // Purpose: Global constants. // +// // // +// //////////////////////////////////////////////////////////////////////////// +// +// +// namespace Crossword.Constants; +// +// /// +// /// Game Constants +// /// +// public sealed class GameConstants +// { +// //default puzzledata for testing +// //public const string DefaultPuzzleData = "505*JX000000*0707*0 0 1 1#0 2 1 4#0 3 1 7#4 3 1 8#1 4 1 10#0 6 1 11#0 0 2 1#2 0 2 2#5 0 2 3#1 2 2 5#4 2 2 6#6 3 2 9*Try#Writing surface#Night bird#Truck#Opposite of male#Nearest#Car#Piece of furniture#Part of a flower#Terrible#Avoid#Unscramble XNET*ATTEMPT#TABLET#OWL#VAN#FEMALE#CLOSEST#AUTO#TABLE#PETAL#AWFUL#EVADE#NEXT*ABCDEFLMNOPSTUVWX*30 1 1 0 1 5*Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!"; +// public const string? DefaultPuzzleData = "761*QX000001*0909*0 0 1 1#4 1 1 6#0 2 1 7#2 3 1 9#0 5 1 11#4 6 1 16#0 7 1 17#4 8 1 18#0 0 2 1#2 0 2 2#4 0 2 3#6 0 2 4#8 0 2 5#3 2 2 8#5 3 2 10#0 5 2 11#2 5 2 12#4 5 2 13#6 5 2 14#8 5 2 15*Forward#Strictly accurate#Australian marsupial#Moving to avoid#Not accepted conduct#Astonish greatly#Provide meals#Occurrence#Pretend#Public way#Beer froth#Full-length dress#Adult male deer#Crazy#Metric unit of mass#Skin irritation#Friend#Uncommon#Inland body of water#Bench*FORTH#EXACT#KOALA#DODGING#IMMORAL#AMAZE#CATER#EVENT#FAKE#ROAD#HEAD#MAXI#STAG#LOCO#GRAM#ITCH#MATE#RARE#LAKE#SEAT*ZCDEFGHIKLMNORSTVXA*30 1 1 0 1 5*Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!"; +// +// +// //Credits string +// public const string? CreditsText = "**CREDITS**\n" + +// "Original Authors: Bryan Richards & Aaron Saikovski\n" + +// "Original date: 24th March 1997\n" + +// "Description: A Monogame and .Net 8 Core port of the original OzEmail Cyberpuzzles Java based crossword Applet.\n" + +// "Dedicated to Neil Reading (neilski) RIP."; +// +// //game title string +// public const string GameTitle = "CyberPuzzles Crossword v1.0.2"; +// } +// +// +// diff --git a/Crossword/Constants/UIConstants.cs b/Crossword/Constants/UIConstants.cs index e363e17..ad84870 100644 --- a/Crossword/Constants/UIConstants.cs +++ b/Crossword/Constants/UIConstants.cs @@ -1,99 +1,99 @@ - - -using Color = Microsoft.Xna.Framework.Color; - -namespace Crossword.Constants; - -/// -/// UI Constants -/// -public sealed class UIConstants -{ - - //Crossword dimension constants - public const int CrosswordWindowHeight = 600; - public const int CrosswordWindowWidth = 800; - - //Square width and height constants - public const int SquareWidth = 40; - public const int SquareHeight = 40; - public const float SquareSpacer = 1.5f; - - //Highlight Constants - public const int CurrentLetter = 1; - public const int CurrentWord = 2; - public const int CurrentNone = 3; - - - //Font sizes - public const int FntSml = 9; - public const int FntMed = 15; - public const int FntLge = 20; - public const int FntCredits = 13; - - - - //main game offsets - public const int MainOffsetX = 30; - public const int MainOffsetY = 30; - - - //Small number offset - public const float SmlNumOffsetX = 1.8f; - public const float SmlNumOffsetY = 1.7f; - - - //Square char offset - public const float SqCharOffsetX = 12.5f; - public const float SqCharOffsetY = 12f; - - //ClueList offsets/sizes - public const int ClLabelHeight = 20; - public const int ClListboxHeight = 180; - public const int ClListSpacer = 5; - - //Colors for square letters - public static Color SqCorrect = Color.Green; - public static Color SqError = Color.Black; - - //Puzzle tile images - public const string BlackSquare = "images/tile_black"; - public const string HighliteSquare = "images/tile_yellow"; - public const string SquareWord = "images/tile_orange"; - public const string NormalSquare = "images/tile_grey"; - - //Link Buttons - public const string HintButtonImage = "images/btn_get_hint"; - public const string NextPuzzleButtonImage = "images/btn_next_puzzle"; - - - //Fonts - public const string HelveticaBold = "content/fonts/Helvetica-Bold.ttf"; - public const string HelveticaPlain = "content/fonts/Helvetica.ttf"; - - - //Score color - public static Color ScoreColor = Color.Red; - - //Credits Colo - public static Color CreditsColor = Color.Black; - - //Button colours - public static Color ButtonTextColor = Color.White; - public static Color ButtonHoverTextColor = Color.Yellow; - - - //Listbox text colors - public static Color ListBoxTextColor = Color.Black; - - //Square highlight colors - public static Color SquareHighlightCurrent = Color.Cyan; - public static Color SquareHighlightWord = Color.Yellow; - public static Color SquareHighlightNone = Color.White; - public static Color SquareHighlightErr = Color.Red; - public static Color SquareHighlightDefault = Color.Black; - - //Font colors - public static Color SmallFontColor = Color.Black; - -} \ No newline at end of file +// +// +// using Color = Microsoft.Xna.Framework.Color; +// +// namespace Crossword.Constants; +// +// /// +// /// UI Constants +// /// +// public sealed class UIConstants +// { +// +// //Crossword dimension constants +// public const int CrosswordWindowHeight = 600; +// public const int CrosswordWindowWidth = 800; +// +// //Square width and height constants +// public const int SquareWidth = 40; +// public const int SquareHeight = 40; +// public const float SquareSpacer = 1.5f; +// +// //Highlight Constants +// public const int CurrentLetter = 1; +// public const int CurrentWord = 2; +// public const int CurrentNone = 3; +// +// +// //Font sizes +// public const int FntSml = 9; +// public const int FntMed = 15; +// public const int FntLge = 20; +// public const int FntCredits = 13; +// +// +// +// //main game offsets +// public const int MainOffsetX = 30; +// public const int MainOffsetY = 30; +// +// +// //Small number offset +// public const float SmlNumOffsetX = 1.8f; +// public const float SmlNumOffsetY = 1.7f; +// +// +// //Square char offset +// public const float SqCharOffsetX = 12.5f; +// public const float SqCharOffsetY = 12f; +// +// //ClueList offsets/sizes +// public const int ClLabelHeight = 20; +// public const int ClListboxHeight = 180; +// public const int ClListSpacer = 5; +// +// //Colors for square letters +// public static Color SqCorrect = Color.Green; +// public static Color SqError = Color.Black; +// +// //Puzzle tile images +// public const string BlackSquare = "images/tile_black"; +// public const string HighliteSquare = "images/tile_yellow"; +// public const string SquareWord = "images/tile_orange"; +// public const string NormalSquare = "images/tile_grey"; +// +// //Link Buttons +// public const string HintButtonImage = "images/btn_get_hint"; +// public const string NextPuzzleButtonImage = "images/btn_next_puzzle"; +// +// +// //Fonts +// public const string HelveticaBold = "content/fonts/Helvetica-Bold.ttf"; +// public const string HelveticaPlain = "content/fonts/Helvetica.ttf"; +// +// +// //Score color +// public static Color ScoreColor = Color.Red; +// +// //Credits Colo +// public static Color CreditsColor = Color.Black; +// +// //Button colours +// public static Color ButtonTextColor = Color.White; +// public static Color ButtonHoverTextColor = Color.Yellow; +// +// +// //Listbox text colors +// public static Color ListBoxTextColor = Color.Black; +// +// //Square highlight colors +// public static Color SquareHighlightCurrent = Color.Cyan; +// public static Color SquareHighlightWord = Color.Yellow; +// public static Color SquareHighlightNone = Color.White; +// public static Color SquareHighlightErr = Color.Red; +// public static Color SquareHighlightDefault = Color.Black; +// +// //Font colors +// public static Color SmallFontColor = Color.Black; +// +// } \ No newline at end of file diff --git a/Crossword/FetchData/GetCrosswordDataAsync.cs b/Crossword/FetchData/GetCrosswordDataAsync.cs index 78d6426..c9e1b5b 100644 --- a/Crossword/FetchData/GetCrosswordDataAsync.cs +++ b/Crossword/FetchData/GetCrosswordDataAsync.cs @@ -1,6 +1,6 @@ using System; using System.Threading.Tasks; -using Crossword.Constants; +using Crossword.Shared.Constants; using Crossword.Shared.Logger; using Crossword.Shared.Config; diff --git a/Crossword/PuzzleSquares/CheckLetter.cs b/Crossword/PuzzleSquares/CheckLetter.cs index 9e2e739..827b6c8 100644 --- a/Crossword/PuzzleSquares/CheckLetter.cs +++ b/Crossword/PuzzleSquares/CheckLetter.cs @@ -1,4 +1,4 @@ -using Crossword.Constants; +using Crossword.Shared.Constants; namespace Crossword.PuzzleSquares; diff --git a/Crossword/PuzzleSquares/SetHighlighted.cs b/Crossword/PuzzleSquares/SetHighlighted.cs index ac11b41..4a092a9 100644 --- a/Crossword/PuzzleSquares/SetHighlighted.cs +++ b/Crossword/PuzzleSquares/SetHighlighted.cs @@ -1,5 +1,5 @@ using System; -using Crossword.Constants; +using Crossword.Shared.Constants; namespace Crossword.PuzzleSquares; diff --git a/Crossword/PuzzleSquares/SetLetter.cs b/Crossword/PuzzleSquares/SetLetter.cs index 7c32709..3cb044f 100644 --- a/Crossword/PuzzleSquares/SetLetter.cs +++ b/Crossword/PuzzleSquares/SetLetter.cs @@ -1,4 +1,4 @@ -using Crossword.Constants; +using Crossword.Shared.Constants; namespace Crossword.PuzzleSquares; diff --git a/Crossword/PuzzleSquares/SetObjectRef.cs b/Crossword/PuzzleSquares/SetObjectRef.cs index 0c7c801..64bdb88 100644 --- a/Crossword/PuzzleSquares/SetObjectRef.cs +++ b/Crossword/PuzzleSquares/SetObjectRef.cs @@ -1,6 +1,6 @@ using System; using Crossword.ClueAnswerMap; -using Crossword.Constants; +using Crossword.Shared.Constants; namespace Crossword.PuzzleSquares; From c141f6b62afe4bc569670cef1d451961371f61d0 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 09:05:58 +1100 Subject: [PATCH 05/26] updated entities --- Crossword/Crossword.csproj | 1 + Crossword/Entities/CrosswordData.cs | 86 ++++++++++++++-------------- Crossword/Entities/CrosswordState.cs | 54 ++++++++--------- 3 files changed, 71 insertions(+), 70 deletions(-) diff --git a/Crossword/Crossword.csproj b/Crossword/Crossword.csproj index b74c5e9..eafb2f4 100644 --- a/Crossword/Crossword.csproj +++ b/Crossword/Crossword.csproj @@ -86,6 +86,7 @@ + diff --git a/Crossword/Entities/CrosswordData.cs b/Crossword/Entities/CrosswordData.cs index 9424248..44b8dda 100644 --- a/Crossword/Entities/CrosswordData.cs +++ b/Crossword/Entities/CrosswordData.cs @@ -1,43 +1,43 @@ -////////////////////////////////////////////////////////////////////////////// -// // -// Module: CrosswordData.cs // -// Authors: Aaron Saikovski & Bryan Richards // -// Date: 23/01/97 // -// Version: 1.0 // -// Purpose: Utilizes a String Tokenizer to parse the crossword // -// puzzle components from a data set string. // -// // -////////////////////////////////////////////////////////////////////////////// - - -namespace Crossword.Entities; - -public sealed class CrosswordData -{ - #region Fields - - //Instance variables for holding parsed QuickCrossword data - public string? PuzzleType { get; set; } - public int NumCols { get; set; } - public int NumRows { get; set; } - public int NumAcross { get; set; } - public int NumDown { get; set; } - public int PuzzleId { get; set; } - public int[]? ColRef { get; set; } - public int[]? RowRef { get; set; } - public int[]? IsAcross { get; set; } - public int[]? QuesNum { get; set; } - public string[]? Clues { get; set; } - public string[]? Answers { get; set; } - - public int[]? Costs { get; set; } - - public string? GetLetters { get; set; } - public string? Blurb { get; set; } - public int NumQuestions { get; set; } - - public int NumBytes { get; set; } - - #endregion - -} \ No newline at end of file +// ////////////////////////////////////////////////////////////////////////////// +// // // +// // Module: CrosswordData.cs // +// // Authors: Aaron Saikovski & Bryan Richards // +// // Date: 23/01/97 // +// // Version: 1.0 // +// // Purpose: Utilizes a String Tokenizer to parse the crossword // +// // puzzle components from a data set string. // +// // // +// ////////////////////////////////////////////////////////////////////////////// +// +// +// namespace Crossword.Entities; +// +// public sealed class CrosswordData +// { +// #region Fields +// +// //Instance variables for holding parsed QuickCrossword data +// public string? PuzzleType { get; set; } +// public int NumCols { get; set; } +// public int NumRows { get; set; } +// public int NumAcross { get; set; } +// public int NumDown { get; set; } +// public int PuzzleId { get; set; } +// public int[]? ColRef { get; set; } +// public int[]? RowRef { get; set; } +// public int[]? IsAcross { get; set; } +// public int[]? QuesNum { get; set; } +// public string[]? Clues { get; set; } +// public string[]? Answers { get; set; } +// +// public int[]? Costs { get; set; } +// +// public string? GetLetters { get; set; } +// public string? Blurb { get; set; } +// public int NumQuestions { get; set; } +// +// public int NumBytes { get; set; } +// +// #endregion +// +// } \ No newline at end of file diff --git a/Crossword/Entities/CrosswordState.cs b/Crossword/Entities/CrosswordState.cs index 206e638..a720696 100644 --- a/Crossword/Entities/CrosswordState.cs +++ b/Crossword/Entities/CrosswordState.cs @@ -1,27 +1,27 @@ -namespace Crossword.Entities; - -/// -/// CrosswordMain dataset to map clues to answers. -/// -/// -/// constructor -/// -/// -/// -/// -/// -/// -/// -public sealed class CrosswordState(int coordAcross, int coordDown, string answer, string clue, bool isAcross, int questionNum) -{ - #region getters_setters - - public int CoordAcross { get;} = coordAcross; - public int CoordDown { get; } = coordDown; - public string Answer { get; } = answer; - public string Clue { get; } = clue; - public bool IsAcross { get; } = isAcross; - public int QuestionNum { get; } = questionNum; - - #endregion -} \ No newline at end of file +// namespace Crossword.Entities; +// +// /// +// /// CrosswordMain dataset to map clues to answers. +// /// +// /// +// /// constructor +// /// +// /// +// /// +// /// +// /// +// /// +// /// +// public sealed class CrosswordState(int coordAcross, int coordDown, string answer, string clue, bool isAcross, int questionNum) +// { +// #region getters_setters +// +// public int CoordAcross { get;} = coordAcross; +// public int CoordDown { get; } = coordDown; +// public string Answer { get; } = answer; +// public string Clue { get; } = clue; +// public bool IsAcross { get; } = isAcross; +// public int QuestionNum { get; } = questionNum; +// +// #endregion +// } \ No newline at end of file From c65f00ee1d3f4fac08aec4e8b38e2b8072ba5784 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 09:07:50 +1100 Subject: [PATCH 06/26] updated parser --- Crossword/App/init/InitPuzzleData.cs | 2 +- Crossword/App/main/CrosswordMain.cs | 2 +- Crossword/Crossword.csproj | 1 + Crossword/Parsers/GetAnswers.cs | 48 +++---- Crossword/Parsers/GetBlurb.cs | 30 ++--- Crossword/Parsers/GetClues.cs | 64 ++++----- Crossword/Parsers/GetColsAndRows.cs | 36 +++--- Crossword/Parsers/GetCybersilver.cs | 42 +++--- Crossword/Parsers/GetGridPositions.cs | 104 +++++++-------- Crossword/Parsers/GetHintLetters.cs | 30 ++--- Crossword/Parsers/GetNumBytes.cs | 30 ++--- Crossword/Parsers/GetPuzzleIdAndType.cs | 36 +++--- Crossword/Parsers/ParseCrosswordData.cs | 164 ++++++++++++------------ 13 files changed, 295 insertions(+), 294 deletions(-) diff --git a/Crossword/App/init/InitPuzzleData.cs b/Crossword/App/init/InitPuzzleData.cs index 7fc26bd..ec7478d 100644 --- a/Crossword/App/init/InitPuzzleData.cs +++ b/Crossword/App/init/InitPuzzleData.cs @@ -3,7 +3,7 @@ using System.Data; using System.Threading.Tasks; using Crossword.Entities; -using Crossword.Parsers; +using Crossword.Parser; using Crossword.FetchData; diff --git a/Crossword/App/main/CrosswordMain.cs b/Crossword/App/main/CrosswordMain.cs index e6ef298..9012a43 100644 --- a/Crossword/App/main/CrosswordMain.cs +++ b/Crossword/App/main/CrosswordMain.cs @@ -4,7 +4,7 @@ using Crossword.EventHandlers; using Crossword.PuzzleSquares; using Crossword.Entities; -using Crossword.Parsers; +using Crossword.Parser; using FontStashSharp; using InputHandlers.Keyboard; using InputHandlers.Mouse; diff --git a/Crossword/Crossword.csproj b/Crossword/Crossword.csproj index eafb2f4..8e36001 100644 --- a/Crossword/Crossword.csproj +++ b/Crossword/Crossword.csproj @@ -87,6 +87,7 @@ + diff --git a/Crossword/Parsers/GetAnswers.cs b/Crossword/Parsers/GetAnswers.cs index 053c766..c8992af 100644 --- a/Crossword/Parsers/GetAnswers.cs +++ b/Crossword/Parsers/GetAnswers.cs @@ -1,24 +1,24 @@ -using System.Collections.Generic; - -namespace Crossword.Parsers; - -public sealed partial class CrosswordParser -{ - #region - /// - /// GetAnswers - /// - /// - private void GetAnswers(IReadOnlyList strData) - { - var puzzletempstr = strData[5]; - var answertemp = puzzletempstr.Split("#"); - if (_crosswordData == null) return; - _crosswordData.Answers = new string[_crosswordData.NumQuestions]; - for (var k = 0; k < _crosswordData.NumQuestions; k++) - { - _crosswordData.Answers[k] = answertemp[k]; - } - } - #endregion -} \ No newline at end of file +// using System.Collections.Generic; +// +// namespace Crossword.Parsers; +// +// public sealed partial class CrosswordParser +// { +// #region +// /// +// /// GetAnswers +// /// +// /// +// private void GetAnswers(IReadOnlyList strData) +// { +// var puzzletempstr = strData[5]; +// var answertemp = puzzletempstr.Split("#"); +// if (_crosswordData == null) return; +// _crosswordData.Answers = new string[_crosswordData.NumQuestions]; +// for (var k = 0; k < _crosswordData.NumQuestions; k++) +// { +// _crosswordData.Answers[k] = answertemp[k]; +// } +// } +// #endregion +// } \ No newline at end of file diff --git a/Crossword/Parsers/GetBlurb.cs b/Crossword/Parsers/GetBlurb.cs index c011188..7b126ad 100644 --- a/Crossword/Parsers/GetBlurb.cs +++ b/Crossword/Parsers/GetBlurb.cs @@ -1,15 +1,15 @@ -using System.Collections.Generic; - -namespace Crossword.Parsers; - -public sealed partial class CrosswordParser -{ - /// - /// GetBlurb - /// - /// - private void GetBlurb(IReadOnlyList strData) - { - if (_crosswordData != null) _crosswordData.Blurb = strData[8]; - } -} \ No newline at end of file +// using System.Collections.Generic; +// +// namespace Crossword.Parsers; +// +// public sealed partial class CrosswordParser +// { +// /// +// /// GetBlurb +// /// +// /// +// private void GetBlurb(IReadOnlyList strData) +// { +// if (_crosswordData != null) _crosswordData.Blurb = strData[8]; +// } +// } \ No newline at end of file diff --git a/Crossword/Parsers/GetClues.cs b/Crossword/Parsers/GetClues.cs index b4f76bb..ffed159 100644 --- a/Crossword/Parsers/GetClues.cs +++ b/Crossword/Parsers/GetClues.cs @@ -1,32 +1,32 @@ -using System.Collections.Generic; - -namespace Crossword.Parsers; - -public sealed partial class CrosswordParser -{ - /// - /// GetClues - /// - /// - private void GetClues(IReadOnlyList strData) - { - var puzzletempstr = strData[4]; - string[] cluetemp = puzzletempstr.Split("#"); - if (_crosswordData == null) return; - _crosswordData.Clues = new string[_crosswordData.NumQuestions]; - for (var j = 0; j < _crosswordData.NumQuestions; j++) - { - _crosswordData.Clues[j] = cluetemp[j]; - } - - // string[] cluetemp; - // var puzzletempstr = strData[4]; - // cluetemp = puzzletempstr.Split("#"); - // if (_crosswordData == null) return; - // _crosswordData.Clues = new string[_crosswordData.NumQuestions]; - // for (var j = 0; j < _crosswordData.NumQuestions; j++) - // { - // _crosswordData.Clues[j] = cluetemp[j]; - // } - } -} \ No newline at end of file +// using System.Collections.Generic; +// +// namespace Crossword.Parsers; +// +// public sealed partial class CrosswordParser +// { +// /// +// /// GetClues +// /// +// /// +// private void GetClues(IReadOnlyList strData) +// { +// var puzzletempstr = strData[4]; +// string[] cluetemp = puzzletempstr.Split("#"); +// if (_crosswordData == null) return; +// _crosswordData.Clues = new string[_crosswordData.NumQuestions]; +// for (var j = 0; j < _crosswordData.NumQuestions; j++) +// { +// _crosswordData.Clues[j] = cluetemp[j]; +// } +// +// // string[] cluetemp; +// // var puzzletempstr = strData[4]; +// // cluetemp = puzzletempstr.Split("#"); +// // if (_crosswordData == null) return; +// // _crosswordData.Clues = new string[_crosswordData.NumQuestions]; +// // for (var j = 0; j < _crosswordData.NumQuestions; j++) +// // { +// // _crosswordData.Clues[j] = cluetemp[j]; +// // } +// } +// } \ No newline at end of file diff --git a/Crossword/Parsers/GetColsAndRows.cs b/Crossword/Parsers/GetColsAndRows.cs index 6288512..8a44e04 100644 --- a/Crossword/Parsers/GetColsAndRows.cs +++ b/Crossword/Parsers/GetColsAndRows.cs @@ -1,18 +1,18 @@ -using System.Collections.Generic; - -namespace Crossword.Parsers; - -public sealed partial class CrosswordParser -{ - /// - /// GetColsAndRows - /// - /// - private void GetColsAndRows(IReadOnlyList strData) - { - var puzzleTempStr = strData[2]; - if (_crosswordData == null) return; - _crosswordData.NumCols = int.Parse(puzzleTempStr[..2]); - _crosswordData.NumRows = int.Parse(puzzleTempStr[2..]); - } -} \ No newline at end of file +// using System.Collections.Generic; +// +// namespace Crossword.Parsers; +// +// public sealed partial class CrosswordParser +// { +// /// +// /// GetColsAndRows +// /// +// /// +// private void GetColsAndRows(IReadOnlyList strData) +// { +// var puzzleTempStr = strData[2]; +// if (_crosswordData == null) return; +// _crosswordData.NumCols = int.Parse(puzzleTempStr[..2]); +// _crosswordData.NumRows = int.Parse(puzzleTempStr[2..]); +// } +// } \ No newline at end of file diff --git a/Crossword/Parsers/GetCybersilver.cs b/Crossword/Parsers/GetCybersilver.cs index 1840a70..12a246c 100644 --- a/Crossword/Parsers/GetCybersilver.cs +++ b/Crossword/Parsers/GetCybersilver.cs @@ -1,21 +1,21 @@ -using System.Collections.Generic; - -namespace Crossword.Parsers; - -public sealed partial class CrosswordParser -{ - /// - /// GetCybersilver - /// - /// - private void GetCybersilver(IReadOnlyList strData) - { - var puzzletempstr = strData[7]; - var costTemp = puzzletempstr.Split(" "); - - for (var loopIdx = 0; loopIdx < 6; loopIdx++) - { - if (_crosswordData is { Costs: not null }) _crosswordData.Costs[loopIdx] = int.Parse(costTemp[loopIdx]); - } - } -} \ No newline at end of file +// using System.Collections.Generic; +// +// namespace Crossword.Parsers; +// +// public sealed partial class CrosswordParser +// { +// /// +// /// GetCybersilver +// /// +// /// +// private void GetCybersilver(IReadOnlyList strData) +// { +// var puzzletempstr = strData[7]; +// var costTemp = puzzletempstr.Split(" "); +// +// for (var loopIdx = 0; loopIdx < 6; loopIdx++) +// { +// if (_crosswordData is { Costs: not null }) _crosswordData.Costs[loopIdx] = int.Parse(costTemp[loopIdx]); +// } +// } +// } \ No newline at end of file diff --git a/Crossword/Parsers/GetGridPositions.cs b/Crossword/Parsers/GetGridPositions.cs index 92a5ed5..ce898dc 100644 --- a/Crossword/Parsers/GetGridPositions.cs +++ b/Crossword/Parsers/GetGridPositions.cs @@ -1,52 +1,52 @@ - - -using System.Collections.Generic; -using Crossword.Shared.ParserUtils; - -namespace Crossword.Parsers; - -public sealed partial class CrosswordParser -{ - /// - /// GetGridPositions - /// - /// - private void GetGridPositions(IReadOnlyList strData) - { - var puzzleTempStr = strData[3]; - if (_crosswordData == null) return; - _crosswordData.NumQuestions = ParserHelper.CountOccurrences(puzzleTempStr, '#'); - _crosswordData.ColRef = new int[_crosswordData.NumQuestions]; - _crosswordData.RowRef = new int[_crosswordData.NumQuestions]; - _crosswordData.IsAcross = new int[_crosswordData.NumQuestions]; - _crosswordData.QuesNum = new int[_crosswordData.NumQuestions]; - - //split string - var gridPosTmp = puzzleTempStr.Split('#'); - - for (var tokIdx = 0; tokIdx < _crosswordData.NumQuestions; tokIdx++) - { - var subGridDataTemp = gridPosTmp[tokIdx].Split(" "); - - for (var i = 0; i < 4; i++) - { - switch (i) - { - case 0: - _crosswordData.ColRef[tokIdx] = int.Parse(subGridDataTemp[0]); - break; - - case 1: - _crosswordData.RowRef[tokIdx] = int.Parse(subGridDataTemp[1]); - break; - case 2: - _crosswordData.IsAcross[tokIdx] = int.Parse(subGridDataTemp[2]); - break; - case 3: - _crosswordData.QuesNum[tokIdx] = int.Parse(subGridDataTemp[3]); - break; - } - } - } - } -} \ No newline at end of file +// +// +// using System.Collections.Generic; +// using Crossword.Shared.ParserUtils; +// +// namespace Crossword.Parsers; +// +// public sealed partial class CrosswordParser +// { +// /// +// /// GetGridPositions +// /// +// /// +// private void GetGridPositions(IReadOnlyList strData) +// { +// var puzzleTempStr = strData[3]; +// if (_crosswordData == null) return; +// _crosswordData.NumQuestions = ParserHelper.CountOccurrences(puzzleTempStr, '#'); +// _crosswordData.ColRef = new int[_crosswordData.NumQuestions]; +// _crosswordData.RowRef = new int[_crosswordData.NumQuestions]; +// _crosswordData.IsAcross = new int[_crosswordData.NumQuestions]; +// _crosswordData.QuesNum = new int[_crosswordData.NumQuestions]; +// +// //split string +// var gridPosTmp = puzzleTempStr.Split('#'); +// +// for (var tokIdx = 0; tokIdx < _crosswordData.NumQuestions; tokIdx++) +// { +// var subGridDataTemp = gridPosTmp[tokIdx].Split(" "); +// +// for (var i = 0; i < 4; i++) +// { +// switch (i) +// { +// case 0: +// _crosswordData.ColRef[tokIdx] = int.Parse(subGridDataTemp[0]); +// break; +// +// case 1: +// _crosswordData.RowRef[tokIdx] = int.Parse(subGridDataTemp[1]); +// break; +// case 2: +// _crosswordData.IsAcross[tokIdx] = int.Parse(subGridDataTemp[2]); +// break; +// case 3: +// _crosswordData.QuesNum[tokIdx] = int.Parse(subGridDataTemp[3]); +// break; +// } +// } +// } +// } +// } \ No newline at end of file diff --git a/Crossword/Parsers/GetHintLetters.cs b/Crossword/Parsers/GetHintLetters.cs index 69f3487..bc0a4d0 100644 --- a/Crossword/Parsers/GetHintLetters.cs +++ b/Crossword/Parsers/GetHintLetters.cs @@ -1,15 +1,15 @@ -using System.Collections.Generic; - -namespace Crossword.Parsers; - -public sealed partial class CrosswordParser -{ - /// - /// GetHintLetters - /// - /// - private void GetHintLetters(IReadOnlyList strData) - { - if (_crosswordData != null) _crosswordData.GetLetters = strData[6]; - } -} \ No newline at end of file +// using System.Collections.Generic; +// +// namespace Crossword.Parsers; +// +// public sealed partial class CrosswordParser +// { +// /// +// /// GetHintLetters +// /// +// /// +// private void GetHintLetters(IReadOnlyList strData) +// { +// if (_crosswordData != null) _crosswordData.GetLetters = strData[6]; +// } +// } \ No newline at end of file diff --git a/Crossword/Parsers/GetNumBytes.cs b/Crossword/Parsers/GetNumBytes.cs index dd503ed..671fa1e 100644 --- a/Crossword/Parsers/GetNumBytes.cs +++ b/Crossword/Parsers/GetNumBytes.cs @@ -1,15 +1,15 @@ -using System.Collections.Generic; - -namespace Crossword.Parsers; - -public sealed partial class CrosswordParser -{ - /// - /// GetNumBytes - /// - /// - private void GetNumBytes(IReadOnlyList strData) - { - if (_crosswordData != null) _crosswordData.NumBytes = int.Parse(strData[0]); - } -} \ No newline at end of file +// using System.Collections.Generic; +// +// namespace Crossword.Parsers; +// +// public sealed partial class CrosswordParser +// { +// /// +// /// GetNumBytes +// /// +// /// +// private void GetNumBytes(IReadOnlyList strData) +// { +// if (_crosswordData != null) _crosswordData.NumBytes = int.Parse(strData[0]); +// } +// } \ No newline at end of file diff --git a/Crossword/Parsers/GetPuzzleIdAndType.cs b/Crossword/Parsers/GetPuzzleIdAndType.cs index e62a4c9..d6be2c1 100644 --- a/Crossword/Parsers/GetPuzzleIdAndType.cs +++ b/Crossword/Parsers/GetPuzzleIdAndType.cs @@ -1,18 +1,18 @@ -using System.Collections.Generic; - -namespace Crossword.Parsers; - -public sealed partial class CrosswordParser -{ - /// - /// GetPuzzleIdAndType - /// - /// - private void GetPuzzleIdAndType(IReadOnlyList strData) - { - var puzzletempstr = strData[1]; - if (_crosswordData == null) return; - _crosswordData.PuzzleId = int.Parse(puzzletempstr[2..]); - _crosswordData.PuzzleType = puzzletempstr[..2]; - } -} \ No newline at end of file +// using System.Collections.Generic; +// +// namespace Crossword.Parsers; +// +// public sealed partial class CrosswordParser +// { +// /// +// /// GetPuzzleIdAndType +// /// +// /// +// private void GetPuzzleIdAndType(IReadOnlyList strData) +// { +// var puzzletempstr = strData[1]; +// if (_crosswordData == null) return; +// _crosswordData.PuzzleId = int.Parse(puzzletempstr[2..]); +// _crosswordData.PuzzleType = puzzletempstr[..2]; +// } +// } \ No newline at end of file diff --git a/Crossword/Parsers/ParseCrosswordData.cs b/Crossword/Parsers/ParseCrosswordData.cs index 4e9aab7..2e5478e 100644 --- a/Crossword/Parsers/ParseCrosswordData.cs +++ b/Crossword/Parsers/ParseCrosswordData.cs @@ -1,82 +1,82 @@ -using System; -using Crossword.Entities; -namespace Crossword.Parsers; - -public sealed partial class CrosswordParser -{ - //init the crossword data class - private CrosswordData? _crosswordData; - - /// - /// // Main - used to parse QuickCrossword data set from string - /// // Pre : szParseData is NOT null - /// // Post : Returns true if data has been successfully parsed from String and false otherwise - /// - /// - /// - public CrosswordData? ParsePuzzleData(string puzzleData) - { - ArgumentNullException.ThrowIfNull(puzzleData); - - //init the CrosswordData object - _crosswordData = new CrosswordData(); - - //local vars - var strData = puzzleData.Split("*"); - - //Loop over for each of the tokens - for (var tokenIdx = 0; tokenIdx < strData.Length; tokenIdx++) - { - switch (tokenIdx) - { - //Eat the first String - number of bytes in data set - eg. "1075" - case 0: - GetNumBytes(strData); - break; - - //Puzzle ID - eg. "QXW000000" - case 1: - GetPuzzleIdAndType(strData); - break; - - //Number of Columns and Rows - eg. "0909" - case 2: - GetColsAndRows(strData); - break; - - //Grid positions and Data for across and down numbers - eg. "0 0 1 1#6 0 1 4#3 2 1 6#0 3 1 8#3 5 1 11#0 6 1 13#0 8 1 15#4 8 1 16#1 0 2 2#4 0 2 3#6 0 2 4#8 0 2 5#3 2 2 6#5 2 2 7#7 4 2 9#0 5 2 10#4 5 2 12#2 6 2 14" - case 3: - GetGridPositions(strData); - break; - - //Clues - eg. "Bread maker#Skill#Receive#Calm#Real#Taunts#Apple _ _ _#Midday meal#Irritate#Wealthy#Queen,King,__ __ __#Ballet skirt#Book of maps#100 make a dollar#Conjuring#Cease#Prison room#Length of life" - case 4: - GetClues(strData); - break; - - //Answers - eg BAKER#ART#ACCEPT#SOOTHE#ACTUAL#TEASES#PIE#LUNCH#ANNOY#RICH#ACE#TUTU#ATLAS#CENTS#MAGIC#STOP#CELL#AGE - case 5: - GetAnswers(strData); - break; - - //Hint letters - eg "ABCEGHIKLMNOPRSTUY" - case 6: - GetHintLetters(strData); - break; - - //CyberSilver level costs & bonuses - eg. "30 1 1 0 1 5" - case 7: - GetCybersilver(strData); - break; - - //Jim's crappy blurb - eg. "Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!" - case 8: - GetBlurb(strData); - break; - } - } - - //return the crossword data object - return _crosswordData; - } -} \ No newline at end of file +// using System; +// using Crossword.Entities; +// namespace Crossword.Parsers; +// +// public sealed partial class CrosswordParser +// { +// //init the crossword data class +// private CrosswordData? _crosswordData; +// +// /// +// /// // Main - used to parse QuickCrossword data set from string +// /// // Pre : szParseData is NOT null +// /// // Post : Returns true if data has been successfully parsed from String and false otherwise +// /// +// /// +// /// +// public CrosswordData? ParsePuzzleData(string puzzleData) +// { +// ArgumentNullException.ThrowIfNull(puzzleData); +// +// //init the CrosswordData object +// _crosswordData = new CrosswordData(); +// +// //local vars +// var strData = puzzleData.Split("*"); +// +// //Loop over for each of the tokens +// for (var tokenIdx = 0; tokenIdx < strData.Length; tokenIdx++) +// { +// switch (tokenIdx) +// { +// //Eat the first String - number of bytes in data set - eg. "1075" +// case 0: +// GetNumBytes(strData); +// break; +// +// //Puzzle ID - eg. "QXW000000" +// case 1: +// GetPuzzleIdAndType(strData); +// break; +// +// //Number of Columns and Rows - eg. "0909" +// case 2: +// GetColsAndRows(strData); +// break; +// +// //Grid positions and Data for across and down numbers - eg. "0 0 1 1#6 0 1 4#3 2 1 6#0 3 1 8#3 5 1 11#0 6 1 13#0 8 1 15#4 8 1 16#1 0 2 2#4 0 2 3#6 0 2 4#8 0 2 5#3 2 2 6#5 2 2 7#7 4 2 9#0 5 2 10#4 5 2 12#2 6 2 14" +// case 3: +// GetGridPositions(strData); +// break; +// +// //Clues - eg. "Bread maker#Skill#Receive#Calm#Real#Taunts#Apple _ _ _#Midday meal#Irritate#Wealthy#Queen,King,__ __ __#Ballet skirt#Book of maps#100 make a dollar#Conjuring#Cease#Prison room#Length of life" +// case 4: +// GetClues(strData); +// break; +// +// //Answers - eg BAKER#ART#ACCEPT#SOOTHE#ACTUAL#TEASES#PIE#LUNCH#ANNOY#RICH#ACE#TUTU#ATLAS#CENTS#MAGIC#STOP#CELL#AGE +// case 5: +// GetAnswers(strData); +// break; +// +// //Hint letters - eg "ABCEGHIKLMNOPRSTUY" +// case 6: +// GetHintLetters(strData); +// break; +// +// //CyberSilver level costs & bonuses - eg. "30 1 1 0 1 5" +// case 7: +// GetCybersilver(strData); +// break; +// +// //Jim's crappy blurb - eg. "Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!" +// case 8: +// GetBlurb(strData); +// break; +// } +// } +// +// //return the crossword data object +// return _crosswordData; +// } +// } \ No newline at end of file From 2b84d99d782e85dcddfda1cbafbaea0fcdb4506b Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 09:45:07 +1100 Subject: [PATCH 07/26] added data project --- Crossword.Data/CallDataApiAsync.cs | 75 ++++++++++ Crossword.Data/Crossword.Data.csproj | 13 ++ Crossword.Data/GetCrosswordDataAsync.cs | 46 ++++++ Crossword.Net.sln | 6 + Crossword/App/init/InitPuzzleData.cs | 2 +- Crossword/Crossword.csproj | 1 + Crossword/FetchData/CallDataApiAsync.cs | 150 +++++++++---------- Crossword/FetchData/GetCrosswordDataAsync.cs | 92 ++++++------ 8 files changed, 263 insertions(+), 122 deletions(-) create mode 100644 Crossword.Data/CallDataApiAsync.cs create mode 100644 Crossword.Data/Crossword.Data.csproj create mode 100644 Crossword.Data/GetCrosswordDataAsync.cs diff --git a/Crossword.Data/CallDataApiAsync.cs b/Crossword.Data/CallDataApiAsync.cs new file mode 100644 index 0000000..3525fce --- /dev/null +++ b/Crossword.Data/CallDataApiAsync.cs @@ -0,0 +1,75 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Crossword.Shared.Config; +using Crossword.Shared.Logger; +using Crossword.Shared.Constants; +namespace Crossword.Data; + +/// +/// Fetches data from the Data API +/// +public partial class FetchCrosswordData +{ + #region CallDataApiAsync + + /// + /// CallDataApiAsync + /// + /// + private static async Task CallDataApiAsync() + { + //Init the logger and get the active config + var logger = new SerilogLogger(ConfigurationHelper.ActiveConfiguration); + + //Use the HttpClient + using var client = new HttpClient(); + try + { + logger.LogInformation("Start CallDataApiAsync()"); + + //get config values from the appsettings + var apiUrl = ConfigurationHelper.DataApiUrl; + var apiKey = ConfigurationHelper.DataApiKey; + + //pass in the API key to the header + client.DefaultRequestHeaders.Clear(); + client.DefaultRequestHeaders.Add(ApiConstants.ApiKeyName, apiKey); + + //catch inner HttpRequestException + try + { + var response = await client.GetAsync(apiUrl); + + //check for errors...response codes etc + if (response.IsSuccessStatusCode) + { + //get the response from the API call result as a string + return response.Content.ReadAsStringAsync().Result; + } + else + { + throw new Exception($"Failed to call the API. Status code: {response.StatusCode}"); + } + + } + //catch http request exception + catch (HttpRequestException httpex) + { + logger.LogError(httpex, httpex.Message); + throw; + } + } + catch (Exception ex) + { + logger.LogError(ex, ex.Message); + return string.Empty; + } + finally + { + logger.Dispose(); + } + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Data/Crossword.Data.csproj b/Crossword.Data/Crossword.Data.csproj new file mode 100644 index 0000000..cdf9794 --- /dev/null +++ b/Crossword.Data/Crossword.Data.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Crossword.Data/GetCrosswordDataAsync.cs b/Crossword.Data/GetCrosswordDataAsync.cs new file mode 100644 index 0000000..b96cd0d --- /dev/null +++ b/Crossword.Data/GetCrosswordDataAsync.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; +using Crossword.Shared.Constants; +using Crossword.Shared.Logger; +using Crossword.Shared.Config; + +namespace Crossword.Data; + + +public partial class FetchCrosswordData +{ + #region GetCrosswordDataAsync + + /// + /// GetCrosswordDataAsync + /// + /// + public static async Task GetCrosswordDataAsync() + { + //Init the logger and get the active config + var logger = new SerilogLogger(ConfigurationHelper.ActiveConfiguration); + + //Call the API to get the puzzledata....otherwise use default values + try + { + logger.LogInformation("Start GetCrosswordDataAsync()"); + + //call the API + var apiResponse = await CallDataApiAsync(); + + //check what was returned + return string.IsNullOrEmpty(apiResponse) ? GameConstants.DefaultPuzzleData : apiResponse; + } + catch (Exception ex) + { + logger.LogError(ex, ex.Message); + throw; + } + finally + { + logger.Dispose(); + } + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Net.sln b/Crossword.Net.sln index 3004560..7ff4cc4 100644 --- a/Crossword.Net.sln +++ b/Crossword.Net.sln @@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Parser", "Crosswo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crosssword.Entities", "Crosssword.Entities\Crosssword.Entities.csproj", "{629F5D51-C8E0-4C64-BE84-48C5DB565FA8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Data", "Crossword.Data\Crossword.Data.csproj", "{08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -36,5 +38,9 @@ Global {629F5D51-C8E0-4C64-BE84-48C5DB565FA8}.Debug|Any CPU.Build.0 = Debug|Any CPU {629F5D51-C8E0-4C64-BE84-48C5DB565FA8}.Release|Any CPU.ActiveCfg = Release|Any CPU {629F5D51-C8E0-4C64-BE84-48C5DB565FA8}.Release|Any CPU.Build.0 = Release|Any CPU + {08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}.Debug|Any CPU.Build.0 = Debug|Any CPU + {08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}.Release|Any CPU.ActiveCfg = Release|Any CPU + {08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Crossword/App/init/InitPuzzleData.cs b/Crossword/App/init/InitPuzzleData.cs index ec7478d..300ccac 100644 --- a/Crossword/App/init/InitPuzzleData.cs +++ b/Crossword/App/init/InitPuzzleData.cs @@ -5,7 +5,7 @@ using Crossword.Entities; using Crossword.Parser; -using Crossword.FetchData; +using Crossword.Data; namespace Crossword.App; diff --git a/Crossword/Crossword.csproj b/Crossword/Crossword.csproj index 8e36001..31d7f2c 100644 --- a/Crossword/Crossword.csproj +++ b/Crossword/Crossword.csproj @@ -87,6 +87,7 @@ + diff --git a/Crossword/FetchData/CallDataApiAsync.cs b/Crossword/FetchData/CallDataApiAsync.cs index 71f6356..f87db1e 100644 --- a/Crossword/FetchData/CallDataApiAsync.cs +++ b/Crossword/FetchData/CallDataApiAsync.cs @@ -1,75 +1,75 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using Crossword.Shared.Config; -using Crossword.Shared.Logger; -using Crossword.Shared.Constants; -namespace Crossword.FetchData; - -/// -/// Fetches data from the Data API -/// -public partial class FetchCrosswordData -{ - #region CallDataApiAsync - - /// - /// CallDataApiAsync - /// - /// - private static async Task CallDataApiAsync() - { - //Init the logger and get the active config - var logger = new SerilogLogger(ConfigurationHelper.ActiveConfiguration); - - //Use the HttpClient - using var client = new HttpClient(); - try - { - logger.LogInformation("Start CallDataApiAsync()"); - - //get config values from the appsettings - var apiUrl = ConfigurationHelper.DataApiUrl; - var apiKey = ConfigurationHelper.DataApiKey; - - //pass in the API key to the header - client.DefaultRequestHeaders.Clear(); - client.DefaultRequestHeaders.Add(ApiConstants.ApiKeyName, apiKey); - - //catch inner HttpRequestException - try - { - var response = await client.GetAsync(apiUrl); - - //check for errors...response codes etc - if (response.IsSuccessStatusCode) - { - //get the response from the API call result as a string - return response.Content.ReadAsStringAsync().Result; - } - else - { - throw new Exception($"Failed to call the API. Status code: {response.StatusCode}"); - } - - } - //catch http request exception - catch (HttpRequestException httpex) - { - logger.LogError(httpex, httpex.Message); - throw; - } - } - catch (Exception ex) - { - logger.LogError(ex, ex.Message); - return string.Empty; - } - finally - { - logger.Dispose(); - } - } - - #endregion -} \ No newline at end of file +// using System; +// using System.Net.Http; +// using System.Threading.Tasks; +// using Crossword.Shared.Config; +// using Crossword.Shared.Logger; +// using Crossword.Shared.Constants; +// namespace Crossword.FetchData; +// +// /// +// /// Fetches data from the Data API +// /// +// public partial class FetchCrosswordData +// { +// #region CallDataApiAsync +// +// /// +// /// CallDataApiAsync +// /// +// /// +// private static async Task CallDataApiAsync() +// { +// //Init the logger and get the active config +// var logger = new SerilogLogger(ConfigurationHelper.ActiveConfiguration); +// +// //Use the HttpClient +// using var client = new HttpClient(); +// try +// { +// logger.LogInformation("Start CallDataApiAsync()"); +// +// //get config values from the appsettings +// var apiUrl = ConfigurationHelper.DataApiUrl; +// var apiKey = ConfigurationHelper.DataApiKey; +// +// //pass in the API key to the header +// client.DefaultRequestHeaders.Clear(); +// client.DefaultRequestHeaders.Add(ApiConstants.ApiKeyName, apiKey); +// +// //catch inner HttpRequestException +// try +// { +// var response = await client.GetAsync(apiUrl); +// +// //check for errors...response codes etc +// if (response.IsSuccessStatusCode) +// { +// //get the response from the API call result as a string +// return response.Content.ReadAsStringAsync().Result; +// } +// else +// { +// throw new Exception($"Failed to call the API. Status code: {response.StatusCode}"); +// } +// +// } +// //catch http request exception +// catch (HttpRequestException httpex) +// { +// logger.LogError(httpex, httpex.Message); +// throw; +// } +// } +// catch (Exception ex) +// { +// logger.LogError(ex, ex.Message); +// return string.Empty; +// } +// finally +// { +// logger.Dispose(); +// } +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/FetchData/GetCrosswordDataAsync.cs b/Crossword/FetchData/GetCrosswordDataAsync.cs index c9e1b5b..9cc69c3 100644 --- a/Crossword/FetchData/GetCrosswordDataAsync.cs +++ b/Crossword/FetchData/GetCrosswordDataAsync.cs @@ -1,46 +1,46 @@ -using System; -using System.Threading.Tasks; -using Crossword.Shared.Constants; -using Crossword.Shared.Logger; -using Crossword.Shared.Config; - -namespace Crossword.FetchData; - - -public partial class FetchCrosswordData -{ - #region GetCrosswordDataAsync - - /// - /// GetCrosswordDataAsync - /// - /// - public static async Task GetCrosswordDataAsync() - { - //Init the logger and get the active config - var logger = new SerilogLogger(ConfigurationHelper.ActiveConfiguration); - - //Call the API to get the puzzledata....otherwise use default values - try - { - logger.LogInformation("Start GetCrosswordDataAsync()"); - - //call the API - var apiResponse = await CallDataApiAsync(); - - //check what was returned - return string.IsNullOrEmpty(apiResponse) ? GameConstants.DefaultPuzzleData : apiResponse; - } - catch (Exception ex) - { - logger.LogError(ex, ex.Message); - throw; - } - finally - { - logger.Dispose(); - } - } - - #endregion -} \ No newline at end of file +// using System; +// using System.Threading.Tasks; +// using Crossword.Shared.Constants; +// using Crossword.Shared.Logger; +// using Crossword.Shared.Config; +// +// namespace Crossword.FetchData; +// +// +// public partial class FetchCrosswordData +// { +// #region GetCrosswordDataAsync +// +// /// +// /// GetCrosswordDataAsync +// /// +// /// +// public static async Task GetCrosswordDataAsync() +// { +// //Init the logger and get the active config +// var logger = new SerilogLogger(ConfigurationHelper.ActiveConfiguration); +// +// //Call the API to get the puzzledata....otherwise use default values +// try +// { +// logger.LogInformation("Start GetCrosswordDataAsync()"); +// +// //call the API +// var apiResponse = await CallDataApiAsync(); +// +// //check what was returned +// return string.IsNullOrEmpty(apiResponse) ? GameConstants.DefaultPuzzleData : apiResponse; +// } +// catch (Exception ex) +// { +// logger.LogError(ex, ex.Message); +// throw; +// } +// finally +// { +// logger.Dispose(); +// } +// } +// +// #endregion +// } \ No newline at end of file From abcc29a9f229c6c331ccbfd0208f8c8e8f4de98b Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 09:47:10 +1100 Subject: [PATCH 08/26] removed src from shard --- Crossword.Shared/{src => }/Config/ConfigurationHelper.cs | 0 Crossword.Shared/{src => }/Constants/APIConstants.cs | 0 Crossword.Shared/{src => }/Constants/GameConstants.cs | 0 Crossword.Shared/{src => }/Constants/UIConstants.cs | 0 Crossword.Shared/Crossword.Shared.csproj | 4 ---- Crossword.Shared/{src => }/Logger/ILoggerService.cs | 0 Crossword.Shared/{src => }/Logger/SerilogLogger.cs | 0 Crossword.Shared/{src => }/ParserUtils/ParserHelper.cs | 0 8 files changed, 4 deletions(-) rename Crossword.Shared/{src => }/Config/ConfigurationHelper.cs (100%) rename Crossword.Shared/{src => }/Constants/APIConstants.cs (100%) rename Crossword.Shared/{src => }/Constants/GameConstants.cs (100%) rename Crossword.Shared/{src => }/Constants/UIConstants.cs (100%) rename Crossword.Shared/{src => }/Logger/ILoggerService.cs (100%) rename Crossword.Shared/{src => }/Logger/SerilogLogger.cs (100%) rename Crossword.Shared/{src => }/ParserUtils/ParserHelper.cs (100%) diff --git a/Crossword.Shared/src/Config/ConfigurationHelper.cs b/Crossword.Shared/Config/ConfigurationHelper.cs similarity index 100% rename from Crossword.Shared/src/Config/ConfigurationHelper.cs rename to Crossword.Shared/Config/ConfigurationHelper.cs diff --git a/Crossword.Shared/src/Constants/APIConstants.cs b/Crossword.Shared/Constants/APIConstants.cs similarity index 100% rename from Crossword.Shared/src/Constants/APIConstants.cs rename to Crossword.Shared/Constants/APIConstants.cs diff --git a/Crossword.Shared/src/Constants/GameConstants.cs b/Crossword.Shared/Constants/GameConstants.cs similarity index 100% rename from Crossword.Shared/src/Constants/GameConstants.cs rename to Crossword.Shared/Constants/GameConstants.cs diff --git a/Crossword.Shared/src/Constants/UIConstants.cs b/Crossword.Shared/Constants/UIConstants.cs similarity index 100% rename from Crossword.Shared/src/Constants/UIConstants.cs rename to Crossword.Shared/Constants/UIConstants.cs diff --git a/Crossword.Shared/Crossword.Shared.csproj b/Crossword.Shared/Crossword.Shared.csproj index 6e65953..4a3e487 100644 --- a/Crossword.Shared/Crossword.Shared.csproj +++ b/Crossword.Shared/Crossword.Shared.csproj @@ -25,8 +25,4 @@ - - - - diff --git a/Crossword.Shared/src/Logger/ILoggerService.cs b/Crossword.Shared/Logger/ILoggerService.cs similarity index 100% rename from Crossword.Shared/src/Logger/ILoggerService.cs rename to Crossword.Shared/Logger/ILoggerService.cs diff --git a/Crossword.Shared/src/Logger/SerilogLogger.cs b/Crossword.Shared/Logger/SerilogLogger.cs similarity index 100% rename from Crossword.Shared/src/Logger/SerilogLogger.cs rename to Crossword.Shared/Logger/SerilogLogger.cs diff --git a/Crossword.Shared/src/ParserUtils/ParserHelper.cs b/Crossword.Shared/ParserUtils/ParserHelper.cs similarity index 100% rename from Crossword.Shared/src/ParserUtils/ParserHelper.cs rename to Crossword.Shared/ParserUtils/ParserHelper.cs From 41ec3cad2b05af20b6165e1b12db7a8831d69204 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 09:51:19 +1100 Subject: [PATCH 09/26] deleted redundant code --- Crossword/Constants/GameConstants.cs | 37 -------- Crossword/Constants/UIConstants.cs | 99 -------------------- Crossword/Crossword.csproj | 3 - Crossword/Entities/CrosswordData.cs | 43 --------- Crossword/Entities/CrosswordState.cs | 27 ------ Crossword/FetchData/CallDataApiAsync.cs | 75 --------------- Crossword/FetchData/GetCrosswordDataAsync.cs | 46 --------- Crossword/Parsers/GetAnswers.cs | 24 ----- Crossword/Parsers/GetBlurb.cs | 15 --- Crossword/Parsers/GetClues.cs | 32 ------- Crossword/Parsers/GetColsAndRows.cs | 18 ---- Crossword/Parsers/GetCybersilver.cs | 21 ----- Crossword/Parsers/GetGridPositions.cs | 52 ---------- Crossword/Parsers/GetHintLetters.cs | 15 --- Crossword/Parsers/GetNumBytes.cs | 15 --- Crossword/Parsers/GetPuzzleIdAndType.cs | 18 ---- Crossword/Parsers/ParseCrosswordData.cs | 82 ---------------- 17 files changed, 622 deletions(-) delete mode 100644 Crossword/Constants/GameConstants.cs delete mode 100644 Crossword/Constants/UIConstants.cs delete mode 100644 Crossword/Entities/CrosswordData.cs delete mode 100644 Crossword/Entities/CrosswordState.cs delete mode 100644 Crossword/FetchData/CallDataApiAsync.cs delete mode 100644 Crossword/FetchData/GetCrosswordDataAsync.cs delete mode 100644 Crossword/Parsers/GetAnswers.cs delete mode 100644 Crossword/Parsers/GetBlurb.cs delete mode 100644 Crossword/Parsers/GetClues.cs delete mode 100644 Crossword/Parsers/GetColsAndRows.cs delete mode 100644 Crossword/Parsers/GetCybersilver.cs delete mode 100644 Crossword/Parsers/GetGridPositions.cs delete mode 100644 Crossword/Parsers/GetHintLetters.cs delete mode 100644 Crossword/Parsers/GetNumBytes.cs delete mode 100644 Crossword/Parsers/GetPuzzleIdAndType.cs delete mode 100644 Crossword/Parsers/ParseCrosswordData.cs diff --git a/Crossword/Constants/GameConstants.cs b/Crossword/Constants/GameConstants.cs deleted file mode 100644 index 7030354..0000000 --- a/Crossword/Constants/GameConstants.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -// //////////////////////////////////////////////////////////////////////////// -// // // -// // Module: GameConstants.cs // -// // Authors: Aaron Saikovski // -// // Date: 31/10/202 // -// // Version: 1.0 // -// // Purpose: Global constants. // -// // // -// //////////////////////////////////////////////////////////////////////////// -// -// -// namespace Crossword.Constants; -// -// /// -// /// Game Constants -// /// -// public sealed class GameConstants -// { -// //default puzzledata for testing -// //public const string DefaultPuzzleData = "505*JX000000*0707*0 0 1 1#0 2 1 4#0 3 1 7#4 3 1 8#1 4 1 10#0 6 1 11#0 0 2 1#2 0 2 2#5 0 2 3#1 2 2 5#4 2 2 6#6 3 2 9*Try#Writing surface#Night bird#Truck#Opposite of male#Nearest#Car#Piece of furniture#Part of a flower#Terrible#Avoid#Unscramble XNET*ATTEMPT#TABLET#OWL#VAN#FEMALE#CLOSEST#AUTO#TABLE#PETAL#AWFUL#EVADE#NEXT*ABCDEFLMNOPSTUVWX*30 1 1 0 1 5*Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!"; -// public const string? DefaultPuzzleData = "761*QX000001*0909*0 0 1 1#4 1 1 6#0 2 1 7#2 3 1 9#0 5 1 11#4 6 1 16#0 7 1 17#4 8 1 18#0 0 2 1#2 0 2 2#4 0 2 3#6 0 2 4#8 0 2 5#3 2 2 8#5 3 2 10#0 5 2 11#2 5 2 12#4 5 2 13#6 5 2 14#8 5 2 15*Forward#Strictly accurate#Australian marsupial#Moving to avoid#Not accepted conduct#Astonish greatly#Provide meals#Occurrence#Pretend#Public way#Beer froth#Full-length dress#Adult male deer#Crazy#Metric unit of mass#Skin irritation#Friend#Uncommon#Inland body of water#Bench*FORTH#EXACT#KOALA#DODGING#IMMORAL#AMAZE#CATER#EVENT#FAKE#ROAD#HEAD#MAXI#STAG#LOCO#GRAM#ITCH#MATE#RARE#LAKE#SEAT*ZCDEFGHIKLMNORSTVXA*30 1 1 0 1 5*Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!"; -// -// -// //Credits string -// public const string? CreditsText = "**CREDITS**\n" + -// "Original Authors: Bryan Richards & Aaron Saikovski\n" + -// "Original date: 24th March 1997\n" + -// "Description: A Monogame and .Net 8 Core port of the original OzEmail Cyberpuzzles Java based crossword Applet.\n" + -// "Dedicated to Neil Reading (neilski) RIP."; -// -// //game title string -// public const string GameTitle = "CyberPuzzles Crossword v1.0.2"; -// } -// -// -// diff --git a/Crossword/Constants/UIConstants.cs b/Crossword/Constants/UIConstants.cs deleted file mode 100644 index ad84870..0000000 --- a/Crossword/Constants/UIConstants.cs +++ /dev/null @@ -1,99 +0,0 @@ -// -// -// using Color = Microsoft.Xna.Framework.Color; -// -// namespace Crossword.Constants; -// -// /// -// /// UI Constants -// /// -// public sealed class UIConstants -// { -// -// //Crossword dimension constants -// public const int CrosswordWindowHeight = 600; -// public const int CrosswordWindowWidth = 800; -// -// //Square width and height constants -// public const int SquareWidth = 40; -// public const int SquareHeight = 40; -// public const float SquareSpacer = 1.5f; -// -// //Highlight Constants -// public const int CurrentLetter = 1; -// public const int CurrentWord = 2; -// public const int CurrentNone = 3; -// -// -// //Font sizes -// public const int FntSml = 9; -// public const int FntMed = 15; -// public const int FntLge = 20; -// public const int FntCredits = 13; -// -// -// -// //main game offsets -// public const int MainOffsetX = 30; -// public const int MainOffsetY = 30; -// -// -// //Small number offset -// public const float SmlNumOffsetX = 1.8f; -// public const float SmlNumOffsetY = 1.7f; -// -// -// //Square char offset -// public const float SqCharOffsetX = 12.5f; -// public const float SqCharOffsetY = 12f; -// -// //ClueList offsets/sizes -// public const int ClLabelHeight = 20; -// public const int ClListboxHeight = 180; -// public const int ClListSpacer = 5; -// -// //Colors for square letters -// public static Color SqCorrect = Color.Green; -// public static Color SqError = Color.Black; -// -// //Puzzle tile images -// public const string BlackSquare = "images/tile_black"; -// public const string HighliteSquare = "images/tile_yellow"; -// public const string SquareWord = "images/tile_orange"; -// public const string NormalSquare = "images/tile_grey"; -// -// //Link Buttons -// public const string HintButtonImage = "images/btn_get_hint"; -// public const string NextPuzzleButtonImage = "images/btn_next_puzzle"; -// -// -// //Fonts -// public const string HelveticaBold = "content/fonts/Helvetica-Bold.ttf"; -// public const string HelveticaPlain = "content/fonts/Helvetica.ttf"; -// -// -// //Score color -// public static Color ScoreColor = Color.Red; -// -// //Credits Colo -// public static Color CreditsColor = Color.Black; -// -// //Button colours -// public static Color ButtonTextColor = Color.White; -// public static Color ButtonHoverTextColor = Color.Yellow; -// -// -// //Listbox text colors -// public static Color ListBoxTextColor = Color.Black; -// -// //Square highlight colors -// public static Color SquareHighlightCurrent = Color.Cyan; -// public static Color SquareHighlightWord = Color.Yellow; -// public static Color SquareHighlightNone = Color.White; -// public static Color SquareHighlightErr = Color.Red; -// public static Color SquareHighlightDefault = Color.Black; -// -// //Font colors -// public static Color SmallFontColor = Color.Black; -// -// } \ No newline at end of file diff --git a/Crossword/Crossword.csproj b/Crossword/Crossword.csproj index 31d7f2c..5dbaf01 100644 --- a/Crossword/Crossword.csproj +++ b/Crossword/Crossword.csproj @@ -65,9 +65,6 @@ - - - PreserveNewest diff --git a/Crossword/Entities/CrosswordData.cs b/Crossword/Entities/CrosswordData.cs deleted file mode 100644 index 44b8dda..0000000 --- a/Crossword/Entities/CrosswordData.cs +++ /dev/null @@ -1,43 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////////// -// // // -// // Module: CrosswordData.cs // -// // Authors: Aaron Saikovski & Bryan Richards // -// // Date: 23/01/97 // -// // Version: 1.0 // -// // Purpose: Utilizes a String Tokenizer to parse the crossword // -// // puzzle components from a data set string. // -// // // -// ////////////////////////////////////////////////////////////////////////////// -// -// -// namespace Crossword.Entities; -// -// public sealed class CrosswordData -// { -// #region Fields -// -// //Instance variables for holding parsed QuickCrossword data -// public string? PuzzleType { get; set; } -// public int NumCols { get; set; } -// public int NumRows { get; set; } -// public int NumAcross { get; set; } -// public int NumDown { get; set; } -// public int PuzzleId { get; set; } -// public int[]? ColRef { get; set; } -// public int[]? RowRef { get; set; } -// public int[]? IsAcross { get; set; } -// public int[]? QuesNum { get; set; } -// public string[]? Clues { get; set; } -// public string[]? Answers { get; set; } -// -// public int[]? Costs { get; set; } -// -// public string? GetLetters { get; set; } -// public string? Blurb { get; set; } -// public int NumQuestions { get; set; } -// -// public int NumBytes { get; set; } -// -// #endregion -// -// } \ No newline at end of file diff --git a/Crossword/Entities/CrosswordState.cs b/Crossword/Entities/CrosswordState.cs deleted file mode 100644 index a720696..0000000 --- a/Crossword/Entities/CrosswordState.cs +++ /dev/null @@ -1,27 +0,0 @@ -// namespace Crossword.Entities; -// -// /// -// /// CrosswordMain dataset to map clues to answers. -// /// -// /// -// /// constructor -// /// -// /// -// /// -// /// -// /// -// /// -// /// -// public sealed class CrosswordState(int coordAcross, int coordDown, string answer, string clue, bool isAcross, int questionNum) -// { -// #region getters_setters -// -// public int CoordAcross { get;} = coordAcross; -// public int CoordDown { get; } = coordDown; -// public string Answer { get; } = answer; -// public string Clue { get; } = clue; -// public bool IsAcross { get; } = isAcross; -// public int QuestionNum { get; } = questionNum; -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/FetchData/CallDataApiAsync.cs b/Crossword/FetchData/CallDataApiAsync.cs deleted file mode 100644 index f87db1e..0000000 --- a/Crossword/FetchData/CallDataApiAsync.cs +++ /dev/null @@ -1,75 +0,0 @@ -// using System; -// using System.Net.Http; -// using System.Threading.Tasks; -// using Crossword.Shared.Config; -// using Crossword.Shared.Logger; -// using Crossword.Shared.Constants; -// namespace Crossword.FetchData; -// -// /// -// /// Fetches data from the Data API -// /// -// public partial class FetchCrosswordData -// { -// #region CallDataApiAsync -// -// /// -// /// CallDataApiAsync -// /// -// /// -// private static async Task CallDataApiAsync() -// { -// //Init the logger and get the active config -// var logger = new SerilogLogger(ConfigurationHelper.ActiveConfiguration); -// -// //Use the HttpClient -// using var client = new HttpClient(); -// try -// { -// logger.LogInformation("Start CallDataApiAsync()"); -// -// //get config values from the appsettings -// var apiUrl = ConfigurationHelper.DataApiUrl; -// var apiKey = ConfigurationHelper.DataApiKey; -// -// //pass in the API key to the header -// client.DefaultRequestHeaders.Clear(); -// client.DefaultRequestHeaders.Add(ApiConstants.ApiKeyName, apiKey); -// -// //catch inner HttpRequestException -// try -// { -// var response = await client.GetAsync(apiUrl); -// -// //check for errors...response codes etc -// if (response.IsSuccessStatusCode) -// { -// //get the response from the API call result as a string -// return response.Content.ReadAsStringAsync().Result; -// } -// else -// { -// throw new Exception($"Failed to call the API. Status code: {response.StatusCode}"); -// } -// -// } -// //catch http request exception -// catch (HttpRequestException httpex) -// { -// logger.LogError(httpex, httpex.Message); -// throw; -// } -// } -// catch (Exception ex) -// { -// logger.LogError(ex, ex.Message); -// return string.Empty; -// } -// finally -// { -// logger.Dispose(); -// } -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/FetchData/GetCrosswordDataAsync.cs b/Crossword/FetchData/GetCrosswordDataAsync.cs deleted file mode 100644 index 9cc69c3..0000000 --- a/Crossword/FetchData/GetCrosswordDataAsync.cs +++ /dev/null @@ -1,46 +0,0 @@ -// using System; -// using System.Threading.Tasks; -// using Crossword.Shared.Constants; -// using Crossword.Shared.Logger; -// using Crossword.Shared.Config; -// -// namespace Crossword.FetchData; -// -// -// public partial class FetchCrosswordData -// { -// #region GetCrosswordDataAsync -// -// /// -// /// GetCrosswordDataAsync -// /// -// /// -// public static async Task GetCrosswordDataAsync() -// { -// //Init the logger and get the active config -// var logger = new SerilogLogger(ConfigurationHelper.ActiveConfiguration); -// -// //Call the API to get the puzzledata....otherwise use default values -// try -// { -// logger.LogInformation("Start GetCrosswordDataAsync()"); -// -// //call the API -// var apiResponse = await CallDataApiAsync(); -// -// //check what was returned -// return string.IsNullOrEmpty(apiResponse) ? GameConstants.DefaultPuzzleData : apiResponse; -// } -// catch (Exception ex) -// { -// logger.LogError(ex, ex.Message); -// throw; -// } -// finally -// { -// logger.Dispose(); -// } -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/Parsers/GetAnswers.cs b/Crossword/Parsers/GetAnswers.cs deleted file mode 100644 index c8992af..0000000 --- a/Crossword/Parsers/GetAnswers.cs +++ /dev/null @@ -1,24 +0,0 @@ -// using System.Collections.Generic; -// -// namespace Crossword.Parsers; -// -// public sealed partial class CrosswordParser -// { -// #region -// /// -// /// GetAnswers -// /// -// /// -// private void GetAnswers(IReadOnlyList strData) -// { -// var puzzletempstr = strData[5]; -// var answertemp = puzzletempstr.Split("#"); -// if (_crosswordData == null) return; -// _crosswordData.Answers = new string[_crosswordData.NumQuestions]; -// for (var k = 0; k < _crosswordData.NumQuestions; k++) -// { -// _crosswordData.Answers[k] = answertemp[k]; -// } -// } -// #endregion -// } \ No newline at end of file diff --git a/Crossword/Parsers/GetBlurb.cs b/Crossword/Parsers/GetBlurb.cs deleted file mode 100644 index 7b126ad..0000000 --- a/Crossword/Parsers/GetBlurb.cs +++ /dev/null @@ -1,15 +0,0 @@ -// using System.Collections.Generic; -// -// namespace Crossword.Parsers; -// -// public sealed partial class CrosswordParser -// { -// /// -// /// GetBlurb -// /// -// /// -// private void GetBlurb(IReadOnlyList strData) -// { -// if (_crosswordData != null) _crosswordData.Blurb = strData[8]; -// } -// } \ No newline at end of file diff --git a/Crossword/Parsers/GetClues.cs b/Crossword/Parsers/GetClues.cs deleted file mode 100644 index ffed159..0000000 --- a/Crossword/Parsers/GetClues.cs +++ /dev/null @@ -1,32 +0,0 @@ -// using System.Collections.Generic; -// -// namespace Crossword.Parsers; -// -// public sealed partial class CrosswordParser -// { -// /// -// /// GetClues -// /// -// /// -// private void GetClues(IReadOnlyList strData) -// { -// var puzzletempstr = strData[4]; -// string[] cluetemp = puzzletempstr.Split("#"); -// if (_crosswordData == null) return; -// _crosswordData.Clues = new string[_crosswordData.NumQuestions]; -// for (var j = 0; j < _crosswordData.NumQuestions; j++) -// { -// _crosswordData.Clues[j] = cluetemp[j]; -// } -// -// // string[] cluetemp; -// // var puzzletempstr = strData[4]; -// // cluetemp = puzzletempstr.Split("#"); -// // if (_crosswordData == null) return; -// // _crosswordData.Clues = new string[_crosswordData.NumQuestions]; -// // for (var j = 0; j < _crosswordData.NumQuestions; j++) -// // { -// // _crosswordData.Clues[j] = cluetemp[j]; -// // } -// } -// } \ No newline at end of file diff --git a/Crossword/Parsers/GetColsAndRows.cs b/Crossword/Parsers/GetColsAndRows.cs deleted file mode 100644 index 8a44e04..0000000 --- a/Crossword/Parsers/GetColsAndRows.cs +++ /dev/null @@ -1,18 +0,0 @@ -// using System.Collections.Generic; -// -// namespace Crossword.Parsers; -// -// public sealed partial class CrosswordParser -// { -// /// -// /// GetColsAndRows -// /// -// /// -// private void GetColsAndRows(IReadOnlyList strData) -// { -// var puzzleTempStr = strData[2]; -// if (_crosswordData == null) return; -// _crosswordData.NumCols = int.Parse(puzzleTempStr[..2]); -// _crosswordData.NumRows = int.Parse(puzzleTempStr[2..]); -// } -// } \ No newline at end of file diff --git a/Crossword/Parsers/GetCybersilver.cs b/Crossword/Parsers/GetCybersilver.cs deleted file mode 100644 index 12a246c..0000000 --- a/Crossword/Parsers/GetCybersilver.cs +++ /dev/null @@ -1,21 +0,0 @@ -// using System.Collections.Generic; -// -// namespace Crossword.Parsers; -// -// public sealed partial class CrosswordParser -// { -// /// -// /// GetCybersilver -// /// -// /// -// private void GetCybersilver(IReadOnlyList strData) -// { -// var puzzletempstr = strData[7]; -// var costTemp = puzzletempstr.Split(" "); -// -// for (var loopIdx = 0; loopIdx < 6; loopIdx++) -// { -// if (_crosswordData is { Costs: not null }) _crosswordData.Costs[loopIdx] = int.Parse(costTemp[loopIdx]); -// } -// } -// } \ No newline at end of file diff --git a/Crossword/Parsers/GetGridPositions.cs b/Crossword/Parsers/GetGridPositions.cs deleted file mode 100644 index ce898dc..0000000 --- a/Crossword/Parsers/GetGridPositions.cs +++ /dev/null @@ -1,52 +0,0 @@ -// -// -// using System.Collections.Generic; -// using Crossword.Shared.ParserUtils; -// -// namespace Crossword.Parsers; -// -// public sealed partial class CrosswordParser -// { -// /// -// /// GetGridPositions -// /// -// /// -// private void GetGridPositions(IReadOnlyList strData) -// { -// var puzzleTempStr = strData[3]; -// if (_crosswordData == null) return; -// _crosswordData.NumQuestions = ParserHelper.CountOccurrences(puzzleTempStr, '#'); -// _crosswordData.ColRef = new int[_crosswordData.NumQuestions]; -// _crosswordData.RowRef = new int[_crosswordData.NumQuestions]; -// _crosswordData.IsAcross = new int[_crosswordData.NumQuestions]; -// _crosswordData.QuesNum = new int[_crosswordData.NumQuestions]; -// -// //split string -// var gridPosTmp = puzzleTempStr.Split('#'); -// -// for (var tokIdx = 0; tokIdx < _crosswordData.NumQuestions; tokIdx++) -// { -// var subGridDataTemp = gridPosTmp[tokIdx].Split(" "); -// -// for (var i = 0; i < 4; i++) -// { -// switch (i) -// { -// case 0: -// _crosswordData.ColRef[tokIdx] = int.Parse(subGridDataTemp[0]); -// break; -// -// case 1: -// _crosswordData.RowRef[tokIdx] = int.Parse(subGridDataTemp[1]); -// break; -// case 2: -// _crosswordData.IsAcross[tokIdx] = int.Parse(subGridDataTemp[2]); -// break; -// case 3: -// _crosswordData.QuesNum[tokIdx] = int.Parse(subGridDataTemp[3]); -// break; -// } -// } -// } -// } -// } \ No newline at end of file diff --git a/Crossword/Parsers/GetHintLetters.cs b/Crossword/Parsers/GetHintLetters.cs deleted file mode 100644 index bc0a4d0..0000000 --- a/Crossword/Parsers/GetHintLetters.cs +++ /dev/null @@ -1,15 +0,0 @@ -// using System.Collections.Generic; -// -// namespace Crossword.Parsers; -// -// public sealed partial class CrosswordParser -// { -// /// -// /// GetHintLetters -// /// -// /// -// private void GetHintLetters(IReadOnlyList strData) -// { -// if (_crosswordData != null) _crosswordData.GetLetters = strData[6]; -// } -// } \ No newline at end of file diff --git a/Crossword/Parsers/GetNumBytes.cs b/Crossword/Parsers/GetNumBytes.cs deleted file mode 100644 index 671fa1e..0000000 --- a/Crossword/Parsers/GetNumBytes.cs +++ /dev/null @@ -1,15 +0,0 @@ -// using System.Collections.Generic; -// -// namespace Crossword.Parsers; -// -// public sealed partial class CrosswordParser -// { -// /// -// /// GetNumBytes -// /// -// /// -// private void GetNumBytes(IReadOnlyList strData) -// { -// if (_crosswordData != null) _crosswordData.NumBytes = int.Parse(strData[0]); -// } -// } \ No newline at end of file diff --git a/Crossword/Parsers/GetPuzzleIdAndType.cs b/Crossword/Parsers/GetPuzzleIdAndType.cs deleted file mode 100644 index d6be2c1..0000000 --- a/Crossword/Parsers/GetPuzzleIdAndType.cs +++ /dev/null @@ -1,18 +0,0 @@ -// using System.Collections.Generic; -// -// namespace Crossword.Parsers; -// -// public sealed partial class CrosswordParser -// { -// /// -// /// GetPuzzleIdAndType -// /// -// /// -// private void GetPuzzleIdAndType(IReadOnlyList strData) -// { -// var puzzletempstr = strData[1]; -// if (_crosswordData == null) return; -// _crosswordData.PuzzleId = int.Parse(puzzletempstr[2..]); -// _crosswordData.PuzzleType = puzzletempstr[..2]; -// } -// } \ No newline at end of file diff --git a/Crossword/Parsers/ParseCrosswordData.cs b/Crossword/Parsers/ParseCrosswordData.cs deleted file mode 100644 index 2e5478e..0000000 --- a/Crossword/Parsers/ParseCrosswordData.cs +++ /dev/null @@ -1,82 +0,0 @@ -// using System; -// using Crossword.Entities; -// namespace Crossword.Parsers; -// -// public sealed partial class CrosswordParser -// { -// //init the crossword data class -// private CrosswordData? _crosswordData; -// -// /// -// /// // Main - used to parse QuickCrossword data set from string -// /// // Pre : szParseData is NOT null -// /// // Post : Returns true if data has been successfully parsed from String and false otherwise -// /// -// /// -// /// -// public CrosswordData? ParsePuzzleData(string puzzleData) -// { -// ArgumentNullException.ThrowIfNull(puzzleData); -// -// //init the CrosswordData object -// _crosswordData = new CrosswordData(); -// -// //local vars -// var strData = puzzleData.Split("*"); -// -// //Loop over for each of the tokens -// for (var tokenIdx = 0; tokenIdx < strData.Length; tokenIdx++) -// { -// switch (tokenIdx) -// { -// //Eat the first String - number of bytes in data set - eg. "1075" -// case 0: -// GetNumBytes(strData); -// break; -// -// //Puzzle ID - eg. "QXW000000" -// case 1: -// GetPuzzleIdAndType(strData); -// break; -// -// //Number of Columns and Rows - eg. "0909" -// case 2: -// GetColsAndRows(strData); -// break; -// -// //Grid positions and Data for across and down numbers - eg. "0 0 1 1#6 0 1 4#3 2 1 6#0 3 1 8#3 5 1 11#0 6 1 13#0 8 1 15#4 8 1 16#1 0 2 2#4 0 2 3#6 0 2 4#8 0 2 5#3 2 2 6#5 2 2 7#7 4 2 9#0 5 2 10#4 5 2 12#2 6 2 14" -// case 3: -// GetGridPositions(strData); -// break; -// -// //Clues - eg. "Bread maker#Skill#Receive#Calm#Real#Taunts#Apple _ _ _#Midday meal#Irritate#Wealthy#Queen,King,__ __ __#Ballet skirt#Book of maps#100 make a dollar#Conjuring#Cease#Prison room#Length of life" -// case 4: -// GetClues(strData); -// break; -// -// //Answers - eg BAKER#ART#ACCEPT#SOOTHE#ACTUAL#TEASES#PIE#LUNCH#ANNOY#RICH#ACE#TUTU#ATLAS#CENTS#MAGIC#STOP#CELL#AGE -// case 5: -// GetAnswers(strData); -// break; -// -// //Hint letters - eg "ABCEGHIKLMNOPRSTUY" -// case 6: -// GetHintLetters(strData); -// break; -// -// //CyberSilver level costs & bonuses - eg. "30 1 1 0 1 5" -// case 7: -// GetCybersilver(strData); -// break; -// -// //Jim's crappy blurb - eg. "Use the clues to solve this crossword and earn CyberSilver. If you have not played our crosswords before and want help, then click the HELP button. Have fun!" -// case 8: -// GetBlurb(strData); -// break; -// } -// } -// -// //return the crossword data object -// return _crosswordData; -// } -// } \ No newline at end of file From d2e6b4eae072f257f43aea8f11c7f588287e14ff Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 10:47:38 +1100 Subject: [PATCH 10/26] minor refactor --- Crossword.ClueAnswer/CheckHint.cs | 47 +++++++++++++++ Crossword.ClueAnswer/CheckWord.cs | 27 +++++++++ Crossword.ClueAnswer/ClueAnswerMap.cs | 31 ++++++++++ .../Crossword.ClueAnswer.csproj | 13 +++++ Crossword.ClueAnswer/GetNextSq.cs | 39 +++++++++++++ Crossword.ClueAnswer/GetPrevSq.cs | 31 ++++++++++ Crossword.ClueAnswer/GetSquare.cs | 19 +++++++ Crossword.ClueAnswer/HighlightSquares.cs | 50 ++++++++++++++++ Crossword.ClueAnswer/IsCorrect.cs | 21 +++++++ Crossword.ClueAnswer/SetObjectRef.cs | 57 +++++++++++++++++++ Crossword.Net.sln | 12 ++++ Crossword.Square/CanFlipDirection.cs | 26 +++++++++ Crossword.Square/CheckLetter.cs | 21 +++++++ Crossword.Square/CreateSquare.cs | 19 +++++++ Crossword.Square/Crossword.Square.csproj | 14 +++++ Crossword.Square/GetClueAnswerRef.cs | 20 +++++++ Crossword.Square/GetNextSq.cs | 24 ++++++++ Crossword.Square/GetPrevSq.cs | 20 +++++++ Crossword.Square/SetHighlighted.cs | 55 ++++++++++++++++++ Crossword.Square/SetLetter.cs | 22 +++++++ Crossword.Square/SetObjectRef.cs | 31 ++++++++++ Crossword.Square/Square.cs | 41 +++++++++++++ Crossword/{App => }/UI/DrawCreditsLabel.cs | 0 Crossword/{App => }/UI/DrawCrossword.cs | 0 Crossword/{App => }/UI/DrawCrosswordScore.cs | 0 .../{App => }/UI/DrawGetNextPuzzleButton.cs | 0 Crossword/{App => }/UI/DrawHintButton.cs | 0 Crossword/{App => }/UI/LoadAssets.cs | 0 Crossword/{App => }/UI/PuzzleButton.cs | 0 .../{App => }/UI/UpdateCrosswordScore.cs | 0 .../{App => }/handlers/ButtonHandlers.cs | 0 Crossword/{App => }/handlers/KeyDown.cs | 0 .../{App => }/handlers/ListBoxHandlers.cs | 0 Crossword/{App => }/handlers/MouseHandlers.cs | 0 Crossword/{App => }/handlers/NavigateList.cs | 0 Crossword/{App => }/hint/GetUserHint.cs | 0 Crossword/{App => }/hint/QuickSolver.cs | 0 Crossword/{App => }/init/InitArrays.cs | 0 Crossword/{App => }/init/InitClueAnswers.cs | 0 Crossword/{App => }/init/InitControls.cs | 0 Crossword/{App => }/init/InitData.cs | 0 Crossword/{App => }/init/InitDirtySquares.cs | 0 Crossword/{App => }/init/InitListBoxes.cs | 0 Crossword/{App => }/init/InitNextPuzzle.cs | 0 Crossword/{App => }/init/InitPuzzleData.cs | 5 +- .../{App => }/init/InitialiseCrossword.cs | 0 Crossword/{App => }/main/CrosswordMain.cs | 0 Crossword/{App => }/main/MainInit.cs | 0 Crossword/{App => }/monogame/Monogame.cs | 0 .../{App => }/navigation/NavigatePuzzle.cs | 0 50 files changed, 641 insertions(+), 4 deletions(-) create mode 100644 Crossword.ClueAnswer/CheckHint.cs create mode 100644 Crossword.ClueAnswer/CheckWord.cs create mode 100644 Crossword.ClueAnswer/ClueAnswerMap.cs create mode 100644 Crossword.ClueAnswer/Crossword.ClueAnswer.csproj create mode 100644 Crossword.ClueAnswer/GetNextSq.cs create mode 100644 Crossword.ClueAnswer/GetPrevSq.cs create mode 100644 Crossword.ClueAnswer/GetSquare.cs create mode 100644 Crossword.ClueAnswer/HighlightSquares.cs create mode 100644 Crossword.ClueAnswer/IsCorrect.cs create mode 100644 Crossword.ClueAnswer/SetObjectRef.cs create mode 100644 Crossword.Square/CanFlipDirection.cs create mode 100644 Crossword.Square/CheckLetter.cs create mode 100644 Crossword.Square/CreateSquare.cs create mode 100644 Crossword.Square/Crossword.Square.csproj create mode 100644 Crossword.Square/GetClueAnswerRef.cs create mode 100644 Crossword.Square/GetNextSq.cs create mode 100644 Crossword.Square/GetPrevSq.cs create mode 100644 Crossword.Square/SetHighlighted.cs create mode 100644 Crossword.Square/SetLetter.cs create mode 100644 Crossword.Square/SetObjectRef.cs create mode 100644 Crossword.Square/Square.cs rename Crossword/{App => }/UI/DrawCreditsLabel.cs (100%) rename Crossword/{App => }/UI/DrawCrossword.cs (100%) rename Crossword/{App => }/UI/DrawCrosswordScore.cs (100%) rename Crossword/{App => }/UI/DrawGetNextPuzzleButton.cs (100%) rename Crossword/{App => }/UI/DrawHintButton.cs (100%) rename Crossword/{App => }/UI/LoadAssets.cs (100%) rename Crossword/{App => }/UI/PuzzleButton.cs (100%) rename Crossword/{App => }/UI/UpdateCrosswordScore.cs (100%) rename Crossword/{App => }/handlers/ButtonHandlers.cs (100%) rename Crossword/{App => }/handlers/KeyDown.cs (100%) rename Crossword/{App => }/handlers/ListBoxHandlers.cs (100%) rename Crossword/{App => }/handlers/MouseHandlers.cs (100%) rename Crossword/{App => }/handlers/NavigateList.cs (100%) rename Crossword/{App => }/hint/GetUserHint.cs (100%) rename Crossword/{App => }/hint/QuickSolver.cs (100%) rename Crossword/{App => }/init/InitArrays.cs (100%) rename Crossword/{App => }/init/InitClueAnswers.cs (100%) rename Crossword/{App => }/init/InitControls.cs (100%) rename Crossword/{App => }/init/InitData.cs (100%) rename Crossword/{App => }/init/InitDirtySquares.cs (100%) rename Crossword/{App => }/init/InitListBoxes.cs (100%) rename Crossword/{App => }/init/InitNextPuzzle.cs (100%) rename Crossword/{App => }/init/InitPuzzleData.cs (95%) rename Crossword/{App => }/init/InitialiseCrossword.cs (100%) rename Crossword/{App => }/main/CrosswordMain.cs (100%) rename Crossword/{App => }/main/MainInit.cs (100%) rename Crossword/{App => }/monogame/Monogame.cs (100%) rename Crossword/{App => }/navigation/NavigatePuzzle.cs (100%) diff --git a/Crossword.ClueAnswer/CheckHint.cs b/Crossword.ClueAnswer/CheckHint.cs new file mode 100644 index 0000000..b6fab86 --- /dev/null +++ b/Crossword.ClueAnswer/CheckHint.cs @@ -0,0 +1,47 @@ +using System; +using System.Threading.Tasks; + +namespace Crossword.ClueAnswer; + +public sealed partial class ClueAnswer +{ + #region CheckHint + + /// + /// Sets the Hint letter if Get Letter is pressed + /// + /// + /// + public bool CheckHint(char hintLetter) + { + if (hintLetter <= 0) throw new ArgumentOutOfRangeException(nameof(hintLetter)); + + var foundResult = false; + + // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere + if (Answer is null) return foundResult; + var szAnswerLength = Answer.Length; + + + for (var i = 0; i < Answer.Length; i++) + { + if (SqAnswerSquares is null || Answer[i] != hintLetter || + SqAnswerSquares[i]!.Letter == hintLetter) break; + SqAnswerSquares[i]?.SetLetter(hintLetter, IsAcross); + foundResult = true; + + } + //Parallel for loop + // Parallel.For(0, szAnswerLength, i => + // { + // if (SqAnswerSquares is null || Answer[i] != hintLetter || + // SqAnswerSquares[i]!.Letter == hintLetter) return; + // SqAnswerSquares[i]?.SetLetter(hintLetter, IsAcross); + // foundResult = true; + // }); + + return foundResult; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.ClueAnswer/CheckWord.cs b/Crossword.ClueAnswer/CheckWord.cs new file mode 100644 index 0000000..766aa71 --- /dev/null +++ b/Crossword.ClueAnswer/CheckWord.cs @@ -0,0 +1,27 @@ +using System.Threading.Tasks; + +namespace Crossword.ClueAnswer; + +public sealed partial class ClueAnswer +{ + #region CheckWord + + /// + /// Sets the letter colour if Check words is pressed. + /// + public void CheckWord() + { + if (Answer is null) return; + for (var i = 0; i < Answer.Length; i++) + { + SqAnswerSquares?[i]?.CheckLetter(Answer[i]); + } + + // Parallel.For(0, Answer.Length, i => + // { + // SqAnswerSquares?[i]?.CheckLetter(Answer[i]); + // }); + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.ClueAnswer/ClueAnswerMap.cs b/Crossword.ClueAnswer/ClueAnswerMap.cs new file mode 100644 index 0000000..fa007fa --- /dev/null +++ b/Crossword.ClueAnswer/ClueAnswerMap.cs @@ -0,0 +1,31 @@ +//////////////////////////////////////////////////////////////////////////// +// // +// Module: ClueAnswerMap.cs // +// Authors: Aaron Saikovski & Bryan Richards // +// Original Date: 26/02/97 // +// Version: 1.0 // +// Purpose: Clue + Answer references class // +// // +//////////////////////////////////////////////////////////////////////////// + +using Crossword.PuzzleSquares; + +namespace Crossword.ClueAnswer; + +/// +/// ClueAnswerMap Class +/// +public sealed partial class ClueAnswer +{ + #region getters_setters + public string? Answer { get; set; } + public string? Clue { get; set; } + + public int QuestionNumber { get; set; } + + public bool IsAcross { get; set; } = true; + + public Square?[]? SqAnswerSquares { get; set; } + + #endregion +} \ No newline at end of file diff --git a/Crossword.ClueAnswer/Crossword.ClueAnswer.csproj b/Crossword.ClueAnswer/Crossword.ClueAnswer.csproj new file mode 100644 index 0000000..cdf9794 --- /dev/null +++ b/Crossword.ClueAnswer/Crossword.ClueAnswer.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Crossword.ClueAnswer/GetNextSq.cs b/Crossword.ClueAnswer/GetNextSq.cs new file mode 100644 index 0000000..79ba5c4 --- /dev/null +++ b/Crossword.ClueAnswer/GetNextSq.cs @@ -0,0 +1,39 @@ +using System; +using Crossword.PuzzleSquares; + +namespace Crossword.ClueAnswer; + +public sealed partial class ClueAnswer +{ + #region GetNextSq + + /// + /// Returns the next square + /// + /// + /// + public Square? GetNextSq(Square? sq) + { + ArgumentNullException.ThrowIfNull(sq); + var i = 0; + while (Answer != null && i < Answer.Length){ + if (SqAnswerSquares != null && sq == SqAnswerSquares[i]) + if (i < Answer.Length - 1) + return SqAnswerSquares[i + 1]; + i++; + } + return sq; + + // ArgumentNullException.ThrowIfNull(sq); + // var i = 0; + // while (i < Answer.Length){ + // if (sq == SqAnswerSquares[i]) + // if (i < Answer.Length - 1) + // return SqAnswerSquares[i + 1]; + // i++; + // } + // return sq; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.ClueAnswer/GetPrevSq.cs b/Crossword.ClueAnswer/GetPrevSq.cs new file mode 100644 index 0000000..cfd6501 --- /dev/null +++ b/Crossword.ClueAnswer/GetPrevSq.cs @@ -0,0 +1,31 @@ +using System; +using Crossword.PuzzleSquares; + +namespace Crossword.ClueAnswer; + +public sealed partial class ClueAnswer +{ + #region GetPrevSq + + /// + /// Returns the previous square + /// + /// + /// + public Square? GetPrevSq(Square? sq) + { + ArgumentNullException.ThrowIfNull(sq); + + if (Answer is null) return sq; + var i = Answer.Length - 1; + while (i > -1) + { + if (sq == SqAnswerSquares?[i]) return i != 0 ? SqAnswerSquares?[i - 1] : sq; + i--; + } + + return sq; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.ClueAnswer/GetSquare.cs b/Crossword.ClueAnswer/GetSquare.cs new file mode 100644 index 0000000..c2097fa --- /dev/null +++ b/Crossword.ClueAnswer/GetSquare.cs @@ -0,0 +1,19 @@ +using Crossword.PuzzleSquares; + +namespace Crossword.ClueAnswer; + +public sealed partial class ClueAnswer +{ + #region GetSquare + + /// + /// Gets the first square referenced by my answer. + /// + /// + public Square? GetSquare() + { + return SqAnswerSquares?[0]; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.ClueAnswer/HighlightSquares.cs b/Crossword.ClueAnswer/HighlightSquares.cs new file mode 100644 index 0000000..d172bf9 --- /dev/null +++ b/Crossword.ClueAnswer/HighlightSquares.cs @@ -0,0 +1,50 @@ +using System; +using System.Threading.Tasks; +using Crossword.PuzzleSquares; +using Crossword.Shared.Constants; + +namespace Crossword.ClueAnswer; + +public sealed partial class ClueAnswer +{ + #region HighlightSquares + + /// + /// /Highlights the current word and sets active square + /// + /// + /// + public void HighlightSquares(Square? sq, bool setHighLighted) + { + ArgumentNullException.ThrowIfNull(sq); + + if (Answer is null) return; + for (var i = 0; i < Answer.Length; i++) + { + if (!setHighLighted) + SqAnswerSquares?[i]?.SetHighlighted(CWSettings.CurrentNone); + else + { + SqAnswerSquares?[i] + ?.SetHighlighted(SqAnswerSquares?[i] == sq + ? CWSettings.CurrentLetter + : CWSettings.CurrentWord); + } + } + + // Parallel.For(0, Answer.Length, i => + // { + // if (!setHighLighted) + // SqAnswerSquares?[i]?.SetHighlighted(UIConstants.CurrentNone); + // else + // { + // SqAnswerSquares?[i] + // ?.SetHighlighted(SqAnswerSquares?[i] == sq + // ? UIConstants.CurrentLetter + // : UIConstants.CurrentWord); + // } + // }); + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.ClueAnswer/IsCorrect.cs b/Crossword.ClueAnswer/IsCorrect.cs new file mode 100644 index 0000000..89c148f --- /dev/null +++ b/Crossword.ClueAnswer/IsCorrect.cs @@ -0,0 +1,21 @@ +using System.Linq; + +namespace Crossword.ClueAnswer; + +public sealed partial class ClueAnswer +{ + #region IsCorrect + + /// + /// Returns true if all answer letters are correct and false otherwise + /// + /// + public bool IsCorrect() + { + if (Answer is not null) + return !Answer.Where((t, i) => SqAnswerSquares is not null && SqAnswerSquares[i]!.Letter != t).Any(); + return true; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.ClueAnswer/SetObjectRef.cs b/Crossword.ClueAnswer/SetObjectRef.cs new file mode 100644 index 0000000..7481607 --- /dev/null +++ b/Crossword.ClueAnswer/SetObjectRef.cs @@ -0,0 +1,57 @@ +using System; +using System.Threading.Tasks; +using Crossword.PuzzleSquares; + +namespace Crossword.ClueAnswer; + +public sealed partial class ClueAnswer +{ + #region SetObjectRef + + /// + /// Sets the object reference. + /// + /// + /// + /// + /// + /// + public void SetObjectRef(string Answer, string Clue, int QuestionNumber, + bool IsAcross, Square?[]? SqAnswerSquares) + { + ArgumentNullException.ThrowIfNull(Answer); + ArgumentNullException.ThrowIfNull(Clue); + ArgumentNullException.ThrowIfNull(SqAnswerSquares); + + this.Answer = Answer; + this.Clue = Clue; + this.QuestionNumber = QuestionNumber; + this.IsAcross = IsAcross; + + //Initialise the answer squares array. + this.SqAnswerSquares = new Square[Answer.Length]; + + //Copy the array + // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere + var szAnswerLength = Answer.Length; + + //Parallel for loop + Parallel.For(0, szAnswerLength, k => + { + // Create a new Square instance + var sqAnswerSquares = this.SqAnswerSquares; + if (sqAnswerSquares is not null) + { + sqAnswerSquares[k] = new Square(); + sqAnswerSquares[k]?.CreateSquare(0, 0); + sqAnswerSquares[k] = SqAnswerSquares[k]; + } + + // Assign the created Square to the array element + // The original code `this.sqAnswerSquares[k] = sqAnswerSquares[k];` seems redundant, so omitted + if (SqAnswerSquares is not null) SqAnswerSquares?[k]?.SetObjectRef(this.IsAcross, this); + }); + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Net.sln b/Crossword.Net.sln index 7ff4cc4..1fa17f1 100644 --- a/Crossword.Net.sln +++ b/Crossword.Net.sln @@ -12,6 +12,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crosssword.Entities", "Cros EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Data", "Crossword.Data\Crossword.Data.csproj", "{08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Square", "Crossword.Square\Crossword.Square.csproj", "{9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.ClueAnswer", "Crossword.ClueAnswer\Crossword.ClueAnswer.csproj", "{F0A08490-2940-4C75-A202-5C656872195A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -42,5 +46,13 @@ Global {08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}.Debug|Any CPU.Build.0 = Debug|Any CPU {08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}.Release|Any CPU.ActiveCfg = Release|Any CPU {08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}.Release|Any CPU.Build.0 = Release|Any CPU + {9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}.Release|Any CPU.Build.0 = Release|Any CPU + {F0A08490-2940-4C75-A202-5C656872195A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F0A08490-2940-4C75-A202-5C656872195A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F0A08490-2940-4C75-A202-5C656872195A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F0A08490-2940-4C75-A202-5C656872195A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Crossword.Square/CanFlipDirection.cs b/Crossword.Square/CanFlipDirection.cs new file mode 100644 index 0000000..4ffaffb --- /dev/null +++ b/Crossword.Square/CanFlipDirection.cs @@ -0,0 +1,26 @@ +namespace Crossword.Square; + +public sealed partial class Square +{ + #region CanFlipDirection + + /// + /// Can the current orientation be flipped. + /// + /// + /// + public bool CanFlipDirection(bool isAcross) + { + switch (isAcross) + { + //if square is an intersection + case true when ClueAnswerDown is not null: + case false when ClueAnswerAcross is not null: + return true; + default: + return false; + } + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Square/CheckLetter.cs b/Crossword.Square/CheckLetter.cs new file mode 100644 index 0000000..0dd4524 --- /dev/null +++ b/Crossword.Square/CheckLetter.cs @@ -0,0 +1,21 @@ +using Crossword.Shared.Constants; + +namespace Crossword.Square; + +public sealed partial class Square +{ + #region CheckLetter + + /// + /// Check for correctness of letter based on input char parameter and toggles colour accordingly + /// + /// + public void CheckLetter(char correctLetter) + { + if (Letter == ' ') return; + ForeColour = Letter == correctLetter ? UIConstants.SqCorrect : UIConstants.SqError; + IsDirty = true; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Square/CreateSquare.cs b/Crossword.Square/CreateSquare.cs new file mode 100644 index 0000000..e04be98 --- /dev/null +++ b/Crossword.Square/CreateSquare.cs @@ -0,0 +1,19 @@ +namespace Crossword.Square; + +public sealed partial class Square +{ + #region CreateSquare + + /// + /// Allocates memory for blank square + /// + /// + /// + public void CreateSquare(int xCoord, int yCoord) + { + this.xCoord = xCoord; + this.yCoord = yCoord; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Square/Crossword.Square.csproj b/Crossword.Square/Crossword.Square.csproj new file mode 100644 index 0000000..4dcc9f0 --- /dev/null +++ b/Crossword.Square/Crossword.Square.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + Crossword.Squares + + + + + + + diff --git a/Crossword.Square/GetClueAnswerRef.cs b/Crossword.Square/GetClueAnswerRef.cs new file mode 100644 index 0000000..5239ca4 --- /dev/null +++ b/Crossword.Square/GetClueAnswerRef.cs @@ -0,0 +1,20 @@ +using Crossword.ClueAnswerMap; + +namespace Crossword.Square; + +public sealed partial class Square +{ + #region GetClueAnswerRef + + /// + /// returns the Clue/Answer reference + /// + /// + /// + public ClueAnswer? GetClueAnswerRef(bool isAcross) + { + return isAcross ? ClueAnswerAcross : ClueAnswerDown; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Square/GetNextSq.cs b/Crossword.Square/GetNextSq.cs new file mode 100644 index 0000000..a5ae844 --- /dev/null +++ b/Crossword.Square/GetNextSq.cs @@ -0,0 +1,24 @@ +namespace Crossword.Square; + +public sealed partial class Square +{ + #region GetNextSq + + /// + /// Gets the next available square + /// + /// + /// + public Square? GetNextSq(bool isAcross) + { + if (isAcross) + { + return ClueAnswerAcross != null ? ClueAnswerAcross.GetNextSq(this) : this; + } + + return ClueAnswerDown != null ? ClueAnswerDown.GetNextSq(this) : this; + + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Square/GetPrevSq.cs b/Crossword.Square/GetPrevSq.cs new file mode 100644 index 0000000..d058b07 --- /dev/null +++ b/Crossword.Square/GetPrevSq.cs @@ -0,0 +1,20 @@ +namespace Crossword.Square; + +public sealed partial class Square +{ + #region GetPrevSq + + /// + /// /Gets the previous available square + /// + /// + /// + public Square? GetPrevSq(bool isAcross) + { + if (isAcross) + return ClueAnswerAcross is not null ? ClueAnswerAcross.GetPrevSq(this) : this; + return ClueAnswerDown is not null ? ClueAnswerDown.GetPrevSq(this) : this; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Square/SetHighlighted.cs b/Crossword.Square/SetHighlighted.cs new file mode 100644 index 0000000..fce850e --- /dev/null +++ b/Crossword.Square/SetHighlighted.cs @@ -0,0 +1,55 @@ +using System; +using Crossword.Shared.Constants; + +namespace Crossword.Square; + +public sealed partial class Square +{ + #region SetHighlighted + + /// + /// Sets the background colour of a square + /// + /// + public void SetHighlighted(int highlightType) + { + switch (highlightType) + { + case 1: //Current Letter + if (!BackColour.Equals(UIConstants.SquareHighlightCurrent)) + { + BackColour = UIConstants.SquareHighlightCurrent; + IsDirty = true; + } + + break; + case 2: //Current Word + if (!BackColour.Equals(UIConstants.SquareHighlightWord)) + { + BackColour = UIConstants.SquareHighlightWord; + IsDirty = true; + } + + break; + case 3: //Current None + if (!BackColour.Equals(UIConstants.SquareHighlightNone)) + { + BackColour = UIConstants.SquareHighlightNone; + IsDirty = true; + } + + break; + default: //Something went wrong.... + if (BackColour.Equals(UIConstants.SquareHighlightErr)) + { + Console.WriteLine($"Bogus color: {highlightType}"); + BackColour = UIConstants.SquareHighlightErr; + IsDirty = true; + } + + break; + } + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Square/SetLetter.cs b/Crossword.Square/SetLetter.cs new file mode 100644 index 0000000..e3756b9 --- /dev/null +++ b/Crossword.Square/SetLetter.cs @@ -0,0 +1,22 @@ +using Crossword.Shared.Constants; + +namespace Crossword.Square; + +public sealed partial class Square +{ + #region SetLetter + + /// + /// Set the colour for a letter. + /// + /// + /// + public void SetLetter(char letter, bool isAcross) + { + Letter = letter; + IsDirty = true; + ForeColour = UIConstants.SquareHighlightDefault; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Square/SetObjectRef.cs b/Crossword.Square/SetObjectRef.cs new file mode 100644 index 0000000..ad91e9e --- /dev/null +++ b/Crossword.Square/SetObjectRef.cs @@ -0,0 +1,31 @@ +using System; +using Crossword.ClueAnswerMap; +using Crossword.Shared.Constants; + +namespace Crossword.Square; + +public sealed partial class Square +{ + #region SetObjectRef + + /// + /// Set the object reference to clueanswer object + /// + /// + /// + public void SetObjectRef(bool isAcross, ClueAnswer clueAnswer) + { + ArgumentNullException.ThrowIfNull(clueAnswer); + + if (isAcross) + ClueAnswerAcross = clueAnswer; + else + ClueAnswerDown = clueAnswer; + + IsCharAllowed = true; + IsDirty = true; + BackColour = UIConstants.SquareHighlightNone; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Square/Square.cs b/Crossword.Square/Square.cs new file mode 100644 index 0000000..07ce305 --- /dev/null +++ b/Crossword.Square/Square.cs @@ -0,0 +1,41 @@ +//////////////////////////////////////////////////////////////////////////// +// // +// Module: Square.cs // +// Authors: Aaron Saikovski & Bryan Richards // +// Original Date: 23/01/97 // +// Version: 1.0 // +// Purpose: Defines a Square and it's attributes // +// // +//////////////////////////////////////////////////////////////////////////// + +using Crossword.ClueAnswerMap; +using Microsoft.Xna.Framework; + +namespace Crossword.Square; + +//Square class +public sealed partial class Square +{ + #region getters_setters + + public int xCoord { get; set; } + public int yCoord { get; set; } + + + public char Letter { get; set; } + + + public Color ForeColour { get; set; } = Color.Black; + public Color BackColour { get; set; } = Color.Black; + + public bool IsDirty { get; set; } = true; + + public bool IsCharAllowed { get; set; } + + public ClueAnswer? ClueAnswerAcross { get; set; } + public ClueAnswer? ClueAnswerDown { get; set; } + + #endregion + + +} \ No newline at end of file diff --git a/Crossword/App/UI/DrawCreditsLabel.cs b/Crossword/UI/DrawCreditsLabel.cs similarity index 100% rename from Crossword/App/UI/DrawCreditsLabel.cs rename to Crossword/UI/DrawCreditsLabel.cs diff --git a/Crossword/App/UI/DrawCrossword.cs b/Crossword/UI/DrawCrossword.cs similarity index 100% rename from Crossword/App/UI/DrawCrossword.cs rename to Crossword/UI/DrawCrossword.cs diff --git a/Crossword/App/UI/DrawCrosswordScore.cs b/Crossword/UI/DrawCrosswordScore.cs similarity index 100% rename from Crossword/App/UI/DrawCrosswordScore.cs rename to Crossword/UI/DrawCrosswordScore.cs diff --git a/Crossword/App/UI/DrawGetNextPuzzleButton.cs b/Crossword/UI/DrawGetNextPuzzleButton.cs similarity index 100% rename from Crossword/App/UI/DrawGetNextPuzzleButton.cs rename to Crossword/UI/DrawGetNextPuzzleButton.cs diff --git a/Crossword/App/UI/DrawHintButton.cs b/Crossword/UI/DrawHintButton.cs similarity index 100% rename from Crossword/App/UI/DrawHintButton.cs rename to Crossword/UI/DrawHintButton.cs diff --git a/Crossword/App/UI/LoadAssets.cs b/Crossword/UI/LoadAssets.cs similarity index 100% rename from Crossword/App/UI/LoadAssets.cs rename to Crossword/UI/LoadAssets.cs diff --git a/Crossword/App/UI/PuzzleButton.cs b/Crossword/UI/PuzzleButton.cs similarity index 100% rename from Crossword/App/UI/PuzzleButton.cs rename to Crossword/UI/PuzzleButton.cs diff --git a/Crossword/App/UI/UpdateCrosswordScore.cs b/Crossword/UI/UpdateCrosswordScore.cs similarity index 100% rename from Crossword/App/UI/UpdateCrosswordScore.cs rename to Crossword/UI/UpdateCrosswordScore.cs diff --git a/Crossword/App/handlers/ButtonHandlers.cs b/Crossword/handlers/ButtonHandlers.cs similarity index 100% rename from Crossword/App/handlers/ButtonHandlers.cs rename to Crossword/handlers/ButtonHandlers.cs diff --git a/Crossword/App/handlers/KeyDown.cs b/Crossword/handlers/KeyDown.cs similarity index 100% rename from Crossword/App/handlers/KeyDown.cs rename to Crossword/handlers/KeyDown.cs diff --git a/Crossword/App/handlers/ListBoxHandlers.cs b/Crossword/handlers/ListBoxHandlers.cs similarity index 100% rename from Crossword/App/handlers/ListBoxHandlers.cs rename to Crossword/handlers/ListBoxHandlers.cs diff --git a/Crossword/App/handlers/MouseHandlers.cs b/Crossword/handlers/MouseHandlers.cs similarity index 100% rename from Crossword/App/handlers/MouseHandlers.cs rename to Crossword/handlers/MouseHandlers.cs diff --git a/Crossword/App/handlers/NavigateList.cs b/Crossword/handlers/NavigateList.cs similarity index 100% rename from Crossword/App/handlers/NavigateList.cs rename to Crossword/handlers/NavigateList.cs diff --git a/Crossword/App/hint/GetUserHint.cs b/Crossword/hint/GetUserHint.cs similarity index 100% rename from Crossword/App/hint/GetUserHint.cs rename to Crossword/hint/GetUserHint.cs diff --git a/Crossword/App/hint/QuickSolver.cs b/Crossword/hint/QuickSolver.cs similarity index 100% rename from Crossword/App/hint/QuickSolver.cs rename to Crossword/hint/QuickSolver.cs diff --git a/Crossword/App/init/InitArrays.cs b/Crossword/init/InitArrays.cs similarity index 100% rename from Crossword/App/init/InitArrays.cs rename to Crossword/init/InitArrays.cs diff --git a/Crossword/App/init/InitClueAnswers.cs b/Crossword/init/InitClueAnswers.cs similarity index 100% rename from Crossword/App/init/InitClueAnswers.cs rename to Crossword/init/InitClueAnswers.cs diff --git a/Crossword/App/init/InitControls.cs b/Crossword/init/InitControls.cs similarity index 100% rename from Crossword/App/init/InitControls.cs rename to Crossword/init/InitControls.cs diff --git a/Crossword/App/init/InitData.cs b/Crossword/init/InitData.cs similarity index 100% rename from Crossword/App/init/InitData.cs rename to Crossword/init/InitData.cs diff --git a/Crossword/App/init/InitDirtySquares.cs b/Crossword/init/InitDirtySquares.cs similarity index 100% rename from Crossword/App/init/InitDirtySquares.cs rename to Crossword/init/InitDirtySquares.cs diff --git a/Crossword/App/init/InitListBoxes.cs b/Crossword/init/InitListBoxes.cs similarity index 100% rename from Crossword/App/init/InitListBoxes.cs rename to Crossword/init/InitListBoxes.cs diff --git a/Crossword/App/init/InitNextPuzzle.cs b/Crossword/init/InitNextPuzzle.cs similarity index 100% rename from Crossword/App/init/InitNextPuzzle.cs rename to Crossword/init/InitNextPuzzle.cs diff --git a/Crossword/App/init/InitPuzzleData.cs b/Crossword/init/InitPuzzleData.cs similarity index 95% rename from Crossword/App/init/InitPuzzleData.cs rename to Crossword/init/InitPuzzleData.cs index 300ccac..20c3a07 100644 --- a/Crossword/App/init/InitPuzzleData.cs +++ b/Crossword/init/InitPuzzleData.cs @@ -44,10 +44,7 @@ public sealed partial class CrosswordMain //Check for the result return task is { IsCompleted: true, IsFaulted: false, IsCanceled: false } ? task.Result : null; - // if (task is { IsCompleted: true, IsFaulted: false, IsCanceled: false }) - // { - // return task.Result; - // } + } catch (Exception ex) diff --git a/Crossword/App/init/InitialiseCrossword.cs b/Crossword/init/InitialiseCrossword.cs similarity index 100% rename from Crossword/App/init/InitialiseCrossword.cs rename to Crossword/init/InitialiseCrossword.cs diff --git a/Crossword/App/main/CrosswordMain.cs b/Crossword/main/CrosswordMain.cs similarity index 100% rename from Crossword/App/main/CrosswordMain.cs rename to Crossword/main/CrosswordMain.cs diff --git a/Crossword/App/main/MainInit.cs b/Crossword/main/MainInit.cs similarity index 100% rename from Crossword/App/main/MainInit.cs rename to Crossword/main/MainInit.cs diff --git a/Crossword/App/monogame/Monogame.cs b/Crossword/monogame/Monogame.cs similarity index 100% rename from Crossword/App/monogame/Monogame.cs rename to Crossword/monogame/Monogame.cs diff --git a/Crossword/App/navigation/NavigatePuzzle.cs b/Crossword/navigation/NavigatePuzzle.cs similarity index 100% rename from Crossword/App/navigation/NavigatePuzzle.cs rename to Crossword/navigation/NavigatePuzzle.cs From 19225cafac27bdf25a1de2f1645b3d6f2fd899d1 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 11:55:19 +1100 Subject: [PATCH 11/26] minor --- Crossword.Net.sln | 2 +- Crossword.Square/CanFlipDirection.cs | 26 ------ Crossword.Square/GetClueAnswerRef.cs | 20 ----- Crossword.Square/GetNextSq.cs | 24 ------ Crossword.Square/GetPrevSq.cs | 20 ----- Crossword.Square/SetObjectRef.cs | 31 ------- Crossword.Square/Square.cs | 41 --------- Crossword.Squares/CanFlipDirection.cs | 26 ++++++ .../CheckLetter.cs | 2 +- .../CreateSquare.cs | 2 +- .../Crossword.Squares.csproj | 0 Crossword.Squares/GetClueAnswerRef.cs | 20 +++++ Crossword.Squares/GetNextSq.cs | 24 ++++++ Crossword.Squares/GetPrevSq.cs | 20 +++++ .../SetHighlighted.cs | 4 +- .../SetLetter.cs | 4 +- Crossword.Squares/SetObjectRef.cs | 31 +++++++ Crossword.Squares/Square.cs | 84 +++++++++++++++++++ 18 files changed, 212 insertions(+), 169 deletions(-) delete mode 100644 Crossword.Square/CanFlipDirection.cs delete mode 100644 Crossword.Square/GetClueAnswerRef.cs delete mode 100644 Crossword.Square/GetNextSq.cs delete mode 100644 Crossword.Square/GetPrevSq.cs delete mode 100644 Crossword.Square/SetObjectRef.cs delete mode 100644 Crossword.Square/Square.cs create mode 100644 Crossword.Squares/CanFlipDirection.cs rename {Crossword.Square => Crossword.Squares}/CheckLetter.cs (94%) rename {Crossword.Square => Crossword.Squares}/CreateSquare.cs (92%) rename Crossword.Square/Crossword.Square.csproj => Crossword.Squares/Crossword.Squares.csproj (100%) create mode 100644 Crossword.Squares/GetClueAnswerRef.cs create mode 100644 Crossword.Squares/GetNextSq.cs create mode 100644 Crossword.Squares/GetPrevSq.cs rename {Crossword.Square => Crossword.Squares}/SetHighlighted.cs (97%) rename {Crossword.Square => Crossword.Squares}/SetLetter.cs (93%) create mode 100644 Crossword.Squares/SetObjectRef.cs create mode 100644 Crossword.Squares/Square.cs diff --git a/Crossword.Net.sln b/Crossword.Net.sln index 1fa17f1..a50a3d2 100644 --- a/Crossword.Net.sln +++ b/Crossword.Net.sln @@ -12,7 +12,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crosssword.Entities", "Cros EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Data", "Crossword.Data\Crossword.Data.csproj", "{08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Square", "Crossword.Square\Crossword.Square.csproj", "{9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Squares", "Crossword.Squares\Crossword.Squares.csproj", "{9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.ClueAnswer", "Crossword.ClueAnswer\Crossword.ClueAnswer.csproj", "{F0A08490-2940-4C75-A202-5C656872195A}" EndProject diff --git a/Crossword.Square/CanFlipDirection.cs b/Crossword.Square/CanFlipDirection.cs deleted file mode 100644 index 4ffaffb..0000000 --- a/Crossword.Square/CanFlipDirection.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace Crossword.Square; - -public sealed partial class Square -{ - #region CanFlipDirection - - /// - /// Can the current orientation be flipped. - /// - /// - /// - public bool CanFlipDirection(bool isAcross) - { - switch (isAcross) - { - //if square is an intersection - case true when ClueAnswerDown is not null: - case false when ClueAnswerAcross is not null: - return true; - default: - return false; - } - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.Square/GetClueAnswerRef.cs b/Crossword.Square/GetClueAnswerRef.cs deleted file mode 100644 index 5239ca4..0000000 --- a/Crossword.Square/GetClueAnswerRef.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Crossword.ClueAnswerMap; - -namespace Crossword.Square; - -public sealed partial class Square -{ - #region GetClueAnswerRef - - /// - /// returns the Clue/Answer reference - /// - /// - /// - public ClueAnswer? GetClueAnswerRef(bool isAcross) - { - return isAcross ? ClueAnswerAcross : ClueAnswerDown; - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.Square/GetNextSq.cs b/Crossword.Square/GetNextSq.cs deleted file mode 100644 index a5ae844..0000000 --- a/Crossword.Square/GetNextSq.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Crossword.Square; - -public sealed partial class Square -{ - #region GetNextSq - - /// - /// Gets the next available square - /// - /// - /// - public Square? GetNextSq(bool isAcross) - { - if (isAcross) - { - return ClueAnswerAcross != null ? ClueAnswerAcross.GetNextSq(this) : this; - } - - return ClueAnswerDown != null ? ClueAnswerDown.GetNextSq(this) : this; - - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.Square/GetPrevSq.cs b/Crossword.Square/GetPrevSq.cs deleted file mode 100644 index d058b07..0000000 --- a/Crossword.Square/GetPrevSq.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Crossword.Square; - -public sealed partial class Square -{ - #region GetPrevSq - - /// - /// /Gets the previous available square - /// - /// - /// - public Square? GetPrevSq(bool isAcross) - { - if (isAcross) - return ClueAnswerAcross is not null ? ClueAnswerAcross.GetPrevSq(this) : this; - return ClueAnswerDown is not null ? ClueAnswerDown.GetPrevSq(this) : this; - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.Square/SetObjectRef.cs b/Crossword.Square/SetObjectRef.cs deleted file mode 100644 index ad91e9e..0000000 --- a/Crossword.Square/SetObjectRef.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using Crossword.ClueAnswerMap; -using Crossword.Shared.Constants; - -namespace Crossword.Square; - -public sealed partial class Square -{ - #region SetObjectRef - - /// - /// Set the object reference to clueanswer object - /// - /// - /// - public void SetObjectRef(bool isAcross, ClueAnswer clueAnswer) - { - ArgumentNullException.ThrowIfNull(clueAnswer); - - if (isAcross) - ClueAnswerAcross = clueAnswer; - else - ClueAnswerDown = clueAnswer; - - IsCharAllowed = true; - IsDirty = true; - BackColour = UIConstants.SquareHighlightNone; - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.Square/Square.cs b/Crossword.Square/Square.cs deleted file mode 100644 index 07ce305..0000000 --- a/Crossword.Square/Square.cs +++ /dev/null @@ -1,41 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// // -// Module: Square.cs // -// Authors: Aaron Saikovski & Bryan Richards // -// Original Date: 23/01/97 // -// Version: 1.0 // -// Purpose: Defines a Square and it's attributes // -// // -//////////////////////////////////////////////////////////////////////////// - -using Crossword.ClueAnswerMap; -using Microsoft.Xna.Framework; - -namespace Crossword.Square; - -//Square class -public sealed partial class Square -{ - #region getters_setters - - public int xCoord { get; set; } - public int yCoord { get; set; } - - - public char Letter { get; set; } - - - public Color ForeColour { get; set; } = Color.Black; - public Color BackColour { get; set; } = Color.Black; - - public bool IsDirty { get; set; } = true; - - public bool IsCharAllowed { get; set; } - - public ClueAnswer? ClueAnswerAcross { get; set; } - public ClueAnswer? ClueAnswerDown { get; set; } - - #endregion - - -} \ No newline at end of file diff --git a/Crossword.Squares/CanFlipDirection.cs b/Crossword.Squares/CanFlipDirection.cs new file mode 100644 index 0000000..6c3a05b --- /dev/null +++ b/Crossword.Squares/CanFlipDirection.cs @@ -0,0 +1,26 @@ +// namespace Crossword.Squares; +// +// public sealed partial class Square +// { +// #region CanFlipDirection +// +// /// +// /// Can the current orientation be flipped. +// /// +// /// +// /// +// public bool CanFlipDirection(bool isAcross) +// { +// switch (isAcross) +// { +// //if square is an intersection +// case true when ClueAnswerDown is not null: +// case false when ClueAnswerAcross is not null: +// return true; +// default: +// return false; +// } +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword.Square/CheckLetter.cs b/Crossword.Squares/CheckLetter.cs similarity index 94% rename from Crossword.Square/CheckLetter.cs rename to Crossword.Squares/CheckLetter.cs index 0dd4524..ea60c02 100644 --- a/Crossword.Square/CheckLetter.cs +++ b/Crossword.Squares/CheckLetter.cs @@ -1,6 +1,6 @@ using Crossword.Shared.Constants; -namespace Crossword.Square; +namespace Crossword.Squares; public sealed partial class Square { diff --git a/Crossword.Square/CreateSquare.cs b/Crossword.Squares/CreateSquare.cs similarity index 92% rename from Crossword.Square/CreateSquare.cs rename to Crossword.Squares/CreateSquare.cs index e04be98..c30b5dd 100644 --- a/Crossword.Square/CreateSquare.cs +++ b/Crossword.Squares/CreateSquare.cs @@ -1,4 +1,4 @@ -namespace Crossword.Square; +namespace Crossword.Squares; public sealed partial class Square { diff --git a/Crossword.Square/Crossword.Square.csproj b/Crossword.Squares/Crossword.Squares.csproj similarity index 100% rename from Crossword.Square/Crossword.Square.csproj rename to Crossword.Squares/Crossword.Squares.csproj diff --git a/Crossword.Squares/GetClueAnswerRef.cs b/Crossword.Squares/GetClueAnswerRef.cs new file mode 100644 index 0000000..f038d0c --- /dev/null +++ b/Crossword.Squares/GetClueAnswerRef.cs @@ -0,0 +1,20 @@ +// using Crossword.ClueAnswerMap; +// +// namespace Crossword.Squares; +// +// public sealed partial class Square +// { +// #region GetClueAnswerRef +// +// /// +// /// returns the Clue/Answer reference +// /// +// /// +// /// +// public ClueAnswer? GetClueAnswerRef(bool isAcross) +// { +// return isAcross ? ClueAnswerAcross : ClueAnswerDown; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword.Squares/GetNextSq.cs b/Crossword.Squares/GetNextSq.cs new file mode 100644 index 0000000..683c1d3 --- /dev/null +++ b/Crossword.Squares/GetNextSq.cs @@ -0,0 +1,24 @@ +// namespace Crossword.Squares; +// +// public sealed partial class Square +// { +// #region GetNextSq +// +// /// +// /// Gets the next available square +// /// +// /// +// /// +// public Square? GetNextSq(bool isAcross) +// { +// if (isAcross) +// { +// return ClueAnswerAcross != null ? ClueAnswerAcross.GetNextSq(this) : this; +// } +// +// return ClueAnswerDown != null ? ClueAnswerDown.GetNextSq(this) : this; +// +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword.Squares/GetPrevSq.cs b/Crossword.Squares/GetPrevSq.cs new file mode 100644 index 0000000..13d2c01 --- /dev/null +++ b/Crossword.Squares/GetPrevSq.cs @@ -0,0 +1,20 @@ +// namespace Crossword.Squares; +// +// public sealed partial class Square +// { +// #region GetPrevSq +// +// /// +// /// /Gets the previous available square +// /// +// /// +// /// +// public Square? GetPrevSq(bool isAcross) +// { +// if (isAcross) +// return ClueAnswerAcross is not null ? ClueAnswerAcross.GetPrevSq(this) : this; +// return ClueAnswerDown is not null ? ClueAnswerDown.GetPrevSq(this) : this; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword.Square/SetHighlighted.cs b/Crossword.Squares/SetHighlighted.cs similarity index 97% rename from Crossword.Square/SetHighlighted.cs rename to Crossword.Squares/SetHighlighted.cs index fce850e..6ae24b7 100644 --- a/Crossword.Square/SetHighlighted.cs +++ b/Crossword.Squares/SetHighlighted.cs @@ -1,7 +1,7 @@ -using System; + using Crossword.Shared.Constants; -namespace Crossword.Square; +namespace Crossword.Squares; public sealed partial class Square { diff --git a/Crossword.Square/SetLetter.cs b/Crossword.Squares/SetLetter.cs similarity index 93% rename from Crossword.Square/SetLetter.cs rename to Crossword.Squares/SetLetter.cs index e3756b9..9908b60 100644 --- a/Crossword.Square/SetLetter.cs +++ b/Crossword.Squares/SetLetter.cs @@ -1,6 +1,6 @@ using Crossword.Shared.Constants; -namespace Crossword.Square; +namespace Crossword.Squares; public sealed partial class Square { @@ -19,4 +19,4 @@ public void SetLetter(char letter, bool isAcross) } #endregion -} \ No newline at end of file +} diff --git a/Crossword.Squares/SetObjectRef.cs b/Crossword.Squares/SetObjectRef.cs new file mode 100644 index 0000000..78497c6 --- /dev/null +++ b/Crossword.Squares/SetObjectRef.cs @@ -0,0 +1,31 @@ +// using System; +// using Crossword.ClueAnswerMap; +// using Crossword.Shared.Constants; +// +// namespace Crossword.Squares; +// +// public sealed partial class Square +// { +// #region SetObjectRef +// +// /// +// /// Set the object reference to clueanswer object +// /// +// /// +// /// +// public void SetObjectRef(bool isAcross, ClueAnswer clueAnswer) +// { +// ArgumentNullException.ThrowIfNull(clueAnswer); +// +// if (isAcross) +// ClueAnswerAcross = clueAnswer; +// else +// ClueAnswerDown = clueAnswer; +// +// IsCharAllowed = true; +// IsDirty = true; +// BackColour = UIConstants.SquareHighlightNone; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword.Squares/Square.cs b/Crossword.Squares/Square.cs new file mode 100644 index 0000000..479ea80 --- /dev/null +++ b/Crossword.Squares/Square.cs @@ -0,0 +1,84 @@ + +using Microsoft.Xna.Framework; + +namespace Crossword.Squares; +// +// //Square class +// public sealed partial class Square +// { +// #region getters_setters +// +// public int xCoord { get; set; } +// public int yCoord { get; set; } +// +// +// public char Letter { get; set; } +// +// +// public Color ForeColour { get; set; } = Color.Black; +// public Color BackColour { get; set; } = Color.Black; +// +// public bool IsDirty { get; set; } = true; +// +// public bool IsCharAllowed { get; set; } +// +// // public ClueAnswer? ClueAnswerAcross { get; set; } +// // public ClueAnswer? ClueAnswerDown { get; set; } +// +// #endregion +// +// +// } + +/// +/// Primary constructor for the Square +/// +/// +/// +/// +/// +/// +/// +/// +// public class Square(int xCoord, int yCoord, char? Letter, Color? ForeColour, Color? BackColour, bool IsDirty, bool IsCharAllowed) +// { +// // public Square(int xCoord, int yCoord, char? Letter, Color? ForeColour, Color? BackColour, bool IsDirty, bool IsCharAllowed) +// // { +// // //this.xCoord = xCoord; +// // // this.yCoord = yCoord; +// // } +// +// } + + +public sealed partial class Square +{ + public int xCoord { get; set; } + public int yCoord { get; set; } + + + public char Letter { get; set; } + + + public Color ForeColour { get; set; } = Color.Black; + public Color BackColour { get; set; } = Color.Black; + + public bool IsDirty { get; set; } = true; + + public bool IsCharAllowed { get; set; } + + public Square(int xCoord, int yCoord, char letter, bool isDirty, bool isCharAllowed) + { + this.xCoord = xCoord; + this.yCoord = yCoord; + this.Letter = letter; + this.IsDirty = isDirty; + this.IsCharAllowed = isCharAllowed; + } + + +} + + + + From 3e8032d5258f8d36383165357630df10e04db81d Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 12:41:52 +1100 Subject: [PATCH 12/26] refactor --- Crossword.Squares/CanFlipDirection.cs | 26 ++++++++++++++------- Crossword.Squares/Square.cs | 13 +++++++++-- Crossword/Crossword.csproj | 2 +- Crossword/PuzzleSquares/CanFlipDirection.cs | 9 +++++++ 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Crossword.Squares/CanFlipDirection.cs b/Crossword.Squares/CanFlipDirection.cs index 6c3a05b..6624c51 100644 --- a/Crossword.Squares/CanFlipDirection.cs +++ b/Crossword.Squares/CanFlipDirection.cs @@ -11,15 +11,23 @@ // /// // public bool CanFlipDirection(bool isAcross) // { -// switch (isAcross) -// { -// //if square is an intersection -// case true when ClueAnswerDown is not null: -// case false when ClueAnswerAcross is not null: -// return true; -// default: -// return false; -// } +// // switch (isAcross) +// // { +// // //if square is an intersection +// // case true when ClueAnswerDown is not null: +// // case false when ClueAnswerAcross is not null: +// // return true; +// // default: +// // return false; +// // } +// +// //if square is an intersection +// if ((bIsAcross) && (clDown != null)) +// return true; +// else if ((!bIsAcross) && (clAcross != null)) +// return true; +// else +// return false; // } // // #endregion diff --git a/Crossword.Squares/Square.cs b/Crossword.Squares/Square.cs index 479ea80..5e85b95 100644 --- a/Crossword.Squares/Square.cs +++ b/Crossword.Squares/Square.cs @@ -50,7 +50,9 @@ namespace Crossword.Squares; // // } - +/// +/// Square class +/// public sealed partial class Square { public int xCoord { get; set; } @@ -67,6 +69,14 @@ public sealed partial class Square public bool IsCharAllowed { get; set; } + /// + /// Class constructor + /// + /// + /// + /// + /// + /// public Square(int xCoord, int yCoord, char letter, bool isDirty, bool isCharAllowed) { this.xCoord = xCoord; @@ -75,7 +85,6 @@ public Square(int xCoord, int yCoord, char letter, bool isDirty, bool isCharAllo this.IsDirty = isDirty; this.IsCharAllowed = isCharAllowed; } - } diff --git a/Crossword/Crossword.csproj b/Crossword/Crossword.csproj index 5dbaf01..c59313a 100644 --- a/Crossword/Crossword.csproj +++ b/Crossword/Crossword.csproj @@ -9,10 +9,10 @@ 12 enable Crossword - Crossword 1.0.2 1.0.2 + Crossword app.manifest diff --git a/Crossword/PuzzleSquares/CanFlipDirection.cs b/Crossword/PuzzleSquares/CanFlipDirection.cs index b3d921a..816d26f 100644 --- a/Crossword/PuzzleSquares/CanFlipDirection.cs +++ b/Crossword/PuzzleSquares/CanFlipDirection.cs @@ -20,6 +20,15 @@ public bool CanFlipDirection(bool isAcross) default: return false; } + + //if square is an intersection + // if ((isAcross) && (ClueAnswerDown != null)) + // return true; + // else if ((!isAcross) && (ClueAnswerAcross != null)) + // return true; + // else + // return false; + } #endregion From 300a4f14a89d0dd1802a69d4c7d24806d3139430 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 12:52:47 +1100 Subject: [PATCH 13/26] moved eventhandlers --- Crossword/{handlers => EventHandlers}/ButtonHandlers.cs | 0 Crossword/{handlers => EventHandlers}/KeyDown.cs | 0 Crossword/EventHandlers/KeyboardInputHandler.cs | 2 +- Crossword/{handlers => EventHandlers}/ListBoxHandlers.cs | 0 Crossword/{handlers => EventHandlers}/MouseHandlers.cs | 0 Crossword/EventHandlers/MouseInputHandler.cs | 2 +- Crossword/{handlers => EventHandlers}/NavigateList.cs | 0 Crossword/main/CrosswordMain.cs | 2 +- 8 files changed, 3 insertions(+), 3 deletions(-) rename Crossword/{handlers => EventHandlers}/ButtonHandlers.cs (100%) rename Crossword/{handlers => EventHandlers}/KeyDown.cs (100%) rename Crossword/{handlers => EventHandlers}/ListBoxHandlers.cs (100%) rename Crossword/{handlers => EventHandlers}/MouseHandlers.cs (100%) rename Crossword/{handlers => EventHandlers}/NavigateList.cs (100%) diff --git a/Crossword/handlers/ButtonHandlers.cs b/Crossword/EventHandlers/ButtonHandlers.cs similarity index 100% rename from Crossword/handlers/ButtonHandlers.cs rename to Crossword/EventHandlers/ButtonHandlers.cs diff --git a/Crossword/handlers/KeyDown.cs b/Crossword/EventHandlers/KeyDown.cs similarity index 100% rename from Crossword/handlers/KeyDown.cs rename to Crossword/EventHandlers/KeyDown.cs diff --git a/Crossword/EventHandlers/KeyboardInputHandler.cs b/Crossword/EventHandlers/KeyboardInputHandler.cs index d171a9f..7c0fce7 100644 --- a/Crossword/EventHandlers/KeyboardInputHandler.cs +++ b/Crossword/EventHandlers/KeyboardInputHandler.cs @@ -12,7 +12,7 @@ using InputHandlers.Keyboard; using Microsoft.Xna.Framework.Input; -namespace Crossword.EventHandlers; +namespace Crossword.App; public class KeyboardInputHandler(App.CrosswordMain crosswordMain) : IKeyboardHandler { diff --git a/Crossword/handlers/ListBoxHandlers.cs b/Crossword/EventHandlers/ListBoxHandlers.cs similarity index 100% rename from Crossword/handlers/ListBoxHandlers.cs rename to Crossword/EventHandlers/ListBoxHandlers.cs diff --git a/Crossword/handlers/MouseHandlers.cs b/Crossword/EventHandlers/MouseHandlers.cs similarity index 100% rename from Crossword/handlers/MouseHandlers.cs rename to Crossword/EventHandlers/MouseHandlers.cs diff --git a/Crossword/EventHandlers/MouseInputHandler.cs b/Crossword/EventHandlers/MouseInputHandler.cs index 3103a8c..9a53eee 100644 --- a/Crossword/EventHandlers/MouseInputHandler.cs +++ b/Crossword/EventHandlers/MouseInputHandler.cs @@ -12,7 +12,7 @@ using InputHandlers.Mouse; using Microsoft.Xna.Framework.Input; -namespace Crossword.EventHandlers; +namespace Crossword.App; public class MouseInputHandler(App.CrosswordMain crosswordMain) : IMouseHandler { diff --git a/Crossword/handlers/NavigateList.cs b/Crossword/EventHandlers/NavigateList.cs similarity index 100% rename from Crossword/handlers/NavigateList.cs rename to Crossword/EventHandlers/NavigateList.cs diff --git a/Crossword/main/CrosswordMain.cs b/Crossword/main/CrosswordMain.cs index 9012a43..e1cf728 100644 --- a/Crossword/main/CrosswordMain.cs +++ b/Crossword/main/CrosswordMain.cs @@ -1,7 +1,7 @@ using System; using Crossword.ClueAnswerMap; using Crossword.Shared.Constants; -using Crossword.EventHandlers; +//using Crossword.EventHandlers; using Crossword.PuzzleSquares; using Crossword.Entities; using Crossword.Parser; From 132898a3ef4eef541776ef240ac706b7d656b81f Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 13:07:08 +1100 Subject: [PATCH 14/26] refactored --- .../EventHandlers/KeyboardInputHandler.cs | 2 +- .../NavigatePuzzle.cs | 7 - Crossword/UI/DrawCrossword.cs | 128 ------------------ Crossword/UI/DrawSmallFont.cs | 63 +++++++++ Crossword/UI/DrawSquares.cs | 50 +++++++ Crossword/UI/DrawUserChar.cs | 41 ++++++ Crossword/main/CrosswordMain.cs | 2 +- 7 files changed, 156 insertions(+), 137 deletions(-) rename Crossword/{navigation => EventHandlers}/NavigatePuzzle.cs (96%) create mode 100644 Crossword/UI/DrawSmallFont.cs create mode 100644 Crossword/UI/DrawSquares.cs create mode 100644 Crossword/UI/DrawUserChar.cs diff --git a/Crossword/EventHandlers/KeyboardInputHandler.cs b/Crossword/EventHandlers/KeyboardInputHandler.cs index 7c0fce7..5d4d3af 100644 --- a/Crossword/EventHandlers/KeyboardInputHandler.cs +++ b/Crossword/EventHandlers/KeyboardInputHandler.cs @@ -18,7 +18,7 @@ public class KeyboardInputHandler(App.CrosswordMain crosswordMain) : IKeyboardHa { #region Keyboard_Input_Handler - //CrosswordMain.Application instance + public void HandleKeyboardKeyDown(Keys[] keysDown, Keys keyInFocus, KeyboardModifier keyboardModifier) { diff --git a/Crossword/navigation/NavigatePuzzle.cs b/Crossword/EventHandlers/NavigatePuzzle.cs similarity index 96% rename from Crossword/navigation/NavigatePuzzle.cs rename to Crossword/EventHandlers/NavigatePuzzle.cs index baad51d..bad6307 100644 --- a/Crossword/navigation/NavigatePuzzle.cs +++ b/Crossword/EventHandlers/NavigatePuzzle.cs @@ -96,13 +96,6 @@ private void UpdateListBoxLinkage() clueAnswerIdx = k; break; } - - // Parallel.For(0, NumQuestions, (k, loopState) => - // { - // if (tmp != caPuzzleClueAnswers[k]) return; - // clueAnswerIdx = k; - // loopState.Break(); - // }); //Selects the item in the list box relative to the ClueAnswerMap //and the orientation. diff --git a/Crossword/UI/DrawCrossword.cs b/Crossword/UI/DrawCrossword.cs index fb80ab8..65d5eff 100644 --- a/Crossword/UI/DrawCrossword.cs +++ b/Crossword/UI/DrawCrossword.cs @@ -1,6 +1,5 @@ using System; using Crossword.Shared.Constants; -using FontStashSharp; using Microsoft.Xna.Framework; namespace Crossword.App; @@ -74,131 +73,4 @@ private void DrawCrossword() } #endregion - - #region DrawUserChar - /// - /// Draws char entered by user - /// - /// - /// - private void DrawUserChar(int i, int j) - { - try - { - logger.LogInformation("Start DrawUserChar()"); - - //check for null - if (sqPuzzleSquares[i, j] != null && _puzzleSquares[i, j] != null) - { - //Char entered by user. - _spriteBatch.DrawString(_fntFont, char.ToUpper(sqPuzzleSquares[i, j].Letter).ToString(), - new Vector2(_puzzleSquares[i, j].X + UIConstants.SqCharOffsetX, - _puzzleSquares[i, j].Y + UIConstants.SqCharOffsetY), - sqPuzzleSquares[i, j].ForeColour); - - } - - - } - catch (Exception ex) - { - logger.LogError(ex,ex.Message); - throw; - } - } - #endregion - - #region DrawSmallFont - /// - /// Draws small font Across - /// - /// - /// - private void DrawSmallFontAcross(int i, int j) - { - try - { - logger.LogInformation("Start DrawSmallFontAcross()"); - if (sqPuzzleSquares[i, j]?.ClueAnswerAcross is null) return; - if (sqPuzzleSquares[i, j]?.ClueAnswerAcross?.SqAnswerSquares?[0] != sqPuzzleSquares[i, j]) return; - if (_puzzleSquares is not null) - _spriteBatch.DrawString(_fntnumFont, - sqPuzzleSquares[i, j]?.ClueAnswerAcross?.QuestionNumber.ToString(), - new Vector2(_puzzleSquares[i, j].X + UIConstants.SmlNumOffsetX, - _puzzleSquares[i, j].Y + UIConstants.SmlNumOffsetY), UIConstants.SmallFontColor); - } - catch (Exception ex) - { - logger.LogError(ex,ex.Message); - throw; - } - - } - - /// - /// Draws small font Down - /// - /// - /// - private void DrawSmallFontDown(int i, int j) - { - try - { - logger.LogInformation("Start DrawSmallFontDown()"); - - if (sqPuzzleSquares?[i, j].ClueAnswerDown is null) return; - if (sqPuzzleSquares?[i, j].ClueAnswerDown?.SqAnswerSquares?[0] != sqPuzzleSquares[i, j]) return; - _spriteBatch.DrawString(_fntnumFont, - sqPuzzleSquares[i, j]?.ClueAnswerDown?.QuestionNumber.ToString(), - new Vector2(_puzzleSquares[i, j].X + UIConstants.SmlNumOffsetX, - _puzzleSquares[i, j].Y + UIConstants.SmlNumOffsetY), UIConstants.SmallFontColor); - } - catch (Exception ex) - { - logger.LogError(ex,ex.Message); - throw; - } - - } - #endregion - - #region DrawSquares - /// - /// Draws the crossword squares - /// - /// - /// - /// - private bool DrawSquares(int i, int j) - { - try - { - logger.LogInformation("Start DrawSquares()"); - - //Check to see if a repaint is required - if (!sqPuzzleSquares[i, j]!.IsDirty) return true; - if (sqPuzzleSquares[i, j]!.BackColour.Equals(UIConstants.SquareHighlightNone)) - { - if (_puzzleSquares is not null) _spriteBatch.Draw(_imgNormalSquare, _puzzleSquares[i, j], _rectangleColor); - } - - if (sqPuzzleSquares[i, j]!.BackColour.Equals(UIConstants.SquareHighlightWord)) - { - if (_puzzleSquares is not null) _spriteBatch.Draw(_imgSquareWord, _puzzleSquares[i, j], _rectangleColor); - } - - if (!sqPuzzleSquares[i, j]!.BackColour.Equals(UIConstants.SquareHighlightCurrent)) return false; - if (_puzzleSquares is not null) _spriteBatch.Draw(_imgHighliteSquare, _puzzleSquares[i, j], _rectangleColor); - - return false; - } - catch (Exception ex) - { - logger.LogError(ex,ex.Message); - throw; - } - - } - - #endregion } \ No newline at end of file diff --git a/Crossword/UI/DrawSmallFont.cs b/Crossword/UI/DrawSmallFont.cs new file mode 100644 index 0000000..94cb4d0 --- /dev/null +++ b/Crossword/UI/DrawSmallFont.cs @@ -0,0 +1,63 @@ +using System; +using Crossword.Shared.Constants; +using FontStashSharp; +using Microsoft.Xna.Framework; + +namespace Crossword.App; + +public sealed partial class CrosswordMain +{ + #region DrawSmallFont + + /// + /// Draws small font Across + /// + /// + /// + private void DrawSmallFontAcross(int i, int j) + { + try + { + logger.LogInformation("Start DrawSmallFontAcross()"); + if (sqPuzzleSquares[i, j]?.ClueAnswerAcross is null) return; + if (sqPuzzleSquares[i, j]?.ClueAnswerAcross?.SqAnswerSquares?[0] != sqPuzzleSquares[i, j]) return; + if (_puzzleSquares is not null) + _spriteBatch.DrawString(_fntnumFont, + sqPuzzleSquares[i, j]?.ClueAnswerAcross?.QuestionNumber.ToString(), + new Vector2(_puzzleSquares[i, j].X + UIConstants.SmlNumOffsetX, + _puzzleSquares[i, j].Y + UIConstants.SmlNumOffsetY), UIConstants.SmallFontColor); + } + catch (Exception ex) + { + logger.LogError(ex, ex.Message); + throw; + } + } + + /// + /// Draws small font Down + /// + /// + /// + private void DrawSmallFontDown(int i, int j) + { + try + { + logger.LogInformation("Start DrawSmallFontDown()"); + + if (sqPuzzleSquares?[i, j].ClueAnswerDown is null) return; + if (sqPuzzleSquares?[i, j].ClueAnswerDown?.SqAnswerSquares?[0] != sqPuzzleSquares[i, j]) return; + _spriteBatch.DrawString(_fntnumFont, + sqPuzzleSquares[i, j]?.ClueAnswerDown?.QuestionNumber.ToString(), + new Vector2(_puzzleSquares[i, j].X + UIConstants.SmlNumOffsetX, + _puzzleSquares[i, j].Y + UIConstants.SmlNumOffsetY), UIConstants.SmallFontColor); + } + catch (Exception ex) + { + logger.LogError(ex, ex.Message); + throw; + } + } + + #endregion +} \ No newline at end of file diff --git a/Crossword/UI/DrawSquares.cs b/Crossword/UI/DrawSquares.cs new file mode 100644 index 0000000..df677c9 --- /dev/null +++ b/Crossword/UI/DrawSquares.cs @@ -0,0 +1,50 @@ +using System; +using Crossword.Shared.Constants; + +namespace Crossword.App; + +public sealed partial class CrosswordMain +{ + #region DrawSquares + + /// + /// Draws the crossword squares + /// + /// + /// + /// + private bool DrawSquares(int i, int j) + { + try + { + logger.LogInformation("Start DrawSquares()"); + + //Check to see if a repaint is required + if (!sqPuzzleSquares[i, j]!.IsDirty) return true; + if (sqPuzzleSquares[i, j]!.BackColour.Equals(UIConstants.SquareHighlightNone)) + { + if (_puzzleSquares is not null) + _spriteBatch.Draw(_imgNormalSquare, _puzzleSquares[i, j], _rectangleColor); + } + + if (sqPuzzleSquares[i, j]!.BackColour.Equals(UIConstants.SquareHighlightWord)) + { + if (_puzzleSquares is not null) + _spriteBatch.Draw(_imgSquareWord, _puzzleSquares[i, j], _rectangleColor); + } + + if (!sqPuzzleSquares[i, j]!.BackColour.Equals(UIConstants.SquareHighlightCurrent)) return false; + if (_puzzleSquares is not null) + _spriteBatch.Draw(_imgHighliteSquare, _puzzleSquares[i, j], _rectangleColor); + + return false; + } + catch (Exception ex) + { + logger.LogError(ex, ex.Message); + throw; + } + } + + #endregion +} \ No newline at end of file diff --git a/Crossword/UI/DrawUserChar.cs b/Crossword/UI/DrawUserChar.cs new file mode 100644 index 0000000..8d03c8d --- /dev/null +++ b/Crossword/UI/DrawUserChar.cs @@ -0,0 +1,41 @@ +using System; +using Crossword.Shared.Constants; +using FontStashSharp; +using Microsoft.Xna.Framework; + +namespace Crossword.App; + +public sealed partial class CrosswordMain +{ + #region DrawUserChar + + /// + /// Draws char entered by user + /// + /// + /// + private void DrawUserChar(int i, int j) + { + try + { + logger.LogInformation("Start DrawUserChar()"); + + //check for null + if (sqPuzzleSquares[i, j] != null && _puzzleSquares[i, j] != null) + { + //Char entered by user. + _spriteBatch.DrawString(_fntFont, char.ToUpper(sqPuzzleSquares[i, j].Letter).ToString(), + new Vector2(_puzzleSquares[i, j].X + UIConstants.SqCharOffsetX, + _puzzleSquares[i, j].Y + UIConstants.SqCharOffsetY), + sqPuzzleSquares[i, j].ForeColour); + } + } + catch (Exception ex) + { + logger.LogError(ex, ex.Message); + throw; + } + } + + #endregion +} \ No newline at end of file diff --git a/Crossword/main/CrosswordMain.cs b/Crossword/main/CrosswordMain.cs index e1cf728..05bf007 100644 --- a/Crossword/main/CrosswordMain.cs +++ b/Crossword/main/CrosswordMain.cs @@ -1,7 +1,7 @@ using System; using Crossword.ClueAnswerMap; using Crossword.Shared.Constants; -//using Crossword.EventHandlers; +//using Crossword.App.EventHandlers; using Crossword.PuzzleSquares; using Crossword.Entities; using Crossword.Parser; From 00c07770bcbf1641332bb22f8ed11e1983bf3fff Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 13:22:04 +1100 Subject: [PATCH 15/26] refactor --- Crossword.Data/CallDataApiAsync.cs | 4 +--- Crossword.Data/GetCrosswordDataAsync.cs | 3 +-- .../Crossword.Entities.csproj | 1 + {Crosssword.Entities => Crossword.Entities}/CrosswordData.cs | 0 {Crosssword.Entities => Crossword.Entities}/CrosswordState.cs | 0 Crossword.Net.sln | 2 +- Crossword.Parser/Crossword.Parser.csproj | 2 +- Crossword.Parser/ParseCrosswordData.cs | 1 + Crossword.Shared/Constants/UIConstants.cs | 2 +- Crossword/Crossword.csproj | 2 +- Crossword/init/InitPuzzleData.cs | 1 + Crossword/main/CrosswordMain.cs | 1 + 12 files changed, 10 insertions(+), 9 deletions(-) rename Crosssword.Entities/Crosssword.Entities.csproj => Crossword.Entities/Crossword.Entities.csproj (79%) rename {Crosssword.Entities => Crossword.Entities}/CrosswordData.cs (100%) rename {Crosssword.Entities => Crossword.Entities}/CrosswordState.cs (100%) diff --git a/Crossword.Data/CallDataApiAsync.cs b/Crossword.Data/CallDataApiAsync.cs index 3525fce..c9a623a 100644 --- a/Crossword.Data/CallDataApiAsync.cs +++ b/Crossword.Data/CallDataApiAsync.cs @@ -1,6 +1,4 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; + using Crossword.Shared.Config; using Crossword.Shared.Logger; using Crossword.Shared.Constants; diff --git a/Crossword.Data/GetCrosswordDataAsync.cs b/Crossword.Data/GetCrosswordDataAsync.cs index b96cd0d..6ccd702 100644 --- a/Crossword.Data/GetCrosswordDataAsync.cs +++ b/Crossword.Data/GetCrosswordDataAsync.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading.Tasks; + using Crossword.Shared.Constants; using Crossword.Shared.Logger; using Crossword.Shared.Config; diff --git a/Crosssword.Entities/Crosssword.Entities.csproj b/Crossword.Entities/Crossword.Entities.csproj similarity index 79% rename from Crosssword.Entities/Crosssword.Entities.csproj rename to Crossword.Entities/Crossword.Entities.csproj index 3a63532..cdafd92 100644 --- a/Crosssword.Entities/Crosssword.Entities.csproj +++ b/Crossword.Entities/Crossword.Entities.csproj @@ -4,6 +4,7 @@ net8.0 enable enable + Crosssword.Entities diff --git a/Crosssword.Entities/CrosswordData.cs b/Crossword.Entities/CrosswordData.cs similarity index 100% rename from Crosssword.Entities/CrosswordData.cs rename to Crossword.Entities/CrosswordData.cs diff --git a/Crosssword.Entities/CrosswordState.cs b/Crossword.Entities/CrosswordState.cs similarity index 100% rename from Crosssword.Entities/CrosswordState.cs rename to Crossword.Entities/CrosswordState.cs diff --git a/Crossword.Net.sln b/Crossword.Net.sln index a50a3d2..c355996 100644 --- a/Crossword.Net.sln +++ b/Crossword.Net.sln @@ -8,7 +8,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Shared", "Crosswo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Parser", "Crossword.Parser\Crossword.Parser.csproj", "{2FE9007A-7C46-48AD-86A5-FCADA1AA2D34}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crosssword.Entities", "Crosssword.Entities\Crosssword.Entities.csproj", "{629F5D51-C8E0-4C64-BE84-48C5DB565FA8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Entities", "Crossword.Entities\Crossword.Entities.csproj", "{629F5D51-C8E0-4C64-BE84-48C5DB565FA8}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Data", "Crossword.Data\Crossword.Data.csproj", "{08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}" EndProject diff --git a/Crossword.Parser/Crossword.Parser.csproj b/Crossword.Parser/Crossword.Parser.csproj index 4ccddcc..5df1158 100644 --- a/Crossword.Parser/Crossword.Parser.csproj +++ b/Crossword.Parser/Crossword.Parser.csproj @@ -7,7 +7,7 @@ - + diff --git a/Crossword.Parser/ParseCrosswordData.cs b/Crossword.Parser/ParseCrosswordData.cs index daa4615..c3b0792 100644 --- a/Crossword.Parser/ParseCrosswordData.cs +++ b/Crossword.Parser/ParseCrosswordData.cs @@ -1,5 +1,6 @@ using System; using Crossword.Entities; +using Crossword.Entities; namespace Crossword.Parser; public sealed partial class CrosswordParser diff --git a/Crossword.Shared/Constants/UIConstants.cs b/Crossword.Shared/Constants/UIConstants.cs index 1559fde..13bf3c9 100644 --- a/Crossword.Shared/Constants/UIConstants.cs +++ b/Crossword.Shared/Constants/UIConstants.cs @@ -7,7 +7,7 @@ namespace Crossword.Shared.Constants; /// /// UI Constants /// -public sealed class UIConstants +public static class UIConstants { //Crossword dimension constants diff --git a/Crossword/Crossword.csproj b/Crossword/Crossword.csproj index c59313a..89de626 100644 --- a/Crossword/Crossword.csproj +++ b/Crossword/Crossword.csproj @@ -83,7 +83,7 @@ - + diff --git a/Crossword/init/InitPuzzleData.cs b/Crossword/init/InitPuzzleData.cs index 20c3a07..bba3de7 100644 --- a/Crossword/init/InitPuzzleData.cs +++ b/Crossword/init/InitPuzzleData.cs @@ -3,6 +3,7 @@ using System.Data; using System.Threading.Tasks; using Crossword.Entities; +using Crossword.Entities; using Crossword.Parser; using Crossword.Data; diff --git a/Crossword/main/CrosswordMain.cs b/Crossword/main/CrosswordMain.cs index 05bf007..c2c4c75 100644 --- a/Crossword/main/CrosswordMain.cs +++ b/Crossword/main/CrosswordMain.cs @@ -1,4 +1,5 @@ using System; +using Crossword.Entities; using Crossword.ClueAnswerMap; using Crossword.Shared.Constants; //using Crossword.App.EventHandlers; From fe3236de41c06cb5f27e02ffd56fe7e6370d26c4 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 13:34:38 +1100 Subject: [PATCH 16/26] refactor and cleanup --- Crossword/EventHandlers/KeyboardInputHandler.cs | 2 +- Crossword/EventHandlers/MouseInputHandler.cs | 2 +- Crossword/PuzzleSquares/SetHighlighted.cs | 2 +- Crossword/UI/DrawCreditsLabel.cs | 2 +- Crossword/UI/DrawCrossword.cs | 4 ++-- Crossword/UI/DrawUserChar.cs | 2 +- Crossword/UI/PuzzleButton.cs | 6 +++--- Crossword/init/InitData.cs | 2 +- Crossword/init/InitPuzzleData.cs | 1 - Crossword/main/CrosswordMain.cs | 4 ++-- 10 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Crossword/EventHandlers/KeyboardInputHandler.cs b/Crossword/EventHandlers/KeyboardInputHandler.cs index 5d4d3af..16dd33b 100644 --- a/Crossword/EventHandlers/KeyboardInputHandler.cs +++ b/Crossword/EventHandlers/KeyboardInputHandler.cs @@ -14,7 +14,7 @@ namespace Crossword.App; -public class KeyboardInputHandler(App.CrosswordMain crosswordMain) : IKeyboardHandler +public class KeyboardInputHandler(CrosswordMain crosswordMain) : IKeyboardHandler { #region Keyboard_Input_Handler diff --git a/Crossword/EventHandlers/MouseInputHandler.cs b/Crossword/EventHandlers/MouseInputHandler.cs index 9a53eee..4c08250 100644 --- a/Crossword/EventHandlers/MouseInputHandler.cs +++ b/Crossword/EventHandlers/MouseInputHandler.cs @@ -14,7 +14,7 @@ namespace Crossword.App; -public class MouseInputHandler(App.CrosswordMain crosswordMain) : IMouseHandler +public class MouseInputHandler(CrosswordMain crosswordMain) : IMouseHandler { #region Mouse_Input_Handler diff --git a/Crossword/PuzzleSquares/SetHighlighted.cs b/Crossword/PuzzleSquares/SetHighlighted.cs index 4a092a9..9687797 100644 --- a/Crossword/PuzzleSquares/SetHighlighted.cs +++ b/Crossword/PuzzleSquares/SetHighlighted.cs @@ -42,7 +42,7 @@ public void SetHighlighted(int highlightType) default: //Something went wrong.... if (BackColour.Equals(UIConstants.SquareHighlightErr)) { - Console.WriteLine($"Bogus color: {highlightType}"); + //Console.WriteLine($"Bogus color: {highlightType}"); BackColour = UIConstants.SquareHighlightErr; IsDirty = true; } diff --git a/Crossword/UI/DrawCreditsLabel.cs b/Crossword/UI/DrawCreditsLabel.cs index 58f9e35..9695aa6 100644 --- a/Crossword/UI/DrawCreditsLabel.cs +++ b/Crossword/UI/DrawCreditsLabel.cs @@ -21,7 +21,7 @@ private void DrawCreditsLabel() _creditsLabel.TextColor = UIConstants.CreditsColor; _creditsLabel.Left = rectCrossWord.Left; _creditsLabel.Font = _fntCredits; - _creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + (UIConstants.SquareHeight/2); + _creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + UIConstants.SquareHeight/2; _mainPanel.Widgets.Add(_creditsLabel); } diff --git a/Crossword/UI/DrawCrossword.cs b/Crossword/UI/DrawCrossword.cs index 65d5eff..34b6870 100644 --- a/Crossword/UI/DrawCrossword.cs +++ b/Crossword/UI/DrawCrossword.cs @@ -33,8 +33,8 @@ private void DrawCrossword() //Main puzzle squares array //Draw crossword with squares with spaces _puzzleSquares[i, j] = new Rectangle( - sqPuzzleSquares[i, j]!.xCoord + i * ((int)UIConstants.SquareSpacer), - sqPuzzleSquares[i, j]!.yCoord + j * ((int) UIConstants.SquareSpacer), + sqPuzzleSquares[i, j]!.xCoord + i * (int)UIConstants.SquareSpacer, + sqPuzzleSquares[i, j]!.yCoord + j * (int) UIConstants.SquareSpacer, UIConstants.SquareWidth, UIConstants.SquareHeight); diff --git a/Crossword/UI/DrawUserChar.cs b/Crossword/UI/DrawUserChar.cs index 8d03c8d..2b14019 100644 --- a/Crossword/UI/DrawUserChar.cs +++ b/Crossword/UI/DrawUserChar.cs @@ -21,7 +21,7 @@ private void DrawUserChar(int i, int j) logger.LogInformation("Start DrawUserChar()"); //check for null - if (sqPuzzleSquares[i, j] != null && _puzzleSquares[i, j] != null) + if (_puzzleSquares != null && sqPuzzleSquares[i, j] != null && _puzzleSquares[i, j] != null) { //Char entered by user. _spriteBatch.DrawString(_fntFont, char.ToUpper(sqPuzzleSquares[i, j].Letter).ToString(), diff --git a/Crossword/UI/PuzzleButton.cs b/Crossword/UI/PuzzleButton.cs index 7fe8bee..852a59c 100644 --- a/Crossword/UI/PuzzleButton.cs +++ b/Crossword/UI/PuzzleButton.cs @@ -16,14 +16,14 @@ public class PuzzleButton public event EventHandler? Click; //Image for button - public Texture2D Texture { get; set; } + private Texture2D Texture { get; set; } // Vector fo x,y coords - public Vector2 Position { get; set; } + private Vector2 Position { get; set; } // Rect bounds public Rectangle Bounds => new((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height); - //public Rectangle Bounds => new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height); + #endregion diff --git a/Crossword/init/InitData.cs b/Crossword/init/InitData.cs index 917e190..49cf27b 100644 --- a/Crossword/init/InitData.cs +++ b/Crossword/init/InitData.cs @@ -28,7 +28,7 @@ private void InitData() _szTmpGetLetters = _mrParserData?.GetLetters; //Initialise Blurb - _szBlurb = _mrParserData?.Blurb; + //_szBlurb = _mrParserData?.Blurb; //Initialise dimension variables _nCrosswordWidth = _NumCols * (UIConstants.SquareWidth + (int)UIConstants.SquareSpacer); diff --git a/Crossword/init/InitPuzzleData.cs b/Crossword/init/InitPuzzleData.cs index bba3de7..20c3a07 100644 --- a/Crossword/init/InitPuzzleData.cs +++ b/Crossword/init/InitPuzzleData.cs @@ -3,7 +3,6 @@ using System.Data; using System.Threading.Tasks; using Crossword.Entities; -using Crossword.Entities; using Crossword.Parser; using Crossword.Data; diff --git a/Crossword/main/CrosswordMain.cs b/Crossword/main/CrosswordMain.cs index c2c4c75..3eb5cc9 100644 --- a/Crossword/main/CrosswordMain.cs +++ b/Crossword/main/CrosswordMain.cs @@ -44,7 +44,7 @@ public sealed partial class CrosswordMain : Game //Repaint variables private bool bBufferDirty; - public bool InitCrossword; + private bool InitCrossword; //Image imBackBuffer; private bool NewBackFlush; @@ -58,7 +58,7 @@ public sealed partial class CrosswordMain : Game private int[] _nCosts = [0, 0, 0, 0, 0, 0]; private string? _szGetLetters; private string? _szTmpGetLetters; - private string? _szBlurb; + //private string? _szBlurb; private int NumQuestions; //Puzzle Dataset instance From c1e8b58f41858d1521b2a50b55cad9109fc04a47 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 13:56:55 +1100 Subject: [PATCH 17/26] refactor --- Crossword/init/InitListBoxes.cs | 17 ++++++++++++ Crossword/main/CrosswordMain.cs | 46 +++++---------------------------- 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/Crossword/init/InitListBoxes.cs b/Crossword/init/InitListBoxes.cs index 04cde20..390f299 100644 --- a/Crossword/init/InitListBoxes.cs +++ b/Crossword/init/InitListBoxes.cs @@ -77,6 +77,15 @@ private void InitListBoxDown() SelectionMode = SelectionMode.Single, Height = UIConstants.ClListboxHeight }; + // LstClueDown = new ListView + // { + // Left = rectCrossWord.Right + UIConstants.MainOffsetY, + // Top = UIConstants.ClListboxHeight + UIConstants.ClLabelHeight + UIConstants.ClListSpacer * 2 + + // UIConstants.ClLabelHeight, + // AcceptsKeyboardFocus = true, + // SelectionMode = SelectionMode.Single, + // Height = UIConstants.ClListboxHeight + // }; //set the font LstClueDown.ListBoxStyle.ListItemStyle.LabelStyle.Font = _fntListFont; @@ -123,6 +132,14 @@ private void InitListBoxAcross() SelectionMode = SelectionMode.Single, Height = UIConstants.ClListboxHeight }; + // LstClueAcross = new ListView + // { + // Left = rectCrossWord.Right + UIConstants.MainOffsetX, + // Top = UIConstants.MainOffsetY, + // AcceptsKeyboardFocus = true, + // SelectionMode = SelectionMode.Single, + // Height = UIConstants.ClListboxHeight + // }; //set the font LstClueAcross.ListBoxStyle.ListItemStyle.LabelStyle.Font = _fntListFont; diff --git a/Crossword/main/CrosswordMain.cs b/Crossword/main/CrosswordMain.cs index 3eb5cc9..b732af9 100644 --- a/Crossword/main/CrosswordMain.cs +++ b/Crossword/main/CrosswordMain.cs @@ -36,9 +36,6 @@ public sealed partial class CrosswordMain : Game private bool PuzzleFinished; private bool SetFinished; - //Next Puzzle is currently unavailable flag - //private bool IsNextPuzzleReady = true; - //String for Puzzle ID of last puzzle in set private string? PuzzleData; @@ -58,7 +55,6 @@ public sealed partial class CrosswordMain : Game private int[] _nCosts = [0, 0, 0, 0, 0, 0]; private string? _szGetLetters; private string? _szTmpGetLetters; - //private string? _szBlurb; private int NumQuestions; //Puzzle Dataset instance @@ -70,56 +66,29 @@ public sealed partial class CrosswordMain : Game //ClueAnswerMap Instance variable private ClueAnswer[] caPuzzleClueAnswers; - //Highlight Constants - // private readonly int CurrentLetter = 1; - // private readonly int CurrentWord = 2; - // private readonly int CurrentNone = 3; - - //CrosswordMain.Application dimension constants - // private readonly int MaxCrossWidth = 291; - // private readonly int MaxCrossHeight = 291; //string[,] strGuesses = null; private Square? SqCurrentSquare; public bool IsFinished; - //Square width and height constants - // private static readonly int SquareWidth; - // private static readonly int SquareHeight; - - //X and Y Offsets for the square's answer number. - //private int NXnumOffset = 2, NYnumOffset = 9; - + //Status of row/column orientation (Across or Down) private bool IsAcross = true; - //Mouse Coords - public int NMouseX; - public int NMouseY; - //Tab key variable - //private readonly int NTabPress; - - //Scoring variable - //private int Score; //Component focus variable private int FocusState; - //mouseMove String - //private readonly string PuzzleTitle; - //Number of times Hint has been accessed by the user - //int nUserHintPress; // CrosswordMain.Application score private int CrosswordScore; - //More puzzles in set boolean flag - //private bool _bMorePuzzles; + //Parser class private CrosswordParser _crosswordParser; @@ -145,6 +114,8 @@ public sealed partial class CrosswordMain : Game //list boxes private ListBox LstClueAcross; private ListBox LstClueDown; + // private ListView LstClueAcross; + // private ListView LstClueDown; //Panel for UI private Panel _mainPanel; @@ -161,7 +132,6 @@ public sealed partial class CrosswordMain : Game // Define a color for the rectangles private readonly Color _rectangleColor = Color.White; - //private Color _rectangleBlack = Color.Black; private Texture2D _blackTexture; //Fonts @@ -192,17 +162,13 @@ public sealed partial class CrosswordMain : Game //Rectangle variable public Rectangle rectCrossWord; - //Hint LinkButton - //private TextButton HintButton; - - //Get Next Puzzle LinkButton - // private TextButton GetNextPuzzleButton; + //CrosswordMain.Application Width and Height variables private int _nCrosswordWidth; private int _nCrosswordHeight; - //private readonly int _nCrosswordOffset = 6; + //Offset constants //private readonly int _nCrossBorderWidth = 3; From b329b426df3a30e11a335b354a60d647242b97f1 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 14:22:51 +1100 Subject: [PATCH 18/26] refactored UI elements --- Crossword/UI/DrawCreditsLabel.cs | 41 +++++++++++--- Crossword/UI/DrawCrosswordScore.cs | 91 ++++++++++++++++++++++-------- Crossword/monogame/Monogame.cs | 4 +- 3 files changed, 104 insertions(+), 32 deletions(-) diff --git a/Crossword/UI/DrawCreditsLabel.cs b/Crossword/UI/DrawCreditsLabel.cs index 9695aa6..69aa292 100644 --- a/Crossword/UI/DrawCreditsLabel.cs +++ b/Crossword/UI/DrawCreditsLabel.cs @@ -1,6 +1,8 @@ using System; using Crossword.Shared.Constants; +using Myra.Graphics2D.UI; + namespace Crossword.App; public sealed partial class CrosswordMain @@ -9,20 +11,43 @@ public sealed partial class CrosswordMain /// /// Draws a Credits label /// - private void DrawCreditsLabel() + // private void DrawCreditsLabel() + // { + // try + // { + // logger.LogInformation("Start DrawCreditsLabel()"); + // + // //Max score label + // _mainPanel.Widgets.Remove(_creditsLabel); + // _creditsLabel.Text = GameConstants.CreditsText; + // _creditsLabel.TextColor = UIConstants.CreditsColor; + // _creditsLabel.Left = rectCrossWord.Left; + // _creditsLabel.Font = _fntCredits; + // _creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + UIConstants.SquareHeight/2; + // _mainPanel.Widgets.Add(_creditsLabel); + // + // } + // catch (Exception ex) + // { + // logger.LogError(ex,ex.Message); + // throw; + // } + // } + + private void DrawCreditsLabel(Panel mainPanel, Label creditsLabel) { try { logger.LogInformation("Start DrawCreditsLabel()"); //Max score label - _mainPanel.Widgets.Remove(_creditsLabel); - _creditsLabel.Text = GameConstants.CreditsText; - _creditsLabel.TextColor = UIConstants.CreditsColor; - _creditsLabel.Left = rectCrossWord.Left; - _creditsLabel.Font = _fntCredits; - _creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + UIConstants.SquareHeight/2; - _mainPanel.Widgets.Add(_creditsLabel); + mainPanel.Widgets.Remove(creditsLabel); + creditsLabel.Text = GameConstants.CreditsText; + creditsLabel.TextColor = UIConstants.CreditsColor; + creditsLabel.Left = rectCrossWord.Left; + creditsLabel.Font = _fntCredits; + creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + UIConstants.SquareHeight/2; + mainPanel.Widgets.Add(creditsLabel); } catch (Exception ex) diff --git a/Crossword/UI/DrawCrosswordScore.cs b/Crossword/UI/DrawCrosswordScore.cs index 4c5a2c5..d26c68a 100644 --- a/Crossword/UI/DrawCrosswordScore.cs +++ b/Crossword/UI/DrawCrosswordScore.cs @@ -1,6 +1,7 @@ using System; using Crossword.Shared.Constants; +using Myra.Graphics2D.UI; namespace Crossword.App; @@ -10,7 +11,53 @@ public sealed partial class CrosswordMain /// /// Draws the crossword score and updates the values /// - private void DrawCrosswordScore() + // private void DrawCrosswordScore() + // { + // try + // { + // logger.LogInformation("Start DrawCrosswordScore()"); + // + // if (!IsFinished) + // { + // //Current score label + // _mainPanel.Widgets.Remove(_currentScoreLabel); + // _currentScoreLabel.Text = $"Your Score: {CrosswordScore.ToString()}"; + // _currentScoreLabel.TextColor = UIConstants.ScoreColor; + // _currentScoreLabel.Left = UIConstants.ClListSpacer * 40; + // _currentScoreLabel.Font = _fntScore; + // _currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; + // _mainPanel.Widgets.Add(_currentScoreLabel); + // } + // else + // { + // //Game over label + // _mainPanel.Widgets.Remove(_currentScoreLabel); + // _currentScoreLabel.Text = "GAME OVER!"; + // _currentScoreLabel.TextColor = UIConstants.ScoreColor; + // _currentScoreLabel.Left = UIConstants.ClListSpacer * 40; + // _currentScoreLabel.Font = _fntScore; + // _currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; + // _mainPanel.Widgets.Add(_currentScoreLabel); + // } + // + // //Max score label + // _mainPanel.Widgets.Remove(_maxScoreLabel); + // _maxScoreLabel.Text = $"Max Score: {NumQuestions.ToString()}"; + // _maxScoreLabel.TextColor = UIConstants.ScoreColor; + // _maxScoreLabel.Left = UIConstants.ClListSpacer * 40; + // _maxScoreLabel.Font = _fntScore; + // _maxScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 6; + // _mainPanel.Widgets.Add(_maxScoreLabel); + // + // } + // catch (Exception ex) + // { + // logger.LogError(ex,ex.Message); + // throw; + // } + // } + + private void DrawCrosswordScore(Panel mainPanel, Label currentScoreLabel, Label maxScoreLabel) { try { @@ -19,34 +66,34 @@ private void DrawCrosswordScore() if (!IsFinished) { //Current score label - _mainPanel.Widgets.Remove(_currentScoreLabel); - _currentScoreLabel.Text = $"Your Score: {CrosswordScore.ToString()}"; - _currentScoreLabel.TextColor = UIConstants.ScoreColor; - _currentScoreLabel.Left = UIConstants.ClListSpacer * 40; - _currentScoreLabel.Font = _fntScore; - _currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; - _mainPanel.Widgets.Add(_currentScoreLabel); + mainPanel.Widgets.Remove(currentScoreLabel); + currentScoreLabel.Text = $"Your Score: {CrosswordScore.ToString()}"; + currentScoreLabel.TextColor = UIConstants.ScoreColor; + currentScoreLabel.Left = UIConstants.ClListSpacer * 40; + currentScoreLabel.Font = _fntScore; + currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; + mainPanel.Widgets.Add(currentScoreLabel); } else { //Game over label - _mainPanel.Widgets.Remove(_currentScoreLabel); - _currentScoreLabel.Text = "GAME OVER!"; - _currentScoreLabel.TextColor = UIConstants.ScoreColor; - _currentScoreLabel.Left = UIConstants.ClListSpacer * 40; - _currentScoreLabel.Font = _fntScore; - _currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; - _mainPanel.Widgets.Add(_currentScoreLabel); + mainPanel.Widgets.Remove(currentScoreLabel); + currentScoreLabel.Text = "GAME OVER!"; + currentScoreLabel.TextColor = UIConstants.ScoreColor; + currentScoreLabel.Left = UIConstants.ClListSpacer * 40; + currentScoreLabel.Font = _fntScore; + currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; + mainPanel.Widgets.Add(currentScoreLabel); } //Max score label - _mainPanel.Widgets.Remove(_maxScoreLabel); - _maxScoreLabel.Text = $"Max Score: {NumQuestions.ToString()}"; - _maxScoreLabel.TextColor = UIConstants.ScoreColor; - _maxScoreLabel.Left = UIConstants.ClListSpacer * 40; - _maxScoreLabel.Font = _fntScore; - _maxScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 6; - _mainPanel.Widgets.Add(_maxScoreLabel); + mainPanel.Widgets.Remove(maxScoreLabel); + maxScoreLabel.Text = $"Max Score: {NumQuestions.ToString()}"; + maxScoreLabel.TextColor = UIConstants.ScoreColor; + maxScoreLabel.Left = UIConstants.ClListSpacer * 40; + maxScoreLabel.Font = _fntScore; + maxScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 6; + mainPanel.Widgets.Add(maxScoreLabel); } catch (Exception ex) diff --git a/Crossword/monogame/Monogame.cs b/Crossword/monogame/Monogame.cs index 1615e06..53edb36 100644 --- a/Crossword/monogame/Monogame.cs +++ b/Crossword/monogame/Monogame.cs @@ -101,10 +101,10 @@ protected override void Update(GameTime gameTime) //update game logic UpdateCrosswordScore(); - DrawCrosswordScore(); + DrawCrosswordScore(_mainPanel, _currentScoreLabel, _maxScoreLabel); //draw the credits - DrawCreditsLabel(); + DrawCreditsLabel(_mainPanel, _creditsLabel); base.Update(gameTime); From e97fca95c752ae150d7dd8db3e05e5eb7ca4a346 Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 16:00:58 +1100 Subject: [PATCH 19/26] added crossword.puzzle project --- Crossword.Net.sln | 16 +-- Crossword.Puzzle/ClueAnswerMap/CheckHint.cs | 38 ++++++ Crossword.Puzzle/ClueAnswerMap/CheckWord.cs | 27 +++++ .../ClueAnswerMap/ClueAnswerMap.cs | 31 +++++ Crossword.Puzzle/ClueAnswerMap/GetNextSq.cs | 39 ++++++ Crossword.Puzzle/ClueAnswerMap/GetPrevSq.cs | 31 +++++ Crossword.Puzzle/ClueAnswerMap/GetSquare.cs | 19 +++ .../ClueAnswerMap/HighlightSquares.cs | 50 ++++++++ Crossword.Puzzle/ClueAnswerMap/IsCorrect.cs | 21 ++++ .../ClueAnswerMap/SetObjectRef.cs | 57 +++++++++ Crossword.Puzzle/Crossword.Puzzle.csproj | 17 +++ Crossword.Puzzle/Squares/CanFlipDirection.cs | 35 ++++++ Crossword.Puzzle/Squares/CheckLetter.cs | 21 ++++ Crossword.Puzzle/Squares/CreateSquare.cs | 19 +++ Crossword.Puzzle/Squares/GetClueAnswerRef.cs | 20 +++ Crossword.Puzzle/Squares/GetNextSq.cs | 40 ++++++ Crossword.Puzzle/Squares/GetPrevSq.cs | 20 +++ Crossword.Puzzle/Squares/SetHighlighted.cs | 55 +++++++++ Crossword.Puzzle/Squares/SetLetter.cs | 22 ++++ Crossword.Puzzle/Squares/SetObjectRef.cs | 31 +++++ Crossword.Puzzle/Squares/Square.cs | 39 ++++++ Crossword.Squares/GetClueAnswerRef.cs | 2 +- Crossword.Squares/SetObjectRef.cs | 2 +- Crossword.Squares/Square.cs | 4 +- Crossword/ClueAnswerMap/CheckHint.cs | 76 ++++++------ Crossword/ClueAnswerMap/CheckWord.cs | 54 ++++----- Crossword/ClueAnswerMap/ClueAnswerMap.cs | 62 +++++----- Crossword/ClueAnswerMap/GetNextSq.cs | 78 ++++++------ Crossword/ClueAnswerMap/GetPrevSq.cs | 62 +++++----- Crossword/ClueAnswerMap/GetSquare.cs | 38 +++--- Crossword/ClueAnswerMap/HighlightSquares.cs | 100 +++++++-------- Crossword/ClueAnswerMap/IsCorrect.cs | 42 +++---- Crossword/ClueAnswerMap/SetObjectRef.cs | 114 +++++++++--------- Crossword/Crossword.csproj | 1 + Crossword/EventHandlers/MouseHandlers.cs | 2 +- Crossword/PuzzleSquares/CanFlipDirection.cs | 70 +++++------ Crossword/PuzzleSquares/CheckLetter.cs | 42 +++---- Crossword/PuzzleSquares/CreateSquare.cs | 38 +++--- Crossword/PuzzleSquares/GetClueAnswerRef.cs | 40 +++--- Crossword/PuzzleSquares/GetNextSq.cs | 80 ++++++------ Crossword/PuzzleSquares/GetPrevSq.cs | 40 +++--- Crossword/PuzzleSquares/SetHighlighted.cs | 110 ++++++++--------- Crossword/PuzzleSquares/SetLetter.cs | 44 +++---- Crossword/PuzzleSquares/SetObjectRef.cs | 62 +++++----- Crossword/PuzzleSquares/Square.cs | 78 ++++++------ Crossword/init/InitArrays.cs | 2 +- Crossword/init/InitClueAnswers.cs | 4 +- Crossword/init/InitialiseCrossword.cs | 4 +- Crossword/main/CrosswordMain.cs | 6 +- 49 files changed, 1265 insertions(+), 640 deletions(-) create mode 100644 Crossword.Puzzle/ClueAnswerMap/CheckHint.cs create mode 100644 Crossword.Puzzle/ClueAnswerMap/CheckWord.cs create mode 100644 Crossword.Puzzle/ClueAnswerMap/ClueAnswerMap.cs create mode 100644 Crossword.Puzzle/ClueAnswerMap/GetNextSq.cs create mode 100644 Crossword.Puzzle/ClueAnswerMap/GetPrevSq.cs create mode 100644 Crossword.Puzzle/ClueAnswerMap/GetSquare.cs create mode 100644 Crossword.Puzzle/ClueAnswerMap/HighlightSquares.cs create mode 100644 Crossword.Puzzle/ClueAnswerMap/IsCorrect.cs create mode 100644 Crossword.Puzzle/ClueAnswerMap/SetObjectRef.cs create mode 100644 Crossword.Puzzle/Crossword.Puzzle.csproj create mode 100644 Crossword.Puzzle/Squares/CanFlipDirection.cs create mode 100644 Crossword.Puzzle/Squares/CheckLetter.cs create mode 100644 Crossword.Puzzle/Squares/CreateSquare.cs create mode 100644 Crossword.Puzzle/Squares/GetClueAnswerRef.cs create mode 100644 Crossword.Puzzle/Squares/GetNextSq.cs create mode 100644 Crossword.Puzzle/Squares/GetPrevSq.cs create mode 100644 Crossword.Puzzle/Squares/SetHighlighted.cs create mode 100644 Crossword.Puzzle/Squares/SetLetter.cs create mode 100644 Crossword.Puzzle/Squares/SetObjectRef.cs create mode 100644 Crossword.Puzzle/Squares/Square.cs diff --git a/Crossword.Net.sln b/Crossword.Net.sln index c355996..42e88ab 100644 --- a/Crossword.Net.sln +++ b/Crossword.Net.sln @@ -12,9 +12,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Entities", "Cross EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Data", "Crossword.Data\Crossword.Data.csproj", "{08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Squares", "Crossword.Squares\Crossword.Squares.csproj", "{9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.ClueAnswer", "Crossword.ClueAnswer\Crossword.ClueAnswer.csproj", "{F0A08490-2940-4C75-A202-5C656872195A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Puzzle", "Crossword.Puzzle\Crossword.Puzzle.csproj", "{96B22047-3AAC-44ED-B501-DD8894083A3C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -46,13 +44,9 @@ Global {08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}.Debug|Any CPU.Build.0 = Debug|Any CPU {08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}.Release|Any CPU.ActiveCfg = Release|Any CPU {08FAF8BC-DBEA-4FCF-9BF9-B2B3E8FD1122}.Release|Any CPU.Build.0 = Release|Any CPU - {9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9DA98578-CB2F-494F-B6AF-AE1577EB7F9E}.Release|Any CPU.Build.0 = Release|Any CPU - {F0A08490-2940-4C75-A202-5C656872195A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F0A08490-2940-4C75-A202-5C656872195A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F0A08490-2940-4C75-A202-5C656872195A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F0A08490-2940-4C75-A202-5C656872195A}.Release|Any CPU.Build.0 = Release|Any CPU + {96B22047-3AAC-44ED-B501-DD8894083A3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {96B22047-3AAC-44ED-B501-DD8894083A3C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {96B22047-3AAC-44ED-B501-DD8894083A3C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {96B22047-3AAC-44ED-B501-DD8894083A3C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Crossword.Puzzle/ClueAnswerMap/CheckHint.cs b/Crossword.Puzzle/ClueAnswerMap/CheckHint.cs new file mode 100644 index 0000000..38e89df --- /dev/null +++ b/Crossword.Puzzle/ClueAnswerMap/CheckHint.cs @@ -0,0 +1,38 @@ +using System; +using System.Threading.Tasks; + +namespace Crossword.Puzzle.ClueAnswerMap; + +public sealed partial class ClueAnswer +{ + #region CheckHint + + /// + /// Sets the Hint letter if Get Letter is pressed + /// + /// + /// + public bool CheckHint(char hintLetter) + { + if (hintLetter <= 0) throw new ArgumentOutOfRangeException(nameof(hintLetter)); + + var foundResult = false; + + // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere + if (Answer is null) return foundResult; + var szAnswerLength = Answer.Length; + + //Parallel for loop + Parallel.For(0, szAnswerLength, i => + { + if (SqAnswerSquares is null || Answer[i] != hintLetter || + SqAnswerSquares[i]!.Letter == hintLetter) return; + SqAnswerSquares[i]?.SetLetter(hintLetter, IsAcross); + foundResult = true; + }); + + return foundResult; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/ClueAnswerMap/CheckWord.cs b/Crossword.Puzzle/ClueAnswerMap/CheckWord.cs new file mode 100644 index 0000000..13befbe --- /dev/null +++ b/Crossword.Puzzle/ClueAnswerMap/CheckWord.cs @@ -0,0 +1,27 @@ +using System.Threading.Tasks; + +namespace Crossword.Puzzle.ClueAnswerMap; + +public sealed partial class ClueAnswer +{ + #region CheckWord + + /// + /// Sets the letter colour if Check words is pressed. + /// + public void CheckWord() + { + if (Answer is null) return; + // for (var i = 0; i < Answer.Length; i++) + // { + // SqAnswerSquares?[i]?.CheckLetter(Answer[i]); + // } + + Parallel.For(0, Answer.Length, i => + { + SqAnswerSquares?[i]?.CheckLetter(Answer[i]); + }); + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/ClueAnswerMap/ClueAnswerMap.cs b/Crossword.Puzzle/ClueAnswerMap/ClueAnswerMap.cs new file mode 100644 index 0000000..0d31054 --- /dev/null +++ b/Crossword.Puzzle/ClueAnswerMap/ClueAnswerMap.cs @@ -0,0 +1,31 @@ +//////////////////////////////////////////////////////////////////////////// +// // +// Module: ClueAnswerMap.cs // +// Authors: Aaron Saikovski & Bryan Richards // +// Original Date: 26/02/97 // +// Version: 1.0 // +// Purpose: Clue + Answer references class // +// // +//////////////////////////////////////////////////////////////////////////// + +using Crossword.Puzzle.Squares; + +namespace Crossword.Puzzle.ClueAnswerMap; + +/// +/// ClueAnswerMap Class +/// +public sealed partial class ClueAnswer +{ + #region getters_setters + public string? Answer { get; set; } + public string? Clue { get; set; } + + public int QuestionNumber { get; set; } + + public bool IsAcross { get; set; } = true; + + public Square?[]? SqAnswerSquares { get; set; } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/ClueAnswerMap/GetNextSq.cs b/Crossword.Puzzle/ClueAnswerMap/GetNextSq.cs new file mode 100644 index 0000000..6f8d20d --- /dev/null +++ b/Crossword.Puzzle/ClueAnswerMap/GetNextSq.cs @@ -0,0 +1,39 @@ +using System; +using Crossword.Puzzle.Squares; + +namespace Crossword.Puzzle.ClueAnswerMap; + +public sealed partial class ClueAnswer +{ + #region GetNextSq + + /// + /// Returns the next square + /// + /// + /// + public Square? GetNextSq(Square? sq) + { + ArgumentNullException.ThrowIfNull(sq); + var i = 0; + while (Answer != null && i < Answer.Length){ + if (SqAnswerSquares != null && sq == SqAnswerSquares[i]) + if (i < Answer.Length - 1) + return SqAnswerSquares[i + 1]; + i++; + } + return sq; + + // ArgumentNullException.ThrowIfNull(sq); + // var i = 0; + // while (i < Answer.Length){ + // if (sq == SqAnswerSquares[i]) + // if (i < Answer.Length - 1) + // return SqAnswerSquares[i + 1]; + // i++; + // } + // return sq; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/ClueAnswerMap/GetPrevSq.cs b/Crossword.Puzzle/ClueAnswerMap/GetPrevSq.cs new file mode 100644 index 0000000..7557eca --- /dev/null +++ b/Crossword.Puzzle/ClueAnswerMap/GetPrevSq.cs @@ -0,0 +1,31 @@ +using System; +using Crossword.Puzzle.Squares; + +namespace Crossword.Puzzle.ClueAnswerMap; + +public sealed partial class ClueAnswer +{ + #region GetPrevSq + + /// + /// Returns the previous square + /// + /// + /// + public Square? GetPrevSq(Square? sq) + { + ArgumentNullException.ThrowIfNull(sq); + + if (Answer is null) return sq; + var i = Answer.Length - 1; + while (i > -1) + { + if (sq == SqAnswerSquares?[i]) return i != 0 ? SqAnswerSquares?[i - 1] : sq; + i--; + } + + return sq; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/ClueAnswerMap/GetSquare.cs b/Crossword.Puzzle/ClueAnswerMap/GetSquare.cs new file mode 100644 index 0000000..7d2b436 --- /dev/null +++ b/Crossword.Puzzle/ClueAnswerMap/GetSquare.cs @@ -0,0 +1,19 @@ +using Crossword.Puzzle.Squares; + +namespace Crossword.Puzzle.ClueAnswerMap; + +public sealed partial class ClueAnswer +{ + #region GetSquare + + /// + /// Gets the first square referenced by my answer. + /// + /// + public Square? GetSquare() + { + return SqAnswerSquares?[0]; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/ClueAnswerMap/HighlightSquares.cs b/Crossword.Puzzle/ClueAnswerMap/HighlightSquares.cs new file mode 100644 index 0000000..fb9698f --- /dev/null +++ b/Crossword.Puzzle/ClueAnswerMap/HighlightSquares.cs @@ -0,0 +1,50 @@ +using System; +using System.Threading.Tasks; +using Crossword.Puzzle.Squares; +using Crossword.Shared.Constants; + +namespace Crossword.Puzzle.ClueAnswerMap; + +public sealed partial class ClueAnswer +{ + #region HighlightSquares + + /// + /// /Highlights the current word and sets active square + /// + /// + /// + public void HighlightSquares(Square? sq, bool setHighLighted) + { + ArgumentNullException.ThrowIfNull(sq); + + if (Answer is null) return; + // for (var i = 0; i < Answer.Length; i++) + // { + // if (!setHighLighted) + // SqAnswerSquares?[i]?.SetHighlighted(CWSettings.CurrentNone); + // else + // { + // SqAnswerSquares?[i] + // ?.SetHighlighted(SqAnswerSquares?[i] == sq + // ? CWSettings.CurrentLetter + // : CWSettings.CurrentWord); + // } + // } + + Parallel.For(0, Answer.Length, i => + { + if (!setHighLighted) + SqAnswerSquares?[i]?.SetHighlighted(UIConstants.CurrentNone); + else + { + SqAnswerSquares?[i] + ?.SetHighlighted(SqAnswerSquares?[i] == sq + ? UIConstants.CurrentLetter + : UIConstants.CurrentWord); + } + }); + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/ClueAnswerMap/IsCorrect.cs b/Crossword.Puzzle/ClueAnswerMap/IsCorrect.cs new file mode 100644 index 0000000..39657f4 --- /dev/null +++ b/Crossword.Puzzle/ClueAnswerMap/IsCorrect.cs @@ -0,0 +1,21 @@ +using System.Linq; + +namespace Crossword.Puzzle.ClueAnswerMap; + +public sealed partial class ClueAnswer +{ + #region IsCorrect + + /// + /// Returns true if all answer letters are correct and false otherwise + /// + /// + public bool IsCorrect() + { + if (Answer is not null) + return !Answer.Where((t, i) => SqAnswerSquares is not null && SqAnswerSquares[i]!.Letter != t).Any(); + return true; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/ClueAnswerMap/SetObjectRef.cs b/Crossword.Puzzle/ClueAnswerMap/SetObjectRef.cs new file mode 100644 index 0000000..1ade060 --- /dev/null +++ b/Crossword.Puzzle/ClueAnswerMap/SetObjectRef.cs @@ -0,0 +1,57 @@ +using System; +using System.Threading.Tasks; +using Crossword.Puzzle.Squares; + +namespace Crossword.Puzzle.ClueAnswerMap; + +public sealed partial class ClueAnswer +{ + #region SetObjectRef + + /// + /// Sets the object reference. + /// + /// + /// + /// + /// + /// + public void SetObjectRef(string Answer, string Clue, int QuestionNumber, + bool IsAcross, Square?[]? SqAnswerSquares) + { + ArgumentNullException.ThrowIfNull(Answer); + ArgumentNullException.ThrowIfNull(Clue); + ArgumentNullException.ThrowIfNull(SqAnswerSquares); + + this.Answer = Answer; + this.Clue = Clue; + this.QuestionNumber = QuestionNumber; + this.IsAcross = IsAcross; + + //Initialise the answer squares array. + this.SqAnswerSquares = new Square[Answer.Length]; + + //Copy the array + // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere + var szAnswerLength = Answer.Length; + + //Parallel for loop + Parallel.For(0, szAnswerLength, k => + { + // Create a new Square instance + var sqAnswerSquares = this.SqAnswerSquares; + if (sqAnswerSquares is not null) + { + sqAnswerSquares[k] = new Square(); + sqAnswerSquares[k]?.CreateSquare(0, 0); + sqAnswerSquares[k] = SqAnswerSquares[k]; + } + + // Assign the created Square to the array element + // The original code `this.sqAnswerSquares[k] = sqAnswerSquares[k];` seems redundant, so omitted + if (SqAnswerSquares is not null) SqAnswerSquares?[k]?.SetObjectRef(this.IsAcross, this); + }); + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/Crossword.Puzzle.csproj b/Crossword.Puzzle/Crossword.Puzzle.csproj new file mode 100644 index 0000000..08682a1 --- /dev/null +++ b/Crossword.Puzzle/Crossword.Puzzle.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/Crossword.Puzzle/Squares/CanFlipDirection.cs b/Crossword.Puzzle/Squares/CanFlipDirection.cs new file mode 100644 index 0000000..8d6629a --- /dev/null +++ b/Crossword.Puzzle/Squares/CanFlipDirection.cs @@ -0,0 +1,35 @@ +namespace Crossword.Puzzle.Squares; + +public sealed partial class Square +{ + #region CanFlipDirection + + /// + /// Can the current orientation be flipped. + /// + /// + /// + public bool CanFlipDirection(bool isAcross) + { + switch (isAcross) + { + //if square is an intersection + case true when ClueAnswerDown is not null: + case false when ClueAnswerAcross is not null: + return true; + default: + return false; + } + + //if square is an intersection + // if ((isAcross) && (ClueAnswerDown != null)) + // return true; + // else if ((!isAcross) && (ClueAnswerAcross != null)) + // return true; + // else + // return false; + + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/Squares/CheckLetter.cs b/Crossword.Puzzle/Squares/CheckLetter.cs new file mode 100644 index 0000000..9be9632 --- /dev/null +++ b/Crossword.Puzzle/Squares/CheckLetter.cs @@ -0,0 +1,21 @@ +using Crossword.Shared.Constants; + +namespace Crossword.Puzzle.Squares; + +public sealed partial class Square +{ + #region CheckLetter + + /// + /// Check for correctness of letter based on input char parameter and toggles colour accordingly + /// + /// + public void CheckLetter(char correctLetter) + { + if (Letter == ' ') return; + ForeColour = Letter == correctLetter ? UIConstants.SqCorrect : UIConstants.SqError; + IsDirty = true; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/Squares/CreateSquare.cs b/Crossword.Puzzle/Squares/CreateSquare.cs new file mode 100644 index 0000000..70904d7 --- /dev/null +++ b/Crossword.Puzzle/Squares/CreateSquare.cs @@ -0,0 +1,19 @@ +namespace Crossword.Puzzle.Squares; + +public sealed partial class Square +{ + #region CreateSquare + + /// + /// Allocates memory for blank square + /// + /// + /// + public void CreateSquare(int xCoord, int yCoord) + { + this.xCoord = xCoord; + this.yCoord = yCoord; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/Squares/GetClueAnswerRef.cs b/Crossword.Puzzle/Squares/GetClueAnswerRef.cs new file mode 100644 index 0000000..647910d --- /dev/null +++ b/Crossword.Puzzle/Squares/GetClueAnswerRef.cs @@ -0,0 +1,20 @@ +using Crossword.Puzzle.ClueAnswerMap; + +namespace Crossword.Puzzle.Squares; + +public sealed partial class Square +{ + #region GetClueAnswerRef + + /// + /// returns the Clue/Answer reference + /// + /// + /// + public ClueAnswer? GetClueAnswerRef(bool isAcross) + { + return isAcross ? ClueAnswerAcross : ClueAnswerDown; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/Squares/GetNextSq.cs b/Crossword.Puzzle/Squares/GetNextSq.cs new file mode 100644 index 0000000..f4015d2 --- /dev/null +++ b/Crossword.Puzzle/Squares/GetNextSq.cs @@ -0,0 +1,40 @@ +namespace Crossword.Puzzle.Squares; + +public sealed partial class Square +{ + #region GetNextSq + + /// + /// Gets the next available square + /// + /// + /// + public Square? GetNextSq(bool isAcross) + { + if (isAcross) + { + return ClueAnswerAcross != null ? ClueAnswerAcross.GetNextSq(this) : this; + } + + return ClueAnswerDown != null ? ClueAnswerDown.GetNextSq(this) : this; + + + // if (isAcross) + // { + // if(ClueAnswerAcross != null) + // return ClueAnswerAcross.GetNextSq(this); + // else + // return this; + // } + // else + // { + // if(ClueAnswerDown != null) + // return ClueAnswerDown.GetNextSq(this); + // else + // return this; + // } + + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/Squares/GetPrevSq.cs b/Crossword.Puzzle/Squares/GetPrevSq.cs new file mode 100644 index 0000000..03a69fe --- /dev/null +++ b/Crossword.Puzzle/Squares/GetPrevSq.cs @@ -0,0 +1,20 @@ +namespace Crossword.Puzzle.Squares; + +public sealed partial class Square +{ + #region GetPrevSq + + /// + /// /Gets the previous available square + /// + /// + /// + public Square? GetPrevSq(bool isAcross) + { + if (isAcross) + return ClueAnswerAcross is not null ? ClueAnswerAcross.GetPrevSq(this) : this; + return ClueAnswerDown is not null ? ClueAnswerDown.GetPrevSq(this) : this; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/Squares/SetHighlighted.cs b/Crossword.Puzzle/Squares/SetHighlighted.cs new file mode 100644 index 0000000..2f554d4 --- /dev/null +++ b/Crossword.Puzzle/Squares/SetHighlighted.cs @@ -0,0 +1,55 @@ +using System; +using Crossword.Shared.Constants; + +namespace Crossword.Puzzle.Squares; + +public sealed partial class Square +{ + #region SetHighlighted + + /// + /// Sets the background colour of a square + /// + /// + public void SetHighlighted(int highlightType) + { + switch (highlightType) + { + case 1: //Current Letter + if (!BackColour.Equals(UIConstants.SquareHighlightCurrent)) + { + BackColour = UIConstants.SquareHighlightCurrent; + IsDirty = true; + } + + break; + case 2: //Current Word + if (!BackColour.Equals(UIConstants.SquareHighlightWord)) + { + BackColour = UIConstants.SquareHighlightWord; + IsDirty = true; + } + + break; + case 3: //Current None + if (!BackColour.Equals(UIConstants.SquareHighlightNone)) + { + BackColour = UIConstants.SquareHighlightNone; + IsDirty = true; + } + + break; + default: //Something went wrong.... + if (BackColour.Equals(UIConstants.SquareHighlightErr)) + { + //Console.WriteLine($"Bogus color: {highlightType}"); + BackColour = UIConstants.SquareHighlightErr; + IsDirty = true; + } + + break; + } + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/Squares/SetLetter.cs b/Crossword.Puzzle/Squares/SetLetter.cs new file mode 100644 index 0000000..2903676 --- /dev/null +++ b/Crossword.Puzzle/Squares/SetLetter.cs @@ -0,0 +1,22 @@ +using Crossword.Shared.Constants; + +namespace Crossword.Puzzle.Squares; + +public sealed partial class Square +{ + #region SetLetter + + /// + /// Set the colour for a letter. + /// + /// + /// + public void SetLetter(char letter, bool isAcross) + { + Letter = letter; + IsDirty = true; + ForeColour = UIConstants.SquareHighlightDefault; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/Squares/SetObjectRef.cs b/Crossword.Puzzle/Squares/SetObjectRef.cs new file mode 100644 index 0000000..01bc0e1 --- /dev/null +++ b/Crossword.Puzzle/Squares/SetObjectRef.cs @@ -0,0 +1,31 @@ +using System; +using Crossword.Puzzle.ClueAnswerMap; +using Crossword.Shared.Constants; + +namespace Crossword.Puzzle.Squares; + +public sealed partial class Square +{ + #region SetObjectRef + + /// + /// Set the object reference to clueanswer object + /// + /// + /// + public void SetObjectRef(bool isAcross, ClueAnswer clueAnswer) + { + ArgumentNullException.ThrowIfNull(clueAnswer); + + if (isAcross) + ClueAnswerAcross = clueAnswer; + else + ClueAnswerDown = clueAnswer; + + IsCharAllowed = true; + IsDirty = true; + BackColour = UIConstants.SquareHighlightNone; + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Puzzle/Squares/Square.cs b/Crossword.Puzzle/Squares/Square.cs new file mode 100644 index 0000000..e072e77 --- /dev/null +++ b/Crossword.Puzzle/Squares/Square.cs @@ -0,0 +1,39 @@ +//////////////////////////////////////////////////////////////////////////// +// // +// Module: Square.cs // +// Authors: Aaron Saikovski & Bryan Richards // +// Original Date: 23/01/97 // +// Version: 1.0 // +// Purpose: Defines a Square and it's attributes // +// // +//////////////////////////////////////////////////////////////////////////// + +using Crossword.Puzzle.ClueAnswerMap; +using Microsoft.Xna.Framework; + +namespace Crossword.Puzzle.Squares; + +//Square class +public sealed partial class Square +{ + #region getters_setters + + public int xCoord { get; set; } + public int yCoord { get; set; } + + + public char Letter { get; set; } + + + public Color ForeColour { get; set; } = Color.Black; + public Color BackColour { get; set; } = Color.Black; + + public bool IsDirty { get; set; } = true; + + public bool IsCharAllowed { get; set; } + + public ClueAnswer? ClueAnswerAcross { get; set; } + public ClueAnswer? ClueAnswerDown { get; set; } + + #endregion +} \ No newline at end of file diff --git a/Crossword.Squares/GetClueAnswerRef.cs b/Crossword.Squares/GetClueAnswerRef.cs index f038d0c..4718f5f 100644 --- a/Crossword.Squares/GetClueAnswerRef.cs +++ b/Crossword.Squares/GetClueAnswerRef.cs @@ -11,7 +11,7 @@ // /// // /// // /// -// public ClueAnswer? GetClueAnswerRef(bool isAcross) +// public ClueAnswerMap? GetClueAnswerRef(bool isAcross) // { // return isAcross ? ClueAnswerAcross : ClueAnswerDown; // } diff --git a/Crossword.Squares/SetObjectRef.cs b/Crossword.Squares/SetObjectRef.cs index 78497c6..03573af 100644 --- a/Crossword.Squares/SetObjectRef.cs +++ b/Crossword.Squares/SetObjectRef.cs @@ -13,7 +13,7 @@ // /// // /// // /// -// public void SetObjectRef(bool isAcross, ClueAnswer clueAnswer) +// public void SetObjectRef(bool isAcross, ClueAnswerMap clueAnswer) // { // ArgumentNullException.ThrowIfNull(clueAnswer); // diff --git a/Crossword.Squares/Square.cs b/Crossword.Squares/Square.cs index 5e85b95..ccafce6 100644 --- a/Crossword.Squares/Square.cs +++ b/Crossword.Squares/Square.cs @@ -22,8 +22,8 @@ namespace Crossword.Squares; // // public bool IsCharAllowed { get; set; } // -// // public ClueAnswer? ClueAnswerAcross { get; set; } -// // public ClueAnswer? ClueAnswerDown { get; set; } +// // public ClueAnswerMap? ClueAnswerAcross { get; set; } +// // public ClueAnswerMap? ClueAnswerDown { get; set; } // // #endregion // diff --git a/Crossword/ClueAnswerMap/CheckHint.cs b/Crossword/ClueAnswerMap/CheckHint.cs index c29c373..70ff5e9 100644 --- a/Crossword/ClueAnswerMap/CheckHint.cs +++ b/Crossword/ClueAnswerMap/CheckHint.cs @@ -1,38 +1,38 @@ -using System; -using System.Threading.Tasks; - -namespace Crossword.ClueAnswerMap; - -public sealed partial class ClueAnswer -{ - #region CheckHint - - /// - /// Sets the Hint letter if Get Letter is pressed - /// - /// - /// - public bool CheckHint(char hintLetter) - { - if (hintLetter <= 0) throw new ArgumentOutOfRangeException(nameof(hintLetter)); - - var foundResult = false; - - // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere - if (Answer is null) return foundResult; - var szAnswerLength = Answer.Length; - - //Parallel for loop - Parallel.For(0, szAnswerLength, i => - { - if (SqAnswerSquares is null || Answer[i] != hintLetter || - SqAnswerSquares[i]!.Letter == hintLetter) return; - SqAnswerSquares[i]?.SetLetter(hintLetter, IsAcross); - foundResult = true; - }); - - return foundResult; - } - - #endregion -} \ No newline at end of file +// using System; +// using System.Threading.Tasks; +// +// namespace Crossword.ClueAnswerMap; +// +// public sealed partial class ClueAnswer +// { +// #region CheckHint +// +// /// +// /// Sets the Hint letter if Get Letter is pressed +// /// +// /// +// /// +// public bool CheckHint(char hintLetter) +// { +// if (hintLetter <= 0) throw new ArgumentOutOfRangeException(nameof(hintLetter)); +// +// var foundResult = false; +// +// // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere +// if (Answer is null) return foundResult; +// var szAnswerLength = Answer.Length; +// +// //Parallel for loop +// Parallel.For(0, szAnswerLength, i => +// { +// if (SqAnswerSquares is null || Answer[i] != hintLetter || +// SqAnswerSquares[i]!.Letter == hintLetter) return; +// SqAnswerSquares[i]?.SetLetter(hintLetter, IsAcross); +// foundResult = true; +// }); +// +// return foundResult; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/CheckWord.cs b/Crossword/ClueAnswerMap/CheckWord.cs index bff52ac..7c88ac6 100644 --- a/Crossword/ClueAnswerMap/CheckWord.cs +++ b/Crossword/ClueAnswerMap/CheckWord.cs @@ -1,27 +1,27 @@ -using System.Threading.Tasks; - -namespace Crossword.ClueAnswerMap; - -public sealed partial class ClueAnswer -{ - #region CheckWord - - /// - /// Sets the letter colour if Check words is pressed. - /// - public void CheckWord() - { - if (Answer is null) return; - // for (var i = 0; i < Answer.Length; i++) - // { - // SqAnswerSquares?[i]?.CheckLetter(Answer[i]); - // } - - Parallel.For(0, Answer.Length, i => - { - SqAnswerSquares?[i]?.CheckLetter(Answer[i]); - }); - } - - #endregion -} \ No newline at end of file +// using System.Threading.Tasks; +// +// namespace Crossword.ClueAnswerMap; +// +// public sealed partial class ClueAnswer +// { +// #region CheckWord +// +// /// +// /// Sets the letter colour if Check words is pressed. +// /// +// public void CheckWord() +// { +// if (Answer is null) return; +// // for (var i = 0; i < Answer.Length; i++) +// // { +// // SqAnswerSquares?[i]?.CheckLetter(Answer[i]); +// // } +// +// Parallel.For(0, Answer.Length, i => +// { +// SqAnswerSquares?[i]?.CheckLetter(Answer[i]); +// }); +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/ClueAnswerMap.cs b/Crossword/ClueAnswerMap/ClueAnswerMap.cs index b6bdf78..522b816 100644 --- a/Crossword/ClueAnswerMap/ClueAnswerMap.cs +++ b/Crossword/ClueAnswerMap/ClueAnswerMap.cs @@ -1,31 +1,31 @@ -//////////////////////////////////////////////////////////////////////////// -// // -// Module: ClueAnswerMap.cs // -// Authors: Aaron Saikovski & Bryan Richards // -// Original Date: 26/02/97 // -// Version: 1.0 // -// Purpose: Clue + Answer references class // -// // -//////////////////////////////////////////////////////////////////////////// - -using Crossword.PuzzleSquares; - -namespace Crossword.ClueAnswerMap; - -/// -/// ClueAnswerMap Class -/// -public sealed partial class ClueAnswer -{ - #region getters_setters - public string? Answer { get; set; } - public string? Clue { get; set; } - - public int QuestionNumber { get; set; } - - public bool IsAcross { get; set; } = true; - - public Square?[]? SqAnswerSquares { get; set; } - - #endregion -} \ No newline at end of file +// //////////////////////////////////////////////////////////////////////////// +// // // +// // Module: ClueAnswerMap.cs // +// // Authors: Aaron Saikovski & Bryan Richards // +// // Original Date: 26/02/97 // +// // Version: 1.0 // +// // Purpose: Clue + Answer references class // +// // // +// //////////////////////////////////////////////////////////////////////////// +// +// using Crossword.PuzzleSquares; +// +// namespace Crossword.ClueAnswerMap; +// +// /// +// /// ClueAnswerMap Class +// /// +// public sealed partial class ClueAnswer +// { +// #region getters_setters +// public string? Answer { get; set; } +// public string? Clue { get; set; } +// +// public int QuestionNumber { get; set; } +// +// public bool IsAcross { get; set; } = true; +// +// public Square?[]? SqAnswerSquares { get; set; } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/GetNextSq.cs b/Crossword/ClueAnswerMap/GetNextSq.cs index 8077351..0c9aafd 100644 --- a/Crossword/ClueAnswerMap/GetNextSq.cs +++ b/Crossword/ClueAnswerMap/GetNextSq.cs @@ -1,39 +1,39 @@ -using System; -using Crossword.PuzzleSquares; - -namespace Crossword.ClueAnswerMap; - -public sealed partial class ClueAnswer -{ - #region GetNextSq - - /// - /// Returns the next square - /// - /// - /// - public Square? GetNextSq(Square? sq) - { - ArgumentNullException.ThrowIfNull(sq); - var i = 0; - while (Answer != null && i < Answer.Length){ - if (SqAnswerSquares != null && sq == SqAnswerSquares[i]) - if (i < Answer.Length - 1) - return SqAnswerSquares[i + 1]; - i++; - } - return sq; - - // ArgumentNullException.ThrowIfNull(sq); - // var i = 0; - // while (i < Answer.Length){ - // if (sq == SqAnswerSquares[i]) - // if (i < Answer.Length - 1) - // return SqAnswerSquares[i + 1]; - // i++; - // } - // return sq; - } - - #endregion -} \ No newline at end of file +// using System; +// using Crossword.PuzzleSquares; +// +// namespace Crossword.ClueAnswerMap; +// +// public sealed partial class ClueAnswer +// { +// #region GetNextSq +// +// /// +// /// Returns the next square +// /// +// /// +// /// +// public Square? GetNextSq(Square? sq) +// { +// ArgumentNullException.ThrowIfNull(sq); +// var i = 0; +// while (Answer != null && i < Answer.Length){ +// if (SqAnswerSquares != null && sq == SqAnswerSquares[i]) +// if (i < Answer.Length - 1) +// return SqAnswerSquares[i + 1]; +// i++; +// } +// return sq; +// +// // ArgumentNullException.ThrowIfNull(sq); +// // var i = 0; +// // while (i < Answer.Length){ +// // if (sq == SqAnswerSquares[i]) +// // if (i < Answer.Length - 1) +// // return SqAnswerSquares[i + 1]; +// // i++; +// // } +// // return sq; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/GetPrevSq.cs b/Crossword/ClueAnswerMap/GetPrevSq.cs index dc1a2bf..6108e40 100644 --- a/Crossword/ClueAnswerMap/GetPrevSq.cs +++ b/Crossword/ClueAnswerMap/GetPrevSq.cs @@ -1,31 +1,31 @@ -using System; -using Crossword.PuzzleSquares; - -namespace Crossword.ClueAnswerMap; - -public sealed partial class ClueAnswer -{ - #region GetPrevSq - - /// - /// Returns the previous square - /// - /// - /// - public Square? GetPrevSq(Square? sq) - { - ArgumentNullException.ThrowIfNull(sq); - - if (Answer is null) return sq; - var i = Answer.Length - 1; - while (i > -1) - { - if (sq == SqAnswerSquares?[i]) return i != 0 ? SqAnswerSquares?[i - 1] : sq; - i--; - } - - return sq; - } - - #endregion -} \ No newline at end of file +// using System; +// using Crossword.PuzzleSquares; +// +// namespace Crossword.ClueAnswerMap; +// +// public sealed partial class ClueAnswer +// { +// #region GetPrevSq +// +// /// +// /// Returns the previous square +// /// +// /// +// /// +// public Square? GetPrevSq(Square? sq) +// { +// ArgumentNullException.ThrowIfNull(sq); +// +// if (Answer is null) return sq; +// var i = Answer.Length - 1; +// while (i > -1) +// { +// if (sq == SqAnswerSquares?[i]) return i != 0 ? SqAnswerSquares?[i - 1] : sq; +// i--; +// } +// +// return sq; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/GetSquare.cs b/Crossword/ClueAnswerMap/GetSquare.cs index e14eb43..1c7e120 100644 --- a/Crossword/ClueAnswerMap/GetSquare.cs +++ b/Crossword/ClueAnswerMap/GetSquare.cs @@ -1,19 +1,19 @@ -using Crossword.PuzzleSquares; - -namespace Crossword.ClueAnswerMap; - -public sealed partial class ClueAnswer -{ - #region GetSquare - - /// - /// Gets the first square referenced by my answer. - /// - /// - public Square? GetSquare() - { - return SqAnswerSquares?[0]; - } - - #endregion -} \ No newline at end of file +// using Crossword.PuzzleSquares; +// +// namespace Crossword.ClueAnswerMap; +// +// public sealed partial class ClueAnswer +// { +// #region GetSquare +// +// /// +// /// Gets the first square referenced by my answer. +// /// +// /// +// public Square? GetSquare() +// { +// return SqAnswerSquares?[0]; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/HighlightSquares.cs b/Crossword/ClueAnswerMap/HighlightSquares.cs index 4ba4b62..1ddb948 100644 --- a/Crossword/ClueAnswerMap/HighlightSquares.cs +++ b/Crossword/ClueAnswerMap/HighlightSquares.cs @@ -1,50 +1,50 @@ -using System; -using System.Threading.Tasks; -using Crossword.PuzzleSquares; -using Crossword.Shared.Constants; - -namespace Crossword.ClueAnswerMap; - -public sealed partial class ClueAnswer -{ - #region HighlightSquares - - /// - /// /Highlights the current word and sets active square - /// - /// - /// - public void HighlightSquares(Square? sq, bool setHighLighted) - { - ArgumentNullException.ThrowIfNull(sq); - - if (Answer is null) return; - // for (var i = 0; i < Answer.Length; i++) - // { - // if (!setHighLighted) - // SqAnswerSquares?[i]?.SetHighlighted(CWSettings.CurrentNone); - // else - // { - // SqAnswerSquares?[i] - // ?.SetHighlighted(SqAnswerSquares?[i] == sq - // ? CWSettings.CurrentLetter - // : CWSettings.CurrentWord); - // } - // } - - Parallel.For(0, Answer.Length, i => - { - if (!setHighLighted) - SqAnswerSquares?[i]?.SetHighlighted(UIConstants.CurrentNone); - else - { - SqAnswerSquares?[i] - ?.SetHighlighted(SqAnswerSquares?[i] == sq - ? UIConstants.CurrentLetter - : UIConstants.CurrentWord); - } - }); - } - - #endregion -} \ No newline at end of file +// using System; +// using System.Threading.Tasks; +// using Crossword.PuzzleSquares; +// using Crossword.Shared.Constants; +// +// namespace Crossword.ClueAnswerMap; +// +// public sealed partial class ClueAnswer +// { +// #region HighlightSquares +// +// /// +// /// /Highlights the current word and sets active square +// /// +// /// +// /// +// public void HighlightSquares(Square? sq, bool setHighLighted) +// { +// ArgumentNullException.ThrowIfNull(sq); +// +// if (Answer is null) return; +// // for (var i = 0; i < Answer.Length; i++) +// // { +// // if (!setHighLighted) +// // SqAnswerSquares?[i]?.SetHighlighted(CWSettings.CurrentNone); +// // else +// // { +// // SqAnswerSquares?[i] +// // ?.SetHighlighted(SqAnswerSquares?[i] == sq +// // ? CWSettings.CurrentLetter +// // : CWSettings.CurrentWord); +// // } +// // } +// +// Parallel.For(0, Answer.Length, i => +// { +// if (!setHighLighted) +// SqAnswerSquares?[i]?.SetHighlighted(UIConstants.CurrentNone); +// else +// { +// SqAnswerSquares?[i] +// ?.SetHighlighted(SqAnswerSquares?[i] == sq +// ? UIConstants.CurrentLetter +// : UIConstants.CurrentWord); +// } +// }); +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/IsCorrect.cs b/Crossword/ClueAnswerMap/IsCorrect.cs index dc14b4e..4f57ada 100644 --- a/Crossword/ClueAnswerMap/IsCorrect.cs +++ b/Crossword/ClueAnswerMap/IsCorrect.cs @@ -1,21 +1,21 @@ -using System.Linq; - -namespace Crossword.ClueAnswerMap; - -public sealed partial class ClueAnswer -{ - #region IsCorrect - - /// - /// Returns true if all answer letters are correct and false otherwise - /// - /// - public bool IsCorrect() - { - if (Answer is not null) - return !Answer.Where((t, i) => SqAnswerSquares is not null && SqAnswerSquares[i]!.Letter != t).Any(); - return true; - } - - #endregion -} \ No newline at end of file +// using System.Linq; +// +// namespace Crossword.ClueAnswerMap; +// +// public sealed partial class ClueAnswer +// { +// #region IsCorrect +// +// /// +// /// Returns true if all answer letters are correct and false otherwise +// /// +// /// +// public bool IsCorrect() +// { +// if (Answer is not null) +// return !Answer.Where((t, i) => SqAnswerSquares is not null && SqAnswerSquares[i]!.Letter != t).Any(); +// return true; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/SetObjectRef.cs b/Crossword/ClueAnswerMap/SetObjectRef.cs index a625e2d..76b67aa 100644 --- a/Crossword/ClueAnswerMap/SetObjectRef.cs +++ b/Crossword/ClueAnswerMap/SetObjectRef.cs @@ -1,57 +1,57 @@ -using System; -using System.Threading.Tasks; -using Crossword.PuzzleSquares; - -namespace Crossword.ClueAnswerMap; - -public sealed partial class ClueAnswer -{ - #region SetObjectRef - - /// - /// Sets the object reference. - /// - /// - /// - /// - /// - /// - public void SetObjectRef(string Answer, string Clue, int QuestionNumber, - bool IsAcross, Square?[]? SqAnswerSquares) - { - ArgumentNullException.ThrowIfNull(Answer); - ArgumentNullException.ThrowIfNull(Clue); - ArgumentNullException.ThrowIfNull(SqAnswerSquares); - - this.Answer = Answer; - this.Clue = Clue; - this.QuestionNumber = QuestionNumber; - this.IsAcross = IsAcross; - - //Initialise the answer squares array. - this.SqAnswerSquares = new Square[Answer.Length]; - - //Copy the array - // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere - var szAnswerLength = Answer.Length; - - //Parallel for loop - Parallel.For(0, szAnswerLength, k => - { - // Create a new Square instance - var sqAnswerSquares = this.SqAnswerSquares; - if (sqAnswerSquares is not null) - { - sqAnswerSquares[k] = new Square(); - sqAnswerSquares[k]?.CreateSquare(0, 0); - sqAnswerSquares[k] = SqAnswerSquares[k]; - } - - // Assign the created Square to the array element - // The original code `this.sqAnswerSquares[k] = sqAnswerSquares[k];` seems redundant, so omitted - if (SqAnswerSquares is not null) SqAnswerSquares?[k]?.SetObjectRef(this.IsAcross, this); - }); - } - - #endregion -} \ No newline at end of file +// using System; +// using System.Threading.Tasks; +// using Crossword.PuzzleSquares; +// +// namespace Crossword.ClueAnswerMap; +// +// public sealed partial class ClueAnswer +// { +// #region SetObjectRef +// +// /// +// /// Sets the object reference. +// /// +// /// +// /// +// /// +// /// +// /// +// public void SetObjectRef(string Answer, string Clue, int QuestionNumber, +// bool IsAcross, Square?[]? SqAnswerSquares) +// { +// ArgumentNullException.ThrowIfNull(Answer); +// ArgumentNullException.ThrowIfNull(Clue); +// ArgumentNullException.ThrowIfNull(SqAnswerSquares); +// +// this.Answer = Answer; +// this.Clue = Clue; +// this.QuestionNumber = QuestionNumber; +// this.IsAcross = IsAcross; +// +// //Initialise the answer squares array. +// this.SqAnswerSquares = new Square[Answer.Length]; +// +// //Copy the array +// // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere +// var szAnswerLength = Answer.Length; +// +// //Parallel for loop +// Parallel.For(0, szAnswerLength, k => +// { +// // Create a new Square instance +// var sqAnswerSquares = this.SqAnswerSquares; +// if (sqAnswerSquares is not null) +// { +// sqAnswerSquares[k] = new Square(); +// sqAnswerSquares[k]?.CreateSquare(0, 0); +// sqAnswerSquares[k] = SqAnswerSquares[k]; +// } +// +// // Assign the created Square to the array element +// // The original code `this.sqAnswerSquares[k] = sqAnswerSquares[k];` seems redundant, so omitted +// if (SqAnswerSquares is not null) SqAnswerSquares?[k]?.SetObjectRef(this.IsAcross, this); +// }); +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/Crossword.csproj b/Crossword/Crossword.csproj index 89de626..7e2b9a2 100644 --- a/Crossword/Crossword.csproj +++ b/Crossword/Crossword.csproj @@ -86,6 +86,7 @@ + diff --git a/Crossword/EventHandlers/MouseHandlers.cs b/Crossword/EventHandlers/MouseHandlers.cs index e088397..d196606 100644 --- a/Crossword/EventHandlers/MouseHandlers.cs +++ b/Crossword/EventHandlers/MouseHandlers.cs @@ -1,6 +1,6 @@ using System; using System.Threading.Tasks; -using Crossword.PuzzleSquares; +using Crossword.Puzzle.Squares; using Crossword.Shared.Constants; namespace Crossword.App; diff --git a/Crossword/PuzzleSquares/CanFlipDirection.cs b/Crossword/PuzzleSquares/CanFlipDirection.cs index 816d26f..5d0a5e3 100644 --- a/Crossword/PuzzleSquares/CanFlipDirection.cs +++ b/Crossword/PuzzleSquares/CanFlipDirection.cs @@ -1,35 +1,35 @@ -namespace Crossword.PuzzleSquares; - -public sealed partial class Square -{ - #region CanFlipDirection - - /// - /// Can the current orientation be flipped. - /// - /// - /// - public bool CanFlipDirection(bool isAcross) - { - switch (isAcross) - { - //if square is an intersection - case true when ClueAnswerDown is not null: - case false when ClueAnswerAcross is not null: - return true; - default: - return false; - } - - //if square is an intersection - // if ((isAcross) && (ClueAnswerDown != null)) - // return true; - // else if ((!isAcross) && (ClueAnswerAcross != null)) - // return true; - // else - // return false; - - } - - #endregion -} \ No newline at end of file +// namespace Crossword.PuzzleSquares; +// +// public sealed partial class Square +// { +// #region CanFlipDirection +// +// /// +// /// Can the current orientation be flipped. +// /// +// /// +// /// +// public bool CanFlipDirection(bool isAcross) +// { +// switch (isAcross) +// { +// //if square is an intersection +// case true when ClueAnswerDown is not null: +// case false when ClueAnswerAcross is not null: +// return true; +// default: +// return false; +// } +// +// //if square is an intersection +// // if ((isAcross) && (ClueAnswerDown != null)) +// // return true; +// // else if ((!isAcross) && (ClueAnswerAcross != null)) +// // return true; +// // else +// // return false; +// +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/CheckLetter.cs b/Crossword/PuzzleSquares/CheckLetter.cs index 827b6c8..fdfac7a 100644 --- a/Crossword/PuzzleSquares/CheckLetter.cs +++ b/Crossword/PuzzleSquares/CheckLetter.cs @@ -1,21 +1,21 @@ -using Crossword.Shared.Constants; - -namespace Crossword.PuzzleSquares; - -public sealed partial class Square -{ - #region CheckLetter - - /// - /// Check for correctness of letter based on input char parameter and toggles colour accordingly - /// - /// - public void CheckLetter(char correctLetter) - { - if (Letter == ' ') return; - ForeColour = Letter == correctLetter ? UIConstants.SqCorrect : UIConstants.SqError; - IsDirty = true; - } - - #endregion -} \ No newline at end of file +// using Crossword.Shared.Constants; +// +// namespace Crossword.PuzzleSquares; +// +// public sealed partial class Square +// { +// #region CheckLetter +// +// /// +// /// Check for correctness of letter based on input char parameter and toggles colour accordingly +// /// +// /// +// public void CheckLetter(char correctLetter) +// { +// if (Letter == ' ') return; +// ForeColour = Letter == correctLetter ? UIConstants.SqCorrect : UIConstants.SqError; +// IsDirty = true; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/CreateSquare.cs b/Crossword/PuzzleSquares/CreateSquare.cs index 54b5d0a..480f5df 100644 --- a/Crossword/PuzzleSquares/CreateSquare.cs +++ b/Crossword/PuzzleSquares/CreateSquare.cs @@ -1,19 +1,19 @@ -namespace Crossword.PuzzleSquares; - -public sealed partial class Square -{ - #region CreateSquare - - /// - /// Allocates memory for blank square - /// - /// - /// - public void CreateSquare(int xCoord, int yCoord) - { - this.xCoord = xCoord; - this.yCoord = yCoord; - } - - #endregion -} \ No newline at end of file +// namespace Crossword.PuzzleSquares; +// +// public sealed partial class Square +// { +// #region CreateSquare +// +// /// +// /// Allocates memory for blank square +// /// +// /// +// /// +// public void CreateSquare(int xCoord, int yCoord) +// { +// this.xCoord = xCoord; +// this.yCoord = yCoord; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/GetClueAnswerRef.cs b/Crossword/PuzzleSquares/GetClueAnswerRef.cs index b733d48..632651a 100644 --- a/Crossword/PuzzleSquares/GetClueAnswerRef.cs +++ b/Crossword/PuzzleSquares/GetClueAnswerRef.cs @@ -1,20 +1,20 @@ -using Crossword.ClueAnswerMap; - -namespace Crossword.PuzzleSquares; - -public sealed partial class Square -{ - #region GetClueAnswerRef - - /// - /// returns the Clue/Answer reference - /// - /// - /// - public ClueAnswer? GetClueAnswerRef(bool isAcross) - { - return isAcross ? ClueAnswerAcross : ClueAnswerDown; - } - - #endregion -} \ No newline at end of file +// using Crossword.ClueAnswerMap; +// +// namespace Crossword.PuzzleSquares; +// +// public sealed partial class Square +// { +// #region GetClueAnswerRef +// +// /// +// /// returns the Clue/Answer reference +// /// +// /// +// /// +// public ClueAnswer? GetClueAnswerRef(bool isAcross) +// { +// return isAcross ? ClueAnswerAcross : ClueAnswerDown; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/GetNextSq.cs b/Crossword/PuzzleSquares/GetNextSq.cs index 6673ce7..b1bb782 100644 --- a/Crossword/PuzzleSquares/GetNextSq.cs +++ b/Crossword/PuzzleSquares/GetNextSq.cs @@ -1,40 +1,40 @@ -namespace Crossword.PuzzleSquares; - -public sealed partial class Square -{ - #region GetNextSq - - /// - /// Gets the next available square - /// - /// - /// - public Square? GetNextSq(bool isAcross) - { - if (isAcross) - { - return ClueAnswerAcross != null ? ClueAnswerAcross.GetNextSq(this) : this; - } - - return ClueAnswerDown != null ? ClueAnswerDown.GetNextSq(this) : this; - - - // if (isAcross) - // { - // if(ClueAnswerAcross != null) - // return ClueAnswerAcross.GetNextSq(this); - // else - // return this; - // } - // else - // { - // if(ClueAnswerDown != null) - // return ClueAnswerDown.GetNextSq(this); - // else - // return this; - // } - - } - - #endregion -} \ No newline at end of file +// namespace Crossword.PuzzleSquares; +// +// public sealed partial class Square +// { +// #region GetNextSq +// +// /// +// /// Gets the next available square +// /// +// /// +// /// +// public Square? GetNextSq(bool isAcross) +// { +// if (isAcross) +// { +// return ClueAnswerAcross != null ? ClueAnswerAcross.GetNextSq(this) : this; +// } +// +// return ClueAnswerDown != null ? ClueAnswerDown.GetNextSq(this) : this; +// +// +// // if (isAcross) +// // { +// // if(ClueAnswerAcross != null) +// // return ClueAnswerAcross.GetNextSq(this); +// // else +// // return this; +// // } +// // else +// // { +// // if(ClueAnswerDown != null) +// // return ClueAnswerDown.GetNextSq(this); +// // else +// // return this; +// // } +// +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/GetPrevSq.cs b/Crossword/PuzzleSquares/GetPrevSq.cs index 3403220..268a2d7 100644 --- a/Crossword/PuzzleSquares/GetPrevSq.cs +++ b/Crossword/PuzzleSquares/GetPrevSq.cs @@ -1,20 +1,20 @@ -namespace Crossword.PuzzleSquares; - -public sealed partial class Square -{ - #region GetPrevSq - - /// - /// /Gets the previous available square - /// - /// - /// - public Square? GetPrevSq(bool isAcross) - { - if (isAcross) - return ClueAnswerAcross is not null ? ClueAnswerAcross.GetPrevSq(this) : this; - return ClueAnswerDown is not null ? ClueAnswerDown.GetPrevSq(this) : this; - } - - #endregion -} \ No newline at end of file +// namespace Crossword.PuzzleSquares; +// +// public sealed partial class Square +// { +// #region GetPrevSq +// +// /// +// /// /Gets the previous available square +// /// +// /// +// /// +// public Square? GetPrevSq(bool isAcross) +// { +// if (isAcross) +// return ClueAnswerAcross is not null ? ClueAnswerAcross.GetPrevSq(this) : this; +// return ClueAnswerDown is not null ? ClueAnswerDown.GetPrevSq(this) : this; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/SetHighlighted.cs b/Crossword/PuzzleSquares/SetHighlighted.cs index 9687797..de41970 100644 --- a/Crossword/PuzzleSquares/SetHighlighted.cs +++ b/Crossword/PuzzleSquares/SetHighlighted.cs @@ -1,55 +1,55 @@ -using System; -using Crossword.Shared.Constants; - -namespace Crossword.PuzzleSquares; - -public sealed partial class Square -{ - #region SetHighlighted - - /// - /// Sets the background colour of a square - /// - /// - public void SetHighlighted(int highlightType) - { - switch (highlightType) - { - case 1: //Current Letter - if (!BackColour.Equals(UIConstants.SquareHighlightCurrent)) - { - BackColour = UIConstants.SquareHighlightCurrent; - IsDirty = true; - } - - break; - case 2: //Current Word - if (!BackColour.Equals(UIConstants.SquareHighlightWord)) - { - BackColour = UIConstants.SquareHighlightWord; - IsDirty = true; - } - - break; - case 3: //Current None - if (!BackColour.Equals(UIConstants.SquareHighlightNone)) - { - BackColour = UIConstants.SquareHighlightNone; - IsDirty = true; - } - - break; - default: //Something went wrong.... - if (BackColour.Equals(UIConstants.SquareHighlightErr)) - { - //Console.WriteLine($"Bogus color: {highlightType}"); - BackColour = UIConstants.SquareHighlightErr; - IsDirty = true; - } - - break; - } - } - - #endregion -} \ No newline at end of file +// using System; +// using Crossword.Shared.Constants; +// +// namespace Crossword.PuzzleSquares; +// +// public sealed partial class Square +// { +// #region SetHighlighted +// +// /// +// /// Sets the background colour of a square +// /// +// /// +// public void SetHighlighted(int highlightType) +// { +// switch (highlightType) +// { +// case 1: //Current Letter +// if (!BackColour.Equals(UIConstants.SquareHighlightCurrent)) +// { +// BackColour = UIConstants.SquareHighlightCurrent; +// IsDirty = true; +// } +// +// break; +// case 2: //Current Word +// if (!BackColour.Equals(UIConstants.SquareHighlightWord)) +// { +// BackColour = UIConstants.SquareHighlightWord; +// IsDirty = true; +// } +// +// break; +// case 3: //Current None +// if (!BackColour.Equals(UIConstants.SquareHighlightNone)) +// { +// BackColour = UIConstants.SquareHighlightNone; +// IsDirty = true; +// } +// +// break; +// default: //Something went wrong.... +// if (BackColour.Equals(UIConstants.SquareHighlightErr)) +// { +// //Console.WriteLine($"Bogus color: {highlightType}"); +// BackColour = UIConstants.SquareHighlightErr; +// IsDirty = true; +// } +// +// break; +// } +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/SetLetter.cs b/Crossword/PuzzleSquares/SetLetter.cs index 3cb044f..06af65d 100644 --- a/Crossword/PuzzleSquares/SetLetter.cs +++ b/Crossword/PuzzleSquares/SetLetter.cs @@ -1,22 +1,22 @@ -using Crossword.Shared.Constants; - -namespace Crossword.PuzzleSquares; - -public sealed partial class Square -{ - #region SetLetter - - /// - /// Set the colour for a letter. - /// - /// - /// - public void SetLetter(char letter, bool isAcross) - { - Letter = letter; - IsDirty = true; - ForeColour = UIConstants.SquareHighlightDefault; - } - - #endregion -} \ No newline at end of file +// using Crossword.Shared.Constants; +// +// namespace Crossword.PuzzleSquares; +// +// public sealed partial class Square +// { +// #region SetLetter +// +// /// +// /// Set the colour for a letter. +// /// +// /// +// /// +// public void SetLetter(char letter, bool isAcross) +// { +// Letter = letter; +// IsDirty = true; +// ForeColour = UIConstants.SquareHighlightDefault; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/SetObjectRef.cs b/Crossword/PuzzleSquares/SetObjectRef.cs index 64bdb88..8459ee6 100644 --- a/Crossword/PuzzleSquares/SetObjectRef.cs +++ b/Crossword/PuzzleSquares/SetObjectRef.cs @@ -1,31 +1,31 @@ -using System; -using Crossword.ClueAnswerMap; -using Crossword.Shared.Constants; - -namespace Crossword.PuzzleSquares; - -public sealed partial class Square -{ - #region SetObjectRef - - /// - /// Set the object reference to clueanswer object - /// - /// - /// - public void SetObjectRef(bool isAcross, ClueAnswer clueAnswer) - { - ArgumentNullException.ThrowIfNull(clueAnswer); - - if (isAcross) - ClueAnswerAcross = clueAnswer; - else - ClueAnswerDown = clueAnswer; - - IsCharAllowed = true; - IsDirty = true; - BackColour = UIConstants.SquareHighlightNone; - } - - #endregion -} \ No newline at end of file +// using System; +// using Crossword.ClueAnswerMap; +// using Crossword.Shared.Constants; +// +// namespace Crossword.PuzzleSquares; +// +// public sealed partial class Square +// { +// #region SetObjectRef +// +// /// +// /// Set the object reference to clueanswer object +// /// +// /// +// /// +// public void SetObjectRef(bool isAcross, ClueAnswer clueAnswer) +// { +// ArgumentNullException.ThrowIfNull(clueAnswer); +// +// if (isAcross) +// ClueAnswerAcross = clueAnswer; +// else +// ClueAnswerDown = clueAnswer; +// +// IsCharAllowed = true; +// IsDirty = true; +// BackColour = UIConstants.SquareHighlightNone; +// } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/Square.cs b/Crossword/PuzzleSquares/Square.cs index 6423547..8161078 100644 --- a/Crossword/PuzzleSquares/Square.cs +++ b/Crossword/PuzzleSquares/Square.cs @@ -1,39 +1,39 @@ -//////////////////////////////////////////////////////////////////////////// -// // -// Module: Square.cs // -// Authors: Aaron Saikovski & Bryan Richards // -// Original Date: 23/01/97 // -// Version: 1.0 // -// Purpose: Defines a Square and it's attributes // -// // -//////////////////////////////////////////////////////////////////////////// - -using Crossword.ClueAnswerMap; -using Microsoft.Xna.Framework; - -namespace Crossword.PuzzleSquares; - -//Square class -public sealed partial class Square -{ - #region getters_setters - - public int xCoord { get; set; } - public int yCoord { get; set; } - - - public char Letter { get; set; } - - - public Color ForeColour { get; set; } = Color.Black; - public Color BackColour { get; set; } = Color.Black; - - public bool IsDirty { get; set; } = true; - - public bool IsCharAllowed { get; set; } - - public ClueAnswer? ClueAnswerAcross { get; set; } - public ClueAnswer? ClueAnswerDown { get; set; } - - #endregion -} \ No newline at end of file +// //////////////////////////////////////////////////////////////////////////// +// // // +// // Module: Square.cs // +// // Authors: Aaron Saikovski & Bryan Richards // +// // Original Date: 23/01/97 // +// // Version: 1.0 // +// // Purpose: Defines a Square and it's attributes // +// // // +// //////////////////////////////////////////////////////////////////////////// +// +// using Crossword.ClueAnswerMap; +// using Microsoft.Xna.Framework; +// +// namespace Crossword.PuzzleSquares; +// +// //Square class +// public sealed partial class Square +// { +// #region getters_setters +// +// public int xCoord { get; set; } +// public int yCoord { get; set; } +// +// +// public char Letter { get; set; } +// +// +// public Color ForeColour { get; set; } = Color.Black; +// public Color BackColour { get; set; } = Color.Black; +// +// public bool IsDirty { get; set; } = true; +// +// public bool IsCharAllowed { get; set; } +// +// public ClueAnswer? ClueAnswerAcross { get; set; } +// public ClueAnswer? ClueAnswerDown { get; set; } +// +// #endregion +// } \ No newline at end of file diff --git a/Crossword/init/InitArrays.cs b/Crossword/init/InitArrays.cs index 1ae8404..7255488 100644 --- a/Crossword/init/InitArrays.cs +++ b/Crossword/init/InitArrays.cs @@ -1,5 +1,5 @@ using System; -using Crossword.PuzzleSquares; +using Crossword.Puzzle.Squares; using Crossword.Shared.Constants; namespace Crossword.App; diff --git a/Crossword/init/InitClueAnswers.cs b/Crossword/init/InitClueAnswers.cs index ade95cb..92b4957 100644 --- a/Crossword/init/InitClueAnswers.cs +++ b/Crossword/init/InitClueAnswers.cs @@ -1,6 +1,6 @@ using System; -using Crossword.ClueAnswerMap; -using Crossword.PuzzleSquares; +using Crossword.Puzzle.ClueAnswerMap; +using Crossword.Puzzle.Squares; using Microsoft.Xna.Framework; using Myra.Graphics2D.UI; diff --git a/Crossword/init/InitialiseCrossword.cs b/Crossword/init/InitialiseCrossword.cs index b7677ef..9b9f82a 100644 --- a/Crossword/init/InitialiseCrossword.cs +++ b/Crossword/init/InitialiseCrossword.cs @@ -1,6 +1,6 @@ using System; -using Crossword.ClueAnswerMap; -using Crossword.PuzzleSquares; +using Crossword.Puzzle.ClueAnswerMap; +using Crossword.Puzzle.Squares; using Microsoft.Xna.Framework; namespace Crossword.App; diff --git a/Crossword/main/CrosswordMain.cs b/Crossword/main/CrosswordMain.cs index b732af9..6dd364d 100644 --- a/Crossword/main/CrosswordMain.cs +++ b/Crossword/main/CrosswordMain.cs @@ -1,10 +1,8 @@ using System; using Crossword.Entities; -using Crossword.ClueAnswerMap; +using Crossword.Puzzle.ClueAnswerMap; +using Crossword.Puzzle.Squares; using Crossword.Shared.Constants; -//using Crossword.App.EventHandlers; -using Crossword.PuzzleSquares; -using Crossword.Entities; using Crossword.Parser; using FontStashSharp; using InputHandlers.Keyboard; From 7e06954df4e41ba16388738f1260441502b456db Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 16:04:26 +1100 Subject: [PATCH 20/26] minor --- Crossword/ClueAnswerMap/CheckHint.cs | 38 -------------- Crossword/ClueAnswerMap/CheckWord.cs | 27 ---------- Crossword/ClueAnswerMap/ClueAnswerMap.cs | 31 ----------- Crossword/ClueAnswerMap/GetNextSq.cs | 39 -------------- Crossword/ClueAnswerMap/GetPrevSq.cs | 31 ----------- Crossword/ClueAnswerMap/GetSquare.cs | 19 ------- Crossword/ClueAnswerMap/HighlightSquares.cs | 50 ------------------ Crossword/ClueAnswerMap/IsCorrect.cs | 21 -------- Crossword/ClueAnswerMap/SetObjectRef.cs | 57 --------------------- Crossword/PuzzleSquares/CanFlipDirection.cs | 35 ------------- Crossword/PuzzleSquares/CheckLetter.cs | 21 -------- Crossword/PuzzleSquares/CreateSquare.cs | 19 ------- Crossword/PuzzleSquares/GetClueAnswerRef.cs | 20 -------- Crossword/PuzzleSquares/GetNextSq.cs | 40 --------------- Crossword/PuzzleSquares/GetPrevSq.cs | 20 -------- Crossword/PuzzleSquares/SetHighlighted.cs | 55 -------------------- Crossword/PuzzleSquares/SetLetter.cs | 22 -------- Crossword/PuzzleSquares/SetObjectRef.cs | 31 ----------- Crossword/PuzzleSquares/Square.cs | 39 -------------- Crossword/{UI => main}/LoadAssets.cs | 0 20 files changed, 615 deletions(-) delete mode 100644 Crossword/ClueAnswerMap/CheckHint.cs delete mode 100644 Crossword/ClueAnswerMap/CheckWord.cs delete mode 100644 Crossword/ClueAnswerMap/ClueAnswerMap.cs delete mode 100644 Crossword/ClueAnswerMap/GetNextSq.cs delete mode 100644 Crossword/ClueAnswerMap/GetPrevSq.cs delete mode 100644 Crossword/ClueAnswerMap/GetSquare.cs delete mode 100644 Crossword/ClueAnswerMap/HighlightSquares.cs delete mode 100644 Crossword/ClueAnswerMap/IsCorrect.cs delete mode 100644 Crossword/ClueAnswerMap/SetObjectRef.cs delete mode 100644 Crossword/PuzzleSquares/CanFlipDirection.cs delete mode 100644 Crossword/PuzzleSquares/CheckLetter.cs delete mode 100644 Crossword/PuzzleSquares/CreateSquare.cs delete mode 100644 Crossword/PuzzleSquares/GetClueAnswerRef.cs delete mode 100644 Crossword/PuzzleSquares/GetNextSq.cs delete mode 100644 Crossword/PuzzleSquares/GetPrevSq.cs delete mode 100644 Crossword/PuzzleSquares/SetHighlighted.cs delete mode 100644 Crossword/PuzzleSquares/SetLetter.cs delete mode 100644 Crossword/PuzzleSquares/SetObjectRef.cs delete mode 100644 Crossword/PuzzleSquares/Square.cs rename Crossword/{UI => main}/LoadAssets.cs (100%) diff --git a/Crossword/ClueAnswerMap/CheckHint.cs b/Crossword/ClueAnswerMap/CheckHint.cs deleted file mode 100644 index 70ff5e9..0000000 --- a/Crossword/ClueAnswerMap/CheckHint.cs +++ /dev/null @@ -1,38 +0,0 @@ -// using System; -// using System.Threading.Tasks; -// -// namespace Crossword.ClueAnswerMap; -// -// public sealed partial class ClueAnswer -// { -// #region CheckHint -// -// /// -// /// Sets the Hint letter if Get Letter is pressed -// /// -// /// -// /// -// public bool CheckHint(char hintLetter) -// { -// if (hintLetter <= 0) throw new ArgumentOutOfRangeException(nameof(hintLetter)); -// -// var foundResult = false; -// -// // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere -// if (Answer is null) return foundResult; -// var szAnswerLength = Answer.Length; -// -// //Parallel for loop -// Parallel.For(0, szAnswerLength, i => -// { -// if (SqAnswerSquares is null || Answer[i] != hintLetter || -// SqAnswerSquares[i]!.Letter == hintLetter) return; -// SqAnswerSquares[i]?.SetLetter(hintLetter, IsAcross); -// foundResult = true; -// }); -// -// return foundResult; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/CheckWord.cs b/Crossword/ClueAnswerMap/CheckWord.cs deleted file mode 100644 index 7c88ac6..0000000 --- a/Crossword/ClueAnswerMap/CheckWord.cs +++ /dev/null @@ -1,27 +0,0 @@ -// using System.Threading.Tasks; -// -// namespace Crossword.ClueAnswerMap; -// -// public sealed partial class ClueAnswer -// { -// #region CheckWord -// -// /// -// /// Sets the letter colour if Check words is pressed. -// /// -// public void CheckWord() -// { -// if (Answer is null) return; -// // for (var i = 0; i < Answer.Length; i++) -// // { -// // SqAnswerSquares?[i]?.CheckLetter(Answer[i]); -// // } -// -// Parallel.For(0, Answer.Length, i => -// { -// SqAnswerSquares?[i]?.CheckLetter(Answer[i]); -// }); -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/ClueAnswerMap.cs b/Crossword/ClueAnswerMap/ClueAnswerMap.cs deleted file mode 100644 index 522b816..0000000 --- a/Crossword/ClueAnswerMap/ClueAnswerMap.cs +++ /dev/null @@ -1,31 +0,0 @@ -// //////////////////////////////////////////////////////////////////////////// -// // // -// // Module: ClueAnswerMap.cs // -// // Authors: Aaron Saikovski & Bryan Richards // -// // Original Date: 26/02/97 // -// // Version: 1.0 // -// // Purpose: Clue + Answer references class // -// // // -// //////////////////////////////////////////////////////////////////////////// -// -// using Crossword.PuzzleSquares; -// -// namespace Crossword.ClueAnswerMap; -// -// /// -// /// ClueAnswerMap Class -// /// -// public sealed partial class ClueAnswer -// { -// #region getters_setters -// public string? Answer { get; set; } -// public string? Clue { get; set; } -// -// public int QuestionNumber { get; set; } -// -// public bool IsAcross { get; set; } = true; -// -// public Square?[]? SqAnswerSquares { get; set; } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/GetNextSq.cs b/Crossword/ClueAnswerMap/GetNextSq.cs deleted file mode 100644 index 0c9aafd..0000000 --- a/Crossword/ClueAnswerMap/GetNextSq.cs +++ /dev/null @@ -1,39 +0,0 @@ -// using System; -// using Crossword.PuzzleSquares; -// -// namespace Crossword.ClueAnswerMap; -// -// public sealed partial class ClueAnswer -// { -// #region GetNextSq -// -// /// -// /// Returns the next square -// /// -// /// -// /// -// public Square? GetNextSq(Square? sq) -// { -// ArgumentNullException.ThrowIfNull(sq); -// var i = 0; -// while (Answer != null && i < Answer.Length){ -// if (SqAnswerSquares != null && sq == SqAnswerSquares[i]) -// if (i < Answer.Length - 1) -// return SqAnswerSquares[i + 1]; -// i++; -// } -// return sq; -// -// // ArgumentNullException.ThrowIfNull(sq); -// // var i = 0; -// // while (i < Answer.Length){ -// // if (sq == SqAnswerSquares[i]) -// // if (i < Answer.Length - 1) -// // return SqAnswerSquares[i + 1]; -// // i++; -// // } -// // return sq; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/GetPrevSq.cs b/Crossword/ClueAnswerMap/GetPrevSq.cs deleted file mode 100644 index 6108e40..0000000 --- a/Crossword/ClueAnswerMap/GetPrevSq.cs +++ /dev/null @@ -1,31 +0,0 @@ -// using System; -// using Crossword.PuzzleSquares; -// -// namespace Crossword.ClueAnswerMap; -// -// public sealed partial class ClueAnswer -// { -// #region GetPrevSq -// -// /// -// /// Returns the previous square -// /// -// /// -// /// -// public Square? GetPrevSq(Square? sq) -// { -// ArgumentNullException.ThrowIfNull(sq); -// -// if (Answer is null) return sq; -// var i = Answer.Length - 1; -// while (i > -1) -// { -// if (sq == SqAnswerSquares?[i]) return i != 0 ? SqAnswerSquares?[i - 1] : sq; -// i--; -// } -// -// return sq; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/GetSquare.cs b/Crossword/ClueAnswerMap/GetSquare.cs deleted file mode 100644 index 1c7e120..0000000 --- a/Crossword/ClueAnswerMap/GetSquare.cs +++ /dev/null @@ -1,19 +0,0 @@ -// using Crossword.PuzzleSquares; -// -// namespace Crossword.ClueAnswerMap; -// -// public sealed partial class ClueAnswer -// { -// #region GetSquare -// -// /// -// /// Gets the first square referenced by my answer. -// /// -// /// -// public Square? GetSquare() -// { -// return SqAnswerSquares?[0]; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/HighlightSquares.cs b/Crossword/ClueAnswerMap/HighlightSquares.cs deleted file mode 100644 index 1ddb948..0000000 --- a/Crossword/ClueAnswerMap/HighlightSquares.cs +++ /dev/null @@ -1,50 +0,0 @@ -// using System; -// using System.Threading.Tasks; -// using Crossword.PuzzleSquares; -// using Crossword.Shared.Constants; -// -// namespace Crossword.ClueAnswerMap; -// -// public sealed partial class ClueAnswer -// { -// #region HighlightSquares -// -// /// -// /// /Highlights the current word and sets active square -// /// -// /// -// /// -// public void HighlightSquares(Square? sq, bool setHighLighted) -// { -// ArgumentNullException.ThrowIfNull(sq); -// -// if (Answer is null) return; -// // for (var i = 0; i < Answer.Length; i++) -// // { -// // if (!setHighLighted) -// // SqAnswerSquares?[i]?.SetHighlighted(CWSettings.CurrentNone); -// // else -// // { -// // SqAnswerSquares?[i] -// // ?.SetHighlighted(SqAnswerSquares?[i] == sq -// // ? CWSettings.CurrentLetter -// // : CWSettings.CurrentWord); -// // } -// // } -// -// Parallel.For(0, Answer.Length, i => -// { -// if (!setHighLighted) -// SqAnswerSquares?[i]?.SetHighlighted(UIConstants.CurrentNone); -// else -// { -// SqAnswerSquares?[i] -// ?.SetHighlighted(SqAnswerSquares?[i] == sq -// ? UIConstants.CurrentLetter -// : UIConstants.CurrentWord); -// } -// }); -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/IsCorrect.cs b/Crossword/ClueAnswerMap/IsCorrect.cs deleted file mode 100644 index 4f57ada..0000000 --- a/Crossword/ClueAnswerMap/IsCorrect.cs +++ /dev/null @@ -1,21 +0,0 @@ -// using System.Linq; -// -// namespace Crossword.ClueAnswerMap; -// -// public sealed partial class ClueAnswer -// { -// #region IsCorrect -// -// /// -// /// Returns true if all answer letters are correct and false otherwise -// /// -// /// -// public bool IsCorrect() -// { -// if (Answer is not null) -// return !Answer.Where((t, i) => SqAnswerSquares is not null && SqAnswerSquares[i]!.Letter != t).Any(); -// return true; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/ClueAnswerMap/SetObjectRef.cs b/Crossword/ClueAnswerMap/SetObjectRef.cs deleted file mode 100644 index 76b67aa..0000000 --- a/Crossword/ClueAnswerMap/SetObjectRef.cs +++ /dev/null @@ -1,57 +0,0 @@ -// using System; -// using System.Threading.Tasks; -// using Crossword.PuzzleSquares; -// -// namespace Crossword.ClueAnswerMap; -// -// public sealed partial class ClueAnswer -// { -// #region SetObjectRef -// -// /// -// /// Sets the object reference. -// /// -// /// -// /// -// /// -// /// -// /// -// public void SetObjectRef(string Answer, string Clue, int QuestionNumber, -// bool IsAcross, Square?[]? SqAnswerSquares) -// { -// ArgumentNullException.ThrowIfNull(Answer); -// ArgumentNullException.ThrowIfNull(Clue); -// ArgumentNullException.ThrowIfNull(SqAnswerSquares); -// -// this.Answer = Answer; -// this.Clue = Clue; -// this.QuestionNumber = QuestionNumber; -// this.IsAcross = IsAcross; -// -// //Initialise the answer squares array. -// this.SqAnswerSquares = new Square[Answer.Length]; -// -// //Copy the array -// // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere -// var szAnswerLength = Answer.Length; -// -// //Parallel for loop -// Parallel.For(0, szAnswerLength, k => -// { -// // Create a new Square instance -// var sqAnswerSquares = this.SqAnswerSquares; -// if (sqAnswerSquares is not null) -// { -// sqAnswerSquares[k] = new Square(); -// sqAnswerSquares[k]?.CreateSquare(0, 0); -// sqAnswerSquares[k] = SqAnswerSquares[k]; -// } -// -// // Assign the created Square to the array element -// // The original code `this.sqAnswerSquares[k] = sqAnswerSquares[k];` seems redundant, so omitted -// if (SqAnswerSquares is not null) SqAnswerSquares?[k]?.SetObjectRef(this.IsAcross, this); -// }); -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/CanFlipDirection.cs b/Crossword/PuzzleSquares/CanFlipDirection.cs deleted file mode 100644 index 5d0a5e3..0000000 --- a/Crossword/PuzzleSquares/CanFlipDirection.cs +++ /dev/null @@ -1,35 +0,0 @@ -// namespace Crossword.PuzzleSquares; -// -// public sealed partial class Square -// { -// #region CanFlipDirection -// -// /// -// /// Can the current orientation be flipped. -// /// -// /// -// /// -// public bool CanFlipDirection(bool isAcross) -// { -// switch (isAcross) -// { -// //if square is an intersection -// case true when ClueAnswerDown is not null: -// case false when ClueAnswerAcross is not null: -// return true; -// default: -// return false; -// } -// -// //if square is an intersection -// // if ((isAcross) && (ClueAnswerDown != null)) -// // return true; -// // else if ((!isAcross) && (ClueAnswerAcross != null)) -// // return true; -// // else -// // return false; -// -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/CheckLetter.cs b/Crossword/PuzzleSquares/CheckLetter.cs deleted file mode 100644 index fdfac7a..0000000 --- a/Crossword/PuzzleSquares/CheckLetter.cs +++ /dev/null @@ -1,21 +0,0 @@ -// using Crossword.Shared.Constants; -// -// namespace Crossword.PuzzleSquares; -// -// public sealed partial class Square -// { -// #region CheckLetter -// -// /// -// /// Check for correctness of letter based on input char parameter and toggles colour accordingly -// /// -// /// -// public void CheckLetter(char correctLetter) -// { -// if (Letter == ' ') return; -// ForeColour = Letter == correctLetter ? UIConstants.SqCorrect : UIConstants.SqError; -// IsDirty = true; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/CreateSquare.cs b/Crossword/PuzzleSquares/CreateSquare.cs deleted file mode 100644 index 480f5df..0000000 --- a/Crossword/PuzzleSquares/CreateSquare.cs +++ /dev/null @@ -1,19 +0,0 @@ -// namespace Crossword.PuzzleSquares; -// -// public sealed partial class Square -// { -// #region CreateSquare -// -// /// -// /// Allocates memory for blank square -// /// -// /// -// /// -// public void CreateSquare(int xCoord, int yCoord) -// { -// this.xCoord = xCoord; -// this.yCoord = yCoord; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/GetClueAnswerRef.cs b/Crossword/PuzzleSquares/GetClueAnswerRef.cs deleted file mode 100644 index 632651a..0000000 --- a/Crossword/PuzzleSquares/GetClueAnswerRef.cs +++ /dev/null @@ -1,20 +0,0 @@ -// using Crossword.ClueAnswerMap; -// -// namespace Crossword.PuzzleSquares; -// -// public sealed partial class Square -// { -// #region GetClueAnswerRef -// -// /// -// /// returns the Clue/Answer reference -// /// -// /// -// /// -// public ClueAnswer? GetClueAnswerRef(bool isAcross) -// { -// return isAcross ? ClueAnswerAcross : ClueAnswerDown; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/GetNextSq.cs b/Crossword/PuzzleSquares/GetNextSq.cs deleted file mode 100644 index b1bb782..0000000 --- a/Crossword/PuzzleSquares/GetNextSq.cs +++ /dev/null @@ -1,40 +0,0 @@ -// namespace Crossword.PuzzleSquares; -// -// public sealed partial class Square -// { -// #region GetNextSq -// -// /// -// /// Gets the next available square -// /// -// /// -// /// -// public Square? GetNextSq(bool isAcross) -// { -// if (isAcross) -// { -// return ClueAnswerAcross != null ? ClueAnswerAcross.GetNextSq(this) : this; -// } -// -// return ClueAnswerDown != null ? ClueAnswerDown.GetNextSq(this) : this; -// -// -// // if (isAcross) -// // { -// // if(ClueAnswerAcross != null) -// // return ClueAnswerAcross.GetNextSq(this); -// // else -// // return this; -// // } -// // else -// // { -// // if(ClueAnswerDown != null) -// // return ClueAnswerDown.GetNextSq(this); -// // else -// // return this; -// // } -// -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/GetPrevSq.cs b/Crossword/PuzzleSquares/GetPrevSq.cs deleted file mode 100644 index 268a2d7..0000000 --- a/Crossword/PuzzleSquares/GetPrevSq.cs +++ /dev/null @@ -1,20 +0,0 @@ -// namespace Crossword.PuzzleSquares; -// -// public sealed partial class Square -// { -// #region GetPrevSq -// -// /// -// /// /Gets the previous available square -// /// -// /// -// /// -// public Square? GetPrevSq(bool isAcross) -// { -// if (isAcross) -// return ClueAnswerAcross is not null ? ClueAnswerAcross.GetPrevSq(this) : this; -// return ClueAnswerDown is not null ? ClueAnswerDown.GetPrevSq(this) : this; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/SetHighlighted.cs b/Crossword/PuzzleSquares/SetHighlighted.cs deleted file mode 100644 index de41970..0000000 --- a/Crossword/PuzzleSquares/SetHighlighted.cs +++ /dev/null @@ -1,55 +0,0 @@ -// using System; -// using Crossword.Shared.Constants; -// -// namespace Crossword.PuzzleSquares; -// -// public sealed partial class Square -// { -// #region SetHighlighted -// -// /// -// /// Sets the background colour of a square -// /// -// /// -// public void SetHighlighted(int highlightType) -// { -// switch (highlightType) -// { -// case 1: //Current Letter -// if (!BackColour.Equals(UIConstants.SquareHighlightCurrent)) -// { -// BackColour = UIConstants.SquareHighlightCurrent; -// IsDirty = true; -// } -// -// break; -// case 2: //Current Word -// if (!BackColour.Equals(UIConstants.SquareHighlightWord)) -// { -// BackColour = UIConstants.SquareHighlightWord; -// IsDirty = true; -// } -// -// break; -// case 3: //Current None -// if (!BackColour.Equals(UIConstants.SquareHighlightNone)) -// { -// BackColour = UIConstants.SquareHighlightNone; -// IsDirty = true; -// } -// -// break; -// default: //Something went wrong.... -// if (BackColour.Equals(UIConstants.SquareHighlightErr)) -// { -// //Console.WriteLine($"Bogus color: {highlightType}"); -// BackColour = UIConstants.SquareHighlightErr; -// IsDirty = true; -// } -// -// break; -// } -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/SetLetter.cs b/Crossword/PuzzleSquares/SetLetter.cs deleted file mode 100644 index 06af65d..0000000 --- a/Crossword/PuzzleSquares/SetLetter.cs +++ /dev/null @@ -1,22 +0,0 @@ -// using Crossword.Shared.Constants; -// -// namespace Crossword.PuzzleSquares; -// -// public sealed partial class Square -// { -// #region SetLetter -// -// /// -// /// Set the colour for a letter. -// /// -// /// -// /// -// public void SetLetter(char letter, bool isAcross) -// { -// Letter = letter; -// IsDirty = true; -// ForeColour = UIConstants.SquareHighlightDefault; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/SetObjectRef.cs b/Crossword/PuzzleSquares/SetObjectRef.cs deleted file mode 100644 index 8459ee6..0000000 --- a/Crossword/PuzzleSquares/SetObjectRef.cs +++ /dev/null @@ -1,31 +0,0 @@ -// using System; -// using Crossword.ClueAnswerMap; -// using Crossword.Shared.Constants; -// -// namespace Crossword.PuzzleSquares; -// -// public sealed partial class Square -// { -// #region SetObjectRef -// -// /// -// /// Set the object reference to clueanswer object -// /// -// /// -// /// -// public void SetObjectRef(bool isAcross, ClueAnswer clueAnswer) -// { -// ArgumentNullException.ThrowIfNull(clueAnswer); -// -// if (isAcross) -// ClueAnswerAcross = clueAnswer; -// else -// ClueAnswerDown = clueAnswer; -// -// IsCharAllowed = true; -// IsDirty = true; -// BackColour = UIConstants.SquareHighlightNone; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/PuzzleSquares/Square.cs b/Crossword/PuzzleSquares/Square.cs deleted file mode 100644 index 8161078..0000000 --- a/Crossword/PuzzleSquares/Square.cs +++ /dev/null @@ -1,39 +0,0 @@ -// //////////////////////////////////////////////////////////////////////////// -// // // -// // Module: Square.cs // -// // Authors: Aaron Saikovski & Bryan Richards // -// // Original Date: 23/01/97 // -// // Version: 1.0 // -// // Purpose: Defines a Square and it's attributes // -// // // -// //////////////////////////////////////////////////////////////////////////// -// -// using Crossword.ClueAnswerMap; -// using Microsoft.Xna.Framework; -// -// namespace Crossword.PuzzleSquares; -// -// //Square class -// public sealed partial class Square -// { -// #region getters_setters -// -// public int xCoord { get; set; } -// public int yCoord { get; set; } -// -// -// public char Letter { get; set; } -// -// -// public Color ForeColour { get; set; } = Color.Black; -// public Color BackColour { get; set; } = Color.Black; -// -// public bool IsDirty { get; set; } = true; -// -// public bool IsCharAllowed { get; set; } -// -// public ClueAnswer? ClueAnswerAcross { get; set; } -// public ClueAnswer? ClueAnswerDown { get; set; } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword/UI/LoadAssets.cs b/Crossword/main/LoadAssets.cs similarity index 100% rename from Crossword/UI/LoadAssets.cs rename to Crossword/main/LoadAssets.cs From edadd7bc6b06f8aff6cb6165d27e1c7b0b4a0bce Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 16:41:49 +1100 Subject: [PATCH 21/26] added crossword.ui --- Crossword.Net.sln | 6 + Crossword.UI/Crossword.UI.csproj | 17 +++ Crossword.UI/DrawCreditsLabel.cs | 42 ++++++ Crossword.UI/DrawCrosswordScore.cs | 57 ++++++++ Crossword/Crossword.csproj | 1 + Crossword/UI/DrawCreditsLabel.cs | 120 ++++++++-------- Crossword/UI/DrawCrosswordScore.cs | 212 ++++++++++++++--------------- Crossword/monogame/Monogame.cs | 9 +- 8 files changed, 295 insertions(+), 169 deletions(-) create mode 100644 Crossword.UI/Crossword.UI.csproj create mode 100644 Crossword.UI/DrawCreditsLabel.cs create mode 100644 Crossword.UI/DrawCrosswordScore.cs diff --git a/Crossword.Net.sln b/Crossword.Net.sln index 42e88ab..c40f9d3 100644 --- a/Crossword.Net.sln +++ b/Crossword.Net.sln @@ -14,6 +14,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Data", "Crossword EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.Puzzle", "Crossword.Puzzle\Crossword.Puzzle.csproj", "{96B22047-3AAC-44ED-B501-DD8894083A3C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crossword.UI", "Crossword.UI\Crossword.UI.csproj", "{81CBCB4A-2F37-42DF-B001-6E5EEFBC1C14}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -48,5 +50,9 @@ Global {96B22047-3AAC-44ED-B501-DD8894083A3C}.Debug|Any CPU.Build.0 = Debug|Any CPU {96B22047-3AAC-44ED-B501-DD8894083A3C}.Release|Any CPU.ActiveCfg = Release|Any CPU {96B22047-3AAC-44ED-B501-DD8894083A3C}.Release|Any CPU.Build.0 = Release|Any CPU + {81CBCB4A-2F37-42DF-B001-6E5EEFBC1C14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {81CBCB4A-2F37-42DF-B001-6E5EEFBC1C14}.Debug|Any CPU.Build.0 = Debug|Any CPU + {81CBCB4A-2F37-42DF-B001-6E5EEFBC1C14}.Release|Any CPU.ActiveCfg = Release|Any CPU + {81CBCB4A-2F37-42DF-B001-6E5EEFBC1C14}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Crossword.UI/Crossword.UI.csproj b/Crossword.UI/Crossword.UI.csproj new file mode 100644 index 0000000..8c607e9 --- /dev/null +++ b/Crossword.UI/Crossword.UI.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/Crossword.UI/DrawCreditsLabel.cs b/Crossword.UI/DrawCreditsLabel.cs new file mode 100644 index 0000000..b806e7d --- /dev/null +++ b/Crossword.UI/DrawCreditsLabel.cs @@ -0,0 +1,42 @@ +using System; + +using Crossword.Shared.Constants; +using FontStashSharp; +using Myra.Graphics2D.UI; + +namespace Crossword.UI; + +public static partial class CrosswordUI +{ + #region DrawCreditsLabel + + /// + /// Draws credit label + /// + /// + /// + /// + /// + /// + public static void DrawCreditsLabel(Panel mainPanel, Label creditsLabel, int posLeft, int posBottom, DynamicSpriteFont labelFont) + { + try + { + //Max score label + mainPanel.Widgets.Remove(creditsLabel); + creditsLabel.Text = GameConstants.CreditsText; + creditsLabel.TextColor = UIConstants.CreditsColor; + creditsLabel.Left = posLeft; + creditsLabel.Font = labelFont; + creditsLabel.Top = posBottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + UIConstants.SquareHeight/2; + mainPanel.Widgets.Add(creditsLabel); + + } + catch (Exception ex) + { + throw; + } + } + + #endregion +} \ No newline at end of file diff --git a/Crossword.UI/DrawCrosswordScore.cs b/Crossword.UI/DrawCrosswordScore.cs new file mode 100644 index 0000000..7c971f4 --- /dev/null +++ b/Crossword.UI/DrawCrosswordScore.cs @@ -0,0 +1,57 @@ + + +using Crossword.Shared.Constants; +using FontStashSharp; +using Myra.Graphics2D.UI; + +namespace Crossword.UI; + +public static partial class CrosswordUI +{ + #region DrawCrosswordScore + + /// Draws the crossword score and updates the values + public static void DrawCrosswordScore(Panel mainPanel, Label currentScoreLabel, Label maxScoreLabel, bool isFinished, int crosswordScore, int numQuestions, DynamicSpriteFont labelFont, int posBottom) + { + try + { + if (!isFinished) + { + //Current score label + mainPanel.Widgets.Remove(currentScoreLabel); + currentScoreLabel.Text = $"Your Score: {crosswordScore.ToString()}"; + currentScoreLabel.TextColor = UIConstants.ScoreColor; + currentScoreLabel.Left = UIConstants.ClListSpacer * 40; + currentScoreLabel.Font = labelFont; + currentScoreLabel.Top = posBottom + UIConstants.ClListSpacer * 2; + mainPanel.Widgets.Add(currentScoreLabel); + } + else + { + //Game over label + mainPanel.Widgets.Remove(currentScoreLabel); + currentScoreLabel.Text = "GAME OVER!"; + currentScoreLabel.TextColor = UIConstants.ScoreColor; + currentScoreLabel.Left = UIConstants.ClListSpacer * 40; + currentScoreLabel.Font = labelFont; + currentScoreLabel.Top = posBottom + UIConstants.ClListSpacer * 2; + mainPanel.Widgets.Add(currentScoreLabel); + } + + //Max score label + mainPanel.Widgets.Remove(maxScoreLabel); + maxScoreLabel.Text = $"Max Score: {numQuestions.ToString()}"; + maxScoreLabel.TextColor = UIConstants.ScoreColor; + maxScoreLabel.Left = UIConstants.ClListSpacer * 40; + maxScoreLabel.Font = labelFont; + maxScoreLabel.Top = posBottom + UIConstants.ClListSpacer * 6; + mainPanel.Widgets.Add(maxScoreLabel); + + } + catch (Exception ex) + { + throw; + } + } + #endregion +} \ No newline at end of file diff --git a/Crossword/Crossword.csproj b/Crossword/Crossword.csproj index 7e2b9a2..2f61450 100644 --- a/Crossword/Crossword.csproj +++ b/Crossword/Crossword.csproj @@ -88,6 +88,7 @@ + diff --git a/Crossword/UI/DrawCreditsLabel.cs b/Crossword/UI/DrawCreditsLabel.cs index 69aa292..8b0049d 100644 --- a/Crossword/UI/DrawCreditsLabel.cs +++ b/Crossword/UI/DrawCreditsLabel.cs @@ -1,60 +1,60 @@ -using System; - -using Crossword.Shared.Constants; -using Myra.Graphics2D.UI; - -namespace Crossword.App; - -public sealed partial class CrosswordMain -{ -#region DrawCreditsLabel - /// - /// Draws a Credits label - /// - // private void DrawCreditsLabel() - // { - // try - // { - // logger.LogInformation("Start DrawCreditsLabel()"); - // - // //Max score label - // _mainPanel.Widgets.Remove(_creditsLabel); - // _creditsLabel.Text = GameConstants.CreditsText; - // _creditsLabel.TextColor = UIConstants.CreditsColor; - // _creditsLabel.Left = rectCrossWord.Left; - // _creditsLabel.Font = _fntCredits; - // _creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + UIConstants.SquareHeight/2; - // _mainPanel.Widgets.Add(_creditsLabel); - // - // } - // catch (Exception ex) - // { - // logger.LogError(ex,ex.Message); - // throw; - // } - // } - - private void DrawCreditsLabel(Panel mainPanel, Label creditsLabel) - { - try - { - logger.LogInformation("Start DrawCreditsLabel()"); - - //Max score label - mainPanel.Widgets.Remove(creditsLabel); - creditsLabel.Text = GameConstants.CreditsText; - creditsLabel.TextColor = UIConstants.CreditsColor; - creditsLabel.Left = rectCrossWord.Left; - creditsLabel.Font = _fntCredits; - creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + UIConstants.SquareHeight/2; - mainPanel.Widgets.Add(creditsLabel); - - } - catch (Exception ex) - { - logger.LogError(ex,ex.Message); - throw; - } - } - #endregion -} \ No newline at end of file +// using System; +// +// using Crossword.Shared.Constants; +// using Myra.Graphics2D.UI; +// +// namespace Crossword.App; +// +// public sealed partial class CrosswordMain +// { +// // #region DrawCreditsLabel +// // /// +// // /// Draws a Credits label +// // /// +// // // private void DrawCreditsLabel() +// // // { +// // // try +// // // { +// // // logger.LogInformation("Start DrawCreditsLabel()"); +// // // +// // // //Max score label +// // // _mainPanel.Widgets.Remove(_creditsLabel); +// // // _creditsLabel.Text = GameConstants.CreditsText; +// // // _creditsLabel.TextColor = UIConstants.CreditsColor; +// // // _creditsLabel.Left = rectCrossWord.Left; +// // // _creditsLabel.Font = _fntCredits; +// // // _creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + UIConstants.SquareHeight/2; +// // // _mainPanel.Widgets.Add(_creditsLabel); +// // // +// // // } +// // // catch (Exception ex) +// // // { +// // // logger.LogError(ex,ex.Message); +// // // throw; +// // // } +// // // } +// // +// private void DrawCreditsLabel(Panel mainPanel, Label creditsLabel) +// { +// try +// { +// logger.LogInformation("Start DrawCreditsLabel()"); +// +// //Max score label +// mainPanel.Widgets.Remove(creditsLabel); +// creditsLabel.Text = GameConstants.CreditsText; +// creditsLabel.TextColor = UIConstants.CreditsColor; +// creditsLabel.Left = rectCrossWord.Left; +// creditsLabel.Font = _fntCredits; +// creditsLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer + UIConstants.SquareHeight + UIConstants.SquareHeight/2; +// mainPanel.Widgets.Add(creditsLabel); +// +// } +// catch (Exception ex) +// { +// logger.LogError(ex,ex.Message); +// throw; +// } +// } +// // #endregion +// } \ No newline at end of file diff --git a/Crossword/UI/DrawCrosswordScore.cs b/Crossword/UI/DrawCrosswordScore.cs index d26c68a..fe52bf6 100644 --- a/Crossword/UI/DrawCrosswordScore.cs +++ b/Crossword/UI/DrawCrosswordScore.cs @@ -1,106 +1,106 @@ -using System; - -using Crossword.Shared.Constants; -using Myra.Graphics2D.UI; - -namespace Crossword.App; - -public sealed partial class CrosswordMain -{ - #region DrawCrosswordScore - /// - /// Draws the crossword score and updates the values - /// - // private void DrawCrosswordScore() - // { - // try - // { - // logger.LogInformation("Start DrawCrosswordScore()"); - // - // if (!IsFinished) - // { - // //Current score label - // _mainPanel.Widgets.Remove(_currentScoreLabel); - // _currentScoreLabel.Text = $"Your Score: {CrosswordScore.ToString()}"; - // _currentScoreLabel.TextColor = UIConstants.ScoreColor; - // _currentScoreLabel.Left = UIConstants.ClListSpacer * 40; - // _currentScoreLabel.Font = _fntScore; - // _currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; - // _mainPanel.Widgets.Add(_currentScoreLabel); - // } - // else - // { - // //Game over label - // _mainPanel.Widgets.Remove(_currentScoreLabel); - // _currentScoreLabel.Text = "GAME OVER!"; - // _currentScoreLabel.TextColor = UIConstants.ScoreColor; - // _currentScoreLabel.Left = UIConstants.ClListSpacer * 40; - // _currentScoreLabel.Font = _fntScore; - // _currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; - // _mainPanel.Widgets.Add(_currentScoreLabel); - // } - // - // //Max score label - // _mainPanel.Widgets.Remove(_maxScoreLabel); - // _maxScoreLabel.Text = $"Max Score: {NumQuestions.ToString()}"; - // _maxScoreLabel.TextColor = UIConstants.ScoreColor; - // _maxScoreLabel.Left = UIConstants.ClListSpacer * 40; - // _maxScoreLabel.Font = _fntScore; - // _maxScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 6; - // _mainPanel.Widgets.Add(_maxScoreLabel); - // - // } - // catch (Exception ex) - // { - // logger.LogError(ex,ex.Message); - // throw; - // } - // } - - private void DrawCrosswordScore(Panel mainPanel, Label currentScoreLabel, Label maxScoreLabel) - { - try - { - logger.LogInformation("Start DrawCrosswordScore()"); - - if (!IsFinished) - { - //Current score label - mainPanel.Widgets.Remove(currentScoreLabel); - currentScoreLabel.Text = $"Your Score: {CrosswordScore.ToString()}"; - currentScoreLabel.TextColor = UIConstants.ScoreColor; - currentScoreLabel.Left = UIConstants.ClListSpacer * 40; - currentScoreLabel.Font = _fntScore; - currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; - mainPanel.Widgets.Add(currentScoreLabel); - } - else - { - //Game over label - mainPanel.Widgets.Remove(currentScoreLabel); - currentScoreLabel.Text = "GAME OVER!"; - currentScoreLabel.TextColor = UIConstants.ScoreColor; - currentScoreLabel.Left = UIConstants.ClListSpacer * 40; - currentScoreLabel.Font = _fntScore; - currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; - mainPanel.Widgets.Add(currentScoreLabel); - } - - //Max score label - mainPanel.Widgets.Remove(maxScoreLabel); - maxScoreLabel.Text = $"Max Score: {NumQuestions.ToString()}"; - maxScoreLabel.TextColor = UIConstants.ScoreColor; - maxScoreLabel.Left = UIConstants.ClListSpacer * 40; - maxScoreLabel.Font = _fntScore; - maxScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 6; - mainPanel.Widgets.Add(maxScoreLabel); - - } - catch (Exception ex) - { - logger.LogError(ex,ex.Message); - throw; - } - } - #endregion -} \ No newline at end of file +// using System; +// +// using Crossword.Shared.Constants; +// using Myra.Graphics2D.UI; +// +// namespace Crossword.App; +// +// public sealed partial class CrosswordMain +// { +// #region DrawCrosswordScore +// /// +// /// Draws the crossword score and updates the values +// /// +// // private void DrawCrosswordScore() +// // { +// // try +// // { +// // logger.LogInformation("Start DrawCrosswordScore()"); +// // +// // if (!IsFinished) +// // { +// // //Current score label +// // _mainPanel.Widgets.Remove(_currentScoreLabel); +// // _currentScoreLabel.Text = $"Your Score: {CrosswordScore.ToString()}"; +// // _currentScoreLabel.TextColor = UIConstants.ScoreColor; +// // _currentScoreLabel.Left = UIConstants.ClListSpacer * 40; +// // _currentScoreLabel.Font = _fntScore; +// // _currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; +// // _mainPanel.Widgets.Add(_currentScoreLabel); +// // } +// // else +// // { +// // //Game over label +// // _mainPanel.Widgets.Remove(_currentScoreLabel); +// // _currentScoreLabel.Text = "GAME OVER!"; +// // _currentScoreLabel.TextColor = UIConstants.ScoreColor; +// // _currentScoreLabel.Left = UIConstants.ClListSpacer * 40; +// // _currentScoreLabel.Font = _fntScore; +// // _currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; +// // _mainPanel.Widgets.Add(_currentScoreLabel); +// // } +// // +// // //Max score label +// // _mainPanel.Widgets.Remove(_maxScoreLabel); +// // _maxScoreLabel.Text = $"Max Score: {NumQuestions.ToString()}"; +// // _maxScoreLabel.TextColor = UIConstants.ScoreColor; +// // _maxScoreLabel.Left = UIConstants.ClListSpacer * 40; +// // _maxScoreLabel.Font = _fntScore; +// // _maxScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 6; +// // _mainPanel.Widgets.Add(_maxScoreLabel); +// // +// // } +// // catch (Exception ex) +// // { +// // logger.LogError(ex,ex.Message); +// // throw; +// // } +// // } +// +// private void DrawCrosswordScore(Panel mainPanel, Label currentScoreLabel, Label maxScoreLabel) +// { +// try +// { +// logger.LogInformation("Start DrawCrosswordScore()"); +// +// if (!IsFinished) +// { +// //Current score label +// mainPanel.Widgets.Remove(currentScoreLabel); +// currentScoreLabel.Text = $"Your Score: {CrosswordScore.ToString()}"; +// currentScoreLabel.TextColor = UIConstants.ScoreColor; +// currentScoreLabel.Left = UIConstants.ClListSpacer * 40; +// currentScoreLabel.Font = _fntScore; +// currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; +// mainPanel.Widgets.Add(currentScoreLabel); +// } +// else +// { +// //Game over label +// mainPanel.Widgets.Remove(currentScoreLabel); +// currentScoreLabel.Text = "GAME OVER!"; +// currentScoreLabel.TextColor = UIConstants.ScoreColor; +// currentScoreLabel.Left = UIConstants.ClListSpacer * 40; +// currentScoreLabel.Font = _fntScore; +// currentScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 2; +// mainPanel.Widgets.Add(currentScoreLabel); +// } +// +// //Max score label +// mainPanel.Widgets.Remove(maxScoreLabel); +// maxScoreLabel.Text = $"Max Score: {NumQuestions.ToString()}"; +// maxScoreLabel.TextColor = UIConstants.ScoreColor; +// maxScoreLabel.Left = UIConstants.ClListSpacer * 40; +// maxScoreLabel.Font = _fntScore; +// maxScoreLabel.Top = rectCrossWord.Bottom + UIConstants.ClListSpacer * 6; +// mainPanel.Widgets.Add(maxScoreLabel); +// +// } +// catch (Exception ex) +// { +// logger.LogError(ex,ex.Message); +// throw; +// } +// } +// #endregion +// } \ No newline at end of file diff --git a/Crossword/monogame/Monogame.cs b/Crossword/monogame/Monogame.cs index 53edb36..c8047ed 100644 --- a/Crossword/monogame/Monogame.cs +++ b/Crossword/monogame/Monogame.cs @@ -6,7 +6,7 @@ using Myra; using Myra.Graphics2D.UI; - +using Crossword.UI; namespace Crossword.App; @@ -101,10 +101,13 @@ protected override void Update(GameTime gameTime) //update game logic UpdateCrosswordScore(); - DrawCrosswordScore(_mainPanel, _currentScoreLabel, _maxScoreLabel); + //DrawCrosswordScore(_mainPanel, _currentScoreLabel, _maxScoreLabel); + CrosswordUI.DrawCrosswordScore(_mainPanel, _currentScoreLabel, _maxScoreLabel, IsFinished, CrosswordScore, + NumQuestions, _fntScore, rectCrossWord.Bottom); //draw the credits - DrawCreditsLabel(_mainPanel, _creditsLabel); + //DrawCreditsLabel(_mainPanel, _creditsLabel); + CrosswordUI.DrawCreditsLabel(_mainPanel,_creditsLabel,rectCrossWord.Left,rectCrossWord.Bottom,_fntCredits); base.Update(gameTime); From 0d2f7c61bef5149c3d5c6fa02de6bf65b7ce35ef Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Wed, 3 Apr 2024 16:58:25 +1100 Subject: [PATCH 22/26] Ui refactor --- Crossword/UI/DrawSmallFont.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Crossword/UI/DrawSmallFont.cs b/Crossword/UI/DrawSmallFont.cs index 94cb4d0..0ed8587 100644 --- a/Crossword/UI/DrawSmallFont.cs +++ b/Crossword/UI/DrawSmallFont.cs @@ -2,6 +2,7 @@ using Crossword.Shared.Constants; using FontStashSharp; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; namespace Crossword.App; @@ -33,6 +34,26 @@ private void DrawSmallFontAcross(int i, int j) throw; } } + + // private void DrawSmallFontAcross(SpriteBatch spriteBatch, Square sqPuzzleSquare, Rectangle? puzzleSquare) + // { + // try + // { + // //logger.LogInformation("Start DrawSmallFontAcross()"); + // if (sqPuzzleSquare.ClueAnswerAcross is null) return; + // if (sqPuzzleSquare.ClueAnswerAcross?.SqAnswerSquares?[0] != sqPuzzleSquare) return; + // if (puzzleSquare is not null) + // spriteBatch.DrawString(_fntnumFont, + // sqPuzzleSquare.ClueAnswerAcross?.QuestionNumber.ToString(), + // new Vector2(puzzleSquare.X + UIConstants.SmlNumOffsetX, + // puzzleSquare.Y + UIConstants.SmlNumOffsetY), UIConstants.SmallFontColor); + // } + // catch (Exception ex) + // { + // logger.LogError(ex, ex.Message); + // throw; + // } + // } /// /// Draws small font Down From a50cc47e977baa037221ca83bdbae78213c9df2c Mon Sep 17 00:00:00 2001 From: Aaron Saikovski Date: Thu, 4 Apr 2024 15:01:36 +1100 Subject: [PATCH 23/26] Create dotnet.yml --- .github/workflows/dotnet.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..863f75b --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,28 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: [ "main" ] + # pull_request: + # branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + # - name: Test + # run: dotnet test --no-build --verbosity normal From 016884560bf81232a348100933e48fbf224c89cf Mon Sep 17 00:00:00 2001 From: Aaron Saikovski Date: Thu, 4 Apr 2024 15:24:06 +1100 Subject: [PATCH 24/26] Delete Crossword.ClueAnswer directory --- Crossword.ClueAnswer/CheckHint.cs | 47 --------------- Crossword.ClueAnswer/CheckWord.cs | 27 --------- Crossword.ClueAnswer/ClueAnswerMap.cs | 31 ---------- .../Crossword.ClueAnswer.csproj | 13 ----- Crossword.ClueAnswer/GetNextSq.cs | 39 ------------- Crossword.ClueAnswer/GetPrevSq.cs | 31 ---------- Crossword.ClueAnswer/GetSquare.cs | 19 ------- Crossword.ClueAnswer/HighlightSquares.cs | 50 ---------------- Crossword.ClueAnswer/IsCorrect.cs | 21 ------- Crossword.ClueAnswer/SetObjectRef.cs | 57 ------------------- 10 files changed, 335 deletions(-) delete mode 100644 Crossword.ClueAnswer/CheckHint.cs delete mode 100644 Crossword.ClueAnswer/CheckWord.cs delete mode 100644 Crossword.ClueAnswer/ClueAnswerMap.cs delete mode 100644 Crossword.ClueAnswer/Crossword.ClueAnswer.csproj delete mode 100644 Crossword.ClueAnswer/GetNextSq.cs delete mode 100644 Crossword.ClueAnswer/GetPrevSq.cs delete mode 100644 Crossword.ClueAnswer/GetSquare.cs delete mode 100644 Crossword.ClueAnswer/HighlightSquares.cs delete mode 100644 Crossword.ClueAnswer/IsCorrect.cs delete mode 100644 Crossword.ClueAnswer/SetObjectRef.cs diff --git a/Crossword.ClueAnswer/CheckHint.cs b/Crossword.ClueAnswer/CheckHint.cs deleted file mode 100644 index b6fab86..0000000 --- a/Crossword.ClueAnswer/CheckHint.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Threading.Tasks; - -namespace Crossword.ClueAnswer; - -public sealed partial class ClueAnswer -{ - #region CheckHint - - /// - /// Sets the Hint letter if Get Letter is pressed - /// - /// - /// - public bool CheckHint(char hintLetter) - { - if (hintLetter <= 0) throw new ArgumentOutOfRangeException(nameof(hintLetter)); - - var foundResult = false; - - // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere - if (Answer is null) return foundResult; - var szAnswerLength = Answer.Length; - - - for (var i = 0; i < Answer.Length; i++) - { - if (SqAnswerSquares is null || Answer[i] != hintLetter || - SqAnswerSquares[i]!.Letter == hintLetter) break; - SqAnswerSquares[i]?.SetLetter(hintLetter, IsAcross); - foundResult = true; - - } - //Parallel for loop - // Parallel.For(0, szAnswerLength, i => - // { - // if (SqAnswerSquares is null || Answer[i] != hintLetter || - // SqAnswerSquares[i]!.Letter == hintLetter) return; - // SqAnswerSquares[i]?.SetLetter(hintLetter, IsAcross); - // foundResult = true; - // }); - - return foundResult; - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.ClueAnswer/CheckWord.cs b/Crossword.ClueAnswer/CheckWord.cs deleted file mode 100644 index 766aa71..0000000 --- a/Crossword.ClueAnswer/CheckWord.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Threading.Tasks; - -namespace Crossword.ClueAnswer; - -public sealed partial class ClueAnswer -{ - #region CheckWord - - /// - /// Sets the letter colour if Check words is pressed. - /// - public void CheckWord() - { - if (Answer is null) return; - for (var i = 0; i < Answer.Length; i++) - { - SqAnswerSquares?[i]?.CheckLetter(Answer[i]); - } - - // Parallel.For(0, Answer.Length, i => - // { - // SqAnswerSquares?[i]?.CheckLetter(Answer[i]); - // }); - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.ClueAnswer/ClueAnswerMap.cs b/Crossword.ClueAnswer/ClueAnswerMap.cs deleted file mode 100644 index fa007fa..0000000 --- a/Crossword.ClueAnswer/ClueAnswerMap.cs +++ /dev/null @@ -1,31 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// // -// Module: ClueAnswerMap.cs // -// Authors: Aaron Saikovski & Bryan Richards // -// Original Date: 26/02/97 // -// Version: 1.0 // -// Purpose: Clue + Answer references class // -// // -//////////////////////////////////////////////////////////////////////////// - -using Crossword.PuzzleSquares; - -namespace Crossword.ClueAnswer; - -/// -/// ClueAnswerMap Class -/// -public sealed partial class ClueAnswer -{ - #region getters_setters - public string? Answer { get; set; } - public string? Clue { get; set; } - - public int QuestionNumber { get; set; } - - public bool IsAcross { get; set; } = true; - - public Square?[]? SqAnswerSquares { get; set; } - - #endregion -} \ No newline at end of file diff --git a/Crossword.ClueAnswer/Crossword.ClueAnswer.csproj b/Crossword.ClueAnswer/Crossword.ClueAnswer.csproj deleted file mode 100644 index cdf9794..0000000 --- a/Crossword.ClueAnswer/Crossword.ClueAnswer.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - diff --git a/Crossword.ClueAnswer/GetNextSq.cs b/Crossword.ClueAnswer/GetNextSq.cs deleted file mode 100644 index 79ba5c4..0000000 --- a/Crossword.ClueAnswer/GetNextSq.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using Crossword.PuzzleSquares; - -namespace Crossword.ClueAnswer; - -public sealed partial class ClueAnswer -{ - #region GetNextSq - - /// - /// Returns the next square - /// - /// - /// - public Square? GetNextSq(Square? sq) - { - ArgumentNullException.ThrowIfNull(sq); - var i = 0; - while (Answer != null && i < Answer.Length){ - if (SqAnswerSquares != null && sq == SqAnswerSquares[i]) - if (i < Answer.Length - 1) - return SqAnswerSquares[i + 1]; - i++; - } - return sq; - - // ArgumentNullException.ThrowIfNull(sq); - // var i = 0; - // while (i < Answer.Length){ - // if (sq == SqAnswerSquares[i]) - // if (i < Answer.Length - 1) - // return SqAnswerSquares[i + 1]; - // i++; - // } - // return sq; - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.ClueAnswer/GetPrevSq.cs b/Crossword.ClueAnswer/GetPrevSq.cs deleted file mode 100644 index cfd6501..0000000 --- a/Crossword.ClueAnswer/GetPrevSq.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using Crossword.PuzzleSquares; - -namespace Crossword.ClueAnswer; - -public sealed partial class ClueAnswer -{ - #region GetPrevSq - - /// - /// Returns the previous square - /// - /// - /// - public Square? GetPrevSq(Square? sq) - { - ArgumentNullException.ThrowIfNull(sq); - - if (Answer is null) return sq; - var i = Answer.Length - 1; - while (i > -1) - { - if (sq == SqAnswerSquares?[i]) return i != 0 ? SqAnswerSquares?[i - 1] : sq; - i--; - } - - return sq; - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.ClueAnswer/GetSquare.cs b/Crossword.ClueAnswer/GetSquare.cs deleted file mode 100644 index c2097fa..0000000 --- a/Crossword.ClueAnswer/GetSquare.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Crossword.PuzzleSquares; - -namespace Crossword.ClueAnswer; - -public sealed partial class ClueAnswer -{ - #region GetSquare - - /// - /// Gets the first square referenced by my answer. - /// - /// - public Square? GetSquare() - { - return SqAnswerSquares?[0]; - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.ClueAnswer/HighlightSquares.cs b/Crossword.ClueAnswer/HighlightSquares.cs deleted file mode 100644 index d172bf9..0000000 --- a/Crossword.ClueAnswer/HighlightSquares.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Threading.Tasks; -using Crossword.PuzzleSquares; -using Crossword.Shared.Constants; - -namespace Crossword.ClueAnswer; - -public sealed partial class ClueAnswer -{ - #region HighlightSquares - - /// - /// /Highlights the current word and sets active square - /// - /// - /// - public void HighlightSquares(Square? sq, bool setHighLighted) - { - ArgumentNullException.ThrowIfNull(sq); - - if (Answer is null) return; - for (var i = 0; i < Answer.Length; i++) - { - if (!setHighLighted) - SqAnswerSquares?[i]?.SetHighlighted(CWSettings.CurrentNone); - else - { - SqAnswerSquares?[i] - ?.SetHighlighted(SqAnswerSquares?[i] == sq - ? CWSettings.CurrentLetter - : CWSettings.CurrentWord); - } - } - - // Parallel.For(0, Answer.Length, i => - // { - // if (!setHighLighted) - // SqAnswerSquares?[i]?.SetHighlighted(UIConstants.CurrentNone); - // else - // { - // SqAnswerSquares?[i] - // ?.SetHighlighted(SqAnswerSquares?[i] == sq - // ? UIConstants.CurrentLetter - // : UIConstants.CurrentWord); - // } - // }); - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.ClueAnswer/IsCorrect.cs b/Crossword.ClueAnswer/IsCorrect.cs deleted file mode 100644 index 89c148f..0000000 --- a/Crossword.ClueAnswer/IsCorrect.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Linq; - -namespace Crossword.ClueAnswer; - -public sealed partial class ClueAnswer -{ - #region IsCorrect - - /// - /// Returns true if all answer letters are correct and false otherwise - /// - /// - public bool IsCorrect() - { - if (Answer is not null) - return !Answer.Where((t, i) => SqAnswerSquares is not null && SqAnswerSquares[i]!.Letter != t).Any(); - return true; - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.ClueAnswer/SetObjectRef.cs b/Crossword.ClueAnswer/SetObjectRef.cs deleted file mode 100644 index 7481607..0000000 --- a/Crossword.ClueAnswer/SetObjectRef.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Threading.Tasks; -using Crossword.PuzzleSquares; - -namespace Crossword.ClueAnswer; - -public sealed partial class ClueAnswer -{ - #region SetObjectRef - - /// - /// Sets the object reference. - /// - /// - /// - /// - /// - /// - public void SetObjectRef(string Answer, string Clue, int QuestionNumber, - bool IsAcross, Square?[]? SqAnswerSquares) - { - ArgumentNullException.ThrowIfNull(Answer); - ArgumentNullException.ThrowIfNull(Clue); - ArgumentNullException.ThrowIfNull(SqAnswerSquares); - - this.Answer = Answer; - this.Clue = Clue; - this.QuestionNumber = QuestionNumber; - this.IsAcross = IsAcross; - - //Initialise the answer squares array. - this.SqAnswerSquares = new Square[Answer.Length]; - - //Copy the array - // Assuming szAnswer and sqAnswerSquares are declared and initialized somewhere - var szAnswerLength = Answer.Length; - - //Parallel for loop - Parallel.For(0, szAnswerLength, k => - { - // Create a new Square instance - var sqAnswerSquares = this.SqAnswerSquares; - if (sqAnswerSquares is not null) - { - sqAnswerSquares[k] = new Square(); - sqAnswerSquares[k]?.CreateSquare(0, 0); - sqAnswerSquares[k] = SqAnswerSquares[k]; - } - - // Assign the created Square to the array element - // The original code `this.sqAnswerSquares[k] = sqAnswerSquares[k];` seems redundant, so omitted - if (SqAnswerSquares is not null) SqAnswerSquares?[k]?.SetObjectRef(this.IsAcross, this); - }); - } - - #endregion -} \ No newline at end of file From 2565684897fe124652f1420df8b770be31ee133b Mon Sep 17 00:00:00 2001 From: Aaron Saikovski Date: Thu, 4 Apr 2024 15:24:15 +1100 Subject: [PATCH 25/26] Delete Crossword.Squares directory --- Crossword.Squares/CanFlipDirection.cs | 34 -------- Crossword.Squares/CheckLetter.cs | 21 ----- Crossword.Squares/CreateSquare.cs | 19 ----- Crossword.Squares/Crossword.Squares.csproj | 14 ---- Crossword.Squares/GetClueAnswerRef.cs | 20 ----- Crossword.Squares/GetNextSq.cs | 24 ------ Crossword.Squares/GetPrevSq.cs | 20 ----- Crossword.Squares/SetHighlighted.cs | 55 ------------- Crossword.Squares/SetLetter.cs | 22 ----- Crossword.Squares/SetObjectRef.cs | 31 -------- Crossword.Squares/Square.cs | 93 ---------------------- 11 files changed, 353 deletions(-) delete mode 100644 Crossword.Squares/CanFlipDirection.cs delete mode 100644 Crossword.Squares/CheckLetter.cs delete mode 100644 Crossword.Squares/CreateSquare.cs delete mode 100644 Crossword.Squares/Crossword.Squares.csproj delete mode 100644 Crossword.Squares/GetClueAnswerRef.cs delete mode 100644 Crossword.Squares/GetNextSq.cs delete mode 100644 Crossword.Squares/GetPrevSq.cs delete mode 100644 Crossword.Squares/SetHighlighted.cs delete mode 100644 Crossword.Squares/SetLetter.cs delete mode 100644 Crossword.Squares/SetObjectRef.cs delete mode 100644 Crossword.Squares/Square.cs diff --git a/Crossword.Squares/CanFlipDirection.cs b/Crossword.Squares/CanFlipDirection.cs deleted file mode 100644 index 6624c51..0000000 --- a/Crossword.Squares/CanFlipDirection.cs +++ /dev/null @@ -1,34 +0,0 @@ -// namespace Crossword.Squares; -// -// public sealed partial class Square -// { -// #region CanFlipDirection -// -// /// -// /// Can the current orientation be flipped. -// /// -// /// -// /// -// public bool CanFlipDirection(bool isAcross) -// { -// // switch (isAcross) -// // { -// // //if square is an intersection -// // case true when ClueAnswerDown is not null: -// // case false when ClueAnswerAcross is not null: -// // return true; -// // default: -// // return false; -// // } -// -// //if square is an intersection -// if ((bIsAcross) && (clDown != null)) -// return true; -// else if ((!bIsAcross) && (clAcross != null)) -// return true; -// else -// return false; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword.Squares/CheckLetter.cs b/Crossword.Squares/CheckLetter.cs deleted file mode 100644 index ea60c02..0000000 --- a/Crossword.Squares/CheckLetter.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Crossword.Shared.Constants; - -namespace Crossword.Squares; - -public sealed partial class Square -{ - #region CheckLetter - - /// - /// Check for correctness of letter based on input char parameter and toggles colour accordingly - /// - /// - public void CheckLetter(char correctLetter) - { - if (Letter == ' ') return; - ForeColour = Letter == correctLetter ? UIConstants.SqCorrect : UIConstants.SqError; - IsDirty = true; - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.Squares/CreateSquare.cs b/Crossword.Squares/CreateSquare.cs deleted file mode 100644 index c30b5dd..0000000 --- a/Crossword.Squares/CreateSquare.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Crossword.Squares; - -public sealed partial class Square -{ - #region CreateSquare - - /// - /// Allocates memory for blank square - /// - /// - /// - public void CreateSquare(int xCoord, int yCoord) - { - this.xCoord = xCoord; - this.yCoord = yCoord; - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.Squares/Crossword.Squares.csproj b/Crossword.Squares/Crossword.Squares.csproj deleted file mode 100644 index 4dcc9f0..0000000 --- a/Crossword.Squares/Crossword.Squares.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - net8.0 - enable - enable - Crossword.Squares - - - - - - - diff --git a/Crossword.Squares/GetClueAnswerRef.cs b/Crossword.Squares/GetClueAnswerRef.cs deleted file mode 100644 index 4718f5f..0000000 --- a/Crossword.Squares/GetClueAnswerRef.cs +++ /dev/null @@ -1,20 +0,0 @@ -// using Crossword.ClueAnswerMap; -// -// namespace Crossword.Squares; -// -// public sealed partial class Square -// { -// #region GetClueAnswerRef -// -// /// -// /// returns the Clue/Answer reference -// /// -// /// -// /// -// public ClueAnswerMap? GetClueAnswerRef(bool isAcross) -// { -// return isAcross ? ClueAnswerAcross : ClueAnswerDown; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword.Squares/GetNextSq.cs b/Crossword.Squares/GetNextSq.cs deleted file mode 100644 index 683c1d3..0000000 --- a/Crossword.Squares/GetNextSq.cs +++ /dev/null @@ -1,24 +0,0 @@ -// namespace Crossword.Squares; -// -// public sealed partial class Square -// { -// #region GetNextSq -// -// /// -// /// Gets the next available square -// /// -// /// -// /// -// public Square? GetNextSq(bool isAcross) -// { -// if (isAcross) -// { -// return ClueAnswerAcross != null ? ClueAnswerAcross.GetNextSq(this) : this; -// } -// -// return ClueAnswerDown != null ? ClueAnswerDown.GetNextSq(this) : this; -// -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword.Squares/GetPrevSq.cs b/Crossword.Squares/GetPrevSq.cs deleted file mode 100644 index 13d2c01..0000000 --- a/Crossword.Squares/GetPrevSq.cs +++ /dev/null @@ -1,20 +0,0 @@ -// namespace Crossword.Squares; -// -// public sealed partial class Square -// { -// #region GetPrevSq -// -// /// -// /// /Gets the previous available square -// /// -// /// -// /// -// public Square? GetPrevSq(bool isAcross) -// { -// if (isAcross) -// return ClueAnswerAcross is not null ? ClueAnswerAcross.GetPrevSq(this) : this; -// return ClueAnswerDown is not null ? ClueAnswerDown.GetPrevSq(this) : this; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword.Squares/SetHighlighted.cs b/Crossword.Squares/SetHighlighted.cs deleted file mode 100644 index 6ae24b7..0000000 --- a/Crossword.Squares/SetHighlighted.cs +++ /dev/null @@ -1,55 +0,0 @@ - -using Crossword.Shared.Constants; - -namespace Crossword.Squares; - -public sealed partial class Square -{ - #region SetHighlighted - - /// - /// Sets the background colour of a square - /// - /// - public void SetHighlighted(int highlightType) - { - switch (highlightType) - { - case 1: //Current Letter - if (!BackColour.Equals(UIConstants.SquareHighlightCurrent)) - { - BackColour = UIConstants.SquareHighlightCurrent; - IsDirty = true; - } - - break; - case 2: //Current Word - if (!BackColour.Equals(UIConstants.SquareHighlightWord)) - { - BackColour = UIConstants.SquareHighlightWord; - IsDirty = true; - } - - break; - case 3: //Current None - if (!BackColour.Equals(UIConstants.SquareHighlightNone)) - { - BackColour = UIConstants.SquareHighlightNone; - IsDirty = true; - } - - break; - default: //Something went wrong.... - if (BackColour.Equals(UIConstants.SquareHighlightErr)) - { - Console.WriteLine($"Bogus color: {highlightType}"); - BackColour = UIConstants.SquareHighlightErr; - IsDirty = true; - } - - break; - } - } - - #endregion -} \ No newline at end of file diff --git a/Crossword.Squares/SetLetter.cs b/Crossword.Squares/SetLetter.cs deleted file mode 100644 index 9908b60..0000000 --- a/Crossword.Squares/SetLetter.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Crossword.Shared.Constants; - -namespace Crossword.Squares; - -public sealed partial class Square -{ - #region SetLetter - - /// - /// Set the colour for a letter. - /// - /// - /// - public void SetLetter(char letter, bool isAcross) - { - Letter = letter; - IsDirty = true; - ForeColour = UIConstants.SquareHighlightDefault; - } - - #endregion -} diff --git a/Crossword.Squares/SetObjectRef.cs b/Crossword.Squares/SetObjectRef.cs deleted file mode 100644 index 03573af..0000000 --- a/Crossword.Squares/SetObjectRef.cs +++ /dev/null @@ -1,31 +0,0 @@ -// using System; -// using Crossword.ClueAnswerMap; -// using Crossword.Shared.Constants; -// -// namespace Crossword.Squares; -// -// public sealed partial class Square -// { -// #region SetObjectRef -// -// /// -// /// Set the object reference to clueanswer object -// /// -// /// -// /// -// public void SetObjectRef(bool isAcross, ClueAnswerMap clueAnswer) -// { -// ArgumentNullException.ThrowIfNull(clueAnswer); -// -// if (isAcross) -// ClueAnswerAcross = clueAnswer; -// else -// ClueAnswerDown = clueAnswer; -// -// IsCharAllowed = true; -// IsDirty = true; -// BackColour = UIConstants.SquareHighlightNone; -// } -// -// #endregion -// } \ No newline at end of file diff --git a/Crossword.Squares/Square.cs b/Crossword.Squares/Square.cs deleted file mode 100644 index ccafce6..0000000 --- a/Crossword.Squares/Square.cs +++ /dev/null @@ -1,93 +0,0 @@ - -using Microsoft.Xna.Framework; - -namespace Crossword.Squares; -// -// //Square class -// public sealed partial class Square -// { -// #region getters_setters -// -// public int xCoord { get; set; } -// public int yCoord { get; set; } -// -// -// public char Letter { get; set; } -// -// -// public Color ForeColour { get; set; } = Color.Black; -// public Color BackColour { get; set; } = Color.Black; -// -// public bool IsDirty { get; set; } = true; -// -// public bool IsCharAllowed { get; set; } -// -// // public ClueAnswerMap? ClueAnswerAcross { get; set; } -// // public ClueAnswerMap? ClueAnswerDown { get; set; } -// -// #endregion -// -// -// } - -/// -/// Primary constructor for the Square -/// -/// -/// -/// -/// -/// -/// -/// -// public class Square(int xCoord, int yCoord, char? Letter, Color? ForeColour, Color? BackColour, bool IsDirty, bool IsCharAllowed) -// { -// // public Square(int xCoord, int yCoord, char? Letter, Color? ForeColour, Color? BackColour, bool IsDirty, bool IsCharAllowed) -// // { -// // //this.xCoord = xCoord; -// // // this.yCoord = yCoord; -// // } -// -// } - -/// -/// Square class -/// -public sealed partial class Square -{ - public int xCoord { get; set; } - public int yCoord { get; set; } - - - public char Letter { get; set; } - - - public Color ForeColour { get; set; } = Color.Black; - public Color BackColour { get; set; } = Color.Black; - - public bool IsDirty { get; set; } = true; - - public bool IsCharAllowed { get; set; } - - /// - /// Class constructor - /// - /// - /// - /// - /// - /// - public Square(int xCoord, int yCoord, char letter, bool isDirty, bool isCharAllowed) - { - this.xCoord = xCoord; - this.yCoord = yCoord; - this.Letter = letter; - this.IsDirty = isDirty; - this.IsCharAllowed = isCharAllowed; - } - -} - - - - From 8b5786b547ba9a552caa0395a1d7bab121ed7acb Mon Sep 17 00:00:00 2001 From: aaronsaikovski Date: Fri, 5 Apr 2024 08:29:01 +1100 Subject: [PATCH 26/26] updated version and readme --- CHANGELOG.md | 13 +++-- Crossword.Shared/Constants/GameConstants.cs | 2 +- README.md | 54 ++++++++++++++------- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2387a53..14f060f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,19 @@ # Cyberpuzzles Crossword - CHANGELOG ## v1.0.0 (2023-12-07) -- Initial v1.0 release for feedback -## v1.0.1 2023-12-07) +- Initial v1.0 release for feedback - Added serilog logging to both API and main crossword - refactored solution structure and namespace cleanup to make it more in line with CLEAN & SOLID principles - fixed async API call - Merged parser back into main project and deleted the old parser project - modified parser to use better class instantiation methods for better memory management - added newer labels to listboxes - -## v1.0.2 2023-12-20) - Fixed list box headers -- Refactored and performance improvements. \ No newline at end of file +- Refactored and performance improvements. + +## v1.0.0-Beta2 2024-04-05) + +- Major solution and project restructure to follow a more Clean architecture and easier to follow decoupled object hierarchy. +- Refactored for performance and better memory usage. +- diff --git a/Crossword.Shared/Constants/GameConstants.cs b/Crossword.Shared/Constants/GameConstants.cs index 69d29db..d41e432 100644 --- a/Crossword.Shared/Constants/GameConstants.cs +++ b/Crossword.Shared/Constants/GameConstants.cs @@ -30,7 +30,7 @@ public sealed class GameConstants "Dedicated to Neil Reading (neilski) RIP."; //game title string - public const string GameTitle = "CyberPuzzles Crossword v1.0.2"; + public const string GameTitle = "CyberPuzzles Crossword v1.0.0-beta2"; } diff --git a/README.md b/README.md index 76b90d7..6d6bb95 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,17 @@
-# CyberPuzzles - Crossword +# CyberPuzzles - Crossword - v1.0.0-beta2 A Monogame C# .Net 8.0 Core port of a Java Applet game I co-wrote back in 1997. -**Full co-authoring credits go to Bryan Richards and Neil Reading (RIP) from the OzEmail days (circa 1997)** +**Full co-authoring credits go to the ObjectCentric team (Bryan Richards and Neil Reading) from the OzEmail days (circa 1997)**
## Version History: -- 1.0 - Initial release for initial feedback. - Please report all bugs [here](https://github.com/AaronSaikovski/CyberPuzzles/issues). +- 1.0.0-beta2- Major refactor- restructured code with a focus on performance and reduced memory usage. +- 1.0.0 - Initial release for initial feedback. --- @@ -39,7 +40,7 @@ New version Screenshot: ### Software Requirements: -- [Microsoft .Net 8.0 Core SDK/Runtime Framework](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) +- [Microsoft .Net 8.0+ Core SDK/Runtime Framework](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) - [Visual Studio Code](https://code.visualstudio.com/download) - [C# DevKit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit) - Optional - [JetBrains Rider](https://www.jetbrains.com/rider/) @@ -48,31 +49,47 @@ New version Screenshot: ### Project Structure: -The Crossword solution is structured as follows: +The Crossword solution is structured with the following projects: -- Crossword.API.Data - The Data service minimal API with an API key - Parses the local dataset files and randomly returns a string containing the dataset to be parsed by the Crossword.Parser project. -- Crossword.Application - The Main crossword game - All the game and puzzle logic lives here. This will be refactored and cleaned up some more in a future release. -- Crossword.Parser - The main parser that processes the puzzle data set from the API for use by the crossword. -- Crossword.Shared - A shared class library for use in both the main game and API. +- Crossword - The Main crossword game - All the main game play and puzzle logic lives here. +- Crossword.API - The WebAPI Data service - Parses the local dataset files and randomly returns a string containing the dataset to be parsed by the Crossword.Parser project. +- Crossword.Data - Acts as the interface between the main Crossword and the WebAPI to retrieve data. +- Crossword.Entities - Contains the main data objects for the puzzle data and game play state. +- Crossword.Parser - The parser that transforms the puzzle data set from the API to the CrosswordData object for use by the crossword. +- Crossword.Puzzle - The core puzzle state machine - Square and ClueAnswer reference mapping for the in-play crossword. +- Crossword.Shared - A shared class library that has Config, Constants, Logger and ParserUtils functions that are shared across the projects. +- Crossword.UI - Provides the supporting UI elements of the crossword. +- Crossword.EventHandlers - Provides the Event handling for the crossword such as mouse and keyboard input. --- -### Local Setup steps: +### MacOS ARM/X64 Specific setup steps: -1. Clone the repo to the folder 'CyberPuzzles' - 'git clone https://github.com/AaronSaikovski/CyberPuzzles.git' +1. [Download](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) the installers for the Arm64 and x64 versions of the .NET sdk - The mgcb content editor doesn’t work without using the x64 version +2. At the end of your .zshrc or bash or whatever your using set this - `export PATH="/usr/local/share/dotnet/x64:$PATH"` +3. You’ll also run into a free image error to solve that you need to install homebrew and then run - `brew install freeimage` +4. and then link it - `sudo ln -s /opt/homebrew/Cellar/freeimage/3.18.0/lib/libfreeimage.dylib /usr/local/lib/libfreeimage` + +[source](https://community.monogame.net/t/tutorial-for-setting-up-monogame-on-m1-m2-apple-silicon/19669) + +--- + +### Local Build steps: + +1. Clone the repo to your local machine - `git clone https://github.com/AaronSaikovski/CyberPuzzles.git` 2. It will create a folder 'CyberPuzzles' and then 'cd' into the 'CyberPuzzles' folder. -3. Check that the projects and the 'CyberPuzzles.sln' (solution file and projects have been cloned) - List all the files in the folder. -4. run 'dotnet clean'. -5. run 'dotnet restore' to restore the nuget packages. -6. run 'dotnet build' to ensure there aren't any build errors, there may be some warnings. +3. Check that the projects and the `CyberPuzzles.sln` (solution file and projects have been cloned) - List all the files in the folder. +4. run `dotnet clean`. +5. run `dotnet restore --force` to restore the nuget packages. +6. run `dotnet build` to ensure there aren't any build errors, there may be some warnings. - (If you are on MacOS and get some compiler errors with the build, check the MacOS setup steps above.) 7. cd into the 'Crossword.Application' folder. -8. type 'dotnet run' and the crossword should appear. +8. type `dotnet run` and the crossword should appear. 9. There will be an error on startup - "An error occurred: One or more errors occurred. (Connection refused (localhost:7175))" - the crossword is trying to connect to the local instance of the WebAPI, ignore this for now. To build locally for your target native platform: ```bash -## Windows +## Windows- # x86 dotnet build -r win-x64 -c Release @@ -119,7 +136,7 @@ dotnet publish -r osx-x64 -c Release dotnet publish -r osx-arm64 -c Release ``` -**Please note that this game has been tested on MacOS ARM (M1) and Windows x86 only - it hasnt been tested on other platforms due to some limitations with MonoGame.** +**Please note that this game has been tested on MacOS ARM (M1) and Windows x86 only - it hasn't been tested on other platforms due to some limitations with MonoGame.** --- @@ -148,5 +165,6 @@ Please report all bugs and the running list of know issues is [here](https://git - GitHub action for building and releasing onto all platforms. - Reformat puzzle data format to use JSON instead of the custom data file format. - Create a Docker file to host the Dataservice API. +- WebAssembly to be able to be played in a browser. ---