'startrek ver0.14 dim qmap, smap, bs, kg, ep '********** calc sin deg ********** sub c_sin(c, d, x){ dim a a = sin(c * 0.01745329251) * d + x a = round(a, 0) return(a) } '********** calc cos deg ********** sub c_cos(c, d, y){ dim a a = -cos(c * 0.01745329251) * d + y a = round(a, 0) return(a) } '********** set qmap ********** sub set_qmap { dim x, y, n, m 'clear for(y = 0 to 7){ for(x = 0 to 7){ qmap[y][x].star = rnd(9) + 1 qmap[y][x].base = 0 qmap[y][x].klingon = 0 qmap[y][x].secret = 0 } } 'set base bs.number = 0 n = 3 while(n > 0){ x = rnd(8) y = rnd(8) if(qmap[y][x].base == 0){ qmap[y][x].base = 1 bs.number = bs.number + 1 n = n - 1 } } 'set klingon kg.number = 0 n = 30 while(n > 0){ x = rnd(8) y = rnd(8) if(qmap[y][x].klingon == 0){ m = rnd(5) + 1 qmap[y][x].klingon = m kg.number = kg.number + m n = n - m } } 'set enterprize data ep.qpos.x = rnd(8) ep.qpos.y = rnd(8) ep.spos.x = rnd(8) ep.spos.y = rnd(8) ep.energy = 4000 ep.torpedoes = 10 ep.limit = 0 smap.mode = 0 } '********** set smap ********** sub set_smap { dim x, y, n 'clear for(y = 0 to 7){ for(x = 0 to 7){ smap[y][x].data = "." } } 'clear secret qmap[ep.qpos.y][ep.qpos.x].secret = 1 'set enterprize smap[ep.spos.y][ep.spos.x].data = "E" 'set klingon n = qmap[ep.qpos.y][ep.qpos.x].klingon while(n > 0){ x = rnd(8) y = rnd(8) if(smap[y][x].data == "."){ smap[y][x].data = "K" smap[y][x].energy = rnd(150) + 150 n = n - 1 } } 'set base n = qmap[ep.qpos.y][ep.qpos.x].base while(n > 0){ x = rnd(8) y = rnd(8) if(smap[y][x].data == "."){ smap[y][x].data = "B" n = n - 1 } } 'set star n = qmap[ep.qpos.y][ep.qpos.x].star while(n > 0){ x = rnd(8) y = rnd(8) if(smap[y][x].data == "."){ smap[y][x].data = "*" n = n - 1 } } } '********** disp enterprize position ********** sub dsp_epos { print "Enterprize in " print "Q(", ep.qpos.x + 1, ",", ep.qpos.y + 1, ") " print "S(", ep.spos.x + 1, ",", ep.spos.y + 1, ")\n" } '********** check starbase ********** sub chk_base { dim x, y for(y = ep.spos.y - 1 to ep.spos.y + 1){ for(x = ep.spos.x - 1 to ep.spos.x + 1){ if(x >= 0) and (x <= 7) and (y >= 0) and (y <= 7){ if(smap[y][x].data == "B"){ return(1) } } } } return(0) } '********** dsp device ********** sub dsp_device(n) { dim m if(n==0){ print "Short Range Sensor" } if(n==1){ print "Computer Display" } if(n==2){ print "Long Range Sensor" } if(n==3){ print "Phaser" } if(n==4){ print "Photon Torpedo Tubes" } if(n==5){ print "Warp Engine" } if(n==6){ print "Shield" } m = round(ep.device[n].damage - ep.limit, 2) if(m > 0){ print " damaged, ", m, " stardates estimated for repair\n" return(m) } return(0) } '********** set damegi ********** sub s_damegi(n) { if(n == 1){ if(rnd(6) == 0){ print "\n** space storm **\n" } else { return } } n = 6 if(ep.device[6].damage > ep.limit + 0.1){ n = rnd(6) } if(ep.device[n].damage > ep.limit){ ep.device[n].damage = round(ep.device[n].damage + rnd(5) / 100, 2) } else{ ep.device[n].damage = round(ep.limit + rnd(5) / 100, 2) } if(ep.device[n].damage > ep.limit){ dsp_device(n) } } '********** dsp 1 map ********** sub s_dspnum(x, y) { dim n if(qmap[y][x].secret == 1){ n = qmap[y][x].klingon * 100 + qmap[y][x].base * 10 + qmap[y][x].star print right(" " + str(n), 4) } else{ print " ..." } } '********** main galaxy map ********** sub m_gmap { dim n, x, y cls dsp_epos() n = dsp_device(1) if(n > 0) { return } print " of Galaxy Map\n" for(y = 0 to 7){ print y + 1 for(x = 0 to 7){ s_dspnum(x, y) } print "\n" } print " 1 2 3 4 5 6 7 8\n" } '********** main long range sensor ********** sub m_long { dim n, x, y cls dsp_epos() n = dsp_device(2) if(n > 0) { return } print "\n" for(y = ep.qpos.y - 1 to ep.qpos.y + 1){ for(x = ep.qpos.x - 1 to ep.qpos.x + 1){ if(x < 0) or (x > 7) or (y < 0) or (y > 7){ print " ..." } else{ qmap[y][x].secret = 1 s_dspnum(x, y) } } print "\n" } return(0) } '********** main short range sensor ********** sub m_short { dim n, x, y cls dsp_epos() n = dsp_device(0) if(n > 0) { return } print "\n" if(smap.mode == 0){ set_smap() smap.mode = 1 } for(y = 0 to 7){ print y + 1 for(x = 0 to 7){ print " " print smap[y][x].data } print "\n" } print " 1 2 3 4 5 6 7 8\n" } '********** main worp engine ********** sub m_worp { dim n, d, c, ex, ey, x, y print "\n" dsp_epos() n = dsp_device(5) if(n > 0) { return } print "\n" input "Sector distance?", d d = val(d) if(d < 1) {return} if(d > 91){ print "Spock: Are you sure captain ???\n" d = 91 } if(ep.energy < round(d * d / 2, 0)){ print "Scotty: Sir, we do not have the energy.\n" return } input "course? (0-360)", c c = val(c) if(c < 0) or (c > 360){ return } ep.limit = round(ep.limit + int(sqr(d * 2)) * 0.01, 2) ep.energy = round(ep.energy - int(d * d / 2), 0) smap[ep.spos.y][ep.spos.x].data = "." ex = ep.spos.x ey = ep.spos.y for(n = 0 to d - 1){ x = c_sin(c, n + 1, ex) y = c_cos(c, n + 1, ey) if(x < 0) or (x > 7) or (y < 0) or (y > 7){ smap.mode = 0 x = c_sin(c, d, ex) y = c_cos(c, d, ey) ex = mod(x, 8) if(ex < 0){ex = ex + 8} ey = mod(y, 8) if(ey < 0){ey = ey + 8} ep.spos.x = ex ep.spos.y = ey x = ep.qpos.x + int(x / 8) y = ep.qpos.y + int(y / 8) if(x < 0) or (x > 7) or (y < 0) or (y > 7){ print "\n** You wandered outside of the galaxy **\n" ep.qpos.x = rnd(8) ep.qpos.y = rnd(8) return } ep.qpos.x = x ep.qpos.y = y break } if(smap[y][x].data != "."){ print "** emergency stop **\n", "Spock: To error is human\n" break } ep.spos.x = x ep.spos.y = y } smap[ep.spos.y][ep.spos.x].data = "E" if(smap.mode == 0){ set_smap() smap.mode = 1 } if(chk_base() == 1){ print "\nSulu: Capteain, we are docked at starbase.\n" ep.energy = 4000 ep.torpedoes = 10 for n=0 to 7 { ep.device[n].damage = ep.limit } } else{ s_damegi(1) print "\n" } } '********** main photon torpedo tubes ********** sub m_torpedo { dim n, c, ex, ey, x, y, wx, wy ep.limit = round(ep.limit + 0.01, 2) print "\n" dsp_epos() n = dsp_device(4) if(n > 0) { return } print "\n" if(ep.torpedoes == 0){ print "empty\n" return } print "loaded\n" input "course? (0-360)", c c = val(c) if(c < 0) or (c > 360){ return } print "torpedo track\n" ep.torpedoes = ep.torpedoes - 1 ex = ep.spos.x ey = ep.spos.y wx = -1 wy = -1 for(n=0 to 11){ x = c_sin(c, n + 1, ex) y = c_cos(c, n + 1, ey) if(x < 0) or (x > 7) or (y < 0) or (y > 7){ print "missed\n" break } if(x != wx) or (y != wy){ wx = x wy = y print " ", x + 1, ",", y + 1, " " } if(smap[y][x].data == "*"){ print "hit star\n" if(rnd(6) < 3){ print "star absorbed\n" break } print "star destroyed\n" smap[y][x].data = "." qmap[ep.qpos.y][ep.qpos.x].star = qmap[ep.qpos.y][ep.qpos.x].star - 1 break } if(smap[y][x].data == "B"){ print "starbase destroyed\n", "Spock: I often find human behaviour fascinating.\n" smap[y][x].data = "." qmap[ep.qpos.y][ep.qpos.x].base = qmap[ep.qpos.y][ep.qpos.x].base - 1 bs.number = bs.number - 1 break } if(smap[y][x].data == "K"){ print "klingon at S(", x + 1, ",", y + 1, ") ", "** destroyed **\n" smap[y][x].data = "." qmap[ep.qpos.y][ep.qpos.x].klingon = qmap[ep.qpos.y][ep.qpos.x].klingon - 1 kg.number = kg.number - 1 break } } } '********** main phaser ********** sub m_phasers { dim n, e, k, ex, ey, x, y, kx, ky, d ep.limit = round(ep.limit + 0.01, 2) print "\n" dsp_epos() n = dsp_device(3) if(n > 0) { return } print "energized ", ep.energy, "\n" input "What units to fire?", e e = val(e) if(e < 0) or (e > ep.energy){ return } ep.energy = ep.energy - e if(e > 2090) { print "over loased\n" if(ep.device[3].damage > ep.limit){ ep.device[3].damage = ep.device[3].damage + 0.05 } else{ ep.device[3].damage = ep.limit + 0.05 } dsp_device(3) e = 90 } k = qmap[ep.qpos.y][ep.qpos.x].klingon if(k == 0){ print "Phaser fired at empty space.\n" return } ex = ep.spos.x ey = ep.spos.y for(y = 0 to 7){ for(x = 0 to 7){ if(smap[y][x].data == "K"){ kx = x + 1 ky = y + 1 print "Klingon at S(", kx, ",", ky, ") " d = sqr((ex - kx) * (ex - kx) + (ey - ky) * (ey - ky)) if(d < 1){ d = 1 } smap[y][x].energy = smap[y][x].energy - int(e / d) if(smap[y][x].energy > 0){ print "** damaged **\n" } else{ print "** destroyed **\n" smap[y][x].data = "." qmap[ep.qpos.y][ep.qpos.x].klingon = qmap[ep.qpos.y][ep.qpos.x].klingon - 1 kg.number = kg.number - 1 } } } } } '********** main status report ********** sub m_report(md) { dim s, n if(md == 0){ cls } print "Status Report\n" print "star date ", ep.limit + 3200, " time left ", 3 - ep.limit, "\n" s = "green" if(ep.energy < 1000) { s = "yellow" } if(chk_base() == 1) { s = "docked" } if(qmap[ep.qpos.y][ep.qpos.x].klingon > 0) { s = "red" } print "condition ", s, "\n" dsp_epos() print "energy ", ep.energy, "\n" print "torpedoes ", ep.torpedoes, "\n" print "klingons left ", kg.number, "\n" print "starbases ", bs.number, "\n" n = 7 while(n > 0){ n = n - 1 if(ep.device[n].damage > ep.limit){ dsp_device(n) } } } '********** main help ********** sub m_help { cls print "Command:\n", " W - Warp Engine\n", " P - Phaser\n", " T - Photon Torpedo Tubes\n", " S - Short Range Sensor\n", " L - Long Range Sensor\n", " G - Galaxy Map\n", " R - Status Report\n", " Q - Quit\n" } '********** main m_klingon ********** sub m_klingons { dim n, x, y n = qmap[ep.qpos.y][ep.qpos.x].klingon if(n == 0){ return } print "Klingon attack\n" for(y = 0 to 7){ for(x = 0 to 7){ if(smap[y][x].data == "K"){ print smap[y][x].energy, " units hit from Klingon at S(", x + 1, ",", y + 1, ")\n" ep.energy = ep.energy - smap[y][x].energy } } } s_damegi(0) if(ep.energy < 0){ print "\n bang\n" } } '********** main quit ********** sub m_quit { dim s input "quit? (Y, N)", s s = upper(s) if(s == "Y"){ end } } '********** main program ********** sub m_main { dim w, s screen(480, 320) set_qmap() cls print "Stardate 3200, your mission is to destroy " print kg.number, " Klingons in 3 stardates.\n" print "There are " , bs.number, " starbases.\n" while(1){ w = ep.limit input "Command? (W,P,T,S,L,G,R,Q,?)", s s = upper(s) if(s == "W") { m_worp() } if(s == "P") { m_phasers() } if(s == "T") { m_torpedo() } if(s == "S") { m_short() } if(s == "L") { m_long() } if(s == "G") { m_gmap() } if(s == "R") { m_report(0) } if(s == "Q") { m_quit() } if(s == "?") { m_help() } if(ep.limit > w){ m_klingons() } if(kg.number == 0){ print "\nMission accomplished.\n\n" break } if(ep.energy < 1){ print "\nEnterprize destroyed.\n\n" break } if(ep.limit > 3){ print "\nIt's too late\n" print "The federation has been conquered.\n\n" break } } } '********** program start ********** m_main() m_report(1)