From 590f736a7a9d7b4b185d15cd01eb0dde3d7edaa0 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 29 Apr 2015 14:34:26 +0200 Subject: [PATCH 01/29] Add class --- src/Model/Game.cpp | 0 src/Model/Grid.cpp | 0 src/ViewController/MainController.cpp | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/Model/Game.cpp create mode 100644 src/Model/Grid.cpp create mode 100644 src/ViewController/MainController.cpp diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/ViewController/MainController.cpp b/src/ViewController/MainController.cpp new file mode 100644 index 0000000..e69de29 From f6094f0372d6947a9c1478554a168f946c6c6ece Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 29 Apr 2015 14:59:17 +0200 Subject: [PATCH 02/29] Add Case class --- src/Model/Case.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/Model/Case.cpp diff --git a/src/Model/Case.cpp b/src/Model/Case.cpp new file mode 100644 index 0000000..e69de29 From 08113f5b6d701d6dee239225c17a9b5eb47de0c1 Mon Sep 17 00:00:00 2001 From: krilius Date: Wed, 29 Apr 2015 15:40:08 +0400 Subject: [PATCH 03/29] Created basic classes --- src/Model/{Case.cpp => Cell.cpp} | 0 src/Model/Cell.hpp | 18 ++++++++++++++++++ src/Model/Grid.hpp | 0 3 files changed, 18 insertions(+) rename src/Model/{Case.cpp => Cell.cpp} (100%) create mode 100644 src/Model/Cell.hpp create mode 100644 src/Model/Grid.hpp diff --git a/src/Model/Case.cpp b/src/Model/Cell.cpp similarity index 100% rename from src/Model/Case.cpp rename to src/Model/Cell.cpp diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp new file mode 100644 index 0000000..888c63c --- /dev/null +++ b/src/Model/Cell.hpp @@ -0,0 +1,18 @@ +#ifndef DEF_CELL +#define DEF_CELL + +/* Cell.cpp + * Defines the class Cell + * A cell represents a cell in the grid + * Creators : krilius, manzerbredes + * Date : 29/04/2015 */ + +#include +#include + +class Cell +{ +}; + +#endif + diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp new file mode 100644 index 0000000..e69de29 From 3840053da7d3343eeb0c60854f20bcf72c58c45d Mon Sep 17 00:00:00 2001 From: krilius Date: Wed, 29 Apr 2015 15:42:41 +0400 Subject: [PATCH 04/29] First main created --- .gitignore | 2 + LICENSE | 674 --------------------------------------------- src/Model/Cell.cpp | 27 ++ src/Model/Cell.hpp | 15 +- src/Model/Grid.cpp | 37 +++ src/Model/Grid.hpp | 27 ++ src/main.cpp | 24 +- 7 files changed, 112 insertions(+), 694 deletions(-) delete mode 100644 LICENSE diff --git a/.gitignore b/.gitignore index 9be2b10..8f10546 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ CMakeFiles cmake_install.cmake Makefile CMakeCache.txt +*.app +2P11 diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 9cecc1d..0000000 --- a/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - {one line to give the program's name and a brief idea of what it does.} - Copyright (C) {year} {name of author} - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - {project} Copyright (C) {year} {fullname} - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/src/Model/Cell.cpp b/src/Model/Cell.cpp index e69de29..24fc53c 100644 --- a/src/Model/Cell.cpp +++ b/src/Model/Cell.cpp @@ -0,0 +1,27 @@ +#include "Cell.hpp" + +// Constructors + +Cell::Cell() +{ + m_value = " "; +} + +Cell::Cell(std::string value) +{ + m_value = value; +} + +// Destructor + +Cell::~Cell() +{ +} + +// Description + +void Cell::description() +{ + return m_value; +} + diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp index 888c63c..7775bf5 100644 --- a/src/Model/Cell.hpp +++ b/src/Model/Cell.hpp @@ -1,17 +1,28 @@ #ifndef DEF_CELL #define DEF_CELL -/* Cell.cpp +/* Cell.h * Defines the class Cell * A cell represents a cell in the grid * Creators : krilius, manzerbredes * Date : 29/04/2015 */ #include -#include +#include class Cell { + private: + std::string m_value; + + public: + Cell(); + Cell(std::string value); + ~Cell(); + + // Describes the cell in a terminal + std::string description(); + }; #endif diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index e69de29..94ef5d7 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -0,0 +1,37 @@ +#include "Grid.h" + +Grid::Grid(int size) +{ + m_table = std::vector>(size); + for(int i = 0 ; i < size ; i++) + { + m_table[i] = std::vector(size); + for (int j = 0 ; j < size ; j++) + { + Cell * cell = new Cell(); + m_table[i][j] = cell; + } + } +} + +Grid::~Grid() +{ + for(int i = 0 ; i < m_table.size() ; i++) + { + for(int i = 0 ; j < m_table[i].size() ; j++) + delete m_table[i][j]; + } +} + +void Grid::description() +{ + for(int i = 0 ; i < m_table.size() ; i++) + { + for(int j = 0 ; j < m_table[i].size() ; i++) + { + std::cout << m_table[i][j]->description(); + } + std::cout << std::endl; + } +} + diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index e69de29..a9c6c86 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -0,0 +1,27 @@ +#ifndef DEF_GRID +#define DEF_GRID + +/* Grid.h + * Defines the class Grid + * A grid contains a table of cells the game will be set on + * Creators : krilius, manzerbredes + * Date : 29/04/2015 */ + +#include +#include + +#include "Cell.hpp" + +class Grid +{ + private: + std::vector> m_table; + + public: + Grid(int size); + ~Grid(); + void description(); +}; + +#endif + diff --git a/src/main.cpp b/src/main.cpp index 0d3b950..597ce39 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,25 +1,13 @@ -#include +#include #include +#include "Model/Grid.hpp" + int main() { - sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!"); - sf::CircleShape shape(100.f); - shape.setFillColor(sf::Color::Green); + Grid * grid = new Grid(); - while (window.isOpen()) - { - sf::Event event; - while (window.pollEvent(event)) - { - if (event.type == sf::Event::Closed) - window.close(); - } + grid->description(); - window.clear(); - window.draw(shape); - window.display(); - } - - return 0; + return 0; } From 674563203b5653238a2ae6ef4a0a267a7661607b Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 29 Apr 2015 19:20:27 +0200 Subject: [PATCH 05/29] Restore licence --- LICENSE | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9cecc1d --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. From 9fbd4e0fedea42a206843981dffeb87095797581 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 29 Apr 2015 19:34:01 +0200 Subject: [PATCH 06/29] Enable cmake for model --- .gitignore | 2 ++ src/CMakeLists.txt | 4 +++- src/Model/CMakeLists.txt | 8 ++++++++ src/Model/Cell.cpp | 4 ++-- src/Model/Cell.hpp | 2 +- src/Model/Grid.cpp | 5 +++-- src/Model/Grid.hpp | 4 ++-- src/main.cpp | 4 ++-- 8 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 src/Model/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 8f10546..5c15316 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ CMakeFiles +*.a +*.o cmake_install.cmake Makefile CMakeCache.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b30833e..a946644 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,9 +7,11 @@ add_executable( #Find all libraries find_package(SFML 2.2 COMPONENTS system window graphics audio REQUIRED) +set_property(GLOBAL PROPERTY SFML_LIBRARIES "${SFML_LIBRARIES}") +set_property(GLOBAL PROPERTY SFML_INCLUDE_DIR "${SFML_INCLUDE_DIR}") #Include "Includes" and "Libraries" include_directories(${SFML_INCLUDE_DIR}) target_link_libraries(2P11 ${SFML_LIBRARIES}) -message("${SFML_LIBRARIES}") +add_subdirectory(./Model) diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt new file mode 100644 index 0000000..c9cfb6e --- /dev/null +++ b/src/Model/CMakeLists.txt @@ -0,0 +1,8 @@ +#Retrieve crypto++ libraries +get_property(SFML_LIBRARIES GLOBAL PROPERTY SFML_LIBRARIES) + +#Make CryptClass lib +add_library(Model ./Cell.cpp ./Game.cpp ./Grid.cpp) + +#Add crypto++ to CryptClass +target_link_libraries(Model ${SFML_LIBRARIES}) diff --git a/src/Model/Cell.cpp b/src/Model/Cell.cpp index 24fc53c..a0729f7 100644 --- a/src/Model/Cell.cpp +++ b/src/Model/Cell.cpp @@ -19,9 +19,9 @@ Cell::~Cell() } // Description - +/* void Cell::description() { return m_value; } - +*/ diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp index 7775bf5..dd946ab 100644 --- a/src/Model/Cell.hpp +++ b/src/Model/Cell.hpp @@ -21,7 +21,7 @@ class Cell ~Cell(); // Describes the cell in a terminal - std::string description(); + //std::string description(); }; diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index 94ef5d7..d7d3f15 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -1,5 +1,6 @@ -#include "Grid.h" +#include "Grid.hpp" +/* Grid::Grid(int size) { m_table = std::vector>(size); @@ -34,4 +35,4 @@ void Grid::description() std::cout << std::endl; } } - +*/ diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index a9c6c86..304e436 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -11,7 +11,7 @@ #include #include "Cell.hpp" - +/* class Grid { private: @@ -22,6 +22,6 @@ class Grid ~Grid(); void description(); }; +*/ #endif - diff --git a/src/main.cpp b/src/main.cpp index 597ce39..689767a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,9 +5,9 @@ int main() { - Grid * grid = new Grid(); +// Grid * grid = new Grid(); - grid->description(); +// grid->description(); return 0; } From e241abc9df586cce683d6ae89e1d02c13084a10f Mon Sep 17 00:00:00 2001 From: krilius Date: Wed, 29 Apr 2015 20:52:18 +0400 Subject: [PATCH 07/29] bug sous osx --- src/Model/Cell.cpp | 6 +++--- src/Model/Cell.hpp | 2 +- src/Model/Grid.cpp | 12 ++++++------ src/Model/Grid.hpp | 8 ++++---- src/main.cpp | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Model/Cell.cpp b/src/Model/Cell.cpp index a0729f7..22eaafe 100644 --- a/src/Model/Cell.cpp +++ b/src/Model/Cell.cpp @@ -19,9 +19,9 @@ Cell::~Cell() } // Description -/* -void Cell::description() + +std::string Cell::description() { return m_value; } -*/ + diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp index dd946ab..7775bf5 100644 --- a/src/Model/Cell.hpp +++ b/src/Model/Cell.hpp @@ -21,7 +21,7 @@ class Cell ~Cell(); // Describes the cell in a terminal - //std::string description(); + std::string description(); }; diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index d7d3f15..ade3f74 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -1,9 +1,9 @@ #include "Grid.hpp" -/* + Grid::Grid(int size) { - m_table = std::vector>(size); + m_table = std::vector >(size); for(int i = 0 ; i < size ; i++) { m_table[i] = std::vector(size); @@ -19,20 +19,20 @@ Grid::~Grid() { for(int i = 0 ; i < m_table.size() ; i++) { - for(int i = 0 ; j < m_table[i].size() ; j++) + for(int j = 0 ; j < m_table[i].size() ; j++) delete m_table[i][j]; } } -void Grid::description() +void Grid::afficher() { for(int i = 0 ; i < m_table.size() ; i++) { - for(int j = 0 ; j < m_table[i].size() ; i++) + for(int j = 0 ; j < m_table[i].size() ; j++) { std::cout << m_table[i][j]->description(); } std::cout << std::endl; } } -*/ + diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index 304e436..e3bc888 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -11,17 +11,17 @@ #include #include "Cell.hpp" -/* + class Grid { private: - std::vector> m_table; + std::vector > m_table; public: Grid(int size); ~Grid(); - void description(); + void afficher(); }; -*/ + #endif diff --git a/src/main.cpp b/src/main.cpp index 689767a..12f6c6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,9 +5,9 @@ int main() { -// Grid * grid = new Grid(); + Grid * grid = new Grid(4); -// grid->description(); + grid->afficher(); return 0; } From a3b805ee7b96d1d693c4108f0104650cfd60b565 Mon Sep 17 00:00:00 2001 From: krilius Date: Wed, 29 Apr 2015 22:28:29 +0400 Subject: [PATCH 08/29] first step of the model --- src/Model/Cell.cpp | 19 ++++++- src/Model/Cell.hpp | 4 ++ src/Model/Game.cpp | 54 +++++++++++++++++++ src/Model/Game.hpp | 29 ++++++++++ src/Model/Grid.cpp | 128 +++++++++++++++++++++++++++++++++++++++++++-- src/Model/Grid.hpp | 17 +++++- 6 files changed, 243 insertions(+), 8 deletions(-) create mode 100644 src/Model/Game.hpp diff --git a/src/Model/Cell.cpp b/src/Model/Cell.cpp index 22eaafe..ba4bbbd 100644 --- a/src/Model/Cell.cpp +++ b/src/Model/Cell.cpp @@ -4,7 +4,7 @@ Cell::Cell() { - m_value = " "; + m_value = "."; } Cell::Cell(std::string value) @@ -18,6 +18,23 @@ Cell::~Cell() { } +// Getters and setters + +bool Cell::isEmpty() +{ + return (m_value == "."); +} + +std::string Cell::getValue() +{ + return m_value; +} + +bool Cell::equals(Cell *otherCell) +{ + return (m_value == otherCell->getValue()); +} + // Description std::string Cell::description() diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp index 7775bf5..badd070 100644 --- a/src/Model/Cell.hpp +++ b/src/Model/Cell.hpp @@ -20,6 +20,10 @@ class Cell Cell(std::string value); ~Cell(); + bool isEmpty(); + bool equals(Cell * otherCell); + std::string getValue(); + // Describes the cell in a terminal std::string description(); diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index e69de29..1e24b11 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -0,0 +1,54 @@ +#include "Game.hpp" + +Game::Game() +{ + m_grid = new Grid(4); +} + +Game::~Game() +{ + delete m_grid; +} + +void Game::play() +{ + while(!m_grid->gridIsFull()) + { + m_grid->show(); + + pop(); + std::cout << std::endl; + } + + m_grid->show(); +} + +void Game::showGrid() +{ + m_grid->show(); + std::cout << std::endl; +} + +void Game::pop() +{ + bool cellChosen = false; + + int i; + int j; + + while(!cellChosen) + { + i = rand() % 4; + j = rand() % 4; + + if (m_grid->isEmpty(i,j)) + cellChosen = true; + } + + m_grid->setCell(i, j, new Cell("2")); +} + +bool Game::isOver() +{ + return m_grid->gridIsFull(); +} \ No newline at end of file diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp new file mode 100644 index 0000000..8dcaf64 --- /dev/null +++ b/src/Model/Game.hpp @@ -0,0 +1,29 @@ +#ifndef DEF_GAME +#define DEF_GAME + +/* Game.h + * Defines the class Game + * A game allows a player to play. It contains a grid and pops numbers + * Creators : krilius, manzerbredes + * Date : 29/04/2015 */ + +#include + +#include "Grid.hpp" + +class Game +{ + private: + Grid * m_grid; + + public: + Game(); + ~Game(); + + void play(); + void pop(); + void showGrid(); + bool isOver(); +}; + +#endif \ No newline at end of file diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index ade3f74..295b9b4 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -3,6 +3,7 @@ Grid::Grid(int size) { + m_size = size; m_table = std::vector >(size); for(int i = 0 ; i < size ; i++) { @@ -17,18 +18,18 @@ Grid::Grid(int size) Grid::~Grid() { - for(int i = 0 ; i < m_table.size() ; i++) + for(int i = 0 ; i < m_size ; i++) { - for(int j = 0 ; j < m_table[i].size() ; j++) + for(int j = 0 ; j < m_size ; j++) delete m_table[i][j]; } } -void Grid::afficher() +void Grid::show() { - for(int i = 0 ; i < m_table.size() ; i++) + for(int i = 0 ; i < m_size ; i++) { - for(int j = 0 ; j < m_table[i].size() ; j++) + for(int j = 0 ; j < m_size ; j++) { std::cout << m_table[i][j]->description(); } @@ -36,3 +37,120 @@ void Grid::afficher() } } +bool Grid::isEmpty(int i, int j) +{ + if (i >= 0 && i < m_size && j >= 0 && j < m_size) + return m_table[i][j]->isEmpty(); + + return false; +} + +bool Grid::gridIsFull() +{ + bool isFull = true; + + for (int i = 0; i < m_size && isFull; i++) + { + for (int j = 0; j < m_size && isFull; j++) + { + if (m_table[i][j]->isEmpty()) + isFull = false; + } + } + + return isFull; +} + +void Grid::setCell(int i, int j, Cell *cell) +{ + if (i >= 0 && i < m_size && j >= 0 && j < m_size) + { + delete m_table[i][j]; + m_table[i][j] = cell; + } +} + + +void Grid::move(Direction direction) +{ + switch (direction) + { + case Direction::UP: + + break; + + case Direction::DOWN: + break; + + case Direction::LEFT: + break; + + case Direction::RIGHT: + break; + + default: + break; + } +} + +void Grid::moveDown() +{/* + for (int i = 0 ; i < m_size; i++) + { + // If the column is full, check the next column + bool columnIsFull = true; + + for (int j = 0; j < m_size; j++) + { + if (m_table[j][i]->isEmpty()) + { + columnIsFull = false; + break; + } + } + + while (!columnIsFull) + { + // Calculate the first line to merge + int firstLine = m_size - 1; + while (m_table[firstLine][i]->isEmpty() && firstLine > 0) + firstLine--; + if (firstLine == 0) + break; + + // Calculate the second line to merge + int secondLine = firstLine - 1; + while (m_table[secondLine][i]->isEmpty() && secondLine > 0) + secondLine--; + + // If there is only one element, pull it down + if (m_table[secondLine][i]->isEmpty() && firstLine != m_size - 1) + { + Cell * originalCell = m_table[firstLine][i]; + Cell * finalCell = m_table[m_size-1][i]; + + m_table[firstLine][i] = finalCell; + m_table[m_size-1][i] = originalCell; + + break; + } + + // If there is only one element which is at the full bottom, break the loop + if (m_table[secondLine][i]->isEmpty()) + break; + + // If there are two "good" elements, begin the merge process + Cell * cell1 = m_table[firstLine][i]; + Cell * cell2 = m_table[secondLine][i]; + + Cell * mergedCell = NULL; + + // If the two cells are the same, merge them + if (cell1->equals(cell2)) + { + int value = std::stoi(cell1->getValue()); + mergedCell = new Cell(std::to_string(value)); + } + } + }*/ +} diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index e3bc888..2a28559 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -10,17 +10,30 @@ #include #include +#include "ModelConstants.hpp" #include "Cell.hpp" class Grid { private: - std::vector > m_table; + int m_size; + std::vector > m_table; + + void moveUp(); + void moveDown(); + void moveLeft(); + void moveRight(); public: Grid(int size); ~Grid(); - void afficher(); + void show(); + + bool isEmpty(int i, int j); + bool gridIsFull(); + void setCell(int i, int j, Cell * cell); + + void move(Direction direction); }; From ad216d86f6573e3575e85f3a2941f6f34b5b1c0e Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 29 Apr 2015 21:18:06 +0200 Subject: [PATCH 09/29] Add missing dependency in CMakeList.txt --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- src/Model/CMakeLists.txt | 10 ++-------- src/main.cpp | 2 +- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c822dc4..4ab2346 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,5 +14,5 @@ set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV}") cmake_minimum_required(VERSION 2.6) #Add source directory -add_subdirectory(src) +add_subdirectory(./src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a946644..89e46d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,6 @@ set_property(GLOBAL PROPERTY SFML_INCLUDE_DIR "${SFML_INCLUDE_DIR}") #Include "Includes" and "Libraries" include_directories(${SFML_INCLUDE_DIR}) -target_link_libraries(2P11 ${SFML_LIBRARIES}) +target_link_libraries(2P11 ${SFML_LIBRARIES} Model) add_subdirectory(./Model) diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index c9cfb6e..c685c7a 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -1,8 +1,2 @@ -#Retrieve crypto++ libraries -get_property(SFML_LIBRARIES GLOBAL PROPERTY SFML_LIBRARIES) - -#Make CryptClass lib -add_library(Model ./Cell.cpp ./Game.cpp ./Grid.cpp) - -#Add crypto++ to CryptClass -target_link_libraries(Model ${SFML_LIBRARIES}) +#Make Model lib +add_library(Model Grid.cpp Cell.cpp Game.cpp) diff --git a/src/main.cpp b/src/main.cpp index 12f6c6d..00473f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ #include #include -#include "Model/Grid.hpp" +#include "./Model/Grid.hpp" int main() { From 71ebf1235ed023425c2539eabf1d15ba922c1dda Mon Sep 17 00:00:00 2001 From: krilius Date: Thu, 30 Apr 2015 08:48:29 +0400 Subject: [PATCH 10/29] first version of the controller --- src/CTController/CTConsole.cpp | 48 ++++++++++++++++++++++++++++++++++ src/CTController/CTConsole.hpp | 26 ++++++++++++++++++ src/Model/ModelConstants.hpp | 12 +++++++++ src/main.cpp | 17 +++++++----- 4 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 src/CTController/CTConsole.cpp create mode 100644 src/CTController/CTConsole.hpp create mode 100644 src/Model/ModelConstants.hpp diff --git a/src/CTController/CTConsole.cpp b/src/CTController/CTConsole.cpp new file mode 100644 index 0000000..44b598e --- /dev/null +++ b/src/CTController/CTConsole.cpp @@ -0,0 +1,48 @@ +#include "CTConsole.hpp" + +CTConsole::CTConsole() +{ + m_game = new Game(); +} + +CTConsole::~CTConsole() +{ + delete m_game; +} + +void CTConsole::play() +{ + while (!m_game->isOver()) + { + m_game->showGrid(); + char moveChoice = ' '; + + std::cin >> moveChoice; + + switch (moveChoice) + { + case 'z': + std::cout << "up" << std::endl; + break; + + case 's': + std::cout << "down" << std::endl; + break; + + case 'q': + std::cout << "left" << std::endl; + break; + + case 'd': + std::cout << "right" << std::endl; + break; + + default: + break; + } + + std::cout << std::endl; + + m_game->pop(); + } +} \ No newline at end of file diff --git a/src/CTController/CTConsole.hpp b/src/CTController/CTConsole.hpp new file mode 100644 index 0000000..9534877 --- /dev/null +++ b/src/CTController/CTConsole.hpp @@ -0,0 +1,26 @@ +#ifndef DEF_CTCONSOLE +#define DEF_CTCONSOLE + +/* CTConsole.hpp + * Defines the class CTConsole + * CTConsole is a controller which displays a game in a terminal + * Creators : krilius, manzerbredes + * Date : 29/04/2915 */ + +#include + +#include "../Model/Game.hpp" + +class CTConsole +{ +private: + Game * m_game; + +public: + CTConsole(); + ~CTConsole(); + + void play(); +}; + +#endif \ No newline at end of file diff --git a/src/Model/ModelConstants.hpp b/src/Model/ModelConstants.hpp new file mode 100644 index 0000000..5cbc21b --- /dev/null +++ b/src/Model/ModelConstants.hpp @@ -0,0 +1,12 @@ +#ifndef DEF_MODELCONSTANTS +#define DEF_MODELCONSTANTS + +/* ModelConstants.hpp + * Constains constants and enums used in the whole model + * Creators : krilius, manzerbredes + * Date : 29/04/2015 */ + +enum Direction { UP, DOWN, LEFT, RIGHT }; +typedef enum Direction Direction; + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 12f6c6d..9006fcd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,18 @@ #include #include +#include -#include "Model/Grid.hpp" +#include "CTController/CTConsole.hpp" int main() { - Grid * grid = new Grid(4); - - grid->afficher(); - - return 0; + srand(time(NULL)); + + CTConsole * controller = new CTConsole(); + + controller->play(); + + delete controller; + + return 0; } From fa88c91351388c4b2e1791ccab2cd8a959dc976b Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Thu, 30 Apr 2015 09:07:40 +0200 Subject: [PATCH 11/29] Fix some things --- .../ConsoleController/ConsoleController.cpp} | 0 .../ConsoleController/ConsoleController.hpp} | 0 .../MainController.cpp | 0 src/main.cpp | 33 +++++++++++-------- 4 files changed, 20 insertions(+), 13 deletions(-) rename src/{CTController/CTConsole.cpp => Controller/ConsoleController/ConsoleController.cpp} (100%) rename src/{CTController/CTConsole.hpp => Controller/ConsoleController/ConsoleController.hpp} (100%) rename src/{ViewController => View}/MainController.cpp (100%) diff --git a/src/CTController/CTConsole.cpp b/src/Controller/ConsoleController/ConsoleController.cpp similarity index 100% rename from src/CTController/CTConsole.cpp rename to src/Controller/ConsoleController/ConsoleController.cpp diff --git a/src/CTController/CTConsole.hpp b/src/Controller/ConsoleController/ConsoleController.hpp similarity index 100% rename from src/CTController/CTConsole.hpp rename to src/Controller/ConsoleController/ConsoleController.hpp diff --git a/src/ViewController/MainController.cpp b/src/View/MainController.cpp similarity index 100% rename from src/ViewController/MainController.cpp rename to src/View/MainController.cpp diff --git a/src/main.cpp b/src/main.cpp index 206b47a..91a1fe6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,22 +1,29 @@ + +//----- STD include ----- #include #include #include +//---------------------- -<<<<<<< HEAD +//----- Personnal include ----- #include "./Model/Grid.hpp" -======= -#include "CTController/CTConsole.hpp" ->>>>>>> 71ebf1235ed023425c2539eabf1d15ba922c1dda +#include "./Controller/ConsoleController/ConsoleController.hpp" +//----------------------------- + + +//----- Start ----- int main() { - srand(time(NULL)); - - CTConsole * controller = new CTConsole(); - - controller->play(); - - delete controller; - - return 0; + //Init random + srand(time(NULL)); + + //Init console controller + ConsoleController * controller = new ConsoleController(); + + controller->play(); + + delete controller; + + return 0; } From 4b5f429c0d0f369c72ddd0b290769bf61ea83601 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Thu, 30 Apr 2015 09:11:20 +0200 Subject: [PATCH 12/29] Change controller name --- .../ConsoleController/ConsoleController.cpp | 26 +++++++++---------- .../ConsoleController/ConsoleController.hpp | 14 +++++----- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Controller/ConsoleController/ConsoleController.cpp b/src/Controller/ConsoleController/ConsoleController.cpp index 44b598e..2231213 100644 --- a/src/Controller/ConsoleController/ConsoleController.cpp +++ b/src/Controller/ConsoleController/ConsoleController.cpp @@ -1,48 +1,48 @@ -#include "CTConsole.hpp" +#include "ConsoleController.hpp" -CTConsole::CTConsole() +ConsoleController::ConsoleController() { m_game = new Game(); } -CTConsole::~CTConsole() +ConsoleController::~ConsoleController() { delete m_game; } -void CTConsole::play() +void ConsoleController::play() { while (!m_game->isOver()) { m_game->showGrid(); char moveChoice = ' '; - + std::cin >> moveChoice; - + switch (moveChoice) { case 'z': std::cout << "up" << std::endl; break; - + case 's': std::cout << "down" << std::endl; break; - + case 'q': std::cout << "left" << std::endl; break; - + case 'd': std::cout << "right" << std::endl; break; - + default: break; } - + std::cout << std::endl; - + m_game->pop(); } -} \ No newline at end of file +} diff --git a/src/Controller/ConsoleController/ConsoleController.hpp b/src/Controller/ConsoleController/ConsoleController.hpp index 9534877..83c44fc 100644 --- a/src/Controller/ConsoleController/ConsoleController.hpp +++ b/src/Controller/ConsoleController/ConsoleController.hpp @@ -9,18 +9,18 @@ #include -#include "../Model/Game.hpp" +#include "../../Model/Game.hpp" -class CTConsole +class ConsoleController { private: Game * m_game; - + public: - CTConsole(); - ~CTConsole(); - + ConsoleController(); + ~ConsoleController(); + void play(); }; -#endif \ No newline at end of file +#endif From a2ed149069a29212a11eb4a1fa676e6f27d941fd Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Thu, 30 Apr 2015 09:13:23 +0200 Subject: [PATCH 13/29] Fix whitespace --- src/Model/Game.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index 1e24b11..aa3626c 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -15,11 +15,11 @@ void Game::play() while(!m_grid->gridIsFull()) { m_grid->show(); - + pop(); std::cout << std::endl; } - + m_grid->show(); } @@ -32,23 +32,23 @@ void Game::showGrid() void Game::pop() { bool cellChosen = false; - + int i; int j; - + while(!cellChosen) { i = rand() % 4; j = rand() % 4; - + if (m_grid->isEmpty(i,j)) cellChosen = true; } - + m_grid->setCell(i, j, new Cell("2")); } bool Game::isOver() { return m_grid->gridIsFull(); -} \ No newline at end of file +} From e13d24b6c8f5aafa11c027dd971a98f895825b41 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Thu, 30 Apr 2015 09:42:40 +0200 Subject: [PATCH 14/29] Correct LOT OF BUGS --- src/CMakeLists.txt | 3 ++- src/Controller/CMakeLists.txt | 1 + src/Controller/ConsoleController/CMakeLists.txt | 3 +++ src/Controller/ConsoleController/ConsoleController.cpp | 2 +- src/Model/Game.hpp | 3 ++- src/Model/Grid.cpp | 8 ++++---- 6 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 src/Controller/CMakeLists.txt create mode 100644 src/Controller/ConsoleController/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 89e46d5..a1c4ccb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ set_property(GLOBAL PROPERTY SFML_INCLUDE_DIR "${SFML_INCLUDE_DIR}") #Include "Includes" and "Libraries" include_directories(${SFML_INCLUDE_DIR}) -target_link_libraries(2P11 ${SFML_LIBRARIES} Model) +target_link_libraries(2P11 ${SFML_LIBRARIES} Model ConsoleController) add_subdirectory(./Model) +add_subdirectory(./Controller/) diff --git a/src/Controller/CMakeLists.txt b/src/Controller/CMakeLists.txt new file mode 100644 index 0000000..7ebeb19 --- /dev/null +++ b/src/Controller/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(./ConsoleController/) diff --git a/src/Controller/ConsoleController/CMakeLists.txt b/src/Controller/ConsoleController/CMakeLists.txt new file mode 100644 index 0000000..d42803f --- /dev/null +++ b/src/Controller/ConsoleController/CMakeLists.txt @@ -0,0 +1,3 @@ +#Make Model lib +add_library(ConsoleController ./ConsoleController.cpp) +target_link_libraries(ConsoleController Model) diff --git a/src/Controller/ConsoleController/ConsoleController.cpp b/src/Controller/ConsoleController/ConsoleController.cpp index 2231213..dc61ae8 100644 --- a/src/Controller/ConsoleController/ConsoleController.cpp +++ b/src/Controller/ConsoleController/ConsoleController.cpp @@ -1,4 +1,4 @@ -#include "ConsoleController.hpp" +#include "./ConsoleController.hpp" ConsoleController::ConsoleController() { diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp index 8dcaf64..b7e0a60 100644 --- a/src/Model/Game.hpp +++ b/src/Model/Game.hpp @@ -8,6 +8,7 @@ * Date : 29/04/2015 */ #include +#include #include "Grid.hpp" @@ -26,4 +27,4 @@ class Game bool isOver(); }; -#endif \ No newline at end of file +#endif diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index 295b9b4..ca93955 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -75,17 +75,17 @@ void Grid::move(Direction direction) { switch (direction) { - case Direction::UP: + case UP: break; - case Direction::DOWN: + case DOWN: break; - case Direction::LEFT: + case LEFT: break; - case Direction::RIGHT: + case RIGHT: break; default: From 80c37e438ee57f0eceb322dbee778a49d9db0896 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Thu, 30 Apr 2015 10:09:58 +0200 Subject: [PATCH 15/29] Fix space --- .../ConsoleController/ConsoleController.cpp | 56 +++++++++---------- .../ConsoleController/ConsoleController.hpp | 13 ++--- src/main.cpp | 2 + 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/Controller/ConsoleController/ConsoleController.cpp b/src/Controller/ConsoleController/ConsoleController.cpp index dc61ae8..f4d6b4d 100644 --- a/src/Controller/ConsoleController/ConsoleController.cpp +++ b/src/Controller/ConsoleController/ConsoleController.cpp @@ -2,47 +2,45 @@ ConsoleController::ConsoleController() { - m_game = new Game(); + m_game = new Game(); } ConsoleController::~ConsoleController() { - delete m_game; + delete m_game; } void ConsoleController::play() { - while (!m_game->isOver()) - { - m_game->showGrid(); - char moveChoice = ' '; + while (!m_game->isOver()) + { + m_game->showGrid(); + char moveChoice = ' '; - std::cin >> moveChoice; + std::cin >> moveChoice; - switch (moveChoice) - { - case 'z': - std::cout << "up" << std::endl; - break; + switch (moveChoice) + { + case 'z': + std::cout << "up" << std::endl; + break; - case 's': - std::cout << "down" << std::endl; - break; + case 's': + std::cout << "down" << std::endl; + break; - case 'q': - std::cout << "left" << std::endl; - break; + case 'q': + std::cout << "left" << std::endl; + break; + case 'd': + std::cout << "right" << std::endl; + break; - case 'd': - std::cout << "right" << std::endl; - break; + default: + break; + } - default: - break; - } - - std::cout << std::endl; - - m_game->pop(); - } + std::cout << std::endl; + m_game->pop(); + } } diff --git a/src/Controller/ConsoleController/ConsoleController.hpp b/src/Controller/ConsoleController/ConsoleController.hpp index 83c44fc..2cda804 100644 --- a/src/Controller/ConsoleController/ConsoleController.hpp +++ b/src/Controller/ConsoleController/ConsoleController.hpp @@ -8,19 +8,18 @@ * Date : 29/04/2915 */ #include - #include "../../Model/Game.hpp" class ConsoleController { -private: - Game * m_game; + private: -public: - ConsoleController(); - ~ConsoleController(); + Game * m_game; - void play(); + public: + ConsoleController(); + ~ConsoleController(); + void play(); }; #endif diff --git a/src/main.cpp b/src/main.cpp index 91a1fe6..52444a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,8 +21,10 @@ int main() //Init console controller ConsoleController * controller = new ConsoleController(); + //Launch game controller->play(); + //Remove controlelr delete controller; return 0; From 40e0b381c1bb5b8c8274f9149808c2929b16dfa2 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 May 2015 10:20:19 +0200 Subject: [PATCH 16/29] Correct tab --- src/Model/Game.cpp | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index aa3626c..069a481 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -2,53 +2,53 @@ Game::Game() { - m_grid = new Grid(4); + m_grid = new Grid(4); } Game::~Game() { - delete m_grid; + delete m_grid; } void Game::play() { - while(!m_grid->gridIsFull()) - { - m_grid->show(); + while(!m_grid->gridIsFull()) + { + m_grid->show(); - pop(); - std::cout << std::endl; - } + pop(); + std::cout << std::endl; + } - m_grid->show(); + m_grid->show(); } void Game::showGrid() { - m_grid->show(); - std::cout << std::endl; + m_grid->show(); + std::cout << std::endl; } void Game::pop() { - bool cellChosen = false; + bool cellChosen = false; - int i; - int j; + int i; + int j; - while(!cellChosen) - { - i = rand() % 4; - j = rand() % 4; + while(!cellChosen) + { + i = rand() % 4; + j = rand() % 4; - if (m_grid->isEmpty(i,j)) - cellChosen = true; - } + if (m_grid->isEmpty(i,j)) + cellChosen = true; + } - m_grid->setCell(i, j, new Cell("2")); + m_grid->setCell(i, j, new Cell("2")); } bool Game::isOver() { - return m_grid->gridIsFull(); + return m_grid->gridIsFull(); } From 9f07e3c6bdf25b0f6171f6ee7d04be86adfa8421 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 May 2015 10:24:45 +0200 Subject: [PATCH 17/29] Correct space --- src/Model/Game.hpp | 22 +++--- src/Model/Grid.cpp | 192 ++++++++++++++++++++++----------------------- 2 files changed, 107 insertions(+), 107 deletions(-) diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp index b7e0a60..fb09188 100644 --- a/src/Model/Game.hpp +++ b/src/Model/Game.hpp @@ -14,17 +14,17 @@ class Game { - private: - Grid * m_grid; - - public: - Game(); - ~Game(); - - void play(); - void pop(); - void showGrid(); - bool isOver(); + private: + Grid * m_grid; + + public: + Game(); + ~Game(); + + void play(); + void pop(); + void showGrid(); + bool isOver(); }; #endif diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index ca93955..87f294e 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -3,7 +3,7 @@ Grid::Grid(int size) { - m_size = size; + m_size = size; m_table = std::vector >(size); for(int i = 0 ; i < size ; i++) { @@ -39,118 +39,118 @@ void Grid::show() bool Grid::isEmpty(int i, int j) { - if (i >= 0 && i < m_size && j >= 0 && j < m_size) - return m_table[i][j]->isEmpty(); - - return false; + if (i >= 0 && i < m_size && j >= 0 && j < m_size) + return m_table[i][j]->isEmpty(); + + return false; } bool Grid::gridIsFull() { - bool isFull = true; - - for (int i = 0; i < m_size && isFull; i++) - { - for (int j = 0; j < m_size && isFull; j++) - { - if (m_table[i][j]->isEmpty()) - isFull = false; - } - } - - return isFull; + bool isFull = true; + + for (int i = 0; i < m_size && isFull; i++) + { + for (int j = 0; j < m_size && isFull; j++) + { + if (m_table[i][j]->isEmpty()) + isFull = false; + } + } + + return isFull; } void Grid::setCell(int i, int j, Cell *cell) { - if (i >= 0 && i < m_size && j >= 0 && j < m_size) - { - delete m_table[i][j]; - m_table[i][j] = cell; - } + if (i >= 0 && i < m_size && j >= 0 && j < m_size) + { + delete m_table[i][j]; + m_table[i][j] = cell; + } } void Grid::move(Direction direction) { - switch (direction) - { - case UP: - - break; - - case DOWN: - break; - - case LEFT: - break; - - case RIGHT: - break; - - default: - break; - } + switch (direction) + { + case UP: + + break; + + case DOWN: + break; + + case LEFT: + break; + + case RIGHT: + break; + + default: + break; + } } void Grid::moveDown() {/* for (int i = 0 ; i < m_size; i++) { - // If the column is full, check the next column - bool columnIsFull = true; - - for (int j = 0; j < m_size; j++) - { - if (m_table[j][i]->isEmpty()) - { - columnIsFull = false; - break; - } - } - - while (!columnIsFull) - { - // Calculate the first line to merge - int firstLine = m_size - 1; - while (m_table[firstLine][i]->isEmpty() && firstLine > 0) - firstLine--; - if (firstLine == 0) - break; - - // Calculate the second line to merge - int secondLine = firstLine - 1; - while (m_table[secondLine][i]->isEmpty() && secondLine > 0) - secondLine--; - - // If there is only one element, pull it down - if (m_table[secondLine][i]->isEmpty() && firstLine != m_size - 1) - { - Cell * originalCell = m_table[firstLine][i]; - Cell * finalCell = m_table[m_size-1][i]; - - m_table[firstLine][i] = finalCell; - m_table[m_size-1][i] = originalCell; - - break; - } - - // If there is only one element which is at the full bottom, break the loop - if (m_table[secondLine][i]->isEmpty()) - break; - - // If there are two "good" elements, begin the merge process - Cell * cell1 = m_table[firstLine][i]; - Cell * cell2 = m_table[secondLine][i]; - - Cell * mergedCell = NULL; - - // If the two cells are the same, merge them - if (cell1->equals(cell2)) - { - int value = std::stoi(cell1->getValue()); - mergedCell = new Cell(std::to_string(value)); - } - } - }*/ + // If the column is full, check the next column + bool columnIsFull = true; + + for (int j = 0; j < m_size; j++) + { + if (m_table[j][i]->isEmpty()) + { + columnIsFull = false; + break; + } + } + + while (!columnIsFull) + { + // Calculate the first line to merge + int firstLine = m_size - 1; + while (m_table[firstLine][i]->isEmpty() && firstLine > 0) + firstLine--; + if (firstLine == 0) + break; + + // Calculate the second line to merge + int secondLine = firstLine - 1; + while (m_table[secondLine][i]->isEmpty() && secondLine > 0) + secondLine--; + + // If there is only one element, pull it down + if (m_table[secondLine][i]->isEmpty() && firstLine != m_size - 1) + { + Cell * originalCell = m_table[firstLine][i]; + Cell * finalCell = m_table[m_size-1][i]; + + m_table[firstLine][i] = finalCell; + m_table[m_size-1][i] = originalCell; + + break; + } + + // If there is only one element which is at the full bottom, break the loop + if (m_table[secondLine][i]->isEmpty()) + break; + + // If there are two "good" elements, begin the merge process + Cell * cell1 = m_table[firstLine][i]; + Cell * cell2 = m_table[secondLine][i]; + + Cell * mergedCell = NULL; + + // If the two cells are the same, merge them + if (cell1->equals(cell2)) + { + int value = std::stoi(cell1->getValue()); + mergedCell = new Cell(std::to_string(value)); + } + } + }*/ } From a7e0de4bb60cd262579a3fd28ec0a11d769d9722 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 May 2015 10:36:20 +0200 Subject: [PATCH 18/29] Modify show() method presentation --- src/Model/Grid.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index 87f294e..19e8f4d 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -1,10 +1,13 @@ #include "Grid.hpp" - +//Constructor Grid::Grid(int size) { + //Create Vector m_size = size; m_table = std::vector >(size); + + //Init all of line and cell for(int i = 0 ; i < size ; i++) { m_table[i] = std::vector(size); @@ -16,6 +19,7 @@ Grid::Grid(int size) } } +//Destructor Grid::~Grid() { for(int i = 0 ; i < m_size ; i++) @@ -25,16 +29,22 @@ Grid::~Grid() } } + void Grid::show() { + std::cout << "_________________" << std::endl; + std::cout << std::endl; for(int i = 0 ; i < m_size ; i++) { + std::cout << "|"; for(int j = 0 ; j < m_size ; j++) { - std::cout << m_table[i][j]->description(); + std::cout << " " << m_table[i][j]->description() << " |"; } std::cout << std::endl; + std::cout << std::endl; } + std::cout << "_________________" << std::endl; } bool Grid::isEmpty(int i, int j) From 6392288967fa76515c6789d5b99b91d76472caf4 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 May 2015 10:39:26 +0200 Subject: [PATCH 19/29] Modify show() method presentation --- src/Model/Grid.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index 19e8f4d..e484fc3 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -42,7 +42,9 @@ void Grid::show() std::cout << " " << m_table[i][j]->description() << " |"; } std::cout << std::endl; - std::cout << std::endl; + + if (i != m_size -1) + std::cout << std::endl; } std::cout << "_________________" << std::endl; } From 03b57472fc9df72691a112f7b7ba2e7ebb1675cc Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 May 2015 11:59:40 +0200 Subject: [PATCH 20/29] Add arrow support for ConsoleController (using SFML Keyboard.hpp) --- .../ConsoleController/ConsoleController.cpp | 73 ++++++++++++++++--- src/Model/Grid.cpp | 1 - 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/Controller/ConsoleController/ConsoleController.cpp b/src/Controller/ConsoleController/ConsoleController.cpp index f4d6b4d..81e16f4 100644 --- a/src/Controller/ConsoleController/ConsoleController.cpp +++ b/src/Controller/ConsoleController/ConsoleController.cpp @@ -1,4 +1,6 @@ #include "./ConsoleController.hpp" +#include +#include "../../Model/ModelConstants.hpp" ConsoleController::ConsoleController() { @@ -12,35 +14,88 @@ ConsoleController::~ConsoleController() void ConsoleController::play() { + + std::cout << "Use arrows to play !" << std::endl; + + //Init keyPress + Direction keyPress; + + //Display the first grid + m_game->showGrid(); + + //Start game while (!m_game->isOver()) { - m_game->showGrid(); - char moveChoice = ' '; + //Wait for keypress + while(1){ + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) + { + keyPress=LEFT; + while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) + { + //Wait for release + } + break; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) + { + keyPress=RIGHT; + while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) + { + //Wait for release + } + break; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) + { + keyPress=UP; + while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) + { + //Wait for release + } + break; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) + { + // la touche "flèche gauche" est enfoncée : on bouge le personnage + keyPress=DOWN; + while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) + { + //Wait for release + } + break; + } + } - std::cin >> moveChoice; - switch (moveChoice) + //Check for keypress + switch (keyPress) { - case 'z': + case UP: std::cout << "up" << std::endl; break; - case 's': + case DOWN: std::cout << "down" << std::endl; break; - case 'q': + case LEFT: std::cout << "left" << std::endl; break; - case 'd': + case RIGHT: std::cout << "right" << std::endl; break; - default: + default: break; } + //Show the Grid + m_game->showGrid(); std::cout << std::endl; + + //Pop new number m_game->pop(); + } } diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index e484fc3..75c0209 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -29,7 +29,6 @@ Grid::~Grid() } } - void Grid::show() { std::cout << "_________________" << std::endl; From 672358a947ff4bff7e0b4e0afaa90c30480ce65b Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 May 2015 12:56:38 +0200 Subject: [PATCH 21/29] Isolate keypress waiting in a method --- .../ConsoleController/ConsoleController.cpp | 117 ++++++++++-------- .../ConsoleController/ConsoleController.hpp | 2 +- 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/src/Controller/ConsoleController/ConsoleController.cpp b/src/Controller/ConsoleController/ConsoleController.cpp index 81e16f4..a2a4a77 100644 --- a/src/Controller/ConsoleController/ConsoleController.cpp +++ b/src/Controller/ConsoleController/ConsoleController.cpp @@ -14,7 +14,7 @@ ConsoleController::~ConsoleController() void ConsoleController::play() { - + //Intruction msg std::cout << "Use arrows to play !" << std::endl; //Init keyPress @@ -26,67 +26,26 @@ void ConsoleController::play() //Start game while (!m_game->isOver()) { - //Wait for keypress - while(1){ - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) - { - keyPress=LEFT; - while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) - { - //Wait for release - } - break; - } - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) - { - keyPress=RIGHT; - while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) - { - //Wait for release - } - break; - } - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) - { - keyPress=UP; - while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) - { - //Wait for release - } - break; - } - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) - { - // la touche "flèche gauche" est enfoncée : on bouge le personnage - keyPress=DOWN; - while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) - { - //Wait for release - } - break; - } - } + //Get key press + keyPress=this->waitArrowKeyPress(); + + //New line for the console print arrow press + std::cout << std::endl; - //Check for keypress - switch (keyPress) - { + //Print keyPress + switch(keyPress){ case UP: - std::cout << "up" << std::endl; + std::cout << "Keypress : Up" << std::endl; break; - case DOWN: - std::cout << "down" << std::endl; + std::cout << "Keypress : Down" << std::endl; break; - case LEFT: - std::cout << "left" << std::endl; + std::cout << "Keypress : Left" << std::endl; break; case RIGHT: - std::cout << "right" << std::endl; - break; - - default: + std::cout << "Keypress : Right" << std::endl; break; } @@ -94,8 +53,60 @@ void ConsoleController::play() m_game->showGrid(); std::cout << std::endl; + //Pop new number m_game->pop(); } } + + + +Direction ConsoleController::waitArrowKeyPress() +{ + //Initialise keyPress + Direction keyPress; + + //Wait for keypress + while(1){ + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) + { + keyPress=LEFT; + while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) + { + //Wait for release + } + break; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) + { + keyPress=RIGHT; + while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) + { + //Wait for release + } + break; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) + { + keyPress=UP; + while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) + { + //Wait for release + } + break; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) + { + // la touche "flèche gauche" est enfoncée : on bouge le personnage + keyPress=DOWN; + while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) + { + //Wait for release + } + break; + } + } + + return keyPress; +} diff --git a/src/Controller/ConsoleController/ConsoleController.hpp b/src/Controller/ConsoleController/ConsoleController.hpp index 2cda804..317759c 100644 --- a/src/Controller/ConsoleController/ConsoleController.hpp +++ b/src/Controller/ConsoleController/ConsoleController.hpp @@ -15,7 +15,7 @@ class ConsoleController private: Game * m_game; - + Direction waitArrowKeyPress(); public: ConsoleController(); ~ConsoleController(); From 048f1e17b752d2af53db82c1861002283fc300fa Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 May 2015 13:18:26 +0200 Subject: [PATCH 22/29] Add some newers things : -Change helper ModelConstants to Keyboard -Now helpers is in folder Helpers -Change direction name to use CamelCase --- src/CMakeLists.txt | 2 +- .../CMakeLists.txt | 0 .../ConsoleController/CMakeLists.txt | 0 .../ConsoleController/ConsoleController.cpp | 24 +++--- .../ConsoleController/ConsoleController.hpp | 3 +- .../Keyboard.hpp} | 11 ++- src/Model/Grid.cpp | 82 ------------------- src/Model/Grid.hpp | 8 +- src/main.cpp | 2 +- 9 files changed, 25 insertions(+), 107 deletions(-) rename src/{Controller => Controllers}/CMakeLists.txt (100%) rename src/{Controller => Controllers}/ConsoleController/CMakeLists.txt (100%) rename src/{Controller => Controllers}/ConsoleController/ConsoleController.cpp (84%) rename src/{Controller => Controllers}/ConsoleController/ConsoleController.hpp (84%) rename src/{Model/ModelConstants.hpp => Helpers/Keyboard.hpp} (62%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1c4ccb..da444d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,4 +15,4 @@ include_directories(${SFML_INCLUDE_DIR}) target_link_libraries(2P11 ${SFML_LIBRARIES} Model ConsoleController) add_subdirectory(./Model) -add_subdirectory(./Controller/) +add_subdirectory(./Controllers/) diff --git a/src/Controller/CMakeLists.txt b/src/Controllers/CMakeLists.txt similarity index 100% rename from src/Controller/CMakeLists.txt rename to src/Controllers/CMakeLists.txt diff --git a/src/Controller/ConsoleController/CMakeLists.txt b/src/Controllers/ConsoleController/CMakeLists.txt similarity index 100% rename from src/Controller/ConsoleController/CMakeLists.txt rename to src/Controllers/ConsoleController/CMakeLists.txt diff --git a/src/Controller/ConsoleController/ConsoleController.cpp b/src/Controllers/ConsoleController/ConsoleController.cpp similarity index 84% rename from src/Controller/ConsoleController/ConsoleController.cpp rename to src/Controllers/ConsoleController/ConsoleController.cpp index a2a4a77..4be0375 100644 --- a/src/Controller/ConsoleController/ConsoleController.cpp +++ b/src/Controllers/ConsoleController/ConsoleController.cpp @@ -1,6 +1,6 @@ #include "./ConsoleController.hpp" #include -#include "../../Model/ModelConstants.hpp" +#include "../../Helpers/Keyboard.hpp" ConsoleController::ConsoleController() { @@ -18,7 +18,7 @@ void ConsoleController::play() std::cout << "Use arrows to play !" << std::endl; //Init keyPress - Direction keyPress; + kbdh::Direction keyPress; //Display the first grid m_game->showGrid(); @@ -35,16 +35,16 @@ void ConsoleController::play() //Print keyPress switch(keyPress){ - case UP: + case kbdh::Up: std::cout << "Keypress : Up" << std::endl; break; - case DOWN: + case kbdh::Down: std::cout << "Keypress : Down" << std::endl; break; - case LEFT: + case kbdh::Left: std::cout << "Keypress : Left" << std::endl; break; - case RIGHT: + case kbdh::Right: std::cout << "Keypress : Right" << std::endl; break; } @@ -62,16 +62,16 @@ void ConsoleController::play() -Direction ConsoleController::waitArrowKeyPress() +kbdh::Direction ConsoleController::waitArrowKeyPress() { //Initialise keyPress - Direction keyPress; + kbdh::Direction keyPress; //Wait for keypress while(1){ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { - keyPress=LEFT; + keyPress=kbdh::Left; while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { //Wait for release @@ -80,7 +80,7 @@ Direction ConsoleController::waitArrowKeyPress() } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { - keyPress=RIGHT; + keyPress=kbdh::Right; while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { //Wait for release @@ -89,7 +89,7 @@ Direction ConsoleController::waitArrowKeyPress() } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { - keyPress=UP; + keyPress=kbdh::Up; while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { //Wait for release @@ -99,7 +99,7 @@ Direction ConsoleController::waitArrowKeyPress() if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { // la touche "flèche gauche" est enfoncée : on bouge le personnage - keyPress=DOWN; + keyPress=kbdh::Down; while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { //Wait for release diff --git a/src/Controller/ConsoleController/ConsoleController.hpp b/src/Controllers/ConsoleController/ConsoleController.hpp similarity index 84% rename from src/Controller/ConsoleController/ConsoleController.hpp rename to src/Controllers/ConsoleController/ConsoleController.hpp index 317759c..6ce8df9 100644 --- a/src/Controller/ConsoleController/ConsoleController.hpp +++ b/src/Controllers/ConsoleController/ConsoleController.hpp @@ -8,6 +8,7 @@ * Date : 29/04/2915 */ #include +#include "../../Helpers/Keyboard.hpp" #include "../../Model/Game.hpp" class ConsoleController @@ -15,7 +16,7 @@ class ConsoleController private: Game * m_game; - Direction waitArrowKeyPress(); + kbdh::Direction waitArrowKeyPress(); public: ConsoleController(); ~ConsoleController(); diff --git a/src/Model/ModelConstants.hpp b/src/Helpers/Keyboard.hpp similarity index 62% rename from src/Model/ModelConstants.hpp rename to src/Helpers/Keyboard.hpp index 5cbc21b..9d2dfa3 100644 --- a/src/Model/ModelConstants.hpp +++ b/src/Helpers/Keyboard.hpp @@ -6,7 +6,12 @@ * Creators : krilius, manzerbredes * Date : 29/04/2015 */ -enum Direction { UP, DOWN, LEFT, RIGHT }; -typedef enum Direction Direction; +namespace kbdh { -#endif \ No newline at end of file + //Key arrow + enum Direction { Up, Down, Left, Right }; + typedef enum Direction Direction; + +} + +#endif diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index 75c0209..cc9cdb1 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -82,86 +82,4 @@ void Grid::setCell(int i, int j, Cell *cell) } -void Grid::move(Direction direction) -{ - switch (direction) - { - case UP: - break; - - case DOWN: - break; - - case LEFT: - break; - - case RIGHT: - break; - - default: - break; - } -} - -void Grid::moveDown() -{/* - for (int i = 0 ; i < m_size; i++) - { - // If the column is full, check the next column - bool columnIsFull = true; - - for (int j = 0; j < m_size; j++) - { - if (m_table[j][i]->isEmpty()) - { - columnIsFull = false; - break; - } - } - - while (!columnIsFull) - { - // Calculate the first line to merge - int firstLine = m_size - 1; - while (m_table[firstLine][i]->isEmpty() && firstLine > 0) - firstLine--; - if (firstLine == 0) - break; - - // Calculate the second line to merge - int secondLine = firstLine - 1; - while (m_table[secondLine][i]->isEmpty() && secondLine > 0) - secondLine--; - - // If there is only one element, pull it down - if (m_table[secondLine][i]->isEmpty() && firstLine != m_size - 1) - { - Cell * originalCell = m_table[firstLine][i]; - Cell * finalCell = m_table[m_size-1][i]; - - m_table[firstLine][i] = finalCell; - m_table[m_size-1][i] = originalCell; - - break; - } - - // If there is only one element which is at the full bottom, break the loop - if (m_table[secondLine][i]->isEmpty()) - break; - - // If there are two "good" elements, begin the merge process - Cell * cell1 = m_table[firstLine][i]; - Cell * cell2 = m_table[secondLine][i]; - - Cell * mergedCell = NULL; - - // If the two cells are the same, merge them - if (cell1->equals(cell2)) - { - int value = std::stoi(cell1->getValue()); - mergedCell = new Cell(std::to_string(value)); - } - } - }*/ -} diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index 2a28559..c431cb3 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -10,7 +10,7 @@ #include #include -#include "ModelConstants.hpp" +//#include "ModelConstants.hpp" #include "Cell.hpp" class Grid @@ -19,11 +19,6 @@ class Grid int m_size; std::vector > m_table; - void moveUp(); - void moveDown(); - void moveLeft(); - void moveRight(); - public: Grid(int size); ~Grid(); @@ -33,7 +28,6 @@ class Grid bool gridIsFull(); void setCell(int i, int j, Cell * cell); - void move(Direction direction); }; diff --git a/src/main.cpp b/src/main.cpp index 52444a9..26062a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,7 @@ //----- Personnal include ----- #include "./Model/Grid.hpp" -#include "./Controller/ConsoleController/ConsoleController.hpp" +#include "./Controllers/ConsoleController/ConsoleController.hpp" //----------------------------- From 683d7946798634c35df165bf40a97d78f947751c Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 May 2015 15:50:10 +0200 Subject: [PATCH 23/29] Add template support to Cell class --- src/Model/CMakeLists.txt | 7 +++- src/Model/Cell.cpp | 44 ----------------------- src/Model/Cell.hpp | 53 ++++++++++++++++++++-------- src/Model/Elements/CMakeLists.txt | 2 ++ src/Model/Elements/StringElement.cpp | 24 +++++++++++++ src/Model/Elements/StringElement.hpp | 26 ++++++++++++++ src/Model/Game.cpp | 2 +- src/Model/Game.hpp | 2 +- src/Model/Grid.cpp | 8 ++--- src/Model/Grid.hpp | 5 +-- 10 files changed, 106 insertions(+), 67 deletions(-) delete mode 100644 src/Model/Cell.cpp create mode 100644 src/Model/Elements/CMakeLists.txt create mode 100644 src/Model/Elements/StringElement.cpp create mode 100644 src/Model/Elements/StringElement.hpp diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index c685c7a..284be94 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -1,2 +1,7 @@ #Make Model lib -add_library(Model Grid.cpp Cell.cpp Game.cpp) +add_library(Model Grid.cpp Game.cpp) + +target_link_libraries(Model Elements) + +add_subdirectory(./Elements) + diff --git a/src/Model/Cell.cpp b/src/Model/Cell.cpp deleted file mode 100644 index ba4bbbd..0000000 --- a/src/Model/Cell.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "Cell.hpp" - -// Constructors - -Cell::Cell() -{ - m_value = "."; -} - -Cell::Cell(std::string value) -{ - m_value = value; -} - -// Destructor - -Cell::~Cell() -{ -} - -// Getters and setters - -bool Cell::isEmpty() -{ - return (m_value == "."); -} - -std::string Cell::getValue() -{ - return m_value; -} - -bool Cell::equals(Cell *otherCell) -{ - return (m_value == otherCell->getValue()); -} - -// Description - -std::string Cell::description() -{ - return m_value; -} - diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp index badd070..7638c4e 100644 --- a/src/Model/Cell.hpp +++ b/src/Model/Cell.hpp @@ -8,24 +8,49 @@ * Date : 29/04/2015 */ #include -#include -class Cell + +template class Cell { private: - std::string m_value; - - public: - Cell(); - Cell(std::string value); - ~Cell(); + T* m_Element; - bool isEmpty(); - bool equals(Cell * otherCell); - std::string getValue(); - - // Describes the cell in a terminal - std::string description(); + public: + + //Constructor + Cell(std::string value) + { + m_Element=new T(); + m_Element->setValue(value); + } + + //Destructor + ~Cell() + { + delete m_Element; + } + + + bool isEmpty() + { + return true; + } + + std::string getElementValue() + { + return m_Element->getValue(); + } + + bool equals(Cell *otherCell) + { + return true; + } + + // Description + std::string description() + { + return m_Element->description(); + } }; diff --git a/src/Model/Elements/CMakeLists.txt b/src/Model/Elements/CMakeLists.txt new file mode 100644 index 0000000..ef31cd1 --- /dev/null +++ b/src/Model/Elements/CMakeLists.txt @@ -0,0 +1,2 @@ +#Make Model lib +add_library(Elements ./StringElement.cpp) diff --git a/src/Model/Elements/StringElement.cpp b/src/Model/Elements/StringElement.cpp new file mode 100644 index 0000000..f93fe3b --- /dev/null +++ b/src/Model/Elements/StringElement.cpp @@ -0,0 +1,24 @@ +#include "./StringElement.hpp" + + +StringElement::StringElement(){ + this->m_value="."; +} + +StringElement::~StringElement(){ + +} + + + +std::string StringElement::getValue(){ + return this->m_value; +} + +void StringElement::setValue(std::string value){ + this->m_value=value; +} + +std::string StringElement::description(){ + return this->m_value; +} diff --git a/src/Model/Elements/StringElement.hpp b/src/Model/Elements/StringElement.hpp new file mode 100644 index 0000000..db40f58 --- /dev/null +++ b/src/Model/Elements/StringElement.hpp @@ -0,0 +1,26 @@ +#ifndef _STRINGELEMENT_ +#define _STRINGELEMENT_ + + + + +#include + + + +class StringElement +{ + private: + std::string m_value; + + public: + StringElement(); + ~StringElement(); + + std::string getValue(); + void setValue(std::string value); + + std::string description(); +}; + +#endif diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index 069a481..c2252ff 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -45,7 +45,7 @@ void Game::pop() cellChosen = true; } - m_grid->setCell(i, j, new Cell("2")); + m_grid->setCell(i, j, new Cell("2")); } bool Game::isOver() diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp index fb09188..bbdcfcc 100644 --- a/src/Model/Game.hpp +++ b/src/Model/Game.hpp @@ -9,7 +9,7 @@ #include #include - +#include "./Elements/StringElement.hpp" #include "Grid.hpp" class Game diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index cc9cdb1..103b95f 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -5,15 +5,15 @@ Grid::Grid(int size) { //Create Vector m_size = size; - m_table = std::vector >(size); + m_table = std::vector*> >(size); //Init all of line and cell for(int i = 0 ; i < size ; i++) { - m_table[i] = std::vector(size); + m_table[i] = std::vector*>(size); for (int j = 0 ; j < size ; j++) { - Cell * cell = new Cell(); + Cell * cell = new Cell(""); m_table[i][j] = cell; } } @@ -72,7 +72,7 @@ bool Grid::gridIsFull() return isFull; } -void Grid::setCell(int i, int j, Cell *cell) +void Grid::setCell(int i, int j, Cell *cell) { if (i >= 0 && i < m_size && j >= 0 && j < m_size) { diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index c431cb3..a291cc8 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -12,12 +12,13 @@ //#include "ModelConstants.hpp" #include "Cell.hpp" +#include "./Elements/StringElement.hpp" class Grid { private: int m_size; - std::vector > m_table; + std::vector*> > m_table; public: Grid(int size); @@ -26,7 +27,7 @@ class Grid bool isEmpty(int i, int j); bool gridIsFull(); - void setCell(int i, int j, Cell * cell); + void setCell(int i, int j, Cell * cell); }; From 40d48a2d4f477beec0e387114f4335ab1aab1ab6 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 May 2015 15:52:43 +0200 Subject: [PATCH 24/29] Remove useless controller --- src/View/MainController.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/View/MainController.cpp diff --git a/src/View/MainController.cpp b/src/View/MainController.cpp deleted file mode 100644 index e69de29..0000000 From 01b25accba1a5329e220aa647255d2c2b284c16e Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 May 2015 18:19:32 +0200 Subject: [PATCH 25/29] Add operator overload squeleton --- src/Model/CMakeLists.txt | 2 +- src/Model/Cell.hpp | 30 +++++++++++++++++++++------- src/Model/Elements/StringElement.cpp | 25 ++++++++++++++++++++++- src/Model/Elements/StringElement.hpp | 3 +++ src/main.cpp | 15 ++++++++++++++ 5 files changed, 66 insertions(+), 9 deletions(-) diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 284be94..80ea875 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -1,5 +1,5 @@ #Make Model lib -add_library(Model Grid.cpp Game.cpp) +add_library(Model Grid.cpp Game.cpp ) target_link_libraries(Model Elements) diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp index 7638c4e..cb4bc21 100644 --- a/src/Model/Cell.hpp +++ b/src/Model/Cell.hpp @@ -24,35 +24,51 @@ template class Cell m_Element->setValue(value); } + //Destructor ~Cell() { delete m_Element; } - + //Test if the cell is empty bool isEmpty() { return true; } + T getElement(){ + return this->m_Element; + } + + bool equals(Cell *cell){ + /*if(cell->getElement() == this->m_Element){ + return true; + }*/ + return true; + } + + //Return the element value std::string getElementValue() { return m_Element->getValue(); } - bool equals(Cell *otherCell) - { - return true; - } - + // Description std::string description() { return m_Element->description(); } - + }; + + +template +bool operator==(Cell a, Cell b){ + return true; +} + #endif diff --git a/src/Model/Elements/StringElement.cpp b/src/Model/Elements/StringElement.cpp index f93fe3b..fbf57c1 100644 --- a/src/Model/Elements/StringElement.cpp +++ b/src/Model/Elements/StringElement.cpp @@ -2,7 +2,7 @@ StringElement::StringElement(){ - this->m_value="."; + this->m_value=""; } StringElement::~StringElement(){ @@ -20,5 +20,28 @@ void StringElement::setValue(std::string value){ } std::string StringElement::description(){ + if(this->m_value==""){ + return " "; + } return this->m_value; } + +bool StringElement::isEmpty(){ + if(this->m_value==""){ + return true; + } + + return false; +} +bool StringElement::equals(StringElement const& element) const{ + if(this->m_value.compare(element.m_value) == 0){ + return true; + } + + return true; +} + +bool operator==(StringElement const& a, StringElement const& b){ + return a.equals(b); +} + diff --git a/src/Model/Elements/StringElement.hpp b/src/Model/Elements/StringElement.hpp index db40f58..16946a8 100644 --- a/src/Model/Elements/StringElement.hpp +++ b/src/Model/Elements/StringElement.hpp @@ -20,7 +20,10 @@ class StringElement std::string getValue(); void setValue(std::string value); + bool isEmpty(); + bool equals(StringElement const& element) const; std::string description(); + }; #endif diff --git a/src/main.cpp b/src/main.cpp index 26062a9..217fe81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,11 +10,26 @@ #include "./Controllers/ConsoleController/ConsoleController.hpp" //----------------------------- +#include "./Model/Cell.hpp" +//#include "./Model/Elements/StringElement.hpp" //----- Start ----- + + int main() { + Cell cell1("loic"); + Cell cell2("loic"); + + + if(cell1==cell2){ + std::cout << "Egale" << std::endl; + } + else{ + std::cout << "Différent" << std::endl; + } + //Init random srand(time(NULL)); From 6b8a144bd192de206e11a171841ec6161d11b6aa Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Sat, 2 May 2015 11:06:54 +0200 Subject: [PATCH 26/29] Correct bugs --- .gitignore | 1 + .../ConsoleController/ConsoleController.cpp | 3 ++- src/Model/Cell.hpp | 12 +++++------ src/Model/Elements/StringElement.cpp | 11 +++------- src/Model/Elements/StringElement.hpp | 2 +- src/Model/Game.cpp | 20 ++++++++----------- src/Model/Game.hpp | 3 +-- src/Model/Grid.cpp | 18 ++++++++++++----- src/Model/Grid.hpp | 5 ++++- src/main.cpp | 10 +++++----- 10 files changed, 44 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 766f778..5609314 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ CMakeCache.txt *.app 2P11 clear.sh +*.vim diff --git a/src/Controllers/ConsoleController/ConsoleController.cpp b/src/Controllers/ConsoleController/ConsoleController.cpp index 4be0375..4ee4965 100644 --- a/src/Controllers/ConsoleController/ConsoleController.cpp +++ b/src/Controllers/ConsoleController/ConsoleController.cpp @@ -24,8 +24,9 @@ void ConsoleController::play() m_game->showGrid(); //Start game - while (!m_game->isOver()) + while (1) { + std::cout << m_game->isOver(); //Get key press keyPress=this->waitArrowKeyPress(); diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp index cb4bc21..3371fda 100644 --- a/src/Model/Cell.hpp +++ b/src/Model/Cell.hpp @@ -34,18 +34,18 @@ template class Cell //Test if the cell is empty bool isEmpty() { - return true; + return this->m_Element->isEmpty(); } - T getElement(){ + T* getElement(){ return this->m_Element; } bool equals(Cell *cell){ - /*if(cell->getElement() == this->m_Element){ + if(m_Element->equals(cell->getElement())){ return true; - }*/ - return true; + } + return false; } //Return the element value @@ -67,7 +67,7 @@ template class Cell template bool operator==(Cell a, Cell b){ - return true; + return a.equals(&b); } #endif diff --git a/src/Model/Elements/StringElement.cpp b/src/Model/Elements/StringElement.cpp index fbf57c1..a197c22 100644 --- a/src/Model/Elements/StringElement.cpp +++ b/src/Model/Elements/StringElement.cpp @@ -33,15 +33,10 @@ bool StringElement::isEmpty(){ return false; } -bool StringElement::equals(StringElement const& element) const{ - if(this->m_value.compare(element.m_value) == 0){ +bool StringElement::equals(StringElement *element){ + if(this->m_value.compare(element->m_value) == 0){ return true; } - return true; + return false; } - -bool operator==(StringElement const& a, StringElement const& b){ - return a.equals(b); -} - diff --git a/src/Model/Elements/StringElement.hpp b/src/Model/Elements/StringElement.hpp index 16946a8..55c5473 100644 --- a/src/Model/Elements/StringElement.hpp +++ b/src/Model/Elements/StringElement.hpp @@ -21,7 +21,7 @@ class StringElement void setValue(std::string value); bool isEmpty(); - bool equals(StringElement const& element) const; + bool equals(StringElement *element); std::string description(); }; diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index c2252ff..3054990 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -10,18 +10,7 @@ Game::~Game() delete m_grid; } -void Game::play() -{ - while(!m_grid->gridIsFull()) - { - m_grid->show(); - pop(); - std::cout << std::endl; - } - - m_grid->show(); -} void Game::showGrid() { @@ -50,5 +39,12 @@ void Game::pop() bool Game::isOver() { - return m_grid->gridIsFull(); + if(m_grid->gridIsFull()){ + for(int i=0;i<4;i++){ + std::cout << m_grid->getCell(0,i)->description(); + } + + } + + return true; } diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp index bbdcfcc..0666191 100644 --- a/src/Model/Game.hpp +++ b/src/Model/Game.hpp @@ -15,13 +15,12 @@ class Game { private: - Grid * m_grid; + Grid *m_grid; public: Game(); ~Game(); - void play(); void pop(); void showGrid(); bool isOver(); diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index 103b95f..b6ef8c4 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -58,18 +58,17 @@ bool Grid::isEmpty(int i, int j) bool Grid::gridIsFull() { - bool isFull = true; - for (int i = 0; i < m_size && isFull; i++) + for (int i = 0; i < m_size ; i++) { - for (int j = 0; j < m_size && isFull; j++) + for (int j = 0; j < m_size ; j++) { if (m_table[i][j]->isEmpty()) - isFull = false; + return false; } } - return isFull; + return true; } void Grid::setCell(int i, int j, Cell *cell) @@ -81,5 +80,14 @@ void Grid::setCell(int i, int j, Cell *cell) } } +Cell* Grid::getCell(short i, short j){ + return m_table[i][j]; +} +int Grid::getNRows(){ + return m_table[0].size(); +} +int Grid::getNCols(){ + return m_table.size(); +} diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index a291cc8..b7c1f9f 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -27,7 +27,10 @@ class Grid bool isEmpty(int i, int j); bool gridIsFull(); - void setCell(int i, int j, Cell * cell); + int getNRows(); + int getNCols(); + void setCell(int i, int j, Cell *cell); + Cell* getCell(short i, short j); }; diff --git a/src/main.cpp b/src/main.cpp index 217fe81..cfb0c7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,15 +19,15 @@ int main() { - Cell cell1("loic"); - Cell cell2("loic"); + Cell *cell1 = new Cell(""); + Cell *cell2 = new Cell("i"); - if(cell1==cell2){ - std::cout << "Egale" << std::endl; + if(cell2->isEmpty()){ + std::cout << "Empty" << std::endl; } else{ - std::cout << "Différent" << std::endl; + std::cout << "Not empty" << std::endl; } //Init random From 27d646af15bc9147a141aced8cebd30668de9a8e Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Sat, 2 May 2015 18:15:14 +0200 Subject: [PATCH 27/29] Restart project --- CMakeLists.txt | 2 +- .../ConsoleController/ConsoleController.cpp | 3 +- src/Model/Cell.hpp | 74 ------------------- src/Model/Elements/CMakeLists.txt | 2 - src/Model/Elements/StringElement.cpp | 42 ----------- src/Model/Elements/StringElement.hpp | 29 -------- src/Model/Game.cpp | 19 +++-- src/Model/Game.hpp | 2 + src/Model/Grid.cpp | 68 +++++++++++++++++ src/Model/Grid.hpp | 22 +++--- src/main.cpp | 2 +- 11 files changed, 100 insertions(+), 165 deletions(-) delete mode 100644 src/Model/Cell.hpp delete mode 100644 src/Model/Elements/CMakeLists.txt delete mode 100644 src/Model/Elements/StringElement.cpp delete mode 100644 src/Model/Elements/StringElement.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ab2346..b47e302 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(2P11) #Assign Modules path set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") - +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FGS} -std=c++11") #Defined project VERSION set(VERSION_MAJOR 0) set(VERSION_MINOR 1) diff --git a/src/Controllers/ConsoleController/ConsoleController.cpp b/src/Controllers/ConsoleController/ConsoleController.cpp index 4ee4965..bca3ad8 100644 --- a/src/Controllers/ConsoleController/ConsoleController.cpp +++ b/src/Controllers/ConsoleController/ConsoleController.cpp @@ -26,7 +26,7 @@ void ConsoleController::play() //Start game while (1) { - std::cout << m_game->isOver(); + std::cout << "Game over : " << m_game->isOver() << "fin"; //Get key press keyPress=this->waitArrowKeyPress(); @@ -47,6 +47,7 @@ void ConsoleController::play() break; case kbdh::Right: std::cout << "Keypress : Right" << std::endl; + m_game->swipeRight(); break; } diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp deleted file mode 100644 index 3371fda..0000000 --- a/src/Model/Cell.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef DEF_CELL -#define DEF_CELL - -/* Cell.h - * Defines the class Cell - * A cell represents a cell in the grid - * Creators : krilius, manzerbredes - * Date : 29/04/2015 */ - -#include - - -template class Cell -{ - private: - T* m_Element; - - public: - - //Constructor - Cell(std::string value) - { - m_Element=new T(); - m_Element->setValue(value); - } - - - //Destructor - ~Cell() - { - delete m_Element; - } - - //Test if the cell is empty - bool isEmpty() - { - return this->m_Element->isEmpty(); - } - - T* getElement(){ - return this->m_Element; - } - - bool equals(Cell *cell){ - if(m_Element->equals(cell->getElement())){ - return true; - } - return false; - } - - //Return the element value - std::string getElementValue() - { - return m_Element->getValue(); - } - - - // Description - std::string description() - { - return m_Element->description(); - } - -}; - - - -template -bool operator==(Cell a, Cell b){ - return a.equals(&b); -} - -#endif - diff --git a/src/Model/Elements/CMakeLists.txt b/src/Model/Elements/CMakeLists.txt deleted file mode 100644 index ef31cd1..0000000 --- a/src/Model/Elements/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -#Make Model lib -add_library(Elements ./StringElement.cpp) diff --git a/src/Model/Elements/StringElement.cpp b/src/Model/Elements/StringElement.cpp deleted file mode 100644 index a197c22..0000000 --- a/src/Model/Elements/StringElement.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "./StringElement.hpp" - - -StringElement::StringElement(){ - this->m_value=""; -} - -StringElement::~StringElement(){ - -} - - - -std::string StringElement::getValue(){ - return this->m_value; -} - -void StringElement::setValue(std::string value){ - this->m_value=value; -} - -std::string StringElement::description(){ - if(this->m_value==""){ - return " "; - } - return this->m_value; -} - -bool StringElement::isEmpty(){ - if(this->m_value==""){ - return true; - } - - return false; -} -bool StringElement::equals(StringElement *element){ - if(this->m_value.compare(element->m_value) == 0){ - return true; - } - - return false; -} diff --git a/src/Model/Elements/StringElement.hpp b/src/Model/Elements/StringElement.hpp deleted file mode 100644 index 55c5473..0000000 --- a/src/Model/Elements/StringElement.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _STRINGELEMENT_ -#define _STRINGELEMENT_ - - - - -#include - - - -class StringElement -{ - private: - std::string m_value; - - public: - StringElement(); - ~StringElement(); - - std::string getValue(); - void setValue(std::string value); - - bool isEmpty(); - bool equals(StringElement *element); - std::string description(); - -}; - -#endif diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index 3054990..7dc32c6 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -33,18 +33,27 @@ void Game::pop() if (m_grid->isEmpty(i,j)) cellChosen = true; } - - m_grid->setCell(i, j, new Cell("2")); + m_grid->setCell(i, j, new Cell(std::to_string(2))); +} +void Game::swipeRight(){ + m_grid->swipeRight(); } - bool Game::isOver() { if(m_grid->gridIsFull()){ - for(int i=0;i<4;i++){ - std::cout << m_grid->getCell(0,i)->description(); + for(int i=0;igetNRows();i++){ + + for(int j=0;jgetNCols()-1;j++){ + if(m_grid->getCell(i,j)->equals(m_grid->getCell(i,j+1))){ + return false; + } + } } } + else { + return false; + } return true; } diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp index 0666191..c1c636a 100644 --- a/src/Model/Game.hpp +++ b/src/Model/Game.hpp @@ -9,6 +9,7 @@ #include #include +#include #include "./Elements/StringElement.hpp" #include "Grid.hpp" @@ -23,6 +24,7 @@ class Game void pop(); void showGrid(); + void swipeRight(); bool isOver(); }; diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index b6ef8c4..6fc41c6 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -91,3 +91,71 @@ int Grid::getNRows(){ int Grid::getNCols(){ return m_table.size(); } + + +std::vector* > Grid::swipeLine(std::vector* > line){ + std::vector*> newLine = std::vector*>(4); + + + for (int j = 0 ; j < 3 ; j++) + { + if(j>3) + break; + Cell * cell = new Cell(line.at(j)->getElementValue()); + Cell * cellp1 = new Cell(line.at(j+1)->getElementValue()); + + int a=atoi(cell->getElementValue().c_str()); + int ap1=atoi(cellp1->getElementValue().c_str()); + + std::string s=std::to_string(a); + std::string sp1=std::to_string(ap1); + + if(a==ap1 && a!=0){ + s=""; + sp1=std::to_string(a+ap1); + if(ap1 == 0) + newLine[j+1] = new Cell(""); + else + newLine[j+1] = new Cell(sp1); + newLine[j] = new Cell(s); + j++; + } + else{ + if(ap1==0) + newLine[j+1] = new Cell(""); + else + newLine[j+1] = new Cell(sp1); + if(a==0) + newLine[j] = new Cell(""); + else + newLine[j] = new Cell(s); + + } + delete cell; + delete cellp1; + + } + + + for (int j = 0 ; j < 3 ; j++){ + + if(!newLine[j]->isEmpty()){ + if(newLine[j+1]->isEmpty()){ + newLine[j+1]=new Cell(newLine[j]->getElementValue()); + newLine[j]=new Cell(""); + } + } + } + + for(int i=0; i<4;i++){ + + std::cout << "|" << newLine[i]->description() << "|"; + } + std::cout << "done"; + return newLine; +} + +void Grid::swipeRight(){ + std::vector*> a=this->swipeLine(m_table.at(0)); + m_table[0]=a; +} diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index b7c1f9f..810cb9b 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -17,21 +17,23 @@ class Grid { private: - int m_size; + int m_size; std::vector*> > m_table; - + public: Grid(int size); ~Grid(); void show(); - - bool isEmpty(int i, int j); - bool gridIsFull(); - int getNRows(); - int getNCols(); - void setCell(int i, int j, Cell *cell); - Cell* getCell(short i, short j); - + + bool isEmpty(int i, int j); + bool gridIsFull(); + int getNRows(); + int getNCols(); + std::vector* > swipeLine(std::vector* > line); + void swipeRight(); + void setCell(int i, int j, Cell *cell); + Cell* getCell(short i, short j); + }; diff --git a/src/main.cpp b/src/main.cpp index cfb0c7d..24a6af6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,7 @@ int main() { - Cell *cell1 = new Cell(""); + Cell *cell1 = new Cell(""); Cell *cell2 = new Cell("i"); From 36d033caeebd8ccbddf711825a5a96e3930438be Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Sat, 2 May 2015 19:26:01 +0200 Subject: [PATCH 28/29] Make clean code --- src/CMakeLists.txt | 4 +- src/Model/CMakeLists.txt | 7 +- src/Model/Game.cpp | 58 +---------- src/Model/Game.hpp | 8 +- src/Model/Grid.cpp | 203 ++++++++++++++------------------------- src/Model/Grid.hpp | 22 ++--- src/main.cpp | 32 +++--- 7 files changed, 103 insertions(+), 231 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index da444d2..ed13eb5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,7 @@ set_property(GLOBAL PROPERTY SFML_INCLUDE_DIR "${SFML_INCLUDE_DIR}") #Include "Includes" and "Libraries" include_directories(${SFML_INCLUDE_DIR}) -target_link_libraries(2P11 ${SFML_LIBRARIES} Model ConsoleController) +target_link_libraries(2P11 ${SFML_LIBRARIES} Model ) add_subdirectory(./Model) -add_subdirectory(./Controllers/) +#add_subdirectory(./Controllers/) diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 80ea875..888589e 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -1,7 +1,2 @@ #Make Model lib -add_library(Model Grid.cpp Game.cpp ) - -target_link_libraries(Model Elements) - -add_subdirectory(./Elements) - +add_library(Model Grid.cpp Game.cpp) diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index 7dc32c6..32482b7 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -1,59 +1,9 @@ #include "Game.hpp" -Game::Game() -{ - m_grid = new Grid(4); + + +Game::Game() : m_grid(){ } -Game::~Game() -{ - delete m_grid; -} - - - -void Game::showGrid() -{ - m_grid->show(); - std::cout << std::endl; -} - -void Game::pop() -{ - bool cellChosen = false; - - int i; - int j; - - while(!cellChosen) - { - i = rand() % 4; - j = rand() % 4; - - if (m_grid->isEmpty(i,j)) - cellChosen = true; - } - m_grid->setCell(i, j, new Cell(std::to_string(2))); -} -void Game::swipeRight(){ - m_grid->swipeRight(); -} -bool Game::isOver() -{ - if(m_grid->gridIsFull()){ - for(int i=0;igetNRows();i++){ - - for(int j=0;jgetNCols()-1;j++){ - if(m_grid->getCell(i,j)->equals(m_grid->getCell(i,j+1))){ - return false; - } - } - } - - } - else { - return false; - } - - return true; +Game::~Game(){ } diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp index c1c636a..ee3a6a9 100644 --- a/src/Model/Game.hpp +++ b/src/Model/Game.hpp @@ -8,24 +8,18 @@ * Date : 29/04/2015 */ #include -#include #include -#include "./Elements/StringElement.hpp" #include "Grid.hpp" class Game { private: - Grid *m_grid; + Grid m_grid; public: Game(); ~Game(); - void pop(); - void showGrid(); - void swipeRight(); - bool isOver(); }; #endif diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index 6fc41c6..92837f6 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -1,161 +1,100 @@ #include "Grid.hpp" //Constructor -Grid::Grid(int size) -{ - //Create Vector - m_size = size; - m_table = std::vector*> >(size); +Grid::Grid(): m_size(4), m_grid(4){ - //Init all of line and cell - for(int i = 0 ; i < size ; i++) - { - m_table[i] = std::vector*>(size); - for (int j = 0 ; j < size ; j++) - { - Cell * cell = new Cell(""); - m_table[i][j] = cell; + //Init all cells + for(int i=0;idescription() << " |"; + +std::string Grid::description(){ + + //Init stringstream description + std::stringstream description; + + //Start to write description + description << "-----------------" << std::endl; + for(int i=0;i= 0 && i < m_size && j >= 0 && j < m_size) - return m_table[i][j]->isEmpty(); - +bool Grid::isEmpty(int i, int j){ + if(m_grid.at(i).at(j) == 0) + return true; return false; } -bool Grid::gridIsFull() -{ +std::tuple Grid::getRandomEmptyCellCoord(){ - for (int i = 0; i < m_size ; i++) - { - for (int j = 0; j < m_size ; j++) - { - if (m_table[i][j]->isEmpty()) - return false; - } - } + //Init list of candidate + std::vector > candidates; - return true; -} - -void Grid::setCell(int i, int j, Cell *cell) -{ - if (i >= 0 && i < m_size && j >= 0 && j < m_size) - { - delete m_table[i][j]; - m_table[i][j] = cell; - } -} - -Cell* Grid::getCell(short i, short j){ - return m_table[i][j]; -} - -int Grid::getNRows(){ - return m_table[0].size(); -} - -int Grid::getNCols(){ - return m_table.size(); -} - - -std::vector* > Grid::swipeLine(std::vector* > line){ - std::vector*> newLine = std::vector*>(4); - - - for (int j = 0 ; j < 3 ; j++) - { - if(j>3) - break; - Cell * cell = new Cell(line.at(j)->getElementValue()); - Cell * cellp1 = new Cell(line.at(j+1)->getElementValue()); - - int a=atoi(cell->getElementValue().c_str()); - int ap1=atoi(cellp1->getElementValue().c_str()); - - std::string s=std::to_string(a); - std::string sp1=std::to_string(ap1); - - if(a==ap1 && a!=0){ - s=""; - sp1=std::to_string(a+ap1); - if(ap1 == 0) - newLine[j+1] = new Cell(""); - else - newLine[j+1] = new Cell(sp1); - newLine[j] = new Cell(s); - j++; - } - else{ - if(ap1==0) - newLine[j+1] = new Cell(""); - else - newLine[j+1] = new Cell(sp1); - if(a==0) - newLine[j] = new Cell(""); - else - newLine[j] = new Cell(s); - - } - delete cell; - delete cellp1; - - } - - - for (int j = 0 ; j < 3 ; j++){ - - if(!newLine[j]->isEmpty()){ - if(newLine[j+1]->isEmpty()){ - newLine[j+1]=new Cell(newLine[j]->getElementValue()); - newLine[j]=new Cell(""); + //Construct list of candidates + for(int i=0;iisEmpty(i,j)){ + std::tuple currentCandidate(i,j); + candidates.push_back(currentCandidate); } } } - for(int i=0; i<4;i++){ + //If no candidate available + if(candidates.size() == 0) + return std::tuple(-1, -1); - std::cout << "|" << newLine[i]->description() << "|"; + //Select the candidates + int winnerIs(rand() % candidates.size()); + + //Return the candidate + return candidates.at(winnerIs); + +} + + + +//Change value of cell +bool Grid::setCell(std::tuple coord, int value){ + int i=std::get<0>(coord); + int j=std::get<1>(coord); + + if(i>=0 && i=0 && j*> a=this->swipeLine(m_table.at(0)); - m_table[0]=a; +//Another setCell method +bool Grid::setCell(int i, int j, int value){ + std::tuple coord(i,j); + return this->setCell(coord, value); } + + + + + diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index 810cb9b..6942188 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -8,32 +8,26 @@ * Date : 29/04/2015 */ #include +#include #include - -//#include "ModelConstants.hpp" -#include "Cell.hpp" -#include "./Elements/StringElement.hpp" +#include class Grid { private: int m_size; - std::vector*> > m_table; + std::vector > m_grid; public: - Grid(int size); + Grid(); ~Grid(); - void show(); + std::string description(); bool isEmpty(int i, int j); - bool gridIsFull(); - int getNRows(); - int getNCols(); - std::vector* > swipeLine(std::vector* > line); - void swipeRight(); - void setCell(int i, int j, Cell *cell); - Cell* getCell(short i, short j); + std::tuple getRandomEmptyCellCoord(); + bool setCell(std::tuple coord, int value); + bool setCell(int i, int j, int value); }; diff --git a/src/main.cpp b/src/main.cpp index 24a6af6..a7abcae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,14 +3,13 @@ #include #include #include +#include //---------------------- //----- Personnal include ----- #include "./Model/Grid.hpp" -#include "./Controllers/ConsoleController/ConsoleController.hpp" //----------------------------- -#include "./Model/Cell.hpp" //#include "./Model/Elements/StringElement.hpp" //----- Start ----- @@ -19,28 +18,29 @@ int main() { - Cell *cell1 = new Cell(""); - Cell *cell2 = new Cell("i"); - - - if(cell2->isEmpty()){ - std::cout << "Empty" << std::endl; - } - else{ - std::cout << "Not empty" << std::endl; - } - //Init random srand(time(NULL)); + + Grid a; + std::cout << a.description(); + std::cout << std::get<0>(a.getRandomEmptyCellCoord()) << ","<< std::get<1>(a.getRandomEmptyCellCoord()); + while(1){ + + std::tuple c(a.getRandomEmptyCellCoord()); + a.setCell(1,2, 15); + std::cout << a.description(); + std::string chaine; + std::cin >> chaine; + } //Init console controller - ConsoleController * controller = new ConsoleController(); + //ConsoleController * controller = new ConsoleController(); //Launch game - controller->play(); + //controller->play(); //Remove controlelr - delete controller; + //delete controller; return 0; } From 1d09a0fd3ae35ccf51a3b5f929f77a8c8850712c Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Sat, 2 May 2015 22:57:08 +0200 Subject: [PATCH 29/29] End console clean game --- src/CMakeLists.txt | 4 +- .../ConsoleController/ConsoleController.cpp | 53 ++---- .../ConsoleController/ConsoleController.hpp | 4 +- src/Model/Game.cpp | 40 +++++ src/Model/Game.hpp | 8 +- src/Model/Grid.cpp | 170 +++++++++++++++++- src/Model/Grid.hpp | 19 ++ src/main.cpp | 28 +-- 8 files changed, 258 insertions(+), 68 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ed13eb5..da444d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,7 @@ set_property(GLOBAL PROPERTY SFML_INCLUDE_DIR "${SFML_INCLUDE_DIR}") #Include "Includes" and "Libraries" include_directories(${SFML_INCLUDE_DIR}) -target_link_libraries(2P11 ${SFML_LIBRARIES} Model ) +target_link_libraries(2P11 ${SFML_LIBRARIES} Model ConsoleController) add_subdirectory(./Model) -#add_subdirectory(./Controllers/) +add_subdirectory(./Controllers/) diff --git a/src/Controllers/ConsoleController/ConsoleController.cpp b/src/Controllers/ConsoleController/ConsoleController.cpp index bca3ad8..d91e807 100644 --- a/src/Controllers/ConsoleController/ConsoleController.cpp +++ b/src/Controllers/ConsoleController/ConsoleController.cpp @@ -4,62 +4,45 @@ ConsoleController::ConsoleController() { - m_game = new Game(); } ConsoleController::~ConsoleController() { - delete m_game; } -void ConsoleController::play() +void ConsoleController::run() { - //Intruction msg - std::cout << "Use arrows to play !" << std::endl; //Init keyPress kbdh::Direction keyPress; - //Display the first grid - m_game->showGrid(); + //Intruction msg + std::cout << "Use arrows to play !" << std::endl; + + //Pop a random number on the grid + m_game.popRandomNumber(); + + //First cout grid + m_game.coutGrid(); + //Start game - while (1) + while (!m_game.isOver()) { - std::cout << "Game over : " << m_game->isOver() << "fin"; //Get key press keyPress=this->waitArrowKeyPress(); - //New line for the console print arrow press - std::cout << std::endl; + //Apply move + m_game.swipe(keyPress); + //Pop a random number on the grid + m_game.popRandomNumber(); - //Print keyPress - switch(keyPress){ - case kbdh::Up: - std::cout << "Keypress : Up" << std::endl; - break; - case kbdh::Down: - std::cout << "Keypress : Down" << std::endl; - break; - case kbdh::Left: - std::cout << "Keypress : Left" << std::endl; - break; - case kbdh::Right: - std::cout << "Keypress : Right" << std::endl; - m_game->swipeRight(); - break; - } - - //Show the Grid - m_game->showGrid(); - std::cout << std::endl; - - - //Pop new number - m_game->pop(); + //Cout grid + m_game.coutGrid(); } + m_game.coutGrid(); } diff --git a/src/Controllers/ConsoleController/ConsoleController.hpp b/src/Controllers/ConsoleController/ConsoleController.hpp index 6ce8df9..8d73f79 100644 --- a/src/Controllers/ConsoleController/ConsoleController.hpp +++ b/src/Controllers/ConsoleController/ConsoleController.hpp @@ -15,12 +15,12 @@ class ConsoleController { private: - Game * m_game; + Game m_game; kbdh::Direction waitArrowKeyPress(); public: ConsoleController(); ~ConsoleController(); - void play(); + void run(); }; #endif diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index 32482b7..6039bc9 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -7,3 +7,43 @@ Game::Game() : m_grid(){ Game::~Game(){ } + + + +bool Game::swipe(kbdh::Direction direction){ + + switch(direction){ + + case kbdh::Left: + m_grid.swipeLeft(); + break; + case kbdh::Right: + m_grid.swipeRight(); + break; + case kbdh::Up: + m_grid.swipeUp(); + break; + case kbdh::Down: + m_grid.swipeDown(); + break; + } + + return true; +} + + +void Game::coutGrid(){ + std::cout << m_grid.description(); +} + +bool Game::isOver(){ + return m_grid.isOver(); +} + +void Game::popRandomNumber(){ + std::tuple coord(m_grid.getRandomEmptyCellCoord()); + + int number=2; + + m_grid.setCell(coord, number); +} diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp index ee3a6a9..ab19340 100644 --- a/src/Model/Game.hpp +++ b/src/Model/Game.hpp @@ -9,7 +9,9 @@ #include #include +#include "../Helpers/Keyboard.hpp" #include "Grid.hpp" +#include class Game { @@ -19,7 +21,11 @@ class Game public: Game(); ~Game(); - + + bool swipe(kbdh::Direction direction); + void coutGrid(); + void popRandomNumber(); + bool isOver(); }; #endif diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index 92837f6..3a8a075 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -22,24 +22,48 @@ std::string Grid::description(){ //Init stringstream description std::stringstream description; + //Get max str len of the grid + int maxStrLen=this->maxStrLenInGrid(); + //Start to write description - description << "-----------------" << std::endl; + std::stringstream gridBorder; + for(int i=0;i<(maxStrLen+2)*4+1;i++){ + gridBorder<<"-"; + } + description << std::endl << gridBorder.str() << std::endl; for(int i=0;i max) + max=number.size(); + } + } + return max; +} + bool Grid::isEmpty(int i, int j){ if(m_grid.at(i).at(j) == 0) return true; @@ -77,8 +101,8 @@ std::tuple Grid::getRandomEmptyCellCoord(){ //Change value of cell bool Grid::setCell(std::tuple coord, int value){ - int i=std::get<0>(coord); - int j=std::get<1>(coord); + int i=std::get<0>(coord); + int j=std::get<1>(coord); if(i>=0 && i=0 && j Grid::defragmentLine(std::vector line){ + for(int j=0; j Grid::mergeLine(std::vector line){ + for(int i=0; i< m_size-1;i++){ + int val1=line.at(i); + int val2=line.at(i+1); + + if(val1==val2){ + line.at(i)=0; + line.at(i+1)=val1*2; + i++; + } + } + return line; +} + +std::vector Grid::swipeLine(std::vector line){ + + //Swipe line is : + //- A defragmentation + //- A merging + //- Another defragmentation + line=this->defragmentLine(line); + line=this->mergeLine(line); + line=this->defragmentLine(line); + + //Return swiped line + return line; +} +//Swipe to right +void Grid::swipeRight(){ + for(int i=0; iswipeLine(m_grid.at(i)); + } +} +//Swipe to right +void Grid::swipeLeft(){ + for(int i=0; ireverseLine(this->swipeLine(this->reverseLine(m_grid.at(i)))); + } +} + + +void Grid::swipeUp(){ + for(int i=0; i colVect=this->getCol(i); + this->setCol(i,this->reverseLine(this->swipeLine(this->reverseLine(colVect)))); + } +} +void Grid::swipeDown(){ + for(int i=0; i colVect=this->getCol(i); + this->setCol(i,this->swipeLine(colVect)); + } +} + +void Grid::setCol(int col, std::vector colVect){ + for(int i=0;i Grid::getCol(int col){ + + std::vector colVect; + + for(int i=0;i Grid::reverseLine(std::vector line){ + std::vector reversedLine; + + for(int j=m_size-1; j>=0;j--){ + reversedLine.push_back(line.at(j)); + } + + return reversedLine; +} + + +bool Grid::isFull(){ + + for(int i=0;iisFull()) + return false; + + for(int i=0;i colVect(this->getCol(i)); + + for(int j=0;j > m_grid; + int maxStrLenInGrid(); public: Grid(); ~Grid(); @@ -28,6 +29,24 @@ class Grid bool setCell(std::tuple coord, int value); bool setCell(int i, int j, int value); + + std::vector swipeLine(std::vector line); + std::vector defragmentLine(std::vector line); + std::vector mergeLine(std::vector line); + + std::vector getCol(int col); + + bool isFull(); + bool isOver(); + + void setCol(int col, std::vector colVect); + std::vector reverseLine(std::vector line); + + //Moves + void swipeRight(); + void swipeLeft(); + void swipeUp(); + void swipeDown(); }; diff --git a/src/main.cpp b/src/main.cpp index a7abcae..49c7a20 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,3 @@ - //----- STD include ----- #include #include @@ -7,40 +6,25 @@ //---------------------- //----- Personnal include ----- -#include "./Model/Grid.hpp" +#include "./Controllers/ConsoleController/ConsoleController.hpp" //----------------------------- -//#include "./Model/Elements/StringElement.hpp" -//----- Start ----- +//----- Start ----- int main() { //Init random srand(time(NULL)); + //Init controller + ConsoleController controller; - Grid a; - std::cout << a.description(); - std::cout << std::get<0>(a.getRandomEmptyCellCoord()) << ","<< std::get<1>(a.getRandomEmptyCellCoord()); - while(1){ + //Run the game + controller.run(); - std::tuple c(a.getRandomEmptyCellCoord()); - a.setCell(1,2, 15); - std::cout << a.description(); - std::string chaine; - std::cin >> chaine; - } - //Init console controller - //ConsoleController * controller = new ConsoleController(); - - //Launch game - //controller->play(); - - //Remove controlelr - //delete controller; return 0; }