[svn-commits] marquis: trunk r875 - /trunk/menuselect_curses.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Apr 5 14:04:25 CDT 2011


Author: marquis
Date: Tue Apr  5 14:04:19 2011
New Revision: 875

URL: http://svnview.digium.com/svn/menuselect?view=rev&rev=875
Log:
Add multiple levels to cmenuselect-invaders

The current ASCII-based Invaders game in cmenuselect only has one level, and then the game ends.  This patch adds more, with ever-increasing difficulty.

(closes issue #19039)
Reported by: Marquis
Patches:
      invaders.patch uploaded by Marquis (license 32)
Tested by: rgagnon

Modified:
    trunk/menuselect_curses.c

Modified: trunk/menuselect_curses.c
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect_curses.c?view=diff&rev=875&r1=874&r2=875
==============================================================================
--- trunk/menuselect_curses.c (original)
+++ trunk/menuselect_curses.c Tue Apr  5 14:04:19 2011
@@ -566,6 +566,7 @@
 
 static int score = 0;
 static int num_aliens = 0;
+static int alien_sleeptime = 0;
 struct blip *tank = NULL;
 
 /*! Probability of a bomb, out of 100 */
@@ -808,8 +809,13 @@
 			remove_blip(shot);
 			remove_blip(cur);
 			if (!num_aliens) {
-				game_over(1);
-				return 1;
+				if(alien_sleeptime < 101) {
+					game_over(1);
+					return 1;
+				} else {
+					alien_sleeptime = alien_sleeptime - 100;
+					return 1;
+				}
 			}
 		}
 	}
@@ -839,55 +845,61 @@
 	unsigned int jiffies = 1;
 	int quit = 0;
 	struct blip *blip;
-
-	clear();
-	nodelay(stdscr, TRUE);
-	init_blips();
-	repaint_screen();
-
-	for (;;) {
-		c = getch();
-		switch (c) {
-		case ' ':
-			tank_shoot();
-			break;
-		case KEY_LEFT:
-			tank_move_left();
-			break;
-		case KEY_RIGHT:
-			tank_move_right();
-			break;
-		case 'x':
-		case 'X':
-		case 'q':
-		case 'Q':
-			quit = 1;
-		default:
-			/* ignore unknown input */
-			break;
-		}
-		if (quit)
-			break;
-		if (!(jiffies % 25)) {
-			if (move_aliens() || move_bombs()) {
-				game_over(0);
+	alien_sleeptime = 1000;
+
+	while(alien_sleeptime > 100) {
+
+		jiffies = 1;
+		clear();
+		nodelay(stdscr, TRUE);
+		init_blips();
+		repaint_screen();
+
+		for (;;) {
+			c = getch();
+			switch (c) {
+			case ' ':
+				tank_shoot();
+				break;
+			case KEY_LEFT:
+				tank_move_left();
+				break;
+			case KEY_RIGHT:
+				tank_move_right();
+				break;
+			case 'x':
+			case 'X':
+			case 'q':
+			case 'Q':
+				quit = 1;
+			default:
+				/* ignore unknown input */
 				break;
 			}
-			if (check_placement())
+			if (quit)
 				break;
-		}
-		if (!(jiffies % 10)) {
-			move_shots();
-			if (check_placement())
-				break;
-		}
-		repaint_screen();
-		jiffies++;
-		usleep(1000);
-	}
-
-	while ((blip = AST_LIST_REMOVE_HEAD(&blips, entry)))
-		free(blip);
+			if (!(jiffies % 25)) {
+				if (move_aliens() || move_bombs()) {
+					alien_sleeptime = 1;
+					game_over(0);
+					break;
+				}
+				if (check_placement())
+					break;
+			}
+			if (!(jiffies % 10)) {
+				move_shots();
+				if (check_placement())
+					break;
+			}
+			repaint_screen();
+			jiffies++;
+			usleep(alien_sleeptime);
+		}
+
+		while ((blip = AST_LIST_REMOVE_HEAD(&blips, entry)))
+			free(blip);
+	}
 
 	nodelay(stdscr, FALSE);
 }




More information about the svn-commits mailing list