Esempio n. 1
0
// activate an input node with a value
void net_activate(s16 inIdx, const io_t val, void* op) {
  static inode_t* pIn;
  s16 pIndex;
  u8 vis;

  print_dbg("\r\n net_activate, input idx: ");
  print_dbg_hex(inIdx);
  print_dbg(" , value: ");
  print_dbg_hex(val);

  print_dbg(" , op index: ");
  print_dbg_ulong(net->ins[inIdx].opIdx);
  print_dbg(" , input idx: ");
  print_dbg_ulong(net->ins[inIdx].opInIdx);

  if(!netActive) {
    if(op != NULL) {
      // if the net isn't active, dont respond to requests from operators
      print_dbg(" ... ignoring node activation from op.");
      return;
    }
  }



  if(inIdx < 0) {
    return;
  }

  vis = net_get_in_play(inIdx);
    print_dbg(" , play visibility flag : ");
    print_dbg_ulong(vis);

  if(inIdx < net->numIns) {      
    // this is an op input
    pIn = &(net->ins[inIdx]);
    
    print_dbg(" ; input node pointer: 0x"); print_dbg_hex((u32)pIn);

    op_set_in_val(net->ops[pIn->opIdx],
		  pIn->opInIdx,
		  val);
    
  } else { 
    // this is a parameter
    //// FIXME this is horrible
    pIndex = inIdx - net->numIns;
    if (pIndex >= net->numParams) { return; }
    print_dbg(" ; param index: 0x"); print_dbg_ulong(pIndex);
    set_param_value(pIndex, val);
  }

  /// only process for play mode if we're in play mode
  if(pageIdx == ePagePlay) {
    print_dbg(" , play mode ");
    if(opPlay) {
      //      operators have focus, do nothing
      print_dbg(" , op focus mode");
    } else {
      // process if play-mode-visibility is set on this input
      if(vis) {
	print_dbg(" , input enabled");
	play_input(inIdx);
      }
    }
  }  
  
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    WINDOW *my_win, *score;
    WINDOW **car;
    game newGame, tmpGame;
    MEVENT event;

    int ch = 0, choosenCar = -1, soluce_move = 0;
    char message[1024];
    bool quit = false;
    bool show_solution = false;
    gameStruct *resultSolv = NULL;
    //INIT
    setup();
    //END INIT
    //Wait for good size
    wait_for_size(MINH, MINW);
    //Instruction
    show_instruction(MINH, MINW);
    while (!quit) {
        quit = false;
        show_solution = false;
        soluce_move = 0;
        strcpy(message, "Playing");
        //Select game
        newGame = select_game();
        //Check for level file
        if (handle_level(&tmpGame)) {
            delete_game(newGame);
            newGame = tmpGame;
            MAXCOL = game_width(newGame);
            MAXROW = game_height(newGame);
            MINH = MAXROW * SIZE + 2;
            MINW = MAXCOL * SIZE;
        }
        car = malloc(sizeof (WINDOW*) * game_nb_pieces(newGame));
        //First draw
        draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh);
        //Loop while the game is not finished
        while (!game_over(newGame)) {
            //Print on bottom of grid
            mvprintw(MAXROW * SIZE + 1, 0, "Please choose car :");
            ch = getch();
            if (ch == 's' && !show_solution) {
                show_solution = true;
                strcpy(message, "Solution");
                resultSolv = solv(newGame, gameOverRh,true);
                if(!resultSolv){
                    strcpy(message, "No solution");
                    show_solution=false;
                }
            }
            if (show_solution) {
                newGame = play_solution(newGame, resultSolv, soluce_move++);
            } else {
                if (KEY_MOUSE == ch) {
                    /* Mouse event. */
                    if (OK == getmouse(&event)) {
                        choosenCar = get_car_with_mouse(event.y, event.x, car, game_nb_pieces(newGame));
                    }
                } else {
                    if (ch == 'q') {
                        quit = true;
                        break;
                    }
                    play_input(newGame, ch, &choosenCar);
                }
            }
            wait_for_size(MINH, MINW);
            erase_game(newGame, my_win, car, score);
            draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh);
        }
        if (!quit) {
            display_score(newGame);
        }
        for (int i = 0; i < game_nb_pieces(newGame); i++) {
            destroy_win(car[i]);
        }
        destroy_win(my_win);
        destroy_win(score);
        free(car);
        delete_game(newGame);
        if (resultSolv != NULL) {
            delete_game(resultSolv->current);
            free(resultSolv->move);
            free(resultSolv);
            resultSolv = NULL;
        }
    }
    endwin(); /* End curses mode		  */
    return 0;
}