Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Implements 'themes' #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

BayMinimum
Copy link

Added Themes class to handle theming and applied to game (#51)

Added Themes class to handle theming and applied to game
@cawvyoct
Copy link
Collaborator

Thank you for your contribution! 🎉
May I try to code review your PR?
The intention of the code review will be to help foster more PRs from you.
And if so, do you have any concerns from doing the code review which may unintentionally discourage you?

@BayMinimum
Copy link
Author

Of course yes! Please do the review 🙏

@plibither8
Copy link
Owner

@cawvyoct Thank you! I've been quite busy this week, I would love your help 😄

@cawvyoct
Copy link
Collaborator

cawvyoct commented Oct 17, 2018

So, I don't know what level of C++ you know so I will try and keep things generic.

Again, congratulations on reaching this far with your C++ development! It's a good start to greater things 🥇 !

By the way, questions are highly encouraged! ❔ 😃 👍 !
It helps to understand if I didn't explain things in a "digestible" way for you.
I may not suggest exact C++ code to fix problems but I will hint of some C++ techniques which may help you on your way to solve some issues. 🎉 🗺️ 🔍

@cawvyoct
Copy link
Collaborator

Overall tl:dr: try to imagine if contributors added 400 themes to this game, would the code added in the PR help to abstract all the themes so they can be be easily added without "much" problems.

@cawvyoct
Copy link
Collaborator

cawvyoct commented Oct 17, 2018

Overall tl:dr-2: It is always a challenge to define what is an "interface" (API) and what is "data".
It is also a challenge to make things generic (in this case, in C++) for different "applications".

For example, one "application" means "generic for programmers" to read (and understand the source code / flow).
Another "application" which means "generic for contributors" to edit and add their own content without needing to understand all the source code in totality.

src/themes.cpp Outdated
#include "menu.hpp"

std::string Themes::themedOutput(ull value) {
switch (themeCode) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ask the question: "If I had 400 themes, will this switch(...) statement be the only method/way of adding a [theme] to [a theme's registry]?".
Is there a more sustainable "generic" method of doing the action of:

  1. [adding an item (or many items) to a list]
  2. [checking if an item exists in the list], and then,
  3. [acting (possibly x command) when an item is found in the list]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elements{"H", "He", "Li", "Be", "B", "C", "N",
"O", "F", "Ne", "Na", "Ca", "Sc"},
programming_languages{"C", "C++", "PHP", "C#", "Py", "Bash", "Java",
"SQL", "CSS", "HTML", "JS", "Go", "Rust"} {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ask the question: "If I had 400 themes, is the [Theme's class constructor] the only way a theme can be added to this game?"

  • It is possible that if it is not sustainable to do so, you may have to make some API to accept:
    [some "x theme" datatype] and add it to [a list of some "x theme" datatypes]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed: Theme defines just one theme datatype, and ThemeController handles the list of Theme objects

src/themes.cpp Outdated Show resolved Hide resolved
@cawvyoct
Copy link
Collaborator

For now, the questions asked are very similar, (maybe even related to each other...)
However, solving the challenges one by one so that [question A's] answer doesn't clash with [question B's] answer is the part which may be quite ...frustrating! 😟

However, bit by bit, I think you can do it so you can answer: 😃

  1. each question individually... 🔢
  2. each question in unison... 💯

Questions of course are encouraged! ❔ 😃 👍
So don't be shy to ask / post. This is kinda an 🏔️ 🌊 "iceberg" task so discussions / dialogue will help to get the task complete.

Seperated class Themes into Theme and ThemeController to make it more generic and easily expandable
@BayMinimum
Copy link
Author

Thanks for your thoughtful comments, @cawvyoct 😃 I've pushed a commit which I believe to solve both problems. Please take a look ✌️

@plibither8
Copy link
Owner

Hi @BayMinimum, just saw the changes, they look great!

There is one thing that is bugging me 😅. I find it a bit uncomfortable that there are arrays for the possible values, predefined. It seems like we are almost limiting the player from reaching any number or element above the predefined last element of the array. I know it's very rare that a player will ever reach any number above 8192 or the corresponding tiles in the other themes, but we should not limit it to that because of this assumption.

I propose that, instead of having an array, we have a callback function that computes the value of the tile at that index. So for example, if the index is n, the value of the tile should be 2^n (in the normal, classic theme). Similarly, we can compute the nth Fibonacci number or the get the nth element from the Elements array.

@BayMinimum
Copy link
Author

Hey @plibither8, I really agree to you, and I also had the same uncomfortable feeling 😢 but made the limit since I thought the current implementation of game tiles are enforcing such limit. 🤔 The below is going to happen when number grows beyond 8192:
image
If such spacing problems can be fixed in future, I'll happily replace the arrays with functions for 'computable' themes!

@plibither8
Copy link
Owner

Oh! Didn't think about that 😅, you're right, that's definitely an issue! Thanks for #54, we should discuss this there

@plibither8 plibither8 changed the title added: theme feature Feature: Implements 'themes' Oct 19, 2018
This patch allows to create themes that has infinitely-long sequence with function, instead of a vector with finite length
@BayMinimum
Copy link
Author

@plibither8 I've pushed a commit to accept both vectors and functions to create a theme 🍬 Please review those changes when you're free!

@plibither8
Copy link
Owner

Looks great, thanks a lot 😄!

Just one thing before we merge this:

Right now, just to play a single game, the user has to go through 3 screens to finally start playing: the initial menu, the board-size config and finally choosing the theme. A more easy and simple flow would be to have a fourth option in the settings: "Configuration". Here the user can set the board size and theme. The data can be saved in an external text file (config.txt?) in the data/ directory. When we want to start a new game, the program will read the data in the config file and start the game with those settings, allowing an easier interface for the player. What say @BayMinimum @cawvyoct?

@cawvyoct
Copy link
Collaborator

Unfortunately a bit busy at the moment but just to say that keep up the good work @BayMinimum as it seems you understood the hints into refactoring your code so it is a bit more flexible than before. 👍

@plibither8

The data can be saved in an external text file (config.txt?) in the data/ directory. When we want to start a new game, the program will read the data in the config file and start the game with those settings, allowing an easier interface for the player.

👍
Agreed, in the end, some sort of external file settings is the way to go.
There are some problems with this however... A sneak peak to the upcoming code review I will reveal would be versioning.
If we change the settings file, which version of the game will it be valid for? The themes challenge is a good one because all these questions need to be considered / answered.

I also see the need for an "infinite play" mode for the game which has values that go beyond the winning tile value however, this is also a challenge when one adds themes.
For example, what is the "infinite play" tile values for the "elements" theme.
Another sneak peak for the code review: What is the winning tile value for the "elements" theme 😉? Is it defined in the theme's "structure"?

This is why I do think that, for now, an "hard-defined" array-based points system is the way to go unfortunately. The game needs to be refactored a bit in its API to accommodate between "defined" and "generated" tile scoring.

This is why I said in the last code review that this was an iceberg-like challenge 😉
It also means that this PR may take a while before its ready for merging IMO. 😿
I do think that @BayMinimum can do this PR though, however the game needs to be updated alongside this PR (being active).

Again, will update soon and leave more feedback. A bit pressed for time at the moment.. 😿

@cawvyoct
Copy link
Collaborator

cawvyoct commented Nov 2, 2018

Hi @BayMinimum,
Just an update, your themes idea is great! I also liked the way you were going with the design of your Theme data-structure + ThemeController combo.
At the moment, the game is still being refactored quite a bit. 😥 At some point however, you will need to update your PR to match the new refactored code in the codebase.
Would be very grateful if you continued trying to implement theming (when refactoring has settled down) into the project ! 👍
Your contribution has already helped guide things in the project 😸 so hopefully looking forward to more PRs in the near future from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants