SHOW:
|
|
- or go back to the newest paste.
| 1 | --Turtle funkcijas | |
| 2 | -- Ielasa no faila kordinates | |
| 3 | function f_ielas(fails,n) | |
| 4 | local fh = io.open(fails, "r") | |
| 5 | local atbilde = fh:read("*a")
| |
| 6 | fh:close() | |
| 7 | sleep(0) | |
| 8 | if n==true then | |
| 9 | local atbild=1+atbilde | |
| 10 | local atbild=atbild-1 | |
| 11 | return atbild | |
| 12 | else | |
| 13 | return atbilde | |
| 14 | end | |
| 15 | end | |
| 16 | ||
| 17 | function ielasa() | |
| 18 | print("Sakam ielasit failus!")
| |
| 19 | x = f_ielas("x",true)
| |
| 20 | print("X kordinates ielasitas!")
| |
| 21 | y = f_ielas("y",true)
| |
| 22 | print("Y kordinates ielasitas!")
| |
| 23 | z = f_ielas("z",true)
| |
| 24 | print("Z kordinates ielasitas!")
| |
| 25 | f = f_ielas("f",true)
| |
| 26 | print("Ielasits uz kuru pusi robots pagriezts!")
| |
| 27 | xsak = f_ielas("xsak",true)
| |
| 28 | print("Xsak kordinates ielasitas!")
| |
| 29 | ysak = f_ielas("ysak",true)
| |
| 30 | print("Ysak kordinates ielasitas!")
| |
| 31 | zsak = f_ielas("zsak",true)
| |
| 32 | print("Zsak kordinates ielasitas!")
| |
| 33 | fsak = f_ielas("fsak",true)
| |
| 34 | print("Ielasits uz kuru pusi robots pagriezies sākumā!")
| |
| 35 | darb = f_ielas("darb",true)
| |
| 36 | print("Ielasits kada funkcija javeic!")
| |
| 37 | ||
| 38 | end | |
| 39 | ||
| 40 | --Saglaba txt faila kordinates | |
| 41 | function sagl(kuru) -- Kuru var but f < saglaba virzienu un coor saglaba atrasanas vietu | |
| 42 | if kuru=="f" then | |
| 43 | shell.run("delete","f")
| |
| 44 | local fh = io.open("f", "w")
| |
| 45 | fh:write(f) | |
| 46 | fh:close() | |
| 47 | end | |
| 48 | ||
| 49 | if kuru=="coor" then | |
| 50 | shell.run("delete","x")
| |
| 51 | local fh = io.open("x","w")
| |
| 52 | fh:write(x) | |
| 53 | fh:close() | |
| 54 | sleep(0) | |
| 55 | shell.run("delete","y")
| |
| 56 | local fh = io.open("y","w")
| |
| 57 | fh:write(y) | |
| 58 | fh:close() | |
| 59 | sleep(0) | |
| 60 | shell.run("delete","z")
| |
| 61 | local fh = io.open("z","w")
| |
| 62 | fh:write(z) | |
| 63 | fh:close() | |
| 64 | sleep(0) | |
| 65 | end | |
| 66 | ||
| 67 | end | |
| 68 | ||
| 69 | function saglabat(fails, teksts) -- Funkcija saglaba teksta faila tekstu | |
| 70 | --shell.run("delete",fails)
| |
| 71 | fs.delete(fails) | |
| 72 | local fh = io.open(fails,"w") | |
| 73 | fh:write(teksts) | |
| 74 | fh:close() | |
| 75 | return true | |
| 76 | end | |
| 77 | ||
| 78 | function vieta() | |
| 79 | if f==0 then t={0,1} end
| |
| 80 | if f==1 then t={-1,0} end
| |
| 81 | if f==2 then t={0,-1} end
| |
| 82 | if f==3 then t={1,0} end
| |
| 83 | return t | |
| 84 | end | |
| 85 | ||
| 86 | function pagrieziens() | |
| 87 | if f>3 then f=0 end | |
| 88 | if f<0 then f=3 end | |
| 89 | --z ir 2 | |
| 90 | --x ir 1 | |
| 91 | end | |
| 92 | ||
| 93 | ||
| 94 | --Ziemeli ir 2 un z samazinas | |
| 95 | --Austrumi ir 3 un x pieaug | |
| 96 | function paKreisi() | |
| 97 | f = f - 1 | |
| 98 | turtle.turnLeft() | |
| 99 | pagrieziens() | |
| 100 | sagl("f")
| |
| 101 | end | |
| 102 | ||
| 103 | function paLabi() | |
| 104 | f = f + 1 | |
| 105 | turtle.turnRight() | |
| 106 | pagrieziens() | |
| 107 | sagl("f")
| |
| 108 | end | |
| 109 | ||
| 110 | function uzPrieksu() | |
| 111 | if turtle.forward() then | |
| 112 | t=vieta() | |
| 113 | x=x+t[1] | |
| 114 | z=z+t[2] | |
| 115 | sagl("coor")
| |
| 116 | sleep(0) | |
| 117 | return true | |
| 118 | end | |
| 119 | return false | |
| 120 | end | |
| 121 | ||
| 122 | function uzAugsu() | |
| 123 | if turtle.up() then | |
| 124 | y=y+1 | |
| 125 | sleep(0) | |
| 126 | sagl("coor")
| |
| 127 | return true | |
| 128 | end | |
| 129 | return false | |
| 130 | end | |
| 131 | ||
| 132 | function uzLeju() | |
| 133 | if turtle.down() then | |
| 134 | y=y-1 | |
| 135 | sleep(0) | |
| 136 | sagl("coor")
| |
| 137 | return true | |
| 138 | end | |
| 139 | return false | |
| 140 | end | |
| 141 | ||
| 142 | function uzAtpakalu() | |
| 143 | if turtle.back() then | |
| 144 | t=vieta() | |
| 145 | x=x-t[1] | |
| 146 | z=z-t[2] | |
| 147 | sagl("coor")
| |
| 148 | return true | |
| 149 | end | |
| 150 | return false | |
| 151 | end | |
| 152 | ||
| 153 | function Izmest() | |
| 154 | ||
| 155 | local i | |
| 156 | for i=1,9 do | |
| 157 | turtle.select(i) | |
| 158 | turtle.drop() | |
| 159 | end | |
| 160 | ||
| 161 | end | |
| 162 | ||
| 163 | function UzLejuSasist() | |
| 164 | ||
| 165 | if turtle.digDown() then | |
| 166 | return true | |
| 167 | else | |
| 168 | return false | |
| 169 | end | |
| 170 | ||
| 171 | end | |
| 172 | ||
| 173 | function parbinv() --Atdod true, ja pilna inv | |
| 174 | local tmp | |
| 175 | tmp=true | |
| 176 | ||
| 177 | for i=1,9 do | |
| 178 | if (turtle.getItemCount(i)==0) then | |
| 179 | tmp=false | |
| 180 | break | |
| 181 | end | |
| 182 | ||
| 183 | end | |
| 184 | ||
| 185 | return tmp | |
| 186 | ||
| 187 | end | |
| 188 | ||
| 189 | --############################################### | |
| 190 | --Funkcijas apstrādes programmas | |
| 191 | ||
| 192 | function AprekinaRaksanu() | |
| 193 | ||
| 194 | if fsak==0 then | |
| 195 | zraksana=zsak-(kolon-1) | |
| 196 | xraksana=xsak-(rinda-1) | |
| 197 | end | |
| 198 | if fsak==1 then | |
| 199 | zraksana=zsak-(kolon-1) | |
| 200 | xraksana=xsak+(rinda-1) | |
| 201 | end | |
| 202 | if fsak==2 then | |
| 203 | zraksana=zsak+(kolon-1) | |
| 204 | xraksana=xsak+(rinda-1) | |
| 205 | end | |
| 206 | if fsak==3 then | |
| 207 | zraksana=zsak+(kolon-1) | |
| 208 | xraksana=xsak-(rinda-1) | |
| 209 | end | |
| 210 | ||
| 211 | end | |
| 212 | ||
| 213 | function kluda() | |
| 214 | term.setCursorPos(2,6) | |
| 215 | write("Notikusi kluda!")
| |
| 216 | sleep(3) | |
| 217 | os.reboot() | |
| 218 | end | |
| 219 | ||
| 220 | function noklusana(xgal,zgal) | |
| 221 | if x<xgal then | |
| 222 | while f~=3 do paLabi() sleep(1) end | |
| 223 | while x<xgal do | |
| 224 | sleep(0) | |
| 225 | atb=uzPrieksu() | |
| 226 | if atb==false then kluda() end | |
| 227 | end | |
| 228 | else | |
| 229 | while f~=1 do paLabi() sleep(1) end | |
| 230 | while x>xgal do | |
| 231 | sleep(0) | |
| 232 | atb=uzPrieksu() | |
| 233 | if atb==false then kluda() end | |
| 234 | end | |
| 235 | end | |
| 236 | ||
| 237 | if z>zgal then | |
| 238 | while f~=2 do paLabi() sleep(1) end | |
| 239 | while z>zgal do | |
| 240 | sleep(0) | |
| 241 | atb=uzPrieksu() | |
| 242 | if atb==false then kluda() end | |
| 243 | end | |
| 244 | else | |
| 245 | while f~=0 do paLabi() sleep(1) end | |
| 246 | while z<zgal do | |
| 247 | sleep(0) | |
| 248 | atb=uzPrieksu() | |
| 249 | if atb==false then kluda() end | |
| 250 | end | |
| 251 | end | |
| 252 | ||
| 253 | end | |
| 254 | ||
| 255 | ||
| 256 | function UzSakumu() | |
| 257 | while y<ysak do | |
| 258 | uzAugsu() | |
| 259 | end | |
| 260 | ||
| 261 | noklusana(xsak,zsak) | |
| 262 | ||
| 263 | while f~=fsak do | |
| 264 | ||
| 265 | paLabi() | |
| 266 | sleep(1) | |
| 267 | ||
| 268 | end | |
| 269 | ||
| 270 | Izmest() | |
| 271 | end | |
| 272 | ||
| 273 | function UzRaksanu() | |
| 274 | ||
| 275 | while y<ysak do | |
| 276 | uzAugsu() | |
| 277 | end | |
| 278 | ||
| 279 | AprekinaRaksanu() | |
| 280 | sleep(0) | |
| 281 | noklusana(xraksana,zraksana) | |
| 282 | ||
| 283 | end | |
| 284 | ||
| 285 | ||
| 286 | function Rakt() | |
| 287 | ||
| 288 | while true do | |
| 289 | sleep(0) | |
| 290 | if turtle.detectDown() then | |
| 291 | ||
| 292 | if turtle.digDown() then | |
| 293 | uzLeju() | |
| 294 | else | |
| 295 | break | |
| 296 | end | |
| 297 | ||
| 298 | else | |
| 299 | uzLeju() | |
| 300 | end | |
| 301 | ||
| 302 | if parbinv() then | |
| 303 | break | |
| 304 | end | |
| 305 | ||
| 306 | end | |
| 307 | ||
| 308 | if parbinv() then | |
| 309 | ||
| 310 | else | |
| 311 | kolon=kolon+1 | |
| 312 | if kolon>garum then | |
| 313 | kolon=1 | |
| 314 | rinda=rinda+1 | |
| 315 | end | |
| 316 | saglabat('kolon',kolon)
| |
| 317 | saglabat('rinda',rinda)
| |
| 318 | end | |
| 319 | ||
| 320 | end | |
| 321 | ||
| 322 | --######################################################### | |
| 323 | --Programmas izskata funkcijas | |
| 324 | ||
| 325 | --Virsraksts monitoram | |
| 326 | function virsraksts(top) | |
| 327 | term.setCursorPos(3,2) | |
| 328 | write(top) | |
| 329 | end | |
| 330 | ||
| 331 | function izskats() | |
| 332 | term.clear() | |
| 333 | local i,j | |
| 334 | ||
| 335 | term.setCursorPos(1,1) | |
| 336 | write('+')
| |
| 337 | for i=2,(ekrx-1) do | |
| 338 | term.setCursorPos(i,1) | |
| 339 | write('-')
| |
| 340 | end | |
| 341 | term.setCursorPos(ekrx,1) | |
| 342 | write('+')
| |
| 343 | ||
| 344 | term.setCursorPos(1,ekry) | |
| 345 | write('+')
| |
| 346 | for i=2,(ekrx-1) do | |
| 347 | term.setCursorPos(i,ekry) | |
| 348 | write('-')
| |
| 349 | end | |
| 350 | term.setCursorPos(ekrx,ekry) | |
| 351 | write('+')
| |
| 352 | ||
| 353 | for i=2,(ekry-1) do | |
| 354 | term.setCursorPos(1,i) | |
| 355 | write('|')
| |
| 356 | term.setCursorPos(ekrx,i) | |
| 357 | write('|')
| |
| 358 | end | |
| 359 | ||
| 360 | ||
| 361 | ||
| 362 | virsraksts('Xoandbit racejs')
| |
| 363 | ||
| 364 | -- print("###################################")
| |
| 365 | -- print("#======Xoandbit pathfinders=v1====#")
| |
| 366 | -- print(" ")
| |
| 367 | -- print(" ")
| |
| 368 | -- print(" ")
| |
| 369 | -- print(" ")
| |
| 370 | -- print(" ")
| |
| 371 | -- print(" ")
| |
| 372 | -- print(" ")
| |
| 373 | -- print(" ")
| |
| 374 | -- print(" ")
| |
| 375 | -- print("###################################")
| |
| 376 | end | |
| 377 | ||
| 378 | --Jautajuma izskats | |
| 379 | function jautaj(top) | |
| 380 | sleep(1) | |
| 381 | term.setCursorPos(4,4) | |
| 382 | write(top) | |
| 383 | end | |
| 384 | ||
| 385 | --Vaicajums pec ievada | |
| 386 | function vaica() | |
| 387 | term.setCursorPos(3,7) | |
| 388 | status,nolasijums = pcall(read) | |
| 389 | return nolasijums | |
| 390 | end | |
| 391 | ||
| 392 | --Atbilde kaut kam | |
| 393 | function atbilde(atb) | |
| 394 | term.setCursorPos(8,9) | |
| 395 | write(atb) | |
| 396 | end | |
| 397 | ||
| 398 | -- Izskata funkciju beigas | |
| 399 | --############################################# | |
| 400 | --Mainigo funkcijas | |
| 401 | ||
| 402 | ||
| 403 | ||
| 404 | --Tagadejas lietas | |
| 405 | x=0 | |
| 406 | y=0 | |
| 407 | z=0 | |
| 408 | f=0 | |
| 409 | xsak=0 | |
| 410 | ysak=0 | |
| 411 | zsak=0 | |
| 412 | fsak=0 | |
| 413 | darb=0 | |
| 414 | --Lietas uz kurieni! | |
| 415 | term.clear() | |
| 416 | term.setCursorPos(1,1) | |
| 417 | print("Palaizam programmu!")
| |
| 418 | sleep(1) | |
| 419 | ielasa() -- ielasam koordinates | |
| 420 | print('Instalejam ekrana izmerus')
| |
| 421 | ekrx,ekry=term.getSize() | |
| 422 | ekrx=ekrx-1 | |
| 423 | ekry=ekry-1 | |
| 424 | sleep(1) | |
| 425 | print('Instalejam programmas izskatu')
| |
| 426 | sleep(1) | |
| 427 | ||
| 428 | ||
| 429 | ||
| 430 | while true do | |
| 431 | ||
| 432 | if darb==0 then | |
| 433 | ||
| 434 | input='s' | |
| 435 | izskats() | |
| 436 | jautaj('Ievadiet garumu!')
| |
| 437 | input=vaica() | |
| 438 | garum=input | |
| 439 | ||
| 440 | input='s' | |
| 441 | izskats() | |
| 442 | jautaj('Ievadiet platumu /pa labi/!')
| |
| 443 | input=vaica() | |
| 444 | ||
| 445 | platum=input | |
| 446 | ||
| 447 | saglabat('atpakal',atpakal)
| |
| 448 | saglabat('garum',garum)
| |
| 449 | saglabat('platum',platum)
| |
| 450 | saglabat('kolon',1)
| |
| 451 | saglabat('rinda',1)
| |
| 452 | ||
| 453 | saglabat('darb',1)
| |
| 454 | atbilde('Palaizam raceju')
| |
| 455 | sleep(1) | |
| 456 | os.reboot() | |
| 457 | ||
| 458 | else | |
| 459 | if darb==1 then | |
| 460 | ||
| 461 | print() | |
| 462 | print('INICIALIZEJAM RACEJU')
| |
| 463 | ||
| 464 | garum=f_ielas('garum',true)
| |
| 465 | print('Ielasits')
| |
| 466 | platum=f_ielas('platum',true)
| |
| 467 | print('Ielasits')
| |
| 468 | kolon=f_ielas('kolon',true)
| |
| 469 | print('Ielasits')
| |
| 470 | rinda=f_ielas('rinda',true)
| |
| 471 | print('Ielasits')
| |
| 472 | ||
| 473 | xraksana=0 | |
| 474 | zraksana=0 | |
| 475 | ||
| 476 | sleep(1) | |
| 477 | ||
| 478 | ||
| 479 | izskats() | |
| 480 | jautaj('UZ SAKUMU')
| |
| 481 | UzSakumu() | |
| 482 | ||
| 483 | ||
| 484 | while rinda<platum do | |
| 485 | ||
| 486 | izskats() | |
| 487 | jautaj('UZ RAKSANU')
| |
| 488 | UzRaksanu() | |
| 489 | ||
| 490 | izskats() | |
| 491 | jautaj('ROKAM')
| |
| 492 | Rakt() | |
| 493 | ||
| 494 | if parbinv() then | |
| 495 | izskats() | |
| 496 | jautaj('UZ SAKUMU')
| |
| 497 | UzSakumu() | |
| 498 | end | |
| 499 | ||
| 500 | end | |
| 501 | ||
| 502 | saglabat('darb',0)
| |
| 503 | ||
| 504 | end | |
| 505 | ||
| 506 | end | |
| 507 | ||
| 508 | end |