Ejemplo n.º 1
0
 function process_input($input) {
     switch ($input) {
     case 'd' :
       $GLOBALS[CLOCKWORDS_DEBUG] = TRUE;
       exec(":>".CLOCKWORDS_ROOT."debug.txt");
       $return[] = 'debug on';
     case 'y' :
       $cw = new clockwords;
       $return[] = $cw;
       break;
     case 'n' :
       $return[] = false;
       print("\nok, exiting\n");
       break;
     case 'scr' :
       $ocr = new cw_ocr;
       sleep(2);
       $tmp = $ocr->screenGrab();
       $ocr->setCoords($tmp);
       $ocr->trimImage($tmp);
       dpr($tmp);
       exec("eog $tmp &");
       sleep(3);
       unlink($tmp);
       break;
     default :
       throw new Exception("unknown input, exiting");
   }
   return $return;
 }
Ejemplo n.º 2
0
  function putItAllTogether() {
    $ocr = new cw_ocr;
    $w = new cw_words;
    $sql = new cw_sqlite;
    $starttime = time();
    $word='';
    $exceptions=0;
    $notready=true;
    while ($notready) {
      print "\n Waiting for game screen. ".((time()) - ($starttime))." Seconds elapsed.";
      try {
        $filename = $ocr->screenGrab();
        $ocr->patternTest($filename, CLOCKWORDS_ROOT."match_image.pat");
        $notready = false;
        @unlink($filename);
        print "\n Game screen found, let's play!";
      } catch (Exception $e) {
        $notready = true;
        @unlink($filename);
      }
      usleep(500000);
    }
    $stillplaying=0;
    while ($stillplaying < 10) {
      $filename = $ocr->screenGrab();

      try {
        
        if (empty($GLOBALS[CLOCKWORDS_CROP_X])) { $result = $ocr->setCoords($filename); }
        try {
          dpr(array('$stillplaying'=>$stillplaying,'$filename'=>$filename));
          $result = $ocr->patternTest($filename, CLOCKWORDS_ROOT."match3.pat");
          //$stillplaying = ($stillplaying > 0) ? $stillplaying-1 : 0;
        } catch (Exception $e) {
          dpr($e->getMessage());
          //$stillplaying++;
          usleep(500000);
          try {
            $result = $ocr->patternTest($filename, CLOCKWORDS_ROOT."level.pat");
            $stillplaying = 100;
          } catch (Exception $e) {
            //game has not ended...
          }
          }
        try {
          
          $desired = $ocr->doOCR($filename);
          dpr(array('$desired',$desired));
          try {
            //$word = $w->getWord($desired);
            $word = $sql->getAWord($desired);
            dpr(array('$word',$word));
            try {
              $this->type($word);
              $exceptions = ($exceptions > 0) ? $exceptions-1 : $exceptions;
            } catch (Exception $e) { throw $e; }
          } catch (Exception $e) { throw $e; }
        } catch (Exception $e) { throw $e; }
      } catch (Exception $e) { dpr(array($e->getMessage(),$e->getFile(),$e->getLine()));$exceptions++; }
      if ($exceptions > 10) {
        print("\n   too many exceptions!\n");break;
        }
      $sql->removeWord($word);
      $len = strlen($word);
      if ($len > 5) { usleep($len . "00000"); }//the longer the word, the longer we need to wait to reload letters
      
    }
    //die("\n   ".CLOCKWORDS_RUN_TIME." seconds are up\n");
    $this->cleanup();
  }