summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp
index 93f5f82..d551afe 100644
--- a/noncore/games/sfcave/sfcave.cpp
+++ b/noncore/games/sfcave/sfcave.cpp
@@ -573,524 +573,533 @@ void SFCave :: addGate()
573 lastGateBottomY = b1Height; 573 lastGateBottomY = b1Height;
574 574
575 575
576 int x2 = sWidth; 576 int x2 = sWidth;
577 int y2 = y1 + b1Height + gapHeight; 577 int y2 = y1 + b1Height + gapHeight;
578 int b2Height = mapBottom[50] - y2; 578 int b2Height = mapBottom[50] - y2;
579 579
580 580
581 blocks[i].setRect( x1, y1, blockWidth, b1Height ); 581 blocks[i].setRect( x1, y1, blockWidth, b1Height );
582 blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); 582 blocks[i+1].setRect( x2, y2, blockWidth, b2Height );
583 583
584 break; 584 break;
585 } 585 }
586 } 586 }
587} 587}
588 588
589void SFCave :: setPoint( int point ) 589void SFCave :: setPoint( int point )
590{ 590{
591 if ( nextInt(100) >= 80 ) 591 if ( nextInt(100) >= 80 )
592 dir *= -1; 592 dir *= -1;
593 593
594 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); 594 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) );
595 if ( mapTop[point] < 0 ) 595 if ( mapTop[point] < 0 )
596 { 596 {
597 mapTop[point] = 0; 597 mapTop[point] = 0;
598 dir *= -1; 598 dir *= -1;
599 } 599 }
600 else if ( mapTop[point] >= maxHeight ) 600 else if ( mapTop[point] >= maxHeight )
601 { 601 {
602 mapTop[point] = maxHeight; 602 mapTop[point] = maxHeight;
603 dir *= -1; 603 dir *= -1;
604 } 604 }
605 605
606// mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); 606// mapBottom[point] = sHeight - (maxHeight - mapBottom[point]);
607 mapBottom[point] = sHeight - (maxHeight - mapTop[point]); 607 mapBottom[point] = sHeight - (maxHeight - mapTop[point]);
608} 608}
609 609
610void SFCave :: drawBoss() 610void SFCave :: drawBoss()
611{ 611{
612 offscreen->fill( Qt::black ); 612 offscreen->fill( Qt::black );
613 613
614 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 614 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
615} 615}
616 616
617void SFCave :: draw() 617void SFCave :: draw()
618{ 618{
619 //printf( "Paint\n" ); 619 //printf( "Paint\n" );
620 offscreen->fill( Qt::black ); 620 offscreen->fill( Qt::black );
621 621
622 QPainter p( offscreen ); 622 QPainter p( offscreen );
623 QFontMetrics fm = p.fontMetrics(); 623 QFontMetrics fm = p.fontMetrics();
624 p.setPen( Qt::white ); 624 p.setPen( Qt::white );
625 625
626 for ( int i = 0 ; i < MAPSIZE -3; ++i ) 626 for ( int i = 0 ; i < MAPSIZE -3; ++i )
627 { 627 {
628 // Only display top landscape if not running FLY_GAME 628 // Only display top landscape if not running FLY_GAME
629 if ( CURRENT_GAME_TYPE != FLY_GAME ) 629 if ( CURRENT_GAME_TYPE != FLY_GAME )
630 p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); 630 p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] );
631 631
632 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); 632 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] );
633 633
634 if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones ) 634 if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones )
635 { 635 {
636 p.setPen( Qt::red ); 636 p.setPen( Qt::red );
637 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-10, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-10 ); 637 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-10, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-10 );
638 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-20, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-20 ); 638 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-20, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-20 );
639 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-30, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-30 ); 639 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-30, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-30 );
640 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-40, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-40 ); 640 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-40, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-40 );
641 p.setPen( Qt::white ); 641 p.setPen( Qt::white );
642 } 642 }
643 } 643 }
644 644
645 // Uncomment this to show user segment (usful for checking collision boundary with landscape 645 // Uncomment this to show user segment (usful for checking collision boundary with landscape
646// p.setPen( Qt::red ); 646// p.setPen( Qt::red );
647// p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight ); 647// p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight );
648// p.setPen( Qt::white ); 648// p.setPen( Qt::white );
649 649
650 // Draw user 650 // Draw user
651 p.drawRect( user ); 651 p.drawRect( user );
652 652
653 // Draw trails 653 // Draw trails
654 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 654 for ( int i = 0 ; i < TRAILSIZE ; ++i )
655 if ( trail[i].x() >= 0 ) 655 if ( trail[i].x() >= 0 )
656 p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); 656 p.drawRect( trail[i].x(), trail[i].y(), 2, 2 );
657 657
658 // Draw blocks 658 // Draw blocks
659 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 659 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
660 if ( blocks[i].y() != -1 ) 660 if ( blocks[i].y() != -1 )
661 { 661 {
662 p.fillRect( blocks[i], Qt::black ); 662 p.fillRect( blocks[i], Qt::black );
663 p.drawRect( blocks[i] ); 663 p.drawRect( blocks[i] );
664 } 664 }
665 665
666 // draw score 666 // draw score
667 QString s; 667 QString s;
668 s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); 668 s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] );
669 p.drawText( 5, 10, s ); 669 p.drawText( 5, 10, s );
670 670
671 671
672 if ( state == STATE_CRASHING || state == STATE_CRASHED ) 672 if ( state == STATE_CRASHING || state == STATE_CRASHED )
673 { 673 {
674 // add next crash line 674 // add next crash line
675 675
676 if ( crashLineLength != -1 ) 676 if ( crashLineLength != -1 )
677 { 677 {
678 for ( int i = 0 ; i < 36 ; ++i ) 678 for ( int i = 0 ; i < 36 ; ++i )
679 { 679 {
680 int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); 680 int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) );
681 int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); 681 int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y );
682 } 682 }
683 } 683 }
684 684
685 if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) ) 685 if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) )
686 state = STATE_CRASHED; 686 state = STATE_CRASHED;
687 687
688 if ( state == STATE_CRASHED ) 688 if ( state == STATE_CRASHED )
689 { 689 {
690 QString text = "Press up or down to start"; 690 QString text = "Press up or down to start";
691 p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text ); 691 p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text );
692 692
693 text = "Press OK for menu"; 693 text = "Press OK for menu";
694 p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text ); 694 p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text );
695 695
696 text = "Press r to replay"; 696 text = "Press r to replay";
697 p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text ); 697 p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text );
698 698
699 text = "Press s to save the replay"; 699 text = "Press s to save the replay";
700 p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text ); 700 p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text );
701 701
702 text = "Press r to load a saved replay"; 702 text = "Press r to load a saved replay";
703 p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text ); 703 p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text );
704 } 704 }
705 else 705 else
706 crashLineLength ++; 706 crashLineLength ++;
707 } 707 }
708 708
709 p.end(); 709 p.end();
710 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 710 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
711 //printf( "endpaint\n" ); 711 //printf( "endpaint\n" );
712} 712}
713 713
714void SFCave :: handleKeys() 714void SFCave :: handleKeys()
715{ 715{
716 // Find enpty trail and move others 716 // Find enpty trail and move others
717 bool done = false; 717 bool done = false;
718 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 718 for ( int i = 0 ; i < TRAILSIZE ; ++i )
719 { 719 {
720 if ( trail[i].x() < 0 ) 720 if ( trail[i].x() < 0 )
721 { 721 {
722 if ( !done ) 722 if ( !done )
723 { 723 {
724 trail[i].setX( user.x() - 5 ); 724 trail[i].setX( user.x() - 5 );
725 trail[i].setY( user.y() ); 725 trail[i].setY( user.y() );
726 done = true; 726 done = true;
727 } 727 }
728 } 728 }
729 else 729 else
730 { 730 {
731 trail[i].setX( trail[i].x() - (2) ); 731 trail[i].setX( trail[i].x() - (2) );
732 } 732 }
733 } 733 }
734 734
735 if ( speed <= 3 ) 735 if ( speed <= 3 )
736 { 736 {
737 if ( press ) 737 if ( press )
738 thrust -= thrustUp; 738 thrust -= thrustUp;
739 else 739 else
740 thrust += noThrust; 740 thrust += noThrust;
741 741
742 if ( thrust > maxDownThrust ) 742 if ( thrust > maxDownThrust )
743 thrust = maxDownThrust; 743 thrust = maxDownThrust;
744 else if ( thrust < maxUpThrust ) 744 else if ( thrust < maxUpThrust )
745 thrust = maxUpThrust; 745 thrust = maxUpThrust;
746 } 746 }
747 else 747 else
748 { 748 {
749 if ( press ) 749 if ( press )
750 thrust -= 0.5; 750 thrust -= 0.5;
751 else 751 else
752 thrust += 0.8; 752 thrust += 0.8;
753 753
754 if ( thrust > 5.0 ) 754 if ( thrust > 5.0 )
755 thrust = 5.0; 755 thrust = 5.0;
756 else if ( thrust < -3.5 ) 756 else if ( thrust < -3.5 )
757 thrust = -3.5; 757 thrust = -3.5;
758 } 758 }
759 user.moveBy( 0, (int)thrust ); 759 user.moveBy( 0, (int)thrust );
760} 760}
761 761
762void SFCave :: keyPressEvent( QKeyEvent *e ) 762void SFCave :: keyPressEvent( QKeyEvent *e )
763{ 763{
764 if ( state == STATE_MENU ) 764 if ( state == STATE_MENU )
765 { 765 {
766 switch( e->key() ) 766 switch( e->key() )
767 { 767 {
768 case Qt::Key_Down: 768 case Qt::Key_Down:
769 currentMenuOption[currentMenuNr] ++; 769 currentMenuOption[currentMenuNr] ++;
770 if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) 770 if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" )
771 currentMenuOption[currentMenuNr] = 0; 771 currentMenuOption[currentMenuNr] = 0;
772 break; 772 break;
773 case Qt::Key_Up: 773 case Qt::Key_Up:
774 currentMenuOption[currentMenuNr] --; 774 currentMenuOption[currentMenuNr] --;
775 if ( currentMenuOption[currentMenuNr] < 0 ) 775 if ( currentMenuOption[currentMenuNr] < 0 )
776 currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; 776 currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1;
777 break; 777 break;
778 778
779 case Qt::Key_Left: 779 case Qt::Key_Left:
780 if ( currentMenuNr == MENU_OPTIONS_MENU ) 780 if ( currentMenuNr == MENU_OPTIONS_MENU )
781 { 781 {
782 if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) 782 if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE )
783 { 783 {
784 currentGameType --; 784 currentGameType --;
785 if ( currentGameType < 0 ) 785 if ( currentGameType < 0 )
786 currentGameType = NR_GAME_TYPES - 1; 786 currentGameType = NR_GAME_TYPES - 1;
787 } 787 }
788 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) 788 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY )
789 { 789 {
790 currentGameDifficulty --; 790 currentGameDifficulty --;
791 if ( currentGameDifficulty < 0 ) 791 if ( currentGameDifficulty < 0 )
792 currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; 792 currentGameDifficulty = NR_GAME_DIFFICULTIES - 1;
793 } 793 }
794 } 794 }
795 break; 795 break;
796 796
797 case Qt::Key_Right: 797 case Qt::Key_Right:
798 if ( currentMenuNr == MENU_OPTIONS_MENU ) 798 if ( currentMenuNr == MENU_OPTIONS_MENU )
799 { 799 {
800 if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) 800 if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE )
801 { 801 {
802 currentGameType ++; 802 currentGameType ++;
803 if ( currentGameType == NR_GAME_TYPES ) 803 if ( currentGameType == NR_GAME_TYPES )
804 currentGameType = 0; 804 currentGameType = 0;
805 } 805 }
806 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) 806 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY )
807 { 807 {
808 currentGameDifficulty ++; 808 currentGameDifficulty ++;
809 if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) 809 if ( currentGameDifficulty == NR_GAME_DIFFICULTIES )
810 currentGameDifficulty = 0; 810 currentGameDifficulty = 0;
811 } 811 }
812 } 812 }
813 break; 813 break;
814 814
815 case Qt::Key_Space: 815 case Qt::Key_Space:
816 case Qt::Key_Return: 816 case Qt::Key_Return:
817 case Qt::Key_Enter: 817 case Qt::Key_Enter:
818 dealWithMenuSelection(); 818 dealWithMenuSelection();
819 break; 819 break;
820 } 820 }
821 } 821 }
822 else 822 else
823 { 823 {
824 switch( e->key() ) 824 switch( e->key() )
825 { 825 {
826 case Qt::Key_Up: 826 case Qt::Key_Up:
827 case Qt::Key_F9: 827 case Qt::Key_F9:
828 case Qt::Key_Space: 828 case Qt::Key_Space:
829 if ( !press ) 829 if ( !replay && !press )
830 { 830 {
831 press = true; 831 press = true;
832 replayList.append( new int( nrFrames ) ); 832 replayList.append( new int( nrFrames ) );
833 } 833 }
834 break; 834 break;
835 case Qt::Key_M: 835 case Qt::Key_M:
836 case Qt::Key_Return: 836 case Qt::Key_Return:
837 case Qt::Key_Enter: 837 case Qt::Key_Enter:
838 if ( state == STATE_CRASHED ) 838 if ( state == STATE_CRASHED )
839 state = STATE_MENU; 839 state = STATE_MENU;
840 break; 840 break;
841 841
842 case Qt::Key_Z: 842 case Qt::Key_Z:
843 showScoreZones = !showScoreZones; 843 showScoreZones = !showScoreZones;
844 break; 844 break;
845 845
846 default: 846 default:
847 e->ignore(); 847 e->ignore();
848 break; 848 break;
849 } 849 }
850 } 850 }
851} 851}
852 852
853void SFCave :: keyReleaseEvent( QKeyEvent *e ) 853void SFCave :: keyReleaseEvent( QKeyEvent *e )
854{ 854{
855 if ( state == STATE_MENU ) 855 if ( state == STATE_MENU )
856 { 856 {
857 } 857 }
858 else 858 else
859 { 859 {
860 switch( e->key() ) 860 switch( e->key() )
861 { 861 {
862 case Qt::Key_F9: 862 case Qt::Key_F9:
863 case Qt::Key_Space: 863 case Qt::Key_Space:
864 case Qt::Key_Up: 864 case Qt::Key_Up:
865 if ( press ) 865 if ( !replay && press )
866 { 866 {
867 press = false; 867 press = false;
868 868
869 replayList.append( new int( nrFrames ) ); 869 replayList.append( new int( nrFrames ) );
870 } 870 }
871 break; 871 break;
872 872
873 case Qt::Key_R: 873 case Qt::Key_R:
874 if ( state == STATE_CRASHED ) 874 if ( state == STATE_CRASHED )
875 { 875 {
876 state = STATE_REPLAY; 876 state = STATE_REPLAY;
877 } 877 }
878 break; 878 break;
879 879
880 case Qt::Key_Down: 880 case Qt::Key_Down:
881 if ( state == STATE_CRASHED ) 881 if ( state == STATE_CRASHED )
882 state = STATE_NEWGAME; 882 state = STATE_NEWGAME;
883 break; 883 break;
884 884
885 case Qt::Key_S: 885 case Qt::Key_S:
886 saveReplay(); 886 if ( state == STATE_CRASHED )
887 saveReplay();
887 break; 888 break;
888 889
889 case Qt::Key_L: 890 case Qt::Key_L:
890 loadReplay(); 891 if ( state == STATE_CRASHED )
892 loadReplay();
891 break; 893 break;
892 default: 894 default:
893 e->ignore(); 895 e->ignore();
894 break; 896 break;
895 } 897 }
896 } 898 }
897 899
898} 900}
899 901
900void SFCave :: displayMenu() 902void SFCave :: displayMenu()
901{ 903{
902 offscreen->fill( Qt::black ); 904 offscreen->fill( Qt::black );
903 905
904 QPainter p( offscreen ); 906 QPainter p( offscreen );
905 p.setPen( Qt::white ); 907 p.setPen( Qt::white );
906 908
907 QFont f( "Helvetica", 16 ); 909 QFont f( "Helvetica", 16 );
908 p.setFont( f ); 910 p.setFont( f );
909 911
910 QFontMetrics fm = p.fontMetrics(); 912 QFontMetrics fm = p.fontMetrics();
911 913
912 QString text = "SFCave"; 914 QString text = "SFCave";
913 p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); 915 p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text );
914 916
915 text = "Written by Andy Qua"; 917 text = "Written by Andy Qua";
916 p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); 918 p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text );
917 919
918 // Draw options 920 // Draw options
919 int pos = 170; 921 int pos = 170;
920 for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) 922 for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 )
921 { 923 {
922 if ( currentMenuOption[currentMenuNr] == i ) 924 if ( currentMenuOption[currentMenuNr] == i )
923 p.setPen( Qt::yellow ); 925 p.setPen( Qt::yellow );
924 else 926 else
925 p.setPen( Qt::white ); 927 p.setPen( Qt::white );
926 928
927 QString text; 929 QString text;
928 if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) 930 if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 )
929 { 931 {
930 QString val; 932 QString val;
931 if ( i == MENU_GAME_TYPE ) 933 if ( i == MENU_GAME_TYPE )
932 val = gameTypes[currentGameType]; 934 val = gameTypes[currentGameType];
933 else 935 else
934 val = dificultyOption[currentGameDifficulty]; 936 val = dificultyOption[currentGameDifficulty];
935 937
936 text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); 938 text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val );
937 } 939 }
938 else 940 else
939 text = menuOptions[currentMenuNr][i]; 941 text = menuOptions[currentMenuNr][i];
940 942
941 p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); 943 p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text );
942 } 944 }
943 945
944 p.end(); 946 p.end();
945 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 947 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
946} 948}
947 949
948void SFCave :: dealWithMenuSelection() 950void SFCave :: dealWithMenuSelection()
949{ 951{
950 switch( currentMenuNr ) 952 switch( currentMenuNr )
951 { 953 {
952 case MENU_MAIN_MENU: 954 case MENU_MAIN_MENU:
953 { 955 {
954 switch( currentMenuOption[currentMenuNr] ) 956 switch( currentMenuOption[currentMenuNr] )
955 { 957 {
956 case MENU_START_GAME: 958 case MENU_START_GAME:
957 state = STATE_NEWGAME; 959 state = STATE_NEWGAME;
958 break; 960 break;
959 961
960 case MENU_OPTIONS: 962 case MENU_OPTIONS:
961 currentMenuNr = MENU_OPTIONS_MENU; 963 currentMenuNr = MENU_OPTIONS_MENU;
962 currentMenuOption[currentMenuNr] = 0; 964 currentMenuOption[currentMenuNr] = 0;
963 break; 965 break;
964 966
965 case MENU_HELP: 967 case MENU_HELP:
966 { 968 {
967 // Display Help Menu 969 // Display Help Menu
968 HelpWindow *dlg = new HelpWindow( this ); 970 HelpWindow *dlg = new HelpWindow( this );
969 dlg->exec(); 971 dlg->exec();
970 delete dlg; 972 delete dlg;
971 break; 973 break;
972 } 974 }
973 975
974 case MENU_QUIT: 976 case MENU_QUIT:
975 QApplication::exit(); 977 QApplication::exit();
976 break; 978 break;
977 } 979 }
978 980
979 break; 981 break;
980 } 982 }
981 983
982 case MENU_OPTIONS_MENU: 984 case MENU_OPTIONS_MENU:
983 { 985 {
984 switch( currentMenuOption[currentMenuNr] ) 986 switch( currentMenuOption[currentMenuNr] )
985 { 987 {
986 case MENU_GAME_TYPE: 988 case MENU_GAME_TYPE:
987 break; 989 break;
988 990
989 case MENU_GAME_DIFFICULTY: 991 case MENU_GAME_DIFFICULTY:
990 break; 992 break;
991 993
992 case MENU_CLEAR_HIGHSCORES: 994 case MENU_CLEAR_HIGHSCORES:
993 for ( int i = 0 ; i < 3 ; ++i ) 995 for ( int i = 0 ; i < 3 ; ++i )
994 highestScore[currentGameType][i] = 0; 996 highestScore[currentGameType][i] = 0;
995 break; 997 break;
996 998
997 case MENU_BACK: 999 case MENU_BACK:
998 currentMenuNr = MENU_MAIN_MENU; 1000 currentMenuNr = MENU_MAIN_MENU;
999 1001
1000#ifdef QWS 1002#ifdef QWS
1001 Config cfg( "sfcave" ); 1003 Config cfg( "sfcave" );
1002 cfg.setGroup( "settings" ); 1004 cfg.setGroup( "settings" );
1003 cfg.writeEntry( "difficulty", currentGameDifficulty ); 1005 cfg.writeEntry( "difficulty", currentGameDifficulty );
1004 cfg.writeEntry( "gameType", currentGameType ); 1006 cfg.writeEntry( "gameType", currentGameType );
1005#endif 1007#endif
1006 break; 1008 break;
1007 } 1009 }
1008 1010
1009 break; 1011 break;
1010 } 1012 }
1011 } 1013 }
1012} 1014}
1013 1015
1014void SFCave :: saveScore() 1016void SFCave :: saveScore()
1015{ 1017{
1016#ifdef QWS 1018#ifdef QWS
1017 Config cfg( "sfcave" ); 1019 Config cfg( "sfcave" );
1018 cfg.setGroup( "settings" ); 1020 cfg.setGroup( "settings" );
1019 QString key = "highScore_"; 1021 QString key = "highScore_";
1020 1022
1021 cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); 1023 cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] );
1022 key += CURRENT_GAME_TYPE; 1024 key += CURRENT_GAME_TYPE;
1023 cfg.writeEntry( key, highestScore[currentGameType] ); 1025 cfg.writeEntry( key, highestScore[currentGameType] );
1024#endif 1026#endif
1025} 1027}
1026 1028
1027void SFCave :: saveReplay() 1029void SFCave :: saveReplay()
1028{ 1030{
1029 FILE *out; 1031 FILE *out;
1030 out = fopen( (const char *)replayFile, "w" ); 1032 out = fopen( (const char *)replayFile, "w" );
1031 if ( !out ) 1033 if ( !out )
1032 { 1034 {
1033 printf( "Couldn't write to /home/root/sfcave.replay\n" ); 1035 printf( "Couldn't write to /home/root/sfcave.replay\n" );
1034 return; 1036 return;
1035 } 1037 }
1036 1038
1037 // Build up string of values 1039 // Build up string of values
1038 // Format is:: <landscape seed> <framenr> <framenr>....... 1040 // Format is:: <landscape seed> <framenr> <framenr>.......
1039 QString val; 1041 QString val;
1040 val.sprintf( "%d ", currentSeed ); 1042 val.sprintf( "%d ", currentSeed );
1041 1043
1042 QListIterator<int> it( replayList ); 1044 QListIterator<int> it( replayList );
1043 while( it.current() ) 1045 while( it.current() )
1044 { 1046 {
1045 QString tmp; 1047 QString tmp;
1046 tmp.sprintf( "%d ", (*it.current()) ); 1048 tmp.sprintf( "%d ", (*it.current()) );
1047 val += tmp; 1049 val += tmp;
1048 1050
1049 ++it; 1051 ++it;
1050 } 1052 }
1051 val += "\n"; 1053 val += "\n";
1052 1054
1053 QString line; 1055 QString line;
1054 line.sprintf( "%d\n", val.length() ); 1056 line.sprintf( "%d\n", val.length() );
1055 fwrite( (const char *)line, 1, line.length(), out ); 1057 fwrite( (const char *)line, 1, line.length(), out );
1056 fwrite( (const char *)val, 1, val.length(), out ); 1058 fwrite( (const char *)val, 1, val.length(), out );
1057 1059
1058 fclose( out ); 1060 fclose( out );
1059 1061
1060 printf( "Replay saved to %s\n", (const char *)replayFile ); 1062 printf( "Replay saved to %s\n", (const char *)replayFile );
1061 1063
1062} 1064}
1063 1065
1064void SFCave :: loadReplay() 1066void SFCave :: loadReplay()
1065{ 1067{
1066 FILE *in = fopen( (const char *)replayFile, "r" ); 1068 FILE *in = fopen( (const char *)replayFile, "r" );
1067 1069
1070 if ( in == 0 )
1071 {
1072 printf( "Couldn't load replay file!\n" );
1073 return;
1074 }
1068 // Read size of next line 1075 // Read size of next line
1069 char line[10+1]; 1076 char line[10+1];
1070 fgets( line, 10, in ); 1077 fgets( line, 10, in );
1071 1078
1072 int length = -1; 1079 int length = -1;
1073 sscanf( line, "%d", &length ); 1080 sscanf( line, "%d", &length );
1074 char *data = new char[length+1]; 1081 char *data = new char[length+1];
1075 1082
1076 fread( data, 1, length, in ); 1083 fread( data, 1, length, in );
1077 1084
1078 QString sep = " "; 1085 QString sep = " ";
1079 QStringList list = QStringList::split( sep, QString( data ) ); 1086 QStringList list = QStringList::split( sep, QString( data ) );
1080 1087
1081 // print it out 1088 // print it out
1082 QStringList::Iterator it = list.begin(); 1089 QStringList::Iterator it = list.begin();
1083 currentSeed = (*it).toInt(); 1090 currentSeed = (*it).toInt();
1084 ++it; 1091 ++it;
1085 1092
1086 replayList.clear(); 1093 replayList.clear();
1087 for ( ; it != list.end(); ++it ) 1094 for ( ; it != list.end(); ++it )
1088 { 1095 {
1089 int v = (*it).toInt(); 1096 int v = (*it).toInt();
1090 replayList.append( new int( v ) ); 1097 replayList.append( new int( v ) );
1091 } 1098 }
1092 1099
1093 delete data; 1100 delete data;
1094 1101
1095 fclose( in ); 1102 fclose( in );
1103
1104 printf( "Replay loaded from %s\n", (const char *)replayFile );
1096} \ No newline at end of file 1105} \ No newline at end of file