You already took a wrong path. You get the status of the game from the UI. It can work, but it's easy to understand why this is not a robust way of software development. With more complicated problems, it can even push your project to the dead end, mess it up beyond repair. Consider just one thing: you change the colors of the UI, and your game logic will stop working. You have to change the color you compared the result of checking the background with, and it will work again, right? The whole idea is wrong.
First of all, you need to understand that the game itself has its own logic. You need to develop its logic separately, so it would not depend on UI at all. Call it data model, call it just model&heliip; And another, isolated part could be UI or View. And think what should be between them…
I suggest you learn and analyze applicability of the following
architectural patterns (
http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[
^]):
MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],
MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),
MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],
MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.
—SA