summaryrefslogtreecommitdiff
authorandyq <andyq>2002-12-11 17:58:53 (UTC)
committer andyq <andyq>2002-12-11 17:58:53 (UTC)
commitf4865ac8e114baedd13c95160631e4574da9dc84 (patch) (unidiff)
treeecc74f212ffde8b9733ad6a7dd9e2360717917ef
parent676f39d78772b19d11471db55ece82262278f942 (diff)
downloadopie-f4865ac8e114baedd13c95160631e4574da9dc84.zip
opie-f4865ac8e114baedd13c95160631e4574da9dc84.tar.gz
opie-f4865ac8e114baedd13c95160631e4574da9dc84.tar.bz2
Added check for no replay file on loading and fixed bugs where you could screw up the replay by pressing stuff
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
@@ -821,17 +821,17 @@ void SFCave :: keyPressEvent( QKeyEvent *e )
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:
@@ -857,17 +857,17 @@ void SFCave :: keyReleaseEvent( QKeyEvent *e )
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:
@@ -878,21 +878,23 @@ void SFCave :: keyReleaseEvent( QKeyEvent *e )
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}
@@ -1060,16 +1062,21 @@ void SFCave :: saveReplay()
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
@@ -1088,9 +1095,11 @@ void SFCave :: loadReplay()
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