Initial commit on github to give this project a somewhat more 'permanent' home

Signed-off-by: Gwenhael Le Moine <gwenhael.le.moine@gmail.com>
This commit is contained in:
Gwenhael Le Moine 2009-05-12 13:28:12 +07:00
commit f21eee8aaa
96 changed files with 5254 additions and 0 deletions

1
AUTHORS Normal file
View file

@ -0,0 +1 @@
Gwenhael LE MOINE ( cycojesus_¬AT¬_yahoo_¬DOT¬_fr )

340
COPYING Normal file
View file

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) 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
this service 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 make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. 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.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
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
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the 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 a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE 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.
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
convey 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 2 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision 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, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This 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 Library General
Public License instead of this License.

423
Changelog Normal file
View file

@ -0,0 +1,423 @@
2007-11-12 : toward version 2.1.9
- src/main.cc : cleaned up #if defined ()
2006-11-07 : toward version 2.1.9
- src/Makefile : don't complain if symlinks already exist, kill'em.
- src/Board.* : clean-up, tweaking, etc.
2006-10-02 : toward version 2.1.9
- disabled making target 'archive_bin_static' in target 'archive'. It
ends up in error, I don't know why and it breaks target 'archive'.
- bumped up version number in Slackware/ngstar.SlackBuild
- updated copyright notices.
2006-05-23 : toward version 2.1.9
- Fixed compilation with fltk-2.0.x > r5132
2006-02-05 : toward version 2.1.8
- Ncurses_UI : added option to use 'black & white' display :
in ~/.ngstar/config :
black_and_white = 0 or 1 (false or true)
command-line argument -b --black-and-white
- Ncurses_UI : display the board before displaying score or
levelset end's message
2006-01-03 : toward version 2.1.8
- small optimizations in drawing methods
2005-11-15 : toward version 2.1.8
- Ncurses_UI : nice looking panel at the end of a level to display score.
- Ncurses_UI : nice looking panel at the end of a levelset to summurize.
2005-11-13 : toward version 2.1.8
- Board.hh : Began to implement something to make a transition
between levels as well as to inform the player of her
score. Problem getting it to be displayed... :/
- Makefile : make dynamic binaries archive before static binaries
one.
- Board.cc : typo in load_textures()
2005-10-28 : toward version 2.1.7
- Changed FSF address.
- compilation output looks prettier (inspired by fltk2 makefile ;) )
2005-10-22 : toward version 2.1.7
- Fixed bug in Fltk2_UI.cc : controls weren't refreshed when
changing level using vi_levels.
2005-10-10 : toward version 2.1.7
- Rearranged controls, level indicator, output of number of moves
and gifts don't change but are relocated in the second
line. Others controls are re-implemented in a menu, 'Exit' and
'Restart level' are under the File menu entry, levelsets and
themes' lists become menu entries too, and a 'Help' entry is added
with sub-entries 'License' and 'About'.
- Added an 'Show scores' entry under the 'File' menu to display
current levelset's scores.
- LevelMaker_UI : removed 'Help'->'Help' entry, useless, you'd
better read the README file.
- strip binary
2005-10-06 : toward version 2.1.6
- made headers and static & shared libraries installation optional
- added --install-dev switch to ./configure (default: no) (see above)
- added --enable-debug switch to ./configure (default: no)
- added --enable-static switch to ./configure (default: no)
- modified 'make archive' to build separate archives for static
and dynamic binaries archive.
- during compilation use static library by default.
- shared library is not built unless ./configure is called
with --install-dev switch
- modified Slackware/ngstar.SlackBuild to avoid messing up with
ownership and permissions in doinst.sh. Do that when building
packages so that if there's some problem only the packager's
system is messed up, the end-user should get a clean, *working*
package. (Big thanks to the qemu (http://www.qemu.org) programmers
for saving my system ;))
- typos and corrections in README
2005-10-02 : toward version 2.1.6
- Cleaned {src,libngstar2}/Makefiles by letting implicit rules do
their job.
- moved ngstar.SlackBuild into its own Slackware directory to tidy
up.
2005-09-20 : toward version 2.1.5
- removed compilation.conf, included in ./configure
- added tooltips on radio buttons in editor
- cosmetic changes in showing license in editor
- changed ngstar2 occurences to ngstar in README
- set default CFLAGS according to default values in ./configure so
when it's called without arguments everything is ready to compile.
- reformatted --help message in ./configure
- added --{with,without}-{fltk2,ncurses} options to ./configure
- by default if you disable fltk2 in ./configure editor is not
built unless you ask for it explicitly with --enable-editor
- typo in ./configure --help
- typo in src/Fltk2_UI.cc
2005-09-18 : toward version 2.1.5
- configure script now print what has been configured
- typo in configure
- adjust permissions when installing
- set the right ownership & strip binaries in ngstar.SlackBuild
2005-08-30 : toward version 2.1.5
- changed score calculus : nbMoves*100 + nbSeconds. The _lower_
the better.
2005-08-20 : version 2.1.4
- added a Slackware's package creation script : ngstar.SlackBuild
USAGE : Be sure to have in the same directory
ngstar-<version>-src.tar.bz2 and ngstar.SlackBuild , then edit
ngstar.SlackBuild to edit VERSION=<version>. Then, as root, execute the
script. The created package is created in /tmp/
- new method EditorBoard::clear( ) that LevelMaker_UI calls instead
of doing the job itself. Thus harcoded char values of cells are in less
files
- #define's for cells' char values in libngstar2/tools.hh
- compilation.conf : fixed application name (ngstar instead of ngstar2)
- tools.cc : count_file_in_dir skipfiles which filenames ends with ~
2005-08-13 : version 2.1.3
- fixed a typo in Exceptions.hh to print the strings and not their
address in memory
2005-08-11 : version 2.1.2
- Scores almost finished, just need to find a good way to compute
score from nb_moves & duration to complete level.
- got rid of all those Cish malloc()s
- now fltk2 gui & level editor windows are resizable
2005-08-10 : version 2.1.1
- moved levelsets & themes in datas dir
- now EditorBoard inherit from Board
- you now can create levelsets from the level editor. They're created
as $HOME/.ngstar/levelsets/<new_levelset> so you must have a valid
$HOME/.ngstar before.
- building leveleditor don't depend on building fltk2 gui
2005-08-09 : version 2.1.0
- release time
2005-08-08 : version 2.1.0-RC1
- LevelMaker fully functionnal
- added NGStar2::load_level( const char *filename ) for LevelMaker
- merged LevelMaker in the all-in-one binary ( => src/ ).
Run ngstar-editor(_static) to use it.
2005-08-07 : version 2.0.0-RC2
- fine-tuned mouse click position
2005-08-05 : version 2.0.0-RC2
- libngstar2/NGStar2.hh : made set_cell() public for the level editor
- began working on level editor (LevelMaker)
- fixed a nasty bug in fltk2 gui that made it segfault when the window
lost focus then got it again
2005-08-05 : version 2.0.0-RC1
- use $HOME/.ngstar instead of $HOME/.ngstar2 to be compatible with
NGStar(1).
- release time :)
2005-08-03/04 : version 2.0.0-RC1 or How can a sleepless night in the heat of
Hanoï can greatly improve your productivity (assuming you have
near nothing left to read and foreign language bookshops are
next to none in the town, you've watched all your DVDs, only
programming save you from boredom)
- ncurses gui : moved main loop into Ncurses_UI::run()
- moved the two GUIs into one binary. Which one is showed is
determined at runtime by looking at the name of the command (argv[0]).
The test look for either "fltk" or "x" or "X" in the name to determine
if the fltk2 gui is to be runned. If neither is found then if compiled
in it run the ncurses gui.
- Themes and levelsets are searched in $PREFIX/share/ngstar2/ and
$HOME/.ngstar/ and ./ . In fltk2 gui all themes and levelsets found in
these three places are put in the corresponding ComboBox.
- updated README
- added destructor to NGStar2 to free NGStar2::board
- fixed fltk2 gui static compilation (at least it works for me)
- items in Fltk2_UI::l_* are now unique. Beware that if differents
levelsets/themes have the same name only one will be available and that
will be the first found in (in order) default/config path, then
$HOME/.ngstar/* and finally ./ . It means that if you make your own
theme in $HOME/.ngstar/themes/ and give it the same name that one in
in $PREFIX/share/ngstar2/themes then yours won't be available (same for
levelsets).
- Fltk2_UI::l_levelsets & Fltk2_UI::l_themes properly showing current
value.
- Board & Fltk2_UI : fixed late refresh controls.
- fixed a bug in Configuration::set_theme : wouldn't set themes_path
to the new found value.
- if $HOME/.ngstar don't exist Configuration no longer try to create a
default one (code is buggy and this behaviour is a bit too intrusive
anyway). Thus, $HOME/.ngstar become optional.
- added the option -c / --create-default-config. When called it will
create a $HOME/.ngstar/ with default values in config, empty
levelsets/ (and empty themes/ if fltk2 gui was compiled).
- fltk2 gui now handled ngstar2 exceptions.
- disabled making ngstar2.fltk2_static since it's broken.
- fixed bug in NGStar2::read_*_level. now it throw an exception if
the level file is shorter than expected.
- I don't remember exactly when I did it but make install now use a
DESTDIR variable.
- fixed a typo in configure causing Makefile.config to grow over and
over.
- fixed DESTDIR / PREFIX / prefix so make install works
- Board.cc : redraw the board before showing the end-of-levelset
message.
- fixed a typo in libngstar2/Makefile that made make static fail if
make clean was called just before
- replaced {Configuration,NGStar2}::DEBUG_* by overloading operator<<
- fixed bug in Configuration : always started at level 1
2005-08-02 : version 0.4.0
- fltk2 gui finished, now time to debug it
- added or updated GPL notice on sources
2005-07-31 : version 0.3.0
- working on fltk2 gui
2005-07-29 : version 0.2.0
- worked on ncurses gui, considering it finished by now
2005-07-28 : version 0.1.2
- exceptions overload << operator to self what they are
2005-07-27 : version 0.1.2
- moved all logic to libngstar2, now GUIs do only what they should
that handle the interaction with the player
2005-07-23 : version 0.1.1
- solved int to string conversion issue
- fixed bug in NGStar2::read_gsl_level & NGStar2::read_level
- ncurses gui converted to libngstar2
2005-07-22 : version 0.1.1
- started converting ncurses gui to libngstar2
2005-07-21 : version 0.1.0
- fixed Makefile so themes are not installed if fltk2 is disabled
- code make-up in libngstar2
2005-07-20 : NGStar2 version 0.1.0
- started a separate project for NGStar2 including fltk2 gui and
rewriting libngstar into C++
- NGStar(1) is left as this and release as version 1.4.0
- moved Configuration and (in the future) Scores to libngstar
*******************************************************************************
2005-07-21 : version 1.3.5-beta3
- fltk2 gui transferred to new project NGStar2
- fixed Makefile so it don't install themes when fltk GUI is not built
2005-07-07 : version 1.3.5-beta3
- cleaned-up some code
2005-04-25 : version 1.3.5-beta2
- make archive now run ./configure --enable-fltk --enable-ncurses before
building.
2005-02-26 : version 1.3.5beta1
- Added a "so-called" configure script. See ./configure --help for
more informations.
2005-02-17 : version 1.3.5beta1
- Added USE_FLTK & USE_NCURSES in Makefile.config so you can choose
what to build (see comments in Makefile.config)
- Makefiles works as exepected
- fixed ncurses_static compilation
2005-02-16 : version 1.3.5beta1
- "Modularizing" Makefile(s) : now each subdirectory has its own
Makefile and the "main" Makefile just call them.
/!\ ncurses_static target broken /!\
2005-02-11 : version 1.3.4.1
- Modified Makefile to produce two kind of archive : with and without
binaries.
- BUG : Configuration.hh didn't found ngstar.h
2005-02-10 : version 1.3.4
- Release often they say, so maybe it's time for 1.3.4 so here it is ;)
- made ngstar_count_files_in_dir( const char* ) available in ngstar.h
- BUG : throwed an exception if themes/levelsets directory existed
but was empty.
2005-01-25 : version 1.3.4beta7
- began scores calculation & storing ( GUIs/common/Scores.* )
2005-01-19 : version 1.3.4beta6
- small cosmetic changes
2005-01-18 : version 1.3.4beta6
- added time-to-complete-level computation in ncurses GUI
2005-01-08 : version 1.3.4beta6
- ncurses GUI now *really* uses configuration file.
- BUG : wouldn't exit ncurses GUI when last level was finished.
2005-01-05 : version 1.3.4beta6
- functional C++ification of ncurses GUI. It now uses the same
configuration file as fltk GUI ($HOME/.ngstar/config)
2005-01-03 : version 1.3.4beta5
- BUG : ncurses GUI, number of moves wasn't initialized on level
restart
- added GPL notice in GUIs/common/Configuration.*
- small cosmetic changes
- unified Changelog's dates format
2005-01-02 : version 1.3.4beta5
- began translation of ncurses GUI in C++ so it can share more code
with fltk GUI (see GUIs/common/* )
2004-12-16 : version 1.3.4beta5
- changed libngstar/ngstar.h in a more C++ compliant way.
- move Configuration class from GUIs/fltk to GUIs/common
- moved some #define into GUIs/common/config.h
2004-12-11 : version 1.3.4beta4
- added time-to-complete-level computation in fltk GUI
2004-12-06 : version 1.3.4beta4
- automatically create subdirectories levelsets & themes under
$HOME/.ngstar
- clean-up code in libngstar
- added ngstar_check_dir_existence() into libngstar
2004-12-05 : version 1.3.4beta4
- BUG : didn't look in ./levelsets when openining a level
- look for themes & levelsets in $HOME/.ngstar/{themes,levelsets}
2004-12-04 : version 1.3.4beta3
- Added 'static' to Makefile to compile statically linked binaries.
2004-12-02 : version 1.3.4beta2
- new class Configuration to handle configuration file & commandline
parameters
- configuration file in $HOME/.ngstar/config :
LevelSetsPath = <path to levelsets>
ThemesPath = <path to themes>
LevelSet = <name of levelset>
Theme = <name of theme>
if ngstar can't find it it will create one with default values.
2004-12-02 : version 1.3.4beta1
- README fixs (even this one get bugfixes !)
- fallback to current directory if themes & levelsets are not found
in PREFIX thus allowing user to test before install.
(thanks Denilson F. de Sá)
- fixed a typo in libngstar/ngstar.h
2004-11-27 : version 1.3.3
- better arguments parsing
2004-11-25 : version 1.3.3
- Exterminated a nasty bug introduced on 2004-11-04 in ngstar_set_levelset (libngstar)
2004-11-24 : version 1.3.3
- added moves counting to Ncurses GUI
- dropped GLUT GUI
2004-11-23 : version 1.3.3
- corrected Makefile bugs
2004-11-04 : version 1.3.2
- cleanup char* handling
2004-09-28 : version 1.3.2
- new theme cyco001
2004-09-21 : version 1.3.1
- corrected tarballs paths, now it detar in NGStar instead of
home/cycojesus/...
- default PREFIX to /usr/local/instead of /usr/local/stow/...
- default GUI to FLTK, GLUT and NCurses made optional :
make <glut/ncurses>
make <glut/ncurses>_install
make <glut/ncurses>_uninstall
make <glut/ncurses>_clean
make <glut/ncurses>_real-clean
- Added a section in README about theme design
- levels & themes now install in $PREFIX/share/ngstar/ instead of
$PREFIX/share/ngstar-<version>/
2004-09-20 : version 1.3.0
- added possibility to play using the mouse in FLTK GUI
2004-08-04 : version 1.2.0
- resolved compilation problem between libngstar.so and FLTK GUI
- integrate FLTK GUI
2004-01-25 : version 1.0.0
- clean-up in directory architecture of sources
2004-01-16 : version 0.1.1
- cosmetic in Makefile
2003-12-30 : version 0.1.1
- small bug : didn't selected the ball when restarting a level
2003-10-20 : version 0.1.0
- cosmetics in Ncurses GUI
2003-10-19 : version 0.1.0
- new Ncurses GUI that I think justify the version number's jump :D
- big Makefile clean-up
2003-10-17 : version 0.0.5
- moved levelset handling from glut_gui to ngstar_engine
2003-10-16 : version 0.0.4
- moved ngstar_engine to an external librairy (libngstar.so)
- program end nicely (not on error) when you finish all levels of a levelset
- wrote a small description of the API in 'ngstar-API'
2003-10-15 : version 0.0.4
- upper limit for levels
2003-09-13 : version 0.0.3
- not yet released because of procrastination
- added 'n' and 'p' keys to go to next and previous level

1
LICENSE Symbolic link
View file

@ -0,0 +1 @@
COPYING

144
Makefile Normal file
View file

@ -0,0 +1,144 @@
# Makefile
#
# Copyright (C) 2003, 2004, 2005, 2006 Gwenhael LE MOINE
#
# This file is part of NGStar2
#
# NGStar2 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 2 of the License, or
# (at your option) any later version.
#
# NGStar2 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 NGStar2; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
include Makefile.config
SUBDIRS = libngstar2 src
SUBDIRS2 = datas/levelsets
ifdef USE_FLTK2
SUBDIRS2 += datas/themes
else
ifdef BUILD_EDITOR
SUBDIRS2 += datas/themes
endif
endif
#~~~~~~~~~~~~~~~~~~#
#~~ Meta-targets ~~#
#~~~~~~~~~~~~~~~~~~#
all:
ifdef STATIC
for dir in $(SUBDIRS); do \
echo "=== making $$dir ===";\
$(MAKE) -C $$dir static; \
done
else
for dir in $(SUBDIRS); do \
echo "=== making $$dir ===";\
$(MAKE) -C $$dir all; \
done
endif
install:
ifdef STATIC
for dir in $(SUBDIRS); do \
echo "=== installing $$dir ===";\
$(MAKE) -C $$dir install_static; \
done
else
for dir in $(SUBDIRS); do \
echo "=== installing $$dir ===";\
$(MAKE) -C $$dir install; \
done
endif
for dir in $(SUBDIRS2); do \
echo "=== installing $$dir ===";\
$(MAKE) -C $$dir install; \
done
uninstall:
ifdef STATIC
for dir in $(SUBDIRS); do \
echo "=== uninstalling $$dir ===";\
$(MAKE) -C $$dir uninstall_static; \
done
else
for dir in $(SUBDIRS); do \
echo "=== uninstalling $$dir ===";\
$(MAKE) -C $$dir uninstall; \
done
endif
for dir in $(SUBDIRS2); do \
echo "=== uninstalling $$dir ===";\
$(MAKE) -C $$dir uninstall; \
done
clean:
-rm -f $(WD)/*~ $(WD)/.kdbg*
for dir in $(SUBDIRS); do \
echo "=== cleaning $$dir ===";\
$(MAKE) -C $$dir clean; \
done
for dir in $(SUBDIRS2); do \
echo "=== cleaning $$dir ===";\
$(MAKE) -C $$dir clean; \
done
real-clean:
$(MAKE) clean
for dir in $(SUBDIRS); do \
echo "=== real-cleaning $$dir ===";\
$(MAKE) -C $$dir real-clean; \
done
for dir in $(SUBDIRS2); do \
echo "=== real-cleaning $$dir ===";\
$(MAKE) -C $$dir real-clean; \
done
archive:
$(MAKE) archive_bin_dynamic archive_src
archive_bin_dynamic:
echo "=== building archive with dynamic binary ===";
./configure --prefix $(prefix)
$(MAKE) real-clean
$(MAKE)
$(MAKE) clean
cd ..; \
mv $(WD) $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION) ) ; \
tar jcf $(join $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION)-bin), .tar.bz2) $(join $(shell basename $(WD)), -$(MAJOR).$(MINOR).$(REVISION) ); \
tar zcf $(join $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION)-bin), .tar.gz) $(join $(shell basename $(WD)), -$(MAJOR).$(MINOR).$(REVISION) ); \
mv $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION) ) $(WD) ; \
cd $(WD)
archive_bin_static:
echo "=== building archive with static binary ===";
./configure --with-fltk2 --with-ncurses --enable-editor --enable-static --prefix $(prefix)
$(MAKE) real-clean
$(MAKE)
$(MAKE) clean
cd ..; \
mv $(WD) $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION) ) ; \
tar jcf $(join $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION)-bin_static), .tar.bz2) $(join $(shell basename $(WD)), -$(MAJOR).$(MINOR).$(REVISION) ); \
tar zcf $(join $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION)-bin_static), .tar.gz) $(join $(shell basename $(WD)), -$(MAJOR).$(MINOR).$(REVISION) ); \
mv $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION) ) $(WD) ; \
cd $(WD)
archive_src:
echo "=== building source-only archive ===";
$(MAKE) real-clean
cd ..; \
mv $(WD) $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION) ) ; \
tar jcf $(join $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION)-src), .tar.bz2) $(join $(shell basename $(WD)), -$(MAJOR).$(MINOR).$(REVISION) ); \
tar zcf $(join $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION)-src), .tar.gz) $(join $(shell basename $(WD)), -$(MAJOR).$(MINOR).$(REVISION) ); \
mv $(join $(WD), -$(MAJOR).$(MINOR).$(REVISION) ) $(WD) ; \
cd $(WD)

55
Makefile.config Normal file
View file

@ -0,0 +1,55 @@
prefix ?= /usr
USE_FLTK2 = 1
USE_NCURSES = 1
BUILD_EDITOR = 1
#INSTALL_DEV is not set
#STATIC is not set
CPPFLAGS += -D '_USE_FLTK2_ = 1'
CPPFLAGS += -D '_USE_NCURSES_ = 1'
CPPFLAGS += -D '_BUILD_EDITOR_ = 1'
######## THERE IS NO SERVICABLE PARTS BELOW THIS LINE ########
WD = $(shell pwd)
INSTALL = cp -d
DESTIR=
PREFIX ?= $(DESTDIR)$(prefix)
CC = gcc -Wall --pedantic-errors -Wstrict-prototypes
CXX = g++ -Wall --pedantic-errors
AR=ar rcs
CCOPTIMISATION += -O3 -funroll-loops -mtune=i686 -march=i486
CPPFLAGS += -D 'APPLICATION_VERSION="$(NAME) $(MAJOR).$(MINOR).$(REVISION)"' -D 'LEVELSETS_PATH="$(LEVELSETS_DIR)"'
ifdef USE_FLTK2
CPPFLAGS += -D 'THEMES_PATH="$(THEMES_DIR)"'
else
ifdef BUILD_EDITOR
CPPFLAGS += -D 'THEMES_PATH="$(THEMES_DIR)"'
endif
endif
NAME = ngstar
MAJOR = 2
MINOR = 1
REVISION = 9
LEVELSETS_DIR = $(PREFIX)/share/$(NAME)/levelsets
THEMES_DIR = $(PREFIX)/share/$(NAME)/themes
BIN_DIR = $(PREFIX)/bin
DOC_DIR = $(PREFIX)/doc/$(NAME)-$(MAJOR).$(MINOR).$(REVISION)
LIB_DIR = $(PREFIX)/lib
INCLUDES_DIR = $(PREFIX)/include/ngstar2
.PHONY : clean real-clean install uninstall all archive archive_src archive_bin_dynamic archive_bin_static
.cc.o:
echo Compiling $<...
$(CXX) -I.. $(CPPFLAGS) -c $<
# Be quiet when building...
.SILENT:

124
README Normal file
View file

@ -0,0 +1,124 @@
NGStar by Cycojesus (cycojesus_AT_yahoo_DOT_fr)
1/ Compilation & installation
1.1/ Configuration file
2/ How to play
3/ Level design
4/ That's it
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1/ Compilation & installation
-----------------------------
To compile you'll need : a decent C++ compiler (tested with gcc 3.3.x and 3.4.x) and FLTK2
(http://www.fltk.org) and/or Ncurses.
Then :
./configure --help
./configure with the options you chose at the previous step
make
su (if you need it)
make install
(x)ngstar --help
(x)ngstar --create-default-config (optional but recommended, see below)
1.1/ Configuration file
-----------------------
From version 1.3.4beta2 you can configure ngstar from a configuration
file in your home directory : $HOME/.ngstar/config This file have the
following form (case sensitive !) :
LevelSetsPath = <path to levelsets>
ThemesPath = <path to themes>
LevelSet = <name of levelset>
Theme = <name of theme>
CurrentLevel = <number of level>
executing (x)ngstar with option -c (--create-default-config)will create
one with default values that you can't adjust later.
2/ How to play
--------------
The goal is to catch all gifts in the level to get access to the next one.
Use the ball to catch them, use the cube to stop the ball. The ball only
move to the next obstacle (wall or cube).
options are :
(x)ngstar [options]
-v --version :
show version
-h --help :
what you are reading
-l<levelset> --levelset=<levelset> :
use a different levelset (default: "default")
-t<theme> --theme=<theme> : (xngstar only)
use a different theme (default: "default")
-w<n> --wrap=<n> :
wrap to level n
during the game keys are :
* 'space' to select the thing to move, ball or cube
* arrows to move
* 'n' to go to the next level
* 'p' to go to the previous level
* 'r' to restart the current level
* 'q' or Escape to quit the game
or you an use the mouse (or stylus on a pda)
the ball can 'eat' the gifts (losanges), the cube 'eats' nothing but it
will help you stopping the ball.
3/ Level designing
------------------
Use xngstar-editor(_static) or if you really want to do it manually (for
instance if you don't have fltk2 installed) see below :
a level file is composed by 144 cells
cell types:
W : wall
C : cube
B : ball
G : gift
' ' (space) : empty
example:
the level
WWWWWWWWWWWWWWWW
WWWGGGGGGGGGGWWW
W WW B WW W
W WW WW W
W W
W WW WW W
W WW C WW W
WWW WWW
WWWWWWWWWWWWWWWW
is stored like this in the file (no carriage return):
WWWWWWWWWWWWWWWWWWWGGGGGGGGGGWWWW WW B WW WW WW WW WW WW WW WW WW WW C WW WWWW WWWWWWWWWWWWWWWWWWW
levels are groupped in a levelset. A levelset is a directory containing level files
named 1 2 3 .. n. Each file contain one level. Usermade levelsets are stored in $HOME/.ngstar/levelsets/
You can play a specific levelset using the -l<levelset_name> or --levelset=<levelset_name> option or by modifying your config file or if playing with xngstar change from the combo box.
You can also play gstar levels, just rename files to make a levelset
4/ Theme design
---------------
A theme is made of a directory containing 7 (seven) 20x20pixels image files :
tex_ball.png : texture used for the ball
tex_ball_selected.png : texture used for the ball when selected
tex_cube.png : texture used for the cube
tex_cube_selected.png : texture used for the cube when selected
tex_empty.png : texture used for empty spaces
tex_wall.png : texture used for the walls
tex_gift.png : texture used for the little things you have to catch
Usermade themes goes in $HOME/.ngstar/themes/<name of your theme>/
You can use a specific theme using the -t<theme_name> or --theme=<theme_name> option or by modifying your config file.
5/ That's it
------------
Nice game ;)

86
Slackware/ngstar.SlackBuild Executable file
View file

@ -0,0 +1,86 @@
#!/bin/sh
TMP=/tmp
CWD=`pwd`
PKG=$TMP/package-ngstar
rm -rf $PKG
mkdir -p $PKG
VERSION=2.1.9
ARCH=${ARCH:-i486}
BUILD=1cyco
# unpacking archive
cd $TMP
rm -rf ngstar-$VERSION
tar xjvf $CWD/ngstar-$VERSION-src.tar.bz2
cd ngstar-$VERSION
chown -R root.root .
# configuring
./configure \
--enable-ncurses \
--enable-fltk2 \
--enable-editor \
--prefix /usr \
# --install-dev \ #<- intentionaly commented
# --enable-static \ #<- intentionaly commented
# building
make
# installing to temporary directory
make install DESTDIR=$PKG
# tidy up permissions and ownership, installing documentation, stripping binaries
chown -R root.bin $PKG/usr/bin
mkdir -p mkdir -p $PKG/usr/doc/ngstar-$VERSION
cp -a \
AUTHORS Changelog COPYING README TODO \
$PKG/usr/doc/ngstar-$VERSION
chown -R root:root $PKG/usr/doc/ngstar-$VERSION/*
chmod 0644 $PKG/usr/doc/ngstar-$VERSION/*
chown root:bin $PGK/usr/bin/*
chmod 0755 $PGK/usr/bin/*
# chown root:bin $PGK/usr/lib/* #<- uncomment if building with --install-dev
# chmod 0755 $PGK/usr/lib/* #<- uncomment if building with --install-dev
# chmod 0644 $PKG/usr/include/ngstar/* #<- uncomment if building with --install-dev
chown -R root:root $PKG/usr/share
for i in $PKG/usr/share/ngstar/levelsets/* ; do
chmod 0644 $i/* ;
done
for i in $PKG/usr/share/ngstar/themes/* ; do
chmod 0644 $i/* ;
done
strip -s $PKG/usr/bin/*
# writing the two files that makes the future tgz a genuine slackware package
mkdir -p $PKG/install
cat <<EOF > $PKG/install/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.
|-----handy-ruler------------------------------------------------------|
ngstar: ngstar (reflection/puzzle game)
ngstar:
ngstar:
ngstar: The goal is to catch all gifts (<>) in the level to get access to the
ngstar: next one. Use the ball (()) to catch them, use the cube ([]) to stop
ngstar: the ball. The ball only move to the next obstacle (wall or cube).
ngstar: It comes with ncurses UI (ngstar), fltk2 GUI (xngstar) and a fltk2
ngstar: level editor (xngstar-editor).
ngstar:
ngstar: Please read /usr/doc/ngstar/README for more details.
ngstar:
EOF
# building the package
cd $PKG
makepkg -l y -c n $TMP/ngstar-$VERSION-$ARCH-$BUILD.tgz
# that's it ;)

8
TODO Normal file
View file

@ -0,0 +1,8 @@
BUGS :
- score not good (often displayed as -1...)
- Please report to cycojesus__¬AT¬__yahoo__¬DOT¬__fr if you find one
FEATURES :
- check availability of ncurses and/or fltk2 in ./configure
? accept any filename for levels (load the name in a linked list maybe)
- internationalization

213
configure vendored Executable file
View file

@ -0,0 +1,213 @@
#!/bin/sh
VMAJOR=2
VMINOR=1
VREVISION=9
USER_CONF=Makefile.config
prefix=/usr/local
# default values
BUILD_EDITOR="BUILD_EDITOR = 1"
USE_FLTK2="USE_FLTK2 = 1"
USE_NCURSES="USE_NCURSES = 1"
INSTALL_DEV="#INSTALL_DEV is not set"
CPPFLAGS_FLTK2="CPPFLAGS += -D '_USE_FLTK2_ = 1' "
CPPFLAGS_NCURSES="CPPFLAGS += -D '_USE_NCURSES_ = 1' "
CPPFLAGS_EDITOR="CPPFLAGS += -D '_BUILD_EDITOR_ = 1' "
GCC_OPTIONS=""
STATIC="#STATIC is not set"
DEBUG="no"
PROFILING="no"
# commandline arguments processing
while [ "x$1" != "x" ]
do
case "$1" in
--prefix )
shift
prefix=$1
shift
;;
--enable-fltk2 | --with-fltk2 )
USE_FLTK2="USE_FLTK2 = 1"
CPPFLAGS_FLTK2="CPPFLAGS += -D '_USE_FLTK2_ = 1' "
shift
;;
--disable-fltk2 | --without-fltk2 )
USE_FLTK2="#USE_FLTK2 is not set"
CPPFLAGS_FLTK2=""
BUILD_EDITOR="#BUILD_EDITOR is not set"
CPPFLAGS_EDITOR=""
shift
;;
--enable-ncurses | --with-ncurses )
USE_NCURSES="USE_NCURSES = 1"
CPPFLAGS_NCURSES="CPPFLAGS += -D '_USE_NCURSES_ = 1' "
shift
;;
--disable-ncurses | --without-ncurses )
USE_NCURSES="#USE_NCURSES is not set"
CPPFLAGS_NCURSES=""
shift
;;
--enable-editor )
BUILD_EDITOR="BUILD_EDITOR = 1"
CPPFLAGS_EDITOR="CPPFLAGS += -D '_BUILD_EDITOR_ = 1' "
shift
;;
--disable-editor )
BUILD_EDITOR="#BUILD_EDITOR is not set"
CPPFLAGS_EDITOR=""
shift
;;
--install-dev )
INSTALL_DEV="INSTALL_DEV = 1"
shift
;;
--enable-static )
STATIC="STATIC = 1"
shift
;;
--enable-debug )
DEBUG="yes"
GCC_OPTIONS=$(echo $GCC_OPTIONS" -g")
shift
;;
--enable-profiling )
PROFILING="yes"
GCC_OPTIONS=$(echo $GCC_OPTIONS" -pg")
shift
;;
--help | -h | * )
echo "--help | -h : What you're reading at this very moment"
echo ""
echo "--prefix /prefix : Set a specific location to install (default: /usr/local)"
echo ""
echo "--with-fltk2 : enable building FLTK2 (www.fltk.org) GUI (default: yes)"
echo "--with-ncurses : enable building Ncurses GUI (default: yes)"
echo "--enable-editor : enable building level editor (default: yes)"
echo ""
echo "--without-fltk2 : disable building FLTK2 GUI"
echo "--without-ncurses : disable building Ncurses GUI"
echo "--disable-editor : disable building level editor"
echo ""
echo "--install-dev : install headers static & shared libraries (default: no)"
echo "--enable-static : compile statically linked binaries (default: no)"
echo "--enable-debug : compile with debug symbols (default: no)"
echo "--enable-profiling: compile with profiling support (default: no)"
exit
;;
esac
done
# Informing the user of what will be set
echo "ngstar configuration :"
echo " prefix : $prefix"
echo -n " build editor : "
if [ "$BUILD_EDITOR" == "BUILD_EDITOR = 1" ] ; then
echo "yes"
else
echo "no"
fi
echo -n " build fltk2 gui : "
if [ "$USE_FLTK2" == "USE_FLTK2 = 1" ] ; then
echo "yes"
else
echo "no"
fi
echo -n " build ncurses gui : "
if [ "$USE_NCURSES" == "USE_NCURSES = 1" ] ; then
echo "yes"
else
echo "no"
fi
echo -n " install dev tools : "
if [ "$INSTALL_DEV" == "INSTALL_DEV = 1" ] ; then
echo "yes"
else
echo "no"
fi
echo -n " compile static binaries : "
if [ "$STATIC" == "STATIC = 1" ] ; then
echo "yes"
else
echo "no"
fi
echo -n " compile with debug symbols: "
if [ "$DEBUG" == "yes" ] ; then
echo "yes"
else
echo "no"
fi
echo -n " compile with profiling : "
if [ "$PROFILING" == "yes" ] ; then
echo "yes"
else
echo "no"
fi
# Write the config file
echo "prefix ?= $prefix" > $USER_CONF
echo $USE_FLTK2 >> $USER_CONF
echo $USE_NCURSES >> $USER_CONF
echo $BUILD_EDITOR >> $USER_CONF
echo $INSTALL_DEV >> $USER_CONF
echo $STATIC >> $USER_CONF
echo $CPPFLAGS_FLTK2 >> $USER_CONF
echo $CPPFLAGS_NCURSES >> $USER_CONF
echo $CPPFLAGS_EDITOR >> $USER_CONF
cat <<EOF >> $USER_CONF
######## THERE IS NO SERVICABLE PARTS BELOW THIS LINE ########
WD = \$(shell pwd)
INSTALL = cp -d
DESTIR=
PREFIX ?= \$(DESTDIR)\$(prefix)
CC = gcc $GCC_OPTIONS -Wall --pedantic-errors -Wstrict-prototypes
CXX = g++ $GCC_OPTIONS -Wall --pedantic-errors
AR=ar rcs
CCOPTIMISATION += -O3 -funroll-loops -mtune=i686 -march=i486
CPPFLAGS += -D 'APPLICATION_VERSION="\$(NAME) \$(MAJOR).\$(MINOR).\$(REVISION)"' -D 'LEVELSETS_PATH="\$(LEVELSETS_DIR)"'
ifdef USE_FLTK2
CPPFLAGS += -D 'THEMES_PATH="\$(THEMES_DIR)"'
else
ifdef BUILD_EDITOR
CPPFLAGS += -D 'THEMES_PATH="\$(THEMES_DIR)"'
endif
endif
NAME = ngstar
MAJOR = $VMAJOR
MINOR = $VMINOR
REVISION = $VREVISION
LEVELSETS_DIR = \$(PREFIX)/share/\$(NAME)/levelsets
THEMES_DIR = \$(PREFIX)/share/\$(NAME)/themes
BIN_DIR = \$(PREFIX)/bin
DOC_DIR = \$(PREFIX)/doc/\$(NAME)-\$(MAJOR).\$(MINOR).\$(REVISION)
LIB_DIR = \$(PREFIX)/lib
INCLUDES_DIR = \$(PREFIX)/include/ngstar2
.PHONY : clean real-clean install uninstall all archive archive_src archive_bin_dynamic archive_bin_static
.cc.o:
echo Compiling \$<...
\$(CXX) -I.. \$(CPPFLAGS) -c \$<
# Be quiet when building...
.SILENT:
EOF

18
datas/levelsets/Makefile Normal file
View file

@ -0,0 +1,18 @@
include ../../Makefile.config
LEVELSETS = cyco g-star
install :
install -m 0755 -d $(LEVELSETS_DIR)
$(INSTALL) -R $(LEVELSETS) $(LEVELSETS_DIR)
chmod -R 0755 $(LEVELSETS_DIR)
for i in $(LEVELSETS) ; do chmod 0644 $(LEVELSETS_DIR)/$$i/* ; done
uninstall :
-rm -fr $(LEVELSETS_DIR)
clean :
-rm *~ cyco/*~ g-star/*~
# for dir in $(LEVELSETS); do \
# rm $$dir/*~; \
# done

1
datas/levelsets/cyco/1 Normal file
View file

@ -0,0 +1 @@
WWWWWWWWWWWWWWWWWWWGGGGGGGGGGWWWW WW B WW WW WW WW WW WW WW WW WW WW C WW WWWW WWWWWWWWWWWWWWWWWWW

1
datas/levelsets/cyco/2 Normal file
View file

@ -0,0 +1 @@
WWWWWWWWWWWWWWWWWBGGGGGGGGGGGGCWWGGGGGGGGGGGGGGWWGGGGGGGGGGGGGGWWGGGGGGGGGGGGGGWWGGGGGGGGGGGGGGWWGGGGGGGGGGGGGGWWGGGGGGGGGGGGGGWWWWWWWWWWWWWWWWW

1
datas/levelsets/cyco/3 Normal file
View file

@ -0,0 +1 @@
WWWWWWWWWWWWWWWWWGGWG GW WGGWC WW WGGW W W WGGG WW W WGGWG GW W W WGGWWWWWWWWW W W WGG BW W W W WWWWWWWWW

1
datas/levelsets/cyco/4 Normal file
View file

@ -0,0 +1 @@
W G W B G GW W G W C W

1
datas/levelsets/cyco/5 Normal file
View file

@ -0,0 +1 @@
W W W G G G G BC G G W W

1
datas/levelsets/cyco/6 Normal file
View file

@ -0,0 +1 @@
WWWWWWWWWWWWWWWWW WWW G G WW G G G WW BGW WGC WW G G G WW G G WWW WWWWWWWWWWWWWWWWW

BIN
datas/levelsets/g-star/1 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/10 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/11 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/12 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/13 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/14 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/15 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/16 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/17 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/18 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/19 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/2 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/20 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/21 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/22 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/23 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/24 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/25 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/3 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/4 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/5 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/6 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/7 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/8 Normal file

Binary file not shown.

BIN
datas/levelsets/g-star/9 Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

15
datas/themes/Makefile Normal file
View file

@ -0,0 +1,15 @@
include ../../Makefile.config
THEMES = cyco001 cyco002 HP48 inversed
install :
install -m 0755 -d $(THEMES_DIR)
$(INSTALL) -R $(THEMES) $(THEMES_DIR)
chmod -R 0755 $(THEMES_DIR)
for i in $(THEMES) ; do chmod 0644 $(THEMES_DIR)/$$i/* ; done
uninstall :
-rm -fr $(THEMES_DIR)
clean :
-rm *~ cyco001/*~ cyco002/*~ HP48/*~ inversed/*~

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 945 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

BIN
gtkmm/a.out Executable file

Binary file not shown.

12
gtkmm/test.cc Normal file
View file

@ -0,0 +1,12 @@
#include <gtkmm.h>
int main( int argc, char* argv[] )
{
Gtk::Main kit( argc, argv);
Gtk::Window w_main;
Gtk::Main::run( w_main );
return 0;
}

309
libngstar2/Configuration.cc Normal file
View file

@ -0,0 +1,309 @@
/*
* Configuration.cc
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "Configuration.hh"
namespace ngstar2 {
Configuration::Configuration( int argc, char* argv[] )
{
ifstream file;
this->levelsets_path = new string( LEVELSETS_PATH );
this->levelset = new string( "g-star" );
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
this->themes_path = new string( THEMES_PATH );
this->theme = new string( "cyco002" );
#endif
this->fileName = new string( getenv( "HOME" ) );
this->fileName->append( "/.ngstar/config" );
this->set_level( 1 );
#ifdef _USE_NCURSES_
this->black_and_white = 0;
#endif
cerr << "Default values setted" << endl;
// test if ~/.ngstar/config exists
file.open( this->fileName->c_str(), ios::in );
if ( file != NULL ) { // if yes, read it
file.close( );
file.clear( );
this->read( );
cout << "configuration file LOADED" << endl;
}
this->parse_args( argc, argv );
this->set_levelset( this->levelset );
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
this->set_theme( this->theme );
#endif
}
void Configuration::read()
{
ifstream file;
char *a, *egal, *b;
file.open( this->fileName->c_str( ), ios::in );
do {
a = (char*)malloc( strlen( "LevelSetsPath" ) + 1 );
egal = (char*)malloc( 2 );
b = (char*)malloc( 1024 );
file >> a >> egal >> b;
if ( ( new string( "LevelSetsPath" ) )->compare( a ) == 0 ) {
this->levelsets_path = new string( b );
} else
if ( ( new string( "LevelSet" ) )->compare( a ) == 0 ) {
this->levelset = new string( b );
} else
if ( ( new string( "CurrentLevel" ) )->compare( a ) == 0 ) {
this->set_level( atoi( b ) );
}
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
else
if ( ( new string( "ThemesPath" ) )->compare( a ) == 0 ) {
this->themes_path = new string( b );
} else
if ( ( new string( "Theme" ) )->compare( a ) == 0 ) {
this->theme = new string( b );
}
#endif
#ifdef _USE_NCURSES_
else
if ( ( new string( "black_and_white" ) )->compare( a ) == 0 ) {
this->black_and_white = atoi( b );
}
#endif
free( a );
free( egal );
free( b );
} while( !file.eof( ) );
file.close( );
file.clear( );
}
void Configuration::write()
{
ofstream file;
file.open( this->fileName->c_str( ), ios::out );
file << this << endl;
file.close( );
file.clear( );
}
void Configuration::create_default()
{
string *strtmp = new string( getenv( "HOME" ) );
strtmp->append( "/.ngstar" );
// test if directory ~/.ngstar exists
if ( check_dir_existence( strtmp->c_str( ) ) == false ) {
string* strtmp2;
mkdir( strtmp->c_str( ), S_IRWXO | S_IRWXG | S_IRWXU );
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
strtmp2 = new string( strtmp->c_str( ) );
strtmp2->append( "/themes" );
mkdir( strtmp2->c_str( ), S_IRWXO | S_IRWXG | S_IRWXU );
#endif
strtmp2 = new string( strtmp->c_str( ) );
strtmp2->append( "/levelsets" );
mkdir( strtmp2->c_str( ), S_IRWXO | S_IRWXG | S_IRWXU );
}
this->write( );
}
int Configuration::parse_args( int argc, char* argv[] )
{
int option_index;
char c = '?';
char* optstring = "l:t:w:bchv";
static struct option long_options[] = {
{"levelset", required_argument, NULL, 'l'},
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
{"theme", required_argument, NULL, 't'},
#endif
#ifdef _USE_NCURSES_
{"black-and-white", no_argument, NULL, 'b'},
#endif
{"wrap", required_argument, NULL, 'w'},
{"create-default-config", no_argument, NULL, 'c'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{0, 0, 0, 0}
};
char* help_text = "ngstar [options]\n"
"\t-v --version :\n\t\t show version\n"
"\t-h --help :\n\t\t what you are reading\n"
"\t-c --create-default-config :\n\t\t create $HOME/.ngstar/* with default values\n"
"\t-l<levelset> --levelset=<levelset> :\n\t\t use a different levelset (default: \"default\")\n"
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
"\t-t<theme> --theme=<theme> :\n\t\t use a different theme (default: \"default\")\n"
#endif
#ifdef _USE_NCURSES_
"\t-b --black-and-white :\n\t\t don't use colors (ncurses)\n"
#endif
"\t-w<n> --wrap=<n> :\n\t\t wrap to level n\n";
while(c != EOF) {
c = getopt_long(argc, argv, optstring, long_options, &option_index);
switch(c) {
case 'c' :
this->create_default( );
cout << "Default $HOME/.ngstar created" << endl;
exit( 0 );
break;
case 'v' :
cout << APPLICATION_VERSION << endl;
exit(0);
break;
case 'h' :
cout << help_text << endl;
exit(0);
break;
case 'l' :
this->levelset = new string( optarg );
break;
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
case 't' :
this->theme = new string( optarg );
break;
#endif
#ifdef _USE_NCURSES_
case 'b' :
this->black_and_white = 1;
break;
#endif
case 'w' :
this->set_level( atoi( optarg ) );
break;
case '?' :
case ':' :
exit(0);
break;
default : break;
}
}
if (optind < argc) {
cout << "Invalid arguments : " << endl;
while (optind < argc)
cout << argv[optind++] << endl;
cout << endl;
}
return(optind);
}
//
// If given levelset_name exist sets it as current levelset
//
void Configuration::set_levelset( const string *levelset_name )
{
string *strtmp;
this->levelset = new string( levelset_name->c_str( ) );
cerr << "levelset setted in config" << endl;
strtmp = new string( this->levelsets_path->c_str( ) );
strtmp->append( "/" );
strtmp->append( this->levelset->c_str( ) );
if ( check_dir_existence( strtmp->c_str( ) ) == false ) {
strtmp = new string( "./datas/levelsets/" );
strtmp->append( this->levelset->c_str( ) );
if ( check_dir_existence( strtmp->c_str( ) ) == false ) {
strtmp = new string( getenv( "HOME" ) );
strtmp->append( "/.ngstar/levelsets/" );
strtmp->append( this->levelset->c_str( ) );
if ( check_dir_existence( strtmp->c_str( ) ) == false ) {
throw CannotFindLevelsets( this->levelset );
}
else {
this->levelsets_path = new string( getenv( "HOME" ) );
this->levelsets_path->append( "/.ngstar/levelsets/" );
}
}
else {
this->levelsets_path = new string( "./datas/levelsets/" );
}
}
this->nb_levels = count_files_in_dir( strtmp->c_str( ) );
if ( this->current_level > this->nb_levels )
this->current_level = 1;
cerr << "Levelset " << strtmp->c_str( ) << " LOADED : " << this->nb_levels << " levels" << endl;
}
void Configuration::set_level( int lvl )
{
this->current_level = lvl;
}
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
void Configuration::set_theme( const string *theme_name )
{
string *strtmp;
this->theme = new string( theme_name->c_str( ) );
cerr << "theme setted in config" << endl;
strtmp = new string( this->themes_path->c_str( ) );
strtmp->append( "/" );
strtmp->append( this->theme->c_str( ) );
if ( check_dir_existence( strtmp->c_str( ) ) == false ) {
strtmp = new string( "./datas/themes/" );
strtmp->append( this->theme->c_str( ) );
if ( check_dir_existence( strtmp->c_str( ) ) == false ) {
strtmp = new string( getenv( "HOME" ) );
strtmp->append( "/.ngstar/themes/" );
strtmp->append( this->theme->c_str( ) );
if ( check_dir_existence( strtmp->c_str( ) ) == false ) {
throw CannotFindThemes( this->theme );
}
}
else {
this->themes_path = new string( "./datas/themes/" );
}
}
}
#endif
} // end namespace ngstar2

View file

@ -0,0 +1,94 @@
/*
* Configuration.hh
*
* Copyright (C) 2004, 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __CONFIGURATION_HH__
# define __CONFIGURATION_HH__
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
#include <getopt.h>
#include <sys/stat.h>
#include "Exceptions.hh"
#include "tools.hh"
using namespace std;
namespace ngstar2 {
class Configuration {
private:
string* fileName;
public:
// Levels
int current_level;
int nb_levels;
// Levelsets
string* levelsets_path;
string* levelset;
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
// Themes
string* themes_path;
string* theme;
#endif
#ifdef _USE_NCURSES_
int black_and_white;
#endif
Configuration( int argc, char* argv[] );
void read( );
void write( );
void create_default( );
int parse_args( int argc, char* argv[] );
void set_levelset( const string * );
void set_level( int );
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
void set_theme( const string * );
#endif
friend ostream& operator<<(ostream& os, Configuration* config )
{
os << "levelsets_path = " << config->levelsets_path->c_str( ) << endl;
os << "levelset = " << config->levelset->c_str( ) << endl;
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
os << "themes_path = " << config->themes_path->c_str( ) << endl;
os << "theme = " << config->theme->c_str( ) << endl;
#endif
os << "current_level = " << config->current_level << endl;
#ifdef _USE_NCURSES_
os << "black_and_white = " << config->black_and_white << endl;
#endif
return( os );
}
};
} // end namespace ngstar2
#endif /* __CONFIGURATION_HH__*/

136
libngstar2/Exceptions.hh Normal file
View file

@ -0,0 +1,136 @@
/*
* Exceptions.hh
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __EXCEPTIONS_HH__
# define __EXCEPTIONS_HH__
#include <iostream>
#include <string>
using namespace std;
namespace ngstar2 {
class CannotFindLevelsets {
private:
string *levelset;
public:
CannotFindLevelsets( string *levelset )
{
this->levelset = new string( levelset->c_str( ) );
}
friend ostream& operator<<(ostream& os, CannotFindLevelsets cfl )
{
os << "ERROR : Cannot find where levelset " << (cfl.levelset)->c_str( ) << " !";
return( os );
}
};
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
class CannotFindThemes {
private:
string *theme;
public:
CannotFindThemes( string *theme )
{
this->theme = new string( theme->c_str( ) );
}
friend ostream& operator<<(ostream& os, CannotFindThemes cft )
{
os << "ERROR : Cannot find where theme" << cft.theme->c_str( ) << " !";
return( os );
}
};
#endif
class LoadingLevelException {
friend ostream& operator<<(ostream& os, LoadingLevelException lle )
{
os << "Error Loading level";
return( os );
}
};
class InvalidLevelFile : public LoadingLevelException {
private:
string *levelfile;
public:
// InvalidLevelFile( )
// {
// this->levelfile = new string( "Unspecified level" );
// }
InvalidLevelFile( const string *levelfile )
{
this->levelfile = new string( levelfile->c_str( ) );
}
friend ostream& operator<<(ostream& os, InvalidLevelFile ilf )
{
os << "ERROR : Invalid level file " << ilf.levelfile->c_str( ) << " !";
return( os );
}
};
class InvalidCellValue : public LoadingLevelException {
private:
char cell;
public:
InvalidCellValue( char cell )
{
this->cell = cell;
}
friend ostream& operator<<(ostream& os, InvalidCellValue icv )
{
os << "ERROR : Invalid cell " << icv.cell << " in level file !";
return( os );
}
};
class InvalidCellCoordinates : public LoadingLevelException {
private:
int x;
int y;
public:
InvalidCellCoordinates( int x, int y )
{
this->x = x;
this->y = y;
}
friend ostream& operator<<(ostream& os, InvalidCellCoordinates icc )
{
os << "ERROR : Trying to set a cell outside of board !" << endl;
os << "Invalid coordinates are : ( " << icc.x << " ; " << icc.y << " )";
return( os );
}
};
}
#endif /* __EXCEPTIONS_HH__ */

47
libngstar2/Makefile Normal file
View file

@ -0,0 +1,47 @@
include ../Makefile.config
TOOLS_OBJ = tools.o
NGSTAR2_OBJ = NGStar2.o
CONFIGURATION_OBJ = Configuration.o
SCORES_OBJ = Scores.o
NGSTAR_LIBNGSTAR2_INCLUDE = Configuration.hh Exceptions.hh NGStar2.hh Scores.hh tools.hh
NGSTAR_SHARED_LIB = ../libngstar2.so
NGSTAR_STATIC_LIB = ../libngstar2.a
all :
$(MAKE) $(NGSTAR_STATIC_LIB)
ifdef INSTALL_DEV
$(MAKE) $(NGSTAR_SHARED_LIB)
$(NGSTAR_SHARED_LIB) : $(NGSTAR2_OBJ) $(CONFIGURATION_OBJ) $(TOOLS_OBJ) $(SCORES_OBJ) $(NGSTAR_LIBNGSTAR2_INCLUDE)
$(CXX) -shared -Wl -o $@ $(CPPFLAGS) $(NGSTAR2_OBJ) $(CONFIGURATION_OBJ) $(TOOLS_OBJ) $(SCORES_OBJ)
endif
static :
$(MAKE) all
$(NGSTAR_STATIC_LIB) : $(NGSTAR2_OBJ) $(CONFIGURATION_OBJ) $(TOOLS_OBJ) $(SCORES_OBJ) $(NGSTAR_LIBNGSTAR2_INCLUDE)
$(AR) $@ $(NGSTAR2_OBJ) $(CONFIGURATION_OBJ) $(TOOLS_OBJ) $(SCORES_OBJ)
clean :
-rm -f *~ *.o
real-clean :
$(MAKE) clean
-rm -f $(NGSTAR_STATIC_LIB)
ifdef INSTALL_DEV
-rm -f $(NGSTAR_SHARED_LIB)
install: $(NGSTAR_SHARED_LIB) $(NGSTAR_LIBNGSTAR2_INCLUDE)
mkdir -p $(LIB_DIR)
$(INSTALL) $(NGSTAR_SHARED_LIB) $(LIB_DIR)/
$(INSTALL) $(NGSTAR_STATIC_LIB) $(LIB_DIR)/
mkdir -p $(INCLUDES_DIR)
$(INSTALL) $(NGSTAR_LIBNGSTAR2_INCLUDE) $(INCLUDES_DIR)/
for i in $(NGSTAR_LIBNGSTAR2_INCLUDE) ; do chmod 0644 $(INCLUDES_DIR)/$$i ; done
uninstall:
-rm -f $(LIB_DIR)/$(NGSTAR_SHARED_LIB)
-rm -f $(LIB_DIR)/$(NGSTAR_STATIC_LIB)
-rm -f $(INCLUDES_DIR)/$(NGSTAR_LIBNGSTAR2_INCLUDE)
endif

407
libngstar2/NGStar2.cc Normal file
View file

@ -0,0 +1,407 @@
/*
* NGStar2.cc
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* includes */
#include "NGStar2.hh"
#include "tools.hh"
using namespace std;
namespace ngstar2 {
// NGSTAR2 class implementation
// in order of declaration
// private:
//
// Set the cell(x, y) with the given value (if valid)
//
void NGStar2::set_cell( int x, int y , char value )
{
if ( ( x <= NGSTAR_LEVEL_WIDTH ) && ( y <= NGSTAR_LEVEL_HEIGHT ) ) {
switch ( value ) {
case WALL : // char if for ngs levels
case 3 : // int is for gsl levels
this->board[y*NGSTAR_LEVEL_WIDTH+x] = wall;
break;
case EMPTY :
case 2 :
this->board[y*NGSTAR_LEVEL_WIDTH+x] = empty;
break;
case GIFT :
case 4 :
this->board[y*NGSTAR_LEVEL_WIDTH+x] = gift;
this->nb_gifts++;
break;
case BALL :
case 0 :
this->board[y*NGSTAR_LEVEL_WIDTH+x] = ball;
this->ball_X = x;
this->ball_Y = y;
break;
case CUBE :
case 1 :
this->board[y*NGSTAR_LEVEL_WIDTH+x] = cube;
this->cube_X = x;
this->cube_Y = y;
break;
case '\n' :
break;
default :
throw InvalidCellValue( value );
break;
}
} else {
throw InvalidCellCoordinates( x, y );
}
}
//
// Load a level from file filename in NGStar format
//
inline void NGStar2::read_ngs_level( const string *filename )
{
int i;
int j;
char current_cell;
bool ball_set=false;
bool cube_set=false;
ifstream file;
file.open( filename->c_str( ), ios::in );
if ( file == NULL ) {
throw InvalidLevelFile( filename );
}
this->level_h = NGSTAR_LEVEL_HEIGHT;
this->level_w = NGSTAR_LEVEL_WIDTH;
this->board = new cell[ this->level_w * this->level_h ];
for ( i=NGSTAR_LEVEL_HEIGHT ; i-- ; ) {
for ( j=NGSTAR_LEVEL_WIDTH ; j-- ; ) {
file.read( &current_cell, 1 );
if ( file.eof( ) )
throw InvalidLevelFile( filename );
this->set_cell( j, i, current_cell );
if ( current_cell == BALL )
ball_set = true;
else
if ( current_cell == CUBE )
cube_set = true;
}
}
file.close( );
if ( ball_set == false || cube_set == false ) {
throw InvalidLevelFile( filename );
}
}
//
// Load a level from file filename in G-star format
// (from g-star source, translated into C++ and adapted
// but basically the structure is the same)
//
inline void NGStar2::read_gsl_level( const string *filename )
{
int i;
int j;
char current_cell;
char width;
char height;
bool ball_set=false;
bool cube_set=false;
ifstream file;
file.open( filename->c_str( ), ios::binary );
if ( file == NULL ) {
throw InvalidLevelFile( filename );
}
/* skeeping header "gsl1" */
file.seekg( 4 );
file.read( &width, 1 );
file.read( &height, 1 );
this->level_h = (int)height; //NGSTAR_LEVEL_HEIGHT;
this->level_w = (int)width; //NGSTAR_LEVEL_WIDTH;
this->board = new cell[ this->level_w * this->level_h ];
if (( width == NGSTAR_LEVEL_WIDTH ) && ( height == NGSTAR_LEVEL_HEIGHT )) {
for ( i=NGSTAR_LEVEL_HEIGHT ; i-- ; ) {
for ( j=NGSTAR_LEVEL_WIDTH ; j-- ; ) {
file.read( &current_cell, 1 );
if ( file.eof( ) )
throw InvalidLevelFile( filename );
this->set_cell( j, i, current_cell );
if ( current_cell == 0 )
ball_set = true;
else
if ( current_cell == 1 )
cube_set = true;
}
}
}
file.close( );
if ( ball_set == false || cube_set == false ) {
throw InvalidLevelFile( filename );
}
}
//
// Determine the format of level in filename and call
// the corresponding method
//
void NGStar2::read_level( const string *filename )
{
ifstream file;
char *foo = new char[ 5 ];
this->nb_gifts = 0;
file.open( filename->c_str( ), ios::binary );
if ( file == NULL ) {
throw InvalidLevelFile( filename );
}
/* verifying file type (gsl or ngs) */
file.read( foo, 4 );
foo[4] = '\0';
if ( (new string( foo ))->compare( "gsl1" ) == 0 ) {
file.close( );
read_gsl_level( filename );
}
else {
file.close( );
read_ngs_level( filename );
}
this->nb_moves = 0;
this->moving = ball;
}
//
// Move the ball in given direction
// stopped by walls and the cube
//
void NGStar2::move_ball( direction direction )
{
int dh=0;
int dv=0;
unsigned int tmp_ball_X = this->ball_X;
unsigned int tmp_ball_Y = this->ball_Y;
/* determining the direction it will go */
switch ( direction ) {
case go_up : dv=1; break;
case go_down : dv=-1; break;
case go_left : dh=1; break;
case go_right : dh=-1; break;
default : break;
}
/* determining the cell it will go */
while (
/* checking board limits */
(( tmp_ball_Y + dv >= 0 ) &&
( tmp_ball_Y + dv < NGSTAR_LEVEL_HEIGHT )) &&
(( tmp_ball_X + dh >= 0 ) &&
( tmp_ball_X + dh < NGSTAR_LEVEL_WIDTH )) &&
/* is next cell a wall ? */
(this->board[(tmp_ball_Y + dv)*NGSTAR_LEVEL_WIDTH+tmp_ball_X + dh] != wall) &&
(this->board[(tmp_ball_Y + dv)*NGSTAR_LEVEL_WIDTH+tmp_ball_X + dh] != cube)
)
{
tmp_ball_Y += dv;
tmp_ball_X += dh;
/* did it collect a gift ? */
if ( this->board[tmp_ball_Y*NGSTAR_LEVEL_WIDTH+tmp_ball_X] == gift )
{
this->board[tmp_ball_Y*NGSTAR_LEVEL_WIDTH+tmp_ball_X] = empty;
this->nb_gifts--;
}
}
if ( ( tmp_ball_X != this->ball_X ) || ( tmp_ball_Y != this->ball_Y ) ) {
// if it's the first move then set t1 as the start of level
if ( this->nb_moves == 0 )
(void) time( &( this->t1 ) );
/* empty previous cell */
this->board[this->ball_Y*NGSTAR_LEVEL_WIDTH+this->ball_X] = empty;
/* changing coordinates */
this->ball_Y = tmp_ball_Y;
this->ball_X = tmp_ball_X;
/* set destination cell */
this->board[tmp_ball_Y*NGSTAR_LEVEL_WIDTH+tmp_ball_X] = ball;
++(this->nb_moves);
}
}
//
// Move the cube in given direction
// stopped by walls, gifts and the ball
// slightly different from move_ball
//
void NGStar2::move_cube( direction direction )
{
int dh=0;
int dv=0;
unsigned int tmp_cube_X = this->cube_X;
unsigned int tmp_cube_Y = this->cube_Y;
/* determining the direction it will go */
switch ( direction ) {
case go_up : dv=1; break;
case go_down : dv=-1; break;
case go_left : dh=1; break;
case go_right : dh=-1; break;
default : break;
}
/* determining the cell it will go */
while (
/* checking board limits */
(( tmp_cube_Y + dv >= 0 ) &&
( tmp_cube_Y + dv < NGSTAR_LEVEL_HEIGHT )) &&
(( tmp_cube_X + dh >= 0 ) &&
( tmp_cube_X + dh < NGSTAR_LEVEL_WIDTH )) &&
/* is next cell a wall ? */
(this->board[(tmp_cube_Y + dv)*NGSTAR_LEVEL_WIDTH+tmp_cube_X + dh] == empty)
)
{
tmp_cube_Y += dv;
tmp_cube_X += dh;
}
if ( ( tmp_cube_X != this->cube_X ) || ( tmp_cube_Y != this->cube_Y ) ) {
// if it's the first move then set t1 as the start of level
if ( this->nb_moves == 0 )
(void) time( &( this->t1 ) );
/* empty previous cell */
this->board[this->cube_Y*NGSTAR_LEVEL_WIDTH+this->cube_X] = empty;
/* changing coordinates */
this->cube_Y = tmp_cube_Y;
this->cube_X = tmp_cube_X;
/* set destination cell */
this->board[tmp_cube_Y*NGSTAR_LEVEL_WIDTH+tmp_cube_X] = cube;
++(this->nb_moves);
}
}
// public:
//
// Constructor, initialize things
//
NGStar2::NGStar2( Configuration *config )
{
this->config = config;
this->load_level( );
}
//
// Load level nb_level from current levelset if level exists
//
void NGStar2::load_level( )
{
string *level_filename;
if ( ( this->config->levelset != NULL ) &&
( this->config->current_level <= this->config->nb_levels ) ) {
level_filename = new string( this->config->levelsets_path->c_str( ) );
level_filename->append( "/" );
level_filename->append( this->config->levelset->c_str( ) );
level_filename->append( "/" );
level_filename->append( itos( this->config->current_level ) );
read_level( level_filename );
}
}
//
// Load level nb_level from current levelset if level exists
//
void NGStar2::load_level( const char *filename )
{
read_level( new string( filename ) );
}
void NGStar2::next_level ( )
{
if( ( this->config->current_level + 1 ) <= this->config->nb_levels )
++(this->config->current_level);
this->load_level( );
}
void NGStar2::previous_level( )
{
if( this->config->current_level > 1 )
--(this->config->current_level);
this->load_level( );
}
void NGStar2::switch_moving( )
{
++( this->nb_moves );
this->moving = ( this->moving == ball ) ? cube : ball;
}
void NGStar2::move( direction where )
{
if ( this->moving == ball )
this->move_ball( where );
else
this->move_cube( where );
}
//
// Check is there's gifts left and return the result
//
bool NGStar2::is_it_over( void )
{
return( ( this->nb_gifts > 0 ) ? false : true );
}
int NGStar2::get_duration( )
{
time_t t2;
(void) time( &( t2 ) );
return( (int)t2 - ( this->t1 ) );
}
} // end namespace ngstar2

137
libngstar2/NGStar2.hh Normal file
View file

@ -0,0 +1,137 @@
/*
* NGStar2.hh
*
* Copyright (C) 2003, 2004, 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __NGSTAR_H__
#define __NGSTAR_H__
// includes
#include <iostream>
#include <fstream>
#include <string>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include "Exceptions.hh"
#include "Configuration.hh"
#include "tools.hh"
using namespace std;
namespace ngstar2 {
// classe(s)
class NGStar2 {
private:
time_t t1;
inline void read_ngs_level( const string * );
inline void read_gsl_level( const string * );
void read_level ( const string * );
void move_ball ( direction );
void move_cube ( direction );
public:
// variables
Configuration *config;
cell* board;
cell moving;
int nb_gifts;
int nb_moves;
unsigned int level_h;
unsigned int level_w;
unsigned int ball_X;
unsigned int ball_Y;
unsigned int cube_X;
unsigned int cube_Y;
// Constructor
NGStar2( Configuration * );
// Methods
void set_cell ( int, int, char );
void load_level ( void );
void load_level ( const char * );
void next_level ( void );
void previous_level( void );
void switch_moving ( void );
void move ( direction );
bool is_it_over ( void );
int get_duration ( void );
friend ostream& operator<<(ostream& os, NGStar2 *ngstar2 )
{
int i;
int j;
cell current_cell;
for ( i=NGSTAR_LEVEL_HEIGHT ; i-- ; ) {
for ( j=NGSTAR_LEVEL_WIDTH ; j-- ; ) {
current_cell = ngstar2->board[i*NGSTAR_LEVEL_WIDTH+j];
switch ( current_cell ) {
case wall :
os << "W";
break;
case empty :
os << " ";
break;
case gift :
os << "G";
break;
case ball :
os << "B";
break;
case cube :
os << "C";
break;
default :
break;
}
}
os << endl;
}
os << ngstar2->nb_gifts << " gifts ; ";
os << "ball(" << ngstar2->ball_X << "," << ngstar2->ball_Y << ") ; ";
os << "cube(" << ngstar2->cube_X << "," << ngstar2->cube_Y << ")" << endl ;
if ( ngstar2->is_it_over() == true )
os << "it's over" << endl;
else
os << "it ain't over" << endl;
return( os );
}
};
} // end namespace ngstar2
#endif /* __NGSTAR_H__ */

115
libngstar2/Scores.cc Normal file
View file

@ -0,0 +1,115 @@
/*
* Scores.cc
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "Scores.hh"
namespace ngstar2{
// Constructor(s)
Scores::Scores( NGStar2 *engine )
{
this->engine = engine;
this->init( );
}
// Methods
void Scores::init( )
{
int i;
this->scores = new int[ this->engine->config->nb_levels ];
for ( i = 0 ; i < this->engine->config->nb_levels ; ++i )
(this->scores)[ i ] = -1;
// building this->scorefilename
string *DOTngstar_path;
DOTngstar_path = new string( getenv( "HOME" ) );
DOTngstar_path->append( "/.ngstar/" );
if ( check_dir_existence( DOTngstar_path->c_str( ) ) == false )
DOTngstar_path = new string( "/tmp/" );
DOTngstar_path->append( this->engine->config->levelset->c_str( ) );
DOTngstar_path->append( ".scores" );
this->scorefilename = new string( DOTngstar_path->c_str( ) );
this->read( );
}
void Scores::read( )
{
int i;
ifstream file;
file.open( this->scorefilename->c_str( ), ios::in );
if ( file != NULL )
for ( i=0 ; i < this->engine->config->nb_levels ; ++i )
file >> this->scores[i];
file.close( );
file.clear( );
}
void Scores::write( )
{
ofstream file;
file.open( this->scorefilename->c_str( ), ios::out );
file << this;
file.close( );
file.clear( );
}
int Scores::get( )
{
return( this->get( this->engine->config->current_level - 1 ) );
}
int Scores::get( int level )
{
return( (this->scores)[ level ] );
}
void Scores::set( )
{
this->set( this->engine->config->current_level,
this->engine->nb_moves,
this->engine->get_duration( ) );
}
void Scores::set( int level, int nbMoves, int nbSeconds )
{
// int score = abs( nbMoves - nbSeconds );
double score = nbMoves * 100 + nbSeconds;
if ( ( score <= (this->scores)[ level - 1 ] ) ||
( (this->scores)[ level - 1 ] == -1) ) {
(this->scores)[ level - 1 ] = (int) score;
this->write( );
}
}
} // end namespace ngstar2

71
libngstar2/Scores.hh Normal file
View file

@ -0,0 +1,71 @@
/*
* Scores.hh
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __SCORES_H__
#define __SCORES_H__
#include <iostream>
#include <string>
#include <cstdlib>
#include "NGStar2.hh"
using namespace std;
namespace ngstar2 {
class Scores {
private :
NGStar2 *engine;
int *scores;
string *scorefilename;
public:
// Constructor(s)
Scores( NGStar2 * );
// Methods
void init( );
void read( );
void write( );
int get( );
int get( int );
void set( );
void set( int, int, int );
friend ostream& operator<<(ostream& os, Scores* scrs )
{
int i;
for ( i = 0 ; i < scrs->engine->config->nb_levels ; ++i )
os << (scrs->scores)[ i ] << endl;
return( os );
}
};
} // end namespace ngstar2
#endif /* __SCORES_H__ */

79
libngstar2/tools.cc Normal file
View file

@ -0,0 +1,79 @@
/*
* tools.cc
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "tools.hh"
using namespace std;
namespace ngstar2 {
// Utilities functions implementation
int count_files_in_dir( const char* dirname )
{
int counter = 0;
DIR* dir;
struct dirent* dir_content;
/* opening dirname */
dir = opendir( dirname );
if ( !dir ) {
perror("opendir");
return( -1 );
}
else {
/* reading dirname */
while ( (dir_content = readdir( dir )) != NULL )
if ( ( ( dir_content->d_name )[ 0 ] != '.' ) &&
( ( dir_content->d_name )[ strlen( dir_content->d_name ) - 1 ] != '~' ) )
++counter;
/* closing dirname */
if ( closedir( dir ) == -1 ) {
perror( "closedir" );
return -1;
}
return counter;
}
}
bool check_dir_existence( const char* path )
{
bool result;
DIR* dirtmp = opendir( path );
result = ( dirtmp != NULL ) ? true : false;
closedir( dirtmp );
return( result );
}
string itos( int arg )
{
ostringstream buffer;
buffer << arg; // send the int to the ostringstream
return buffer.str(); // capture the string
}
} // end namespace ngstar2

63
libngstar2/tools.hh Normal file
View file

@ -0,0 +1,63 @@
/*
* tools.hh
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __TOOLS_H__
# define __TOOLS_H__
#include <sstream>
#include <string>
#include <cerrno>
#include <cstdio>
#include <cstring>
#include <dirent.h>
using namespace std;
namespace ngstar2 {
// defines
// level dimensions
#define NGSTAR_LEVEL_HEIGHT 9
#define NGSTAR_LEVEL_WIDTH 16
// char values of cells
#define BALL 'B'
#define CUBE 'C'
#define EMPTY ' '
#define GIFT 'G'
#define WALL 'W'
// enums
typedef enum {empty, wall, gift, ball, cube} cell;
typedef enum {go_up, go_down, go_left, go_right} direction;
// utilities functions
int count_files_in_dir ( const char* );
bool check_dir_existence( const char* );
// next function thanks to C & C++ Comeau FAQ
string itos( int arg );
} // end namespace ngstar2
#endif /* __TOOLS_H__ */

301
src/Board.cc Normal file
View file

@ -0,0 +1,301 @@
/*
* Board.cc
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "Board.hh"
// namespaces
using namespace fltk;
using namespace std;
using namespace ngstar2;
Board::Board(int x, int y, int w, int h, const char *label)
: fltk::Widget(x, y, w, h, label)
{
// do initialization stuff...
}
void Board::init( NGStar2 *engine, Configuration *config, Scores *scores )
{
this->config = config;
this->engine = engine;
this->scores = scores;
this->load_textures( );
this->cell_w = this->w( ) / this->engine->level_w;
this->cell_h = this->h( ) / this->engine->level_h;
drawing_area = new Rectangle( );
}
inline void Board::level_over( )
{
this->scores->set( );
if ( this->config->current_level == this->config->nb_levels ) {
int i;
bool tmp = true;
string *message = new string( "This levelset ends here !" );
for ( i=0 ; i<this->config->nb_levels ; ++i ) {
if ( this->scores->get( i ) == -1 ) {
if ( tmp == true )
message->append( "\n\n\tLevels not cleared :\n" );
tmp = false;
message->append( itos( i + 1 ) );
message->append( " " );
}
}
fltk::message( message->c_str( ) );
exit( 0 );
}
else {
try {
this->engine->next_level( );
}
catch ( LoadingLevelException lle ) {
cerr << lle << endl;
exit( -1 );
}
}
}
inline void Board::draw_cell( cell type, int x, int y )
{
SharedImage *texture;
switch( type ) {
case ball:
texture = ( this->engine->moving == ball ) ? this->tex_ball_selected : this->tex_ball;
break;
case cube:
texture = ( this->engine->moving == cube ) ? this->tex_cube_selected : this->tex_cube;
break;
case ngstar2::empty:
texture = this->tex_empty;
break;
case gift:
texture = this->tex_gift;
break;
case wall:
texture = this->tex_wall;
break;
}
this->drawing_area->set( x, y, this->cell_w, this->cell_h );
texture->draw( *( this->drawing_area ) );
}
void Board::draw( )
{
int i, j;
unsigned int cell_x, cell_y;
for ( i=this->engine->level_h ; i-- ; ) {
for ( j=this->engine->level_w ; j-- ; ) {
this->cell_w = this->w( ) / this->engine->level_w;
this->cell_h = this->h( ) / this->engine->level_h;
cell_y = ( this->engine->level_h - i - 1 ) * this->cell_h;
cell_x = ( this->engine->level_w - j - 1) * this->cell_w;
this->draw_cell( this->engine->board[i*this->engine->level_w+j], cell_x, cell_y );
}
}
}
SharedImage * Board::load_texture( string *path, string *name )
{
return( pngImage::get( ( *path + *name ).c_str( ) ) );
}
void Board::load_textures( )
{
string *themepath = new string( this->config->themes_path->c_str( ) );
themepath->append( "/" );
themepath->append( this->config->theme->c_str( ) );
themepath->append( "/" );
this->tex_ball = this->load_texture( themepath, new string( "tex_ball.png" ) );
this->tex_ball_selected = this->load_texture( themepath, new string( "tex_ball_selected.png" ) );
this->tex_cube = this->load_texture( themepath, new string( "tex_cube.png" ) );
this->tex_cube_selected = this->load_texture( themepath, new string( "tex_cube_selected.png" ) );
this->tex_empty = this->load_texture( themepath, new string( "tex_empty.png" ) );
this->tex_gift = this->load_texture( themepath, new string( "tex_gift.png" ) );
this->tex_wall = this->load_texture( themepath, new string( "tex_wall.png" ) );
}
int Board::handle( int event ) {
switch(event) {
case PUSH:
unsigned int mouse_X;
unsigned int mouse_Y;
mouse_X = this->engine->level_w - ( ( event_x() / this->cell_w ) + 1 );
mouse_Y = this->engine->level_h - ( ( event_y() / this->cell_h ) + 1 );
if ( ( this->engine->ball_X == mouse_X ) &&
( this->engine->ball_Y == mouse_Y ) )
this->engine->moving = ball;
else {
if ( ( this->engine->cube_X == mouse_X ) &&
( this->engine->cube_Y == mouse_Y ) )
this->engine->moving = cube;
else {
unsigned int selected_X;
unsigned int selected_Y;
if ( this->engine->moving == ball ) {
selected_X = this->engine->ball_X;
selected_Y = this->engine->ball_Y;
}
else {
selected_X = this->engine->cube_X;
selected_Y = this->engine->cube_Y;
}
if ( mouse_X == selected_X ) {
if ( mouse_Y > selected_Y )
this->engine->move( go_up );
else
this->engine->move( go_down );
}
else {
if ( mouse_Y == selected_Y ) {
if ( mouse_X > selected_X )
this->engine->move( go_left );
else
this->engine->move( go_right );
}
}
}
if ( this->engine->is_it_over( ) == true ) {
// the callback is used to update Fltk2_UI widgets that need it
this->do_callback( );
this->level_over( );
}
}
// the callback is used to update Fltk2_UI widgets that need it
this->do_callback( );
return 1;
case RELEASE:
return 1;
case SHORTCUT:
return 1;
case FOCUS:
focus( this );
return 1;
case UNFOCUS:
return 1;
case KEY:
if ( this->engine->is_it_over( ) == false )
switch ( event_key() ) {
case UpKey :
this->engine->move( go_up );
break;
case DownKey :
this->engine->move( go_down );
break;
case LeftKey :
this->engine->move( go_left );
break;
case RightKey :
this->engine->move( go_right );
break;
case ' ' :
this->engine->switch_moving();
break;
case 'n' :
try {
this->engine->next_level( );
}
catch ( InvalidLevelFile ilf ) {
cerr << ilf << endl;
exit( -1 );
}
catch ( InvalidCellValue icv ) {
cerr << icv << endl;
exit( -1 );
}
catch ( InvalidCellCoordinates icc ) {
cerr << icc << endl;
exit( -1 );
}
break;
case 'p' :
try {
this->engine->previous_level( );
}
catch ( InvalidLevelFile ilf ) {
cerr << ilf << endl;
exit( -1 );
}
catch ( InvalidCellValue icv ) {
cerr << icv << endl;
exit( -1 );
}
catch ( InvalidCellCoordinates icc ) {
cerr << icc << endl;
exit( -1 );
}
break;
case 'q' :
exit( 0 );
break;
case 'r' :
try {
this->engine->load_level( );
}
catch ( InvalidLevelFile ilf ) {
cerr << ilf << endl;
exit( -1 );
}
catch ( InvalidCellValue icv ) {
cerr << icv << endl;
exit( -1 );
}
catch ( InvalidCellCoordinates icc ) {
cerr << icc << endl;
exit( -1 );
}
break;
default :
break;
} // keys sorting switch end
// the callback is used to update Fltk2_UI widgets that need it
this->do_callback( );
if ( this->engine->is_it_over( ) == true )
this->level_over( );
return 1;
default:
return 1;
}
}

92
src/Board.hh Normal file
View file

@ -0,0 +1,92 @@
/*
* Board.hh
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __NGSTAR_BOARD__
# define __NGSTAR_BOARD__
// C++ includes
#include <string>
// C includes
#include <unistd.h>
// FLTK2 includes
#include <fltk/Widget.h>
#include <fltk/SharedImage.h>
#include <fltk/Rectangle.h>
#include <fltk/events.h>
#include <fltk/ask.h>
#include <fltk/draw.h>
#include <fltk/damage.h>
// local includes
#include "../libngstar2/NGStar2.hh"
#include "../libngstar2/Configuration.hh"
#include "../libngstar2/Scores.hh"
// namespaces
using namespace fltk;
using namespace std;
using namespace ngstar2;
class Board : public Widget {
private:
SharedImage * load_texture( string *path, string *name );
protected:
//variables
Configuration *config;
NGStar2 *engine;
Scores *scores;
unsigned int cell_w;
unsigned int cell_h;
Rectangle *drawing_area;
// methods
inline void draw_cell( cell type, int x, int y );
inline void level_over( );
public:
// variables
// textures
SharedImage *tex_ball;
SharedImage *tex_ball_selected;
SharedImage *tex_cube;
SharedImage *tex_cube_selected;
SharedImage *tex_empty;
SharedImage *tex_gift;
SharedImage *tex_wall;
// Constructor
Board( int x, int y, int w, int h, const char *label = 0 );
// Methods
void init( NGStar2 *engine, Configuration *config, Scores *scores );
void load_textures( );
void draw( );
// Method overloaded
int handle( int event );
};
#endif /*__NGSTAR_BOARD__*/

168
src/EditorBoard.cc Normal file
View file

@ -0,0 +1,168 @@
/*
* EditorBoard.cc
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "EditorBoard.hh"
// namespaces
using namespace fltk;
using namespace std;
using namespace ngstar2;
EditorBoard::EditorBoard( int x, int y, int w, int h, const char *label )
: Board( x, y, w, h, label )
{
}
void EditorBoard::init( NGStar2 *engine, Configuration *config )
{
this->config = config;
this->engine = engine;
this->load_textures( );
this->cell_w = this->w( ) / this->engine->level_w;
this->cell_h = this->h( ) / this->engine->level_h;
this->drawing_area = new Rectangle( );
this->cell_to_put = wall;
this->nb_changes_since_save = 0;
}
void EditorBoard::draw_cell( cell type, int x, int y )
{
SharedImage *texture;
switch( type ) {
case ball:
texture = this->tex_ball;
break;
case cube:
texture = this->tex_cube;
break;
case ngstar2::empty:
texture = this->tex_empty;
break;
case gift:
texture = this->tex_gift;
break;
case wall:
texture = this->tex_wall;
break;
default:
cerr << "What was that ?!" << endl;
break;
}
this->drawing_area->set( x, y, this->cell_w, this->cell_h );
texture->draw( *( this->drawing_area ) );
}
int EditorBoard::handle( int event ) {
switch(event) {
case PUSH:
unsigned int mouse_X;
unsigned int mouse_Y;
char cell_pushed;
mouse_X = this->engine->level_w - ( ( event_x() / this->cell_w ) + 1 );
mouse_Y = this->engine->level_h - ( ( event_y() / this->cell_h ) + 1 );
switch( this->cell_to_put ) {
case ball:
cell_pushed = BALL;
break;
case cube:
cell_pushed = CUBE;
break;
case ngstar2::empty:
cell_pushed = EMPTY;
break;
case gift:
cell_pushed = GIFT;
break;
case wall:
cell_pushed = WALL;
break;
default:
cerr << "What was that ?!" << endl;
break;
}
this->engine->set_cell( mouse_X, mouse_Y, cell_pushed );
this->nb_changes_since_save++;
// the callback is used to update LevelMaker_UI widgets that need it
this->do_callback( );
this->redraw( );
return 1;
case RELEASE:
return 1;
case SHORTCUT:
return 1;
case FOCUS:
return 1;
case UNFOCUS:
return 1;
case KEY:
switch ( event_key() ) {
case 'b' :
this->cell_to_put = ball;
break;
case 'c' :
this->cell_to_put = cube;
break;
case 'e' :
this->cell_to_put = ngstar2::empty;
break;
case 'g' :
this->cell_to_put = gift;
break;
case 'w' :
this->cell_to_put = wall;
break;
default :
break;
}
// the callback is used to update LevelMaker_UI widgets that need it
this->do_callback( );
this->redraw( );
return 1;
default:
return 1;
}
}
void EditorBoard::clear( )
{
int x, y;
for ( x=NGSTAR_LEVEL_WIDTH ; x-- ; )
for ( y=NGSTAR_LEVEL_HEIGHT ; y-- ; )
this->engine->set_cell( x, y, EMPTY );
}

97
src/EditorBoard.hh Normal file
View file

@ -0,0 +1,97 @@
/*
* EditorBoard.hh
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __EDITOR_BOARD__
# define __EDITOR_BOARD__
// C++ includes
#include <iostream>
#include <string>
// FLTK2 includes
#include <fltk/Widget.h>
#include <fltk/SharedImage.h>
#include <fltk/Rectangle.h>
#include <fltk/events.h>
#include <fltk/ask.h>
// local includes
#include "../libngstar2/NGStar2.hh"
#include "../libngstar2/Configuration.hh"
#include "../libngstar2/Scores.hh"
#include "Board.hh"
// namespaces
using namespace fltk;
using namespace std;
using namespace ngstar2;
class EditorBoard : public Board {
public:
cell cell_to_put;
int nb_changes_since_save;
EditorBoard( int x, int y, int w, int h, const char *label );
void init( NGStar2 *engine, Configuration *config );
void draw_cell( cell type, int x, int y );
int handle( int event );
void clear( );
// Overloaded oprators
friend ostream& operator<<(ostream& os, EditorBoard *eb )
{
int i, j;
char cell;
for ( i=eb->engine->level_h ; i-- ; ) {
for ( j=eb->engine->level_w ; j-- ; ) {
switch( eb->engine->board[i*eb->engine->level_w+j] ) {
case ball:
cell = BALL;
break;
case cube:
cell = CUBE;
break;
case ngstar2::empty:
cell = EMPTY;
break;
case gift:
cell = GIFT;
break;
case wall:
cell = WALL;
break;
default:
cerr << "What was that ?!" << endl;
break;
}
os << cell;
}
}
return( os );
}
};
#endif /*__EDITOR_BOARD__*/

350
src/Fltk2_UI.cc Normal file
View file

@ -0,0 +1,350 @@
/*
* Fltk2_UI.cc
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "Fltk2_UI.hh"
Fltk2_UI::Fltk2_UI( NGStar2 *engine, Configuration *config, Scores *scores )
{
string *strtmp_path;
string *strtmp_items;
// first take the hook on configuration and engine
this->config = config;
this->engine = engine;
this->scores = scores;
// then create the main (and only) window
this->w_main = new Window( W_MAIN_WIDTH, W_MAIN_HEIGHT, APPLICATION_VERSION );
this->w_main->resizable( this->w_main );
// and populate it
this->w_main->begin( );
{ // no, putting this in a block has no utility aside from making the code easier to read ;)
// first line of controls widgets
this->menus = new MenuBar(0, 0, 320, WIDGETS_HEIGHT);
this->menus->user_data(this); // make this be passed to all menu callbacks
this->menus->add( "&File/&Restart Level", 'r', (Callback*)this->cb_menu_restart_level );
this->menus->add( "&File/Show scores", 0, (Callback*)this->cb_menu_show_scores );
this->menus->add( "&File/Exit", 'q', (Callback*)this->cb_menu_quit );
this->sm_levelsets = new ItemGroup( "Levelsets" );
{ // idem
strtmp_items = new string( );
strtmp_path = new string( this->config->levelsets_path->c_str( ) );
this->make_list( strtmp_path, strtmp_items, this->sm_levelsets, this->cb_menu_levelset );
strtmp_path = new string( getenv( "HOME" ) );
strtmp_path->append( "/.ngstar/levelsets/" );
if ( check_dir_existence( strtmp_path->c_str( ) ) == true )
this->make_list( strtmp_path, strtmp_items, this->sm_levelsets, this->cb_menu_levelset );
strtmp_path = new string( "./datas/levelsets/" );
if ( check_dir_existence( strtmp_path->c_str( ) ) == true )
this->make_list( strtmp_path, strtmp_items, this->sm_levelsets, this->cb_menu_levelset );
}
this->menus->add( this->sm_levelsets );
this->sm_themes = new ItemGroup( "Themes" );
{ // idem
strtmp_items = new string( );
strtmp_path = new string( this->config->themes_path->c_str( ) );
this->make_list( strtmp_path, strtmp_items, this->sm_themes, this->cb_menu_theme );
strtmp_path = new string( getenv( "HOME" ) );
strtmp_path->append( "/.ngstar/themes/" );
if ( check_dir_existence( strtmp_path->c_str( ) ) == true )
this->make_list( strtmp_path, strtmp_items, this->sm_themes, this->cb_menu_theme );
strtmp_path = new string( "./datas/themes/" );
if ( check_dir_existence( strtmp_path->c_str( ) ) == true )
this->make_list( strtmp_path, strtmp_items, this->sm_themes, this->cb_menu_theme );
}
this->menus->add( this->sm_themes );
this->menus->add( "&Help/&License", 0, (Callback*)cb_menu_license );
this->menus->add( "&Help/&About", 0, (Callback*)cb_menu_about );
// second line of controls widgets
this->vi_current_level = new ValueInput( 40, WIDGETS_HEIGHT, VI_CURRENT_LEVEL_WIDTH, WIDGETS_HEIGHT );
this->vi_current_level->value( 1 );
this->vi_current_level->range( 1, this->config->nb_levels );
this->vi_current_level->step( 1 );
this->vi_current_level->label( "Level" );
this->vi_current_level->align( ALIGN_LEFT );
this->vi_current_level->tooltip( "Go to a previous (p) or next (n) level" );
this->vi_current_level->box( THIN_DOWN_BOX );
ATTACH_CALLBACK( this->vi_current_level, this->cb_vi_current_level );
this->o_nb_gifts = new Output( W_MAIN_WIDTH / 3, WIDGETS_HEIGHT, 30, WIDGETS_HEIGHT );
this->o_nb_gifts->value( ( itos( this->engine->nb_gifts ) ).c_str( ) );
this->o_nb_gifts->box( THIN_DOWN_BOX );
this->o_nb_gifts->label( "gift(s)" );
this->o_nb_gifts->align( ALIGN_RIGHT );
this->o_nb_gifts->tooltip( "How many gifts are left to be eaten" );
ATTACH_CALLBACK( this->o_nb_gifts, this->cb_o_nb_gifts );
this->o_nb_moves = new Output( ( W_MAIN_WIDTH / 3 ) * 2, WIDGETS_HEIGHT, 30, WIDGETS_HEIGHT );
this->o_nb_moves->value( ( itos( this->engine->nb_moves ) ).c_str( ) );
this->o_nb_moves->box( THIN_DOWN_BOX );
this->o_nb_moves->label( "move(s)" );
this->o_nb_moves->align( ALIGN_RIGHT );
this->o_nb_moves->tooltip( "How many moves you have made so far" );
ATTACH_CALLBACK( this->o_nb_moves, this->cb_o_nb_moves );
// and finally the board
this->board = new Board( 0, WIDGETS_HEIGHT * 2, W_MAIN_WIDTH, W_MAIN_HEIGHT - ( WIDGETS_HEIGHT * 2 ) );
this->board->init( this->engine, this->config, this->scores );
ATTACH_CALLBACK( this->board, this->cb_board );
focus( this->board );
}
// and it's over, we're ready to show the window
this->w_main->end( );
}
void Fltk2_UI::show( )
{
// show the new born window to the world, it's a... window
this->w_main->show( );
}
void Fltk2_UI::make_list( string* path, string *items, ItemGroup *menu, void (cb)(fltk::Item*, Fltk2_UI*) ) {
DIR* dir;
struct dirent* file;
// Opening directory
if ( ( dir = opendir( path->c_str() ) ) == NULL ) {
cerr << "Can't open directory : " << path->c_str( ) << endl;
exit( 2 );
}
// Reading entries
while ( ( file = readdir( dir ) ) != NULL ) {
string* path_tmp = new string( path->c_str( ) );
path_tmp->append( "/" );
path_tmp->append( file->d_name );
if ( ( check_dir_existence( path_tmp->c_str( ) ) == true ) &&
( (file->d_name)[0] != '.' ) &&
( items->find( file->d_name ) == string::npos ) ) {
if ( items->empty( ) == false ) {
items->append( "|" );
}
items->append( file->d_name );
Item *tmp = new Item( file->d_name );
ATTACH_CALLBACK( tmp, cb );
menu->add( tmp );
}
}
}
// Callbacks
void Fltk2_UI::cb_menu_quit( Widget *, void * )
{
exit( 0 );
}
void Fltk2_UI::cb_menu_restart_level( Widget *, Fltk2_UI *gui )
{
try {
gui->engine->load_level( );
}
catch ( InvalidLevelFile ilf ) {
cerr << ilf << endl;
exit( -1 );
}
catch ( InvalidCellValue icv ) {
cerr << icv << endl;
exit( -1 );
}
catch ( InvalidCellCoordinates icc ) {
cerr << icc << endl;
exit( -1 );
}
gui->board->redraw( );
focus( gui->board );
}
void Fltk2_UI::cb_vi_current_level( ValueInput *vi_current_level, Fltk2_UI *gui )
{
if ( vi_current_level->value( ) < vi_current_level->minimum( ) )
vi_current_level->value( vi_current_level->minimum( ) );
else
if ( vi_current_level->value( ) > vi_current_level->maximum( ) )
vi_current_level->value( vi_current_level->maximum( ) );
gui->config->set_level( (int)vi_current_level->value( ) );
try {
gui->engine->load_level( );
}
catch ( InvalidLevelFile ilf ) {
cerr << ilf << endl;
exit( -1 );
}
catch ( InvalidCellValue icv ) {
cerr << icv << endl;
exit( -1 );
}
catch ( InvalidCellCoordinates icc ) {
cerr << icc << endl;
exit( -1 );
}
gui->board->do_callback( );
gui->board->redraw( );
focus( gui->board );
}
void Fltk2_UI::cb_menu_levelset( Item *m_levelset, Fltk2_UI *gui )
{
try {
gui->config->set_levelset( new string( m_levelset->label( ) ) );
gui->scores->init( );
}
catch ( CannotFindLevelsets cfl ) {
cerr << cfl << endl;
exit( -1 );
}
try {
gui->engine->load_level( );
}
catch ( InvalidLevelFile ilf ) {
cerr << ilf << endl;
exit( -1 );
}
catch ( InvalidCellValue icv ) {
cerr << icv << endl;
exit( -1 );
}
catch ( InvalidCellCoordinates icc ) {
cerr << icc << endl;
exit( -1 );
}
gui->vi_current_level->value( gui->config->current_level );
gui->vi_current_level->range( 1, gui->config->nb_levels );
gui->board->redraw( );
focus( gui->board );
}
void Fltk2_UI::cb_menu_theme( Item *m_theme, Fltk2_UI *gui )
{
try {
gui->config->set_theme( new string( m_theme->label( ) ) );
}
catch ( CannotFindThemes cft ) {
cerr << cft << endl;
exit( -1 );
}
gui->board->load_textures( );
gui->board->redraw( );
focus( gui->board );
}
void Fltk2_UI::cb_o_nb_moves( Output *o_nb_moves, Fltk2_UI *gui )
{
o_nb_moves->value( ( itos( gui->engine->nb_moves ) ).c_str( ) );
// if ( gui->engine->nb_moves > 1 )
// gui->o_nb_moves->copy_label( "moves" );
// else
// gui->o_nb_moves->copy_label( "move" );
focus( gui->board );
}
void Fltk2_UI::cb_o_nb_gifts( Output *o_nb_gifts, Fltk2_UI *gui )
{
o_nb_gifts->value( ( itos( gui->engine->nb_gifts ) ).c_str( ) );
// if ( gui->engine->nb_gifts > 1 )
// o_nb_gifts->label( "gifts" );
// else
// o_nb_gifts->label( "gift" );
focus( gui->board );
}
void Fltk2_UI::cb_board( Board *board, Fltk2_UI *gui )
{
gui->o_nb_moves->do_callback( );
gui->o_nb_gifts->do_callback( );
// we don't want the level reloaded at each move so no do_callback for
// gui->vi_current_level
gui->vi_current_level->value( gui->config->current_level );
gui->w_main->redraw( );
focus( gui->board );
}
void Fltk2_UI::cb_menu_show_scores( Widget*, Fltk2_UI *gui )
{
int i;
string *strtmp;
// get levelset name
strtmp = new string( "Levelset : " );
strtmp->append( gui->config->levelset->c_str( ) );
strtmp->append( "\n\nlevel: score (The lower the better)\n" );
// now add scores
for ( i = 0 ; i < gui->config->nb_levels ; ++i ) {
strtmp->append( ( itos( i + 1 ) ).c_str( ) );
if ( i < 9 )
strtmp->append( " : " );
else
strtmp->append( ": " );
if ( gui->scores->get( i ) < 0 )
strtmp->append( "not yet completed" );
else
strtmp->append( ( itos( gui->scores->get( i ) ) ).c_str( ) );
strtmp->append( "\n" );
}
message( strtmp->c_str( ) );
}
void Fltk2_UI::cb_menu_about(Widget*, void*) {
message( "NGStar\n©Gwenhael Le Moine 2003, 2004, 2005, 2006, 2006" );
}
void Fltk2_UI::cb_menu_license (Widget *, void *)
{
message(" * This program is free software; you can redistribute it and/or modify\n"
" * it under the terms of the GNU General Public License as published by\n"
" * the Free Software Foundation; either version 2 of the License, or\n"
" * (at your option) any later version.\n"
" *\n"
" * This program is distributed in the hope that it will be useful,\n"
" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" * GNU Library General Public License for more details.\n"
" *\n"
" * You should have received a copy of the GNU General Public License\n"
" * along with this program; if not, write to the Free Software\n"
" * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
"\n"
"(See COPYING file for the full license text)"
);
}

106
src/Fltk2_UI.hh Normal file
View file

@ -0,0 +1,106 @@
/*
* Fltk2_UI.hh
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __FLTK2_UI__
# define __FLTK2_UI__
/* includes */
#include <fltk/run.h>
#include <fltk/damage.h>
#include <fltk/Style.h>
// Window
#include <fltk/Window.h>
// Widgets
#include <fltk/Widget.h>
#include <fltk/MenuBar.h>
#include <fltk/ValueInput.h>
#include <fltk/Output.h>
#include <fltk/Item.h>
#include <fltk/ItemGroup.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include "../libngstar2/NGStar2.hh"
#include "../libngstar2/Configuration.hh"
#include "../libngstar2/Scores.hh"
#include "config.h"
#include "Board.hh"
/* defines */
#define B_QUIT_WIDTH 30
#define B_RESTART_LEVEL_WIDTH 85
#define VI_CURRENT_LEVEL_WIDTH 30
/* namespaces */
using namespace fltk;
using namespace std;
class Fltk2_UI {
private:
//variables
// a pointer to Configuration class
Configuration *config;
NGStar2 *engine;
Scores *scores;
// Windows
Window *w_main;
// Widgets
// first line of controls widgets
MenuBar *menus;
ItemGroup *sm_levelsets;
ItemGroup *sm_themes;
// second line line of controls widgets
ValueInput *vi_current_level;
Output *o_nb_gifts;
Output *o_nb_moves;
// and finally the board itself
Board *board;
void make_list( string *path, string *items, ItemGroup *menu, void (cb)(fltk::Item*, Fltk2_UI*) );
// Callbacks
static void cb_menu_quit( Widget *, void * );
static void cb_menu_show_scores( Widget *, Fltk2_UI *gui );
static void cb_menu_license ( Widget *, void * );
static void cb_menu_about( Widget *, void * );
static void cb_menu_restart_level( Widget *, Fltk2_UI *gui );
static void cb_vi_current_level( ValueInput *vi_current_level, Fltk2_UI *gui );
static void cb_menu_levelset( Item *m_levelset, Fltk2_UI *gui );
static void cb_menu_theme( Item *m_theme, Fltk2_UI *gui );
static void cb_o_nb_moves( Output *o_nb_moves, Fltk2_UI *gui );
static void cb_o_nb_gifts( Output *o_nb_gifts, Fltk2_UI *gui );
static void cb_board( Board *board, Fltk2_UI *gui );
public:
Fltk2_UI( NGStar2 *engine, Configuration *config, Scores *scores_holder );
void show( );
};
#endif /*__FLTK2_UI__*/

278
src/LevelMaker_UI.cc Normal file
View file

@ -0,0 +1,278 @@
/*
* LevelMaker_UI.cc
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "LevelMaker_UI.hh"
LevelMaker_UI::LevelMaker_UI( NGStar2 *engine, Configuration *config )
{
// first take the hook on configuration and engine
this->config = config;
this->engine = engine;
this->filename = new string( ( itos( this->config->current_level ) ).c_str( ) );
// then create the main (and only) window
this->w_main = new Window( W_MAIN_WIDTH, 215, APPLICATION_VERSION );
this->w_main->resizable( this->w_main );
// and populate it
this->w_main->begin( );
{ // no, putting this in a block has no utility aside from making the code easier to read ;)
this->g_controls = new Group( 0, 0, W_MAIN_WIDTH, WIDGETS_HEIGHT * 2 );
// first line of controls widgets
this->menus = new MenuBar(0, 0, 320, WIDGETS_HEIGHT);
this->menus->user_data(this); // make this be passed to all menu callbacks
this->menus->add( "&File/&New Level", CTRL+'n', (Callback*)cb_menu_new );
this->menus->add( "&File/&New Levelset...", CTRL+'l', (Callback*)cb_menu_new_levelset );
this->menus->add( "&File/&Open File...", CTRL+'o', (Callback*)cb_menu_open );
this->menus->add( "&File/&Save File", CTRL+'s', (Callback*)cb_menu_save );
this->menus->add( "&File/Save File &As...", CTRL+SHIFT+'S', (Callback*)cb_menu_saveas );
this->menus->add( "&File/E&xit", CTRL+'q', (Callback*)cb_menu_quit );
this->menus->add( "&Help/&License", 0, (Callback*)cb_menu_license );
this->menus->add( "&Help/&About", 0, (Callback*)cb_menu_about );
// second line of controls widgets
this->rlb_ball = new RadioLightButton( 0, WIDGETS_HEIGHT, 40, 20, "" );
this->rlb_cube = new RadioLightButton( 40, WIDGETS_HEIGHT, 40, 20, "" );
this->rlb_empty = new RadioLightButton( 80, WIDGETS_HEIGHT, 40, 20, "" );
this->rlb_gift = new RadioLightButton( 120, WIDGETS_HEIGHT, 40, 20, "" );
this->rlb_wall = new RadioLightButton( 160, WIDGETS_HEIGHT, 40, 20, "" );
// by default we're putting walls
this->rlb_wall->value( true );
this->b_clear_board = new Button( W_MAIN_WIDTH - 20, WIDGETS_HEIGHT, 20, 20, "@square" );
// adding controls to g_controls
// first line
this->g_controls->add( this->menus );
// second line
this->g_controls->add( this->b_clear_board );
this->g_controls->add( this->rlb_ball );
this->g_controls->add( this->rlb_cube );
this->g_controls->add( this->rlb_empty );
this->g_controls->add( this->rlb_gift );
this->g_controls->add( this->rlb_wall );
// and finally the board
this->board = new EditorBoard( 0, 35, W_MAIN_WIDTH, W_MAIN_HEIGHT - ( WIDGETS_HEIGHT * 2 ), "" );
this->board->init( this->engine, this->config );
// Put images on radio light buttons
this->rlb_ball->image( this->board->tex_ball );
this->rlb_cube->image( this->board->tex_cube );
this->rlb_empty->image( this->board->tex_empty );
this->rlb_gift->image( this->board->tex_gift );
this->rlb_wall->image( this->board->tex_wall );
// Attaching callbacks to widgets that need them
ATTACH_CALLBACK( this->b_clear_board, this->cb_b_clear_board );
ATTACH_CALLBACK( this->board, this->cb_board );
ATTACH_CALLBACK( this->rlb_ball, this->cb_rlb );
ATTACH_CALLBACK( this->rlb_cube, this->cb_rlb );
ATTACH_CALLBACK( this->rlb_empty, this->cb_rlb );
ATTACH_CALLBACK( this->rlb_gift, this->cb_rlb );
ATTACH_CALLBACK( this->rlb_wall, this->cb_rlb );
// Tooltips looks good
this->b_clear_board->tooltip( "Clear the board" );
this->rlb_ball->tooltip( "Draw ball (thou shall only draw one)" );
this->rlb_cube->tooltip( "Draw cube (thou shall only draw one)" );
this->rlb_empty->tooltip( "Draw empty space" );
this->rlb_gift->tooltip( "Draw gift" );
this->rlb_wall->tooltip( "Draw wall" );
}
// and it's over, we're ready to show the window
this->w_main->end( );
}
void LevelMaker_UI::show( )
{
// show the new born window to the world, it's a... window !
this->w_main->show( );
}
// Callbacks
void LevelMaker_UI::cb_menu_quit(Widget*, LevelMaker_UI *gui ) {
if ( gui->board->nb_changes_since_save != 0 )
cerr << "You should have saved ..." << endl;
exit(0);
}
void LevelMaker_UI::cb_menu_new(Widget*, LevelMaker_UI *gui ) {
delete gui->filename;
gui->filename = NULL;
gui->cb_b_clear_board( gui->b_clear_board, gui );
}
void LevelMaker_UI::cb_menu_new_levelset(Widget*, LevelMaker_UI *gui ) {
string *levelset_name;
string *levelset_path;
delete gui->filename;
levelset_name = new string( input( "Enter the name of the new levelset : " ) );
levelset_path = new string( getenv( "HOME" ) );
levelset_path->append( "/.ngstar/levelsets/" );
if ( check_dir_existence( levelset_path->c_str( ) ) == false ) {
alert( "Please create $HOME/.ngstar/ with\nngstar --create-default-config" );
}
else {
levelset_path->append( levelset_name->c_str( ) );
mkdir( levelset_path->c_str( ), S_IRWXO | S_IRWXG | S_IRWXU );
levelset_name = new string( levelset_path->c_str( ) );
levelset_name->append( "/1" );
gui->filename = new string( levelset_name->c_str( ) );
gui->cb_b_clear_board( gui->b_clear_board, gui );
}
}
void LevelMaker_UI::cb_menu_open(Widget*, LevelMaker_UI *gui ) {
//use_system_file_chooser( true );
try {
gui->filename = new string( file_chooser( "Select a level" , "[0-9]*", "./" ) );
gui->engine->load_level( gui->filename->c_str( ) );
gui->board->redraw( );
}
catch ( logic_error le ) {}
}
void LevelMaker_UI::cb_menu_save(Widget*, LevelMaker_UI* gui) {
if ( gui->filename == NULL )
gui->cb_menu_saveas( (Widget *)0, gui );
else
gui->save_to_file( );
}
void LevelMaker_UI::cb_menu_saveas(Widget*, LevelMaker_UI *gui ) {
try {
gui->filename = new string( file_chooser( "Please remember that level are named numerically" , "[0-9]*", "./" ) );
gui->save_to_file( );
}
catch ( logic_error le ) {}
}
void LevelMaker_UI::cb_menu_about(Widget*, void*) {
message( "NGStar2 Level Maker\n©Cycojesus 2005, 2006, 2006" );
}
void LevelMaker_UI::cb_menu_license (Widget *, void *)
{
message(" * This program is free software; you can redistribute it and/or modify\n"
" * it under the terms of the GNU General Public License as published by\n"
" * the Free Software Foundation; either version 2 of the License, or\n"
" * (at your option) any later version.\n"
" *\n"
" * This program is distributed in the hope that it will be useful,\n"
" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" * GNU Library General Public License for more details.\n"
" *\n"
" * You should have received a copy of the GNU General Public License\n"
" * along with this program; if not, write to the Free Software\n"
" * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n");
}
void LevelMaker_UI::cb_b_clear_board( Button *b_clear_board, LevelMaker_UI *gui )
{
gui->board->clear( );
gui->board->redraw( );
focus( gui->board );
}
void LevelMaker_UI::cb_board( EditorBoard *board, LevelMaker_UI *gui )
{
focus( gui->board );
}
void LevelMaker_UI::cb_rlb( RadioLightButton *rlb, LevelMaker_UI *gui )
{
if ( rlb == gui->rlb_ball )
gui->board->cell_to_put = ball;
else
if ( rlb == gui->rlb_cube )
gui->board->cell_to_put = cube;
else
if ( rlb == gui->rlb_empty )
gui->board->cell_to_put = ngstar2::empty;
else
if ( rlb == gui->rlb_gift )
gui->board->cell_to_put = gift;
else
if ( rlb == gui->rlb_wall )
gui->board->cell_to_put = wall;
}
void LevelMaker_UI::save_to_file( )
{
int i, j;
int nb_balls=0,
nb_cubes=0,
nb_gifts=0;
// Validating level
for ( i=this->engine->level_h ; i-- ; ) {
for ( j=this->engine->level_w ; j-- ; ) {
switch( this->engine->board[i*this->engine->level_w+j] ) {
case ball:
++nb_balls;
break;
case cube:
++nb_cubes;
break;
case ngstar2::empty:
break;
case gift:
++nb_gifts;
break;
case wall:
break;
default:
cerr << "What was that ?!" << endl;
break;
}
}
}
if ( ( nb_balls != 1 ) ||
( nb_cubes != 1 ) ||
( nb_gifts == 0 ) ) {
alert( "Invalid level." );
}
else {
ofstream file;
file.open( this->filename->c_str( ), ios::out );
file << this->board;
this->board->nb_changes_since_save = 0;
file.close( );
file.clear( );
}
}

121
src/LevelMaker_UI.hh Normal file
View file

@ -0,0 +1,121 @@
/*
* LevelMaker_UI.hh
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __LEVELMAKER_UI__
# define __LEVELMAKER_UI__
/* includes */
#include <stdexcept>
#include <fltk/run.h>
#include <fltk/damage.h>
#include <fltk/Style.h>
// Window
#include <fltk/Window.h>
// Groups
#include <fltk/Group.h>
// Widgets
#include <fltk/Widget.h>
#include <fltk/Button.h>
#include <fltk/MenuBar.h>
#include <fltk/Output.h>
#include <fltk/ComboBox.h>
#include <fltk/Group.h>
#include <fltk/RadioLightButton.h>
#include <fltk/file_chooser.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include "../libngstar2/NGStar2.hh"
#include "../libngstar2/Configuration.hh"
#include "../src/config.h"
#include "EditorBoard.hh"
/* defines */
#define B_QUIT_WIDTH 30
#define B_RESTART_LEVEL_WIDTH 85
#define VI_CURRENT_LEVEL_WIDTH 30
/* namespaces */
using namespace fltk;
using namespace std;
class LevelMaker_UI {
private:
//variables
// a pointer to Configuration class
Configuration *config;
NGStar2 *engine;
// filename to write the new made/modified levelto
string *filename;
// Windows
Window *w_main;
// Groups
Group *g_controls;
// Widgets
// first line of controls widgets
MenuBar *menus;
// second line line of controls widgets
Button *b_clear_board;
RadioLightButton *rlb_ball;
RadioLightButton *rlb_cube;
RadioLightButton *rlb_empty;
RadioLightButton *rlb_gift;
RadioLightButton *rlb_wall;
// Callbacks
// Menu callbacks
static void cb_menu_quit( Widget *, LevelMaker_UI * );
static void cb_menu_new( Widget *, LevelMaker_UI * );
static void cb_menu_new_levelset( Widget *, LevelMaker_UI * );
static void cb_menu_open( Widget *, LevelMaker_UI * );
static void cb_menu_save( Widget *, LevelMaker_UI * );
static void cb_menu_saveas( Widget *, LevelMaker_UI * );
static void cb_menu_license ( Widget *, void * );
static void cb_menu_about( Widget *, void * );
static void cb_b_clear_board( Button *b_clear_board, LevelMaker_UI *gui );
static void cb_board( EditorBoard *board, LevelMaker_UI *gui );
static void cb_rlb( RadioLightButton *rlb, LevelMaker_UI *gui );
// Methods
void save_to_file( );
public:
// and finally the board itself
EditorBoard *board;
LevelMaker_UI( NGStar2 *engine, Configuration *config );
void show( );
};
#endif /*__LEVELMAKER_UI__*/

131
src/Makefile Normal file
View file

@ -0,0 +1,131 @@
include ../Makefile.config
CC_INCLUDES = `fltk2-config --use-images --cxxflags`
CC_LIBS = -L../ -lngstar2
CC_LIBS_STATIC = -L../ -lngstar2
BIN_DEPS =
ifdef USE_FLTK2
CPPFLAGS += -D 'THEMES_PATH="$(THEMES_DIR)"'
CC_LIBS += `fltk2-config --use-images --ldflags` -lpng -lz
CC_LIBS_STATIC += `fltk2-config --use-images --ldflags` -lpng -lz -lfontconfig -lexpat -lfreetype -lXrender -lX11
else
ifdef BUILD_EDITOR
CPPFLAGS += -D 'THEMES_PATH="$(THEMES_DIR)"'
CC_LIBS += `fltk2-config --use-images --ldflags` -lpng -lz
CC_LIBS_STATIC += `fltk2-config --use-images --ldflags` -lpng -lz -lfontconfig -lexpat -lfreetype -lXrender -lX11
endif
endif
ifdef USE_FLTK2
FLTK2_UI_OBJ=Fltk2_UI.o
BOARD_OBJ=Board.o
BIN_DEPS += $(FLTK2_UI_OBJ) $(BOARD_OBJ)
endif
ifdef BUILD_EDITOR
LM_UI_OBJ=LevelMaker_UI.o
EBOARD_OBJ=EditorBoard.o
BOARD_OBJ=Board.o
BIN_DEPS += $(LM_UI_OBJ) $(EBOARD_OBJ)
ifndef USE_FLTK2
BIN_DEPS += $(BOARD_OBJ)
endif
endif
ifdef USE_NCURSES
CC_LIBS += -lncurses -lgpm
CC_LIBS_STATIC += -lncurses -lgpm
NCURSES_UI_OBJ = Ncurses_UI.o
BIN_DEPS += $(NCURSES_UI_OBJ)
endif
SOURCE= main.cc
BIN= ../ngstar
BIN_FLTK2= ../xngstar
BIN_EDITOR= ../xngstar-editor
BIN_STATIC=../ngstar_static
BIN_STATIC_FLTK2=../xngstar_static
BIN_STATIC_EDITOR= ../xngstar-editor_static
all :
$(MAKE) $(BIN)
static :
$(MAKE) $(BIN_STATIC)
$(BIN) : $(SOURCE) $(BIN_DEPS)
echo "Compiling $(BIN)"
$(CXX) $< $(BIN_DEPS) -o $@ $(CC_LIBS) $(CC_INCLUDES) $(CPPFLAGS)
strip -s $@
ifdef USE_FLTK2
-ln -sf `basename $(BIN)` $(BIN_FLTK2)
endif
ifdef BUILD_EDITOR
-ln -sf `basename $(BIN)` $(BIN_EDITOR)
endif
$(BIN_STATIC) : $(SOURCE) $(BIN_DEPS)
echo "Compiling $(BIN)"
$(CXX) -static $< $(BIN_DEPS) -o $@ $(CC_LIBS_STATIC) $(CC_INCLUDES) $(CPPFLAGS)
strip -s $@
ifdef USE_FLTK2
-ln -sf `basename $(BIN_STATIC)` $(BIN_STATIC_FLTK2)
endif
ifdef BUILD_EDITOR
-ln -sf `basename $(BIN_STATIC)` $(BIN_STATIC_EDITOR)
endif
install : $(BIN)
mkdir -p $(BIN_DIR)/
$(INSTALL) $(BIN) $(BIN_DIR)/
ifdef USE_FLTK2
$(INSTALL) $(BIN_FLTK2) $(BIN_DIR)/
endif
ifdef BUILD_EDITOR
$(INSTALL) $(BIN_EDITOR) $(BIN_DIR)/
endif
uninstall : $(BIN_DIR)/$(BIN)
-rm $(BIN_DIR)/$(BIN)
ifdef USE_FLTK2
-rm $(BIN_DIR)/$(BIN_FLTK2)
endif
ifdef BUILD_EDITOR
-rm $(BIN_DIR)/$(BIN_EDITOR)
endif
install_static : $(BIN_STATIC)
mkdir -p $(BIN_DIR)/
$(INSTALL) $(BIN_STATIC) $(BIN_DIR)/
ifdef USE_FLTK2
$(INSTALL) $(BIN_STATIC_FLTK2) $(BIN_DIR)/
endif
ifdef BUILD_EDITOR
$(INSTALL) $(BIN_STATIC_EDITOR) $(BIN_DIR)/
endif
uninstall_static : $(BIN_DIR)/$(BIN_STATIC)
-rm $(BIN_DIR)/$(BIN_STATIC)
ifdef USE_FLTK2
-rm $(BIN_DIR)/$(BIN_STATIC_FLTK2)
endif
ifdef BUILD_EDITOR
-rm $(BIN_DIR)/$(BIN_STATIC_EDITOR)
endif
clean :
-rm ./*.o ./*~
real-clean :
$(MAKE) clean
-rm $(BIN)
-rm $(BIN_STATIC)
ifdef USE_FLTK2
-rm $(BIN_FLTK2)
-rm $(BIN_STATIC_FLTK2)
endif
ifdef BUILD_EDITOR
-rm $(BIN_EDITOR)
-rm $(BIN_STATIC_EDITOR)
endif

405
src/Ncurses_UI.cc Normal file
View file

@ -0,0 +1,405 @@
/*
* Ncurses_UI.cc
*
* Copyright (C) 2003, 2004, 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* includes */
#include "Ncurses_UI.hh"
using namespace ngstar2;
Ncurses_UI::Ncurses_UI( NGStar2 *engine, Configuration* config, Scores *scores )
{
/* global variables initialization */
this->config = config;
this->engine = engine;
this->scores = scores;
/* ncurses initialization */
this->w_main = initscr( );
noecho( );
cbreak( );
nonl( );
intrflush( this->w_main, FALSE );
keypad( this->w_main, TRUE );
if ( ( has_colors( ) == TRUE ) && ( this->config->black_and_white == 0 ) ) {
start_color( );
init_pair( color_CUBE, COLOR_RED, COLOR_BLACK );
init_pair( color_BALL, COLOR_BLUE, COLOR_BLACK );
init_pair( color_GIFT, COLOR_YELLOW, COLOR_BLACK );
init_pair( color_WALL, COLOR_WHITE, COLOR_WHITE );
init_pair( color_EMPTY, COLOR_BLACK, COLOR_BLACK );
init_pair( color_TEXT, COLOR_YELLOW, COLOR_BLACK );
init_pair( color_CUBE_SELECTED, COLOR_RED, COLOR_YELLOW );
init_pair( color_BALL_SELECTED, COLOR_BLUE, COLOR_YELLOW );
init_pair( color_BORDER, COLOR_WHITE, COLOR_BLACK );
}
try {
this->engine->load_level( );
}
catch ( InvalidLevelFile ilf ) {
cerr << ilf << endl;
this->~Ncurses_UI( );
exit( -1 );
}
catch ( InvalidCellValue icv ) {
cerr << icv << endl;
this->~Ncurses_UI( );
exit( -1 );
}
catch ( InvalidCellCoordinates icc ) {
cerr << icc << endl;
this->~Ncurses_UI( );
exit( -1 );
}
}
Ncurses_UI::~Ncurses_UI( )
{
echo( );
nocbreak( );
endwin( );
}
void Ncurses_UI::display_board( void )
{
int i, j, x, y;
cell current_cell;
/* border */
attron( COLOR_PAIR( color_BORDER ));
attron( A_BOLD );
mvhline( 0, 2, 0, 32 );
mvhline( 10, 2, 0, 32 );
mvvline( 1, 1, 0, 9 );
mvvline( 1, 34, 0, 9 );
mvprintw( 0, 1, "%c", '+' );//ACS_ULCORNER );
mvprintw( 0, 34, "%c", '+' );//ACS_URCORNER );
mvprintw( 10, 1, "%c", '+' );//ACS_LLCORNER );
mvprintw( 10, 34, "%c", '+' );//ACS_LRCORNER );
move( 0, 0 );
attroff( A_BOLD );
attroff( COLOR_PAIR( color_BORDER ));
/* board */
for ( i=NGSTAR_LEVEL_HEIGHT ; i-- ; ) {
for ( j=NGSTAR_LEVEL_WIDTH ; j-- ; ) {
current_cell = this->engine->board[i*NGSTAR_LEVEL_WIDTH+j];
x = 2+(NGSTAR_LEVEL_WIDTH-j-1)*2;
y = NGSTAR_LEVEL_HEIGHT-i;
switch ( current_cell ) {
case wall :
attron( COLOR_PAIR( color_WALL ));
mvwprintw( w_main, y, x, SYMBOL_WALL );
attroff( COLOR_PAIR( color_WALL ));
break;
case empty :
attron( COLOR_PAIR( color_EMPTY ));
mvwprintw( w_main, y, x, SYMBOL_EMPTY );
attroff( COLOR_PAIR( color_EMPTY ));
break;
case gift :
attron( COLOR_PAIR( color_GIFT ));
attron( A_BOLD );
mvwprintw( w_main, y, x, SYMBOL_GIFT );
attroff( A_BOLD );
attroff( COLOR_PAIR( color_GIFT ));
break;
case ball :
if ( this->engine->moving == ball ) {
attron( COLOR_PAIR( color_BALL_SELECTED ));
attron( A_BOLD );
}
else
attron( COLOR_PAIR( color_BALL ));
mvwprintw( w_main, y, x, SYMBOL_BALL );
if ( this->engine->moving == ball ) {
attroff( A_BOLD );
attroff( COLOR_PAIR( color_BALL_SELECTED ));
}
else
attroff( COLOR_PAIR( color_BALL ));
break;
case cube :
if ( this->engine->moving == cube ) {
attron( COLOR_PAIR( color_CUBE_SELECTED ));
attron( A_BOLD );
}
else
attron( COLOR_PAIR( color_CUBE ));
mvwprintw( w_main, y, x, SYMBOL_CUBE );
if ( this->engine->moving == cube ) {
attroff( A_BOLD );
attroff( COLOR_PAIR( color_CUBE_SELECTED ));
}
else
attroff( COLOR_PAIR( color_CUBE ));
break;
default :
break;
}
}
}
// touchwin( this->w_board );
wrefresh( this->w_main );
}
void Ncurses_UI::display_info_panel( void )
{
attron( COLOR_PAIR( color_TEXT ));
attron( A_BOLD );
mvwprintw( this->w_main, 0, 40, APPLICATION_VERSION );
attroff( A_BOLD );
mvwprintw( this->w_main, 2, 40, "level %i / %i", this->config->current_level, this->config->nb_levels );
mvwprintw( this->w_main, 3, 40, "levelset : %s ", this->config->levelset->c_str( ) );
mvwprintw( this->w_main, 4, 40, "%i gifts ; %i moves ", this->engine->nb_gifts, this->engine->nb_moves );
mvwprintw( this->w_main, 5, 40, "ARROWS to move" );
mvwprintw( this->w_main, 6, 40, "SPACE to switch ball/cube" );
mvwprintw( this->w_main, 7, 40, "N next level, P previous level" );
mvwprintw( this->w_main, 8, 40, "R to restart the current level" );
mvwprintw( this->w_main, 9, 40, "and Q to quit" );
mvwprintw( this->w_main, 10, 40, "" );
attroff( COLOR_PAIR( color_TEXT ));
}
void Ncurses_UI::clear_board( void )
{
int i, j;
int x, y;
/* clear board */
for ( i=NGSTAR_LEVEL_HEIGHT ; i-- ; ) {
for ( j=NGSTAR_LEVEL_WIDTH ; j-- ; ) {
x = 2+(NGSTAR_LEVEL_WIDTH-j-1)*2;
y = NGSTAR_LEVEL_HEIGHT-i;
attron( COLOR_PAIR( color_EMPTY ));
mvwprintw( w_main, y, x, SYMBOL_EMPTY );
attroff( COLOR_PAIR( color_EMPTY ));
refresh( );
usleep( 5000 );
}
}
}
void Ncurses_UI::display_score( void )
{
this->display( );
this->clear_board( );
attron( COLOR_PAIR( color_TEXT ));
attron( A_BOLD );
mvwprintw( this->w_main, 2, 5, "level cleared !" );
mvwprintw( this->w_main, 4, 5, "moves : %i", this->engine->nb_moves );
mvwprintw( this->w_main, 5, 5, "time : %i seconds", this->engine->get_duration( ) );
mvwprintw( this->w_main, 6, 5, " ---------" );
mvwprintw( this->w_main, 7, 5, "Score : %i", this->scores->get( config->current_level ) );
attroff( A_BOLD );
attroff( COLOR_PAIR( color_TEXT ));
wrefresh( this->w_main );
this->display_info_panel();
refresh();
sleep( 1 );
this->clear_board( );
}
void Ncurses_UI::display_finished_levelset( void )
{
int i;
bool all_levels_cleared = true;
string *remaining_levels = new string( "\t" );
for ( i=0 ; i<this->config->nb_levels ; ++i ) {
if ( this->scores->get( i ) == -1 ) {
all_levels_cleared = false;
remaining_levels->append( itos( i + 1 ) );
remaining_levels->append( " " );
if ( ( ( i + 1 ) % 8 ) == 0 )
remaining_levels->append( "\n\t" );
}
}
this->display( );
this->clear_board( );
attron( COLOR_PAIR( color_TEXT ));
attron( A_BOLD );
mvwprintw( this->w_main, 2, 5, "levelset ends here !" );
if ( all_levels_cleared == true )
mvwprintw( this->w_main, 4, 5, "all levels cleared !" );
else {
mvwprintw( this->w_main, 4, 5, "levels not cleared :" );
mvwprintw( this->w_main, 5, 5, "%s", remaining_levels->c_str( ) );
}
attroff( A_BOLD );
mvwprintw( this->w_main, 9, 5, "(press a key to exit)" );
attroff( COLOR_PAIR( color_TEXT ));
wrefresh( this->w_main );
this->display_info_panel();
refresh();
// sleep( 1 );
// this->clear_board( );
}
void Ncurses_UI::display( void )
{
this->display_board();
this->display_info_panel();
refresh();
}
void Ncurses_UI::keys_handling( int key, bool allow_moving )
{
// beep();
switch ( key )
{
case ' ' :
this->engine->switch_moving();
break;
case 'n' :
case 'N' :
case '>' :
try {
this->engine->next_level( );
}
catch ( LoadingLevelException lle ) {
cerr << lle << endl;
this->~Ncurses_UI( );
exit( -1 );
}
break;
case 'p' :
case 'P' :
case '<' :
try {
this->engine->previous_level( );
}
catch ( LoadingLevelException lle ) {
cerr << lle << endl;
this->~Ncurses_UI( );
exit( -1 );
}
break;
case 'r' :
case 'R' :
try {
this->engine->load_level( );
}
catch ( LoadingLevelException lle ) {
cerr << lle << endl;
this->~Ncurses_UI( );
exit( -1 );
}
break;
case 'q' :
case 'Q' :
break ;
default:
if ( allow_moving == true ) {
switch( key )
{
case 'o' :
case KEY_UP :
this->engine->move( go_up );
break;
case 'l' :
case KEY_DOWN :
this->engine->move( go_down );
break;
case 'k' :
case KEY_LEFT :
this->engine->move( go_left );
break;
case 'm' :
case KEY_RIGHT :
this->engine->move( go_right );
break;
default:
break;
}
}
}
}
void Ncurses_UI::run( void )
{
int key;
do {
this->display();
key = getch();
this->keys_handling( key, true );
// if the level is over, load the next one
if ( this->engine->is_it_over() == true ) {
this->scores->set( );
this->display_score( );
this->keys_handling( key, false );
if ( config->current_level < config->nb_levels ) {
try {
this->engine->next_level( );
}
catch ( InvalidLevelFile ilf ) {
cerr << ilf << endl;
this->~Ncurses_UI( );
exit( -1 );
}
catch ( InvalidCellValue icv ) {
cerr << icv << endl;
this->~Ncurses_UI( );
exit( -1 );
}
catch ( InvalidCellCoordinates icc ) {
cerr << icc << endl;
this->~Ncurses_UI( );
exit( -1 );
}
this->engine->nb_moves = 0;
}
else {
// if there isn't a next one, quit
// but let's draw the board a last time so it can be seen
this->display( );
this->display_finished_levelset( );
getch( );
this->~Ncurses_UI( );
cout << "So you've finished this levelset..." << endl;
exit( 0 );
}
}
} while (( key != 'q' ) && ( key != 'Q' ));
// Have to call ui's destructor explicitly because it won't do it itself ?!..
this->~Ncurses_UI( );
}

78
src/Ncurses_UI.hh Normal file
View file

@ -0,0 +1,78 @@
/*
* Ncurses_UI.hh
*
* Copyright (C) 2003, 2004, 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __NCURSESUSERINTERFACE_HH__
# define __NCURSESUSERINTERFACE_HH__
/* includes */
#include <ncurses.h>
#include "../libngstar2/NGStar2.hh"
#include "../libngstar2/Configuration.hh"
#include "../libngstar2/Scores.hh"
/* defines */
#define SYMBOL_BALL "()"
#define SYMBOL_CUBE "[]"
#define SYMBOL_EMPTY " "
#define SYMBOL_GIFT "<>"
#define SYMBOL_WALL "##"
using namespace ngstar2;
class Ncurses_UI {
private :
Configuration *config;
NGStar2 *engine;
Scores *scores;
WINDOW *w_main;
enum { color_BALL = 1,
color_CUBE,
color_EMPTY,
color_GIFT,
color_WALL,
color_TEXT,
color_BALL_SELECTED,
color_CUBE_SELECTED,
color_BORDER };
// Methods
void display_board( void );
void display_info_panel( void );
void display_score( void );
void display_finished_levelset( void );
void clear_board( void );
void display( void );
void keys_handling( int key, bool allow_moving );
public :
// Constructor
Ncurses_UI( NGStar2 *, Configuration *, Scores * );
// Destructor
~Ncurses_UI( void );
// Methods
void run( void );
};
#endif /* __NCURSESUSERINTERFACE_HH__ */

43
src/config.h Normal file
View file

@ -0,0 +1,43 @@
/*
* config.h : Global wide configuration
*
* Copyngstar_right (C) 2003 Gwenhael LE MOINE
*
* This file is part of NGStar
*
* NGStar 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 2 of the License, or
* (at your option) any later version.
*
* NGStar 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 NGStar; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __NGSTAR_CONFIG__
# define __NGSTAR_CONFIG__
#ifndef APPLICATION_VERSION
# define APPLICATION_VERSION "FLTK's NGStar X.x.x"
#endif /* APPLICATION_VERSION */
#ifndef THEMES_PATH
# define THEMES_PATH "./themes"
#endif /* THEMES_PATH */
#define WIDGETS_HEIGHT 15
#define NGSTAR_BOARD_HEIGHT 180
#define W_MAIN_WIDTH 320
#define W_MAIN_HEIGHT ( ( WIDGETS_HEIGHT * 2 ) + NGSTAR_BOARD_HEIGHT )
#define ATTACH_CALLBACK( widget, method ) \
widget->callback( reinterpret_cast< void(*)(Widget*,void*) >( method ), this )
#endif /*__NGSTAR_CONFIG__*/

180
src/main.cc Normal file
View file

@ -0,0 +1,180 @@
/*
* main.cc
*
* Copyright (C) 2005, 2006 Gwenhael LE MOINE
*
* This file is part of NGStar2
*
* NGStar2 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 2 of the License, or
* (at your option) any later version.
*
* NGStar2 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 NGStar2; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <string>
#if defined (_USE_FLTK2_) || defined (_BUILD_EDITOR_)
# include <fltk/run.h>
#endif
#if defined (_USE_FLTK2_)
# include "Fltk2_UI.hh"
#endif
#if defined (_BUILD_EDITOR_)
# include "LevelMaker_UI.hh"
#endif
#if defined (_USE_NCURSES_)
# include "Ncurses_UI.hh"
#endif
#include "../libngstar2/NGStar2.hh"
#include "../libngstar2/Configuration.hh"
#include "../libngstar2/Scores.hh"
#include "../libngstar2/Exceptions.hh"
using namespace std;
using namespace ngstar2;
int main( int argc, char* argv[] )
{
string *bin_name;
Configuration *config;
NGStar2 *engine;
Scores *scores;
/****************************************/
/* Initialize NGStar */
/****************************************/
// Reading $HOME/.ngstar/config & commandline parameters
try {
config = new Configuration( argc, argv );
cerr << "Config loaded" << endl;
}
catch( CannotFindLevelsets cfl) {
cerr << cfl << endl;
exit( -1 );
}
// initializing NGStar2 engine
try {
engine = new NGStar2( config );
cerr << "NGStar2 engine loaded" << endl;
}
catch( InvalidLevelFile ilf ) {
cerr << ilf << endl;
exit( -1 );
}
catch( InvalidCellValue icv ) {
cerr << icv << endl;
exit( -1 );
}
catch( InvalidCellCoordinates icc ) {
cerr << icc << endl;
exit( -1 );
}
scores = new Scores( engine );
enum { ncurses, fltk2, editor };
int what_to_run;
bin_name = new string( basename( argv[0] ) );
#if defined (_USE_FLTK2_)
# if defined (_USE_NCURSES_)
if ( ( ( bin_name->find( "fltk" ) != string::npos ) ||
( bin_name->find( "x" ) != string::npos ) ||
( bin_name->find( "X" ) != string::npos ) )
# if defined (_BUILD_EDITOR_)
&& ( bin_name->find( "editor" ) == string::npos )
# endif
)
# endif
what_to_run = fltk2;
# if defined (_USE_NCURSES_)
else
# endif
#endif
#if defined (_BUILD_EDITOR_)
# if defined (_USE_NCURSES_)
if ( ( bin_name->find( "editor" ) != string::npos ) )
# endif
what_to_run = editor;
# if defined (_USE_NCURSES_)
else
# endif
#endif
#if defined (_USE_NCURSES_)
what_to_run = ncurses;
#endif
switch ( what_to_run ){
case fltk2 :
#if defined (_USE_FLTK2_)
/****************************************/
/* fltk2 interface */
/****************************************/
Fltk2_UI *fltk2_ui;
fltk2_ui = new Fltk2_UI( engine, config, scores );
cerr << "Fltk2_UI loaded" << endl;
/*
* Main loop
*/
fltk2_ui->show( );
return( run( ) );
#endif
#if defined (_USE_NCURSES_)
case ncurses :
/****************************************/
/* ncurses interface */
/****************************************/
Ncurses_UI *ncurses_ui;
ncurses_ui = new Ncurses_UI( engine, config, scores );
cerr << "Ncurses_UI loaded" << endl;
/*
* Main loop
*/
ncurses_ui->run( );
return( 0 );
#endif
#if defined (_BUILD_EDITOR_)
case editor :
/****************************************/
/* Editor interface */
/****************************************/
LevelMaker_UI *levelmaker_ui;
levelmaker_ui = new LevelMaker_UI( engine, config );
cerr << "LevelMaker_UI loaded" << endl;
/*
* Main loop
*/
levelmaker_ui->show( );
return( fltk::run( ) );
#endif
default :
cerr << "Well... Err... You must at least compile one interface... !" << endl;
}
return( 0 );
}