'=========================================================================== ' Subject: GUESS 4 NUMBERS Date: 11-16-97 (20:36) ' Author: Andrey Berezansky Code: QB, QBasic, PDS ' Origin: nikolai@nsi.co.il Packet: GAMES.ABC '=========================================================================== ' game by Berezansky Andrey ' rules are: ' you have to guess 4 numbers (that computer has randomly chosen) ' by pressing numbers from 0 to 9 ,every number that you press ' will give you 1 clue (the clues will appear when 4 numbers ' are pressed) : either the number is right and it is in ' right position , or the number is right and it is in wrong ' position ,if the number is wrong no clues will appear . ' EXAMPLE : if computer number is 1111 and you guess is 1234 you will ' recive one clue - one number is right and he is in right place. ' ' SEE ANOTHER EXAMPLE IN THE GAME ! (just try to play and you will figure out ' what to do) ! ' send any coments to NIKOL@CS.BGU.AC.IL DECLARE SUB calc () DECLARE SUB drow () DECLARE SUB nxt () RANDOMIZE TIMER SCREEN 9 10 CLS DIM SHARED a(4) DIM SHARED num(4) FOR i = 1 TO 4 num(i) = INT(RND * 10) NEXT 'num(1) = 1: num(2) = 1: num(3) = 2: num(4) = 3 x = 6: y = 2: n = 1: exitt = 0: endd = 0 '---------table----------------- FOR i = 2 TO 21 LOCATE i, 1: PRINT i - 1 NEXT LINE (31, 13)-(105, 293), 4, B LINE (106, 13)-(180, 293), 4, B FOR i = 27 TO 293 STEP 14 LINE (31, i)-(180, i), 4 NEXT COLOR 13 FOR u = 200 TO 578 col = col + 1 IF col = 15 THEN col = 8 LINE (u, 1)-(u + 40, 15), col LINE (u + 1, 1)-(u + 41, 15), col LINE (u + 2, 1)-(u + 42, 15), col LINE (u + 3, 1)-(u + 43, 15), col LOCATE 1, 33: PRINT " game NUMBERS by BEREZANSKY ANDREY " NEXT COLOR 15 LOCATE 4, 30: PRINT " - number is right and in right position" LOCATE 5, 30: PRINT " - number is right but in wrong position" LOCATE 7, 29: PRINT "EXAMPLE : if the number is 1234 and you guess" LOCATE 8, 29: PRINT "is 1111 the result will be - " LINE (240, 42)-(256, 54), 12, BF LINE (240, 56)-(256, 68), 11, BF LINE (455, 99)-(471, 111), 12, BF LINE (473, 99)-(489, 111), 11, BF LINE (491, 99)-(507, 111), 11, BF LINE (509, 99)-(525, 111), 11, BF '------------------------------- DO WHILE exitt = 0 SELECT CASE INKEY$ CASE "1" LOCATE y, x: PRINT "1"; x = x + 2: a(n) = 1: n = n + 1 CASE "2" LOCATE y, x: PRINT "2"; x = x + 2: a(n) = 2: n = n + 1 CASE "3" LOCATE y, x: PRINT "3"; x = x + 2: a(n) = 3: n = n + 1 CASE "4" LOCATE y, x: PRINT "4"; x = x + 2: a(n) = 4: n = n + 1 CASE "5" LOCATE y, x: PRINT "5"; x = x + 2: a(n) = 5: n = n + 1 CASE "6" LOCATE y, x: PRINT "6"; x = x + 2: a(n) = 6: n = n + 1 CASE "7" LOCATE y, x: PRINT "7"; x = x + 2: a(n) = 7: n = n + 1 CASE "8" LOCATE y, x: PRINT "8"; x = x + 2: a(n) = 8: n = n + 1 CASE "9" LOCATE y, x: PRINT "9"; x = x + 2: a(n) = 9: n = n + 1 CASE "0" LOCATE y, x: PRINT "0"; x = x + 2: a(n) = 0: n = n + 1 END SELECT CALL nxt LOOP IF y > 21 THEN COLOR 14 LOCATE 12, 42: PRINT " YOU LOOSE !!! " LOCATE 13, 42: PRINT "real numbers are : " FOR i = 1 TO 4 LOCATE 14, i * 3 + 41: PRINT num(i); NEXT END IF COLOR 15 DO WHILE endd = 0 LOCATE 17, 44: PRINT "PLAY ANOTHER ?" SELECT CASE INKEY$ CASE "y" endd = 1 GOTO 10 CASE "n" endd = 1 END SELECT LOOP LOCATE 19, 48: PRINT "BYE" SUB calc SHARED fl, nfl, y, exitt FOR i = 1 TO 4 FOR ii = 1 TO 4 IF a(i) = num(ii) AND i = ii THEN aa = aa + 1 IF a(i) = num(ii) AND i <> ii THEN bb = bb + 1 NEXT ii IF aa = 1 THEN fl = fl + 1 IF bb > 0 AND aa = 0 THEN nfl = nfl + 1 aa = 0: bb = 0 NEXT 'LOCATE 10, 50: PRINT fl, nfl 'DO WHILE INKEY$ = "": LOOP IF fl > 0 OR nfl > 0 THEN drow IF fl = 4 THEN COLOR 14 y = y - 1 LOCATE 11, 34: PRINT "YOU WIN !!! WITH "; y; " GUESSES !" exitt = 1 END IF fl = 0: nfl = 0 END SUB SUB drow SHARED fl, nfl, y FOR i = 1 TO fl x1 = 92 + 16 * i + (i - 1) * 2 y1 = 14 + (y - 2) * 14 x2 = 92 + 16 * (i + 1) + (i - 1) * 2 y2 = 26 + (y - 2) * 14 LINE (x1, y1)-(x2, y2), 12, BF NEXT FOR i = fl + 1 TO nfl + fl x1 = 92 + 16 * i + (i - 1) * 2 y1 = 14 + (y - 2) * 14 x2 = 92 + 16 * (i + 1) + (i - 1) * 2 y2 = 26 + (y - 2) * 14 LINE (x1, y1)-(x2, y2), 11, BF NEXT END SUB SUB nxt SHARED x, y, exitt, n FOR i = 27 TO 293 STEP 14 LINE (31, i)-(180, i), 4 NEXT IF x > 12 THEN CALL calc y = y + 1: x = 6: n = 1 END IF IF y > 21 THEN exitt = 1 END SUB