Esempio n. 1
0
void game()
{
    extern void newgame();

    movenr = gameover = 0;
    newgame();
}
Esempio n. 2
0
/**
 * Renderiza o menu baseado na seleção
 * \param tela Tela onde o menu será renderizado
 */
void gunther_menu(SDL_Surface* screen)
{
	int section = TITLE;

	while (section != QUIT){
		switch(section){
			case TITLE:
				section = title(screen);
				break;
			case NEWGAME:
				section = newgame(screen);
				break;
			case LOADGAME:
				section = loadgame(screen);
				break;
			case OPTIONS:
				section = options(screen);
				break;
			case MANUAL:
				section = manual(screen,0);
				break;
			case COMMANDS:
				section = manual(screen,COMMANDS);
				break;
			case CREDITS:
				section = credits(screen);
				break;
			default:
				section = QUIT;
		}
	}
}
Esempio n. 3
0
void load(struct gameinfo *gi, char *filename) {
	unsigned int i, l, r_size;
	FILE *f = fopen(filename, "rb"); //open file
	if (f) {
		fscanf(f, "%d", &r_size); //read board size
		newgame(gi, r_size); //start a new game
		gi->gs->blackcount = 0;
		gi->gs->whitecount = 0;
		for (i = 0; i<r_size; i++)
			for (l = 0; l<r_size; l++)
				switch (fgetc(f)) {//read and count pieces
					case 'b':
						gi->gs->blackcount++;
						gi->gs->board[l][i] = 'B';
						break;
					case 'w':
						gi->gs->whitecount++;
						gi->gs->board[l][i] = 'W';
						break;
					default:
						gi->gs->board[l][i] = ' ';
			}
		gi->gs->nowplaying = fgetc(f); //get current player
		fclose(f);
		findlegal(gi);
		showstate(gi);
	}
	else printf("Unable to open file %s\n", filename);
}
Esempio n. 4
0
jboolean nhjni_run() {
  windowprocs = _nhjni_proxy_procs;
  _nhjni_proxy_init();
  int fd = create_levelfile(0, (char *)0);
  if (fd < 0) {
    raw_print("Cannot create lock file");
  } else {
    hackpid = 1;
    write(fd, (genericptr_t) &hackpid, sizeof(hackpid));
    close(fd);
  }
  
  iflags.news = TRUE;
  int argc=1;
  char *argv[]={"nethack",NULL};
  
  initoptions();
  init_nhwindows(&argc,argv);
  dlb_init();
  vision_init();
  display_gamewindows();
  
  if ((fd = restore_saved_game()) >= 0) {
    const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1);

    pline("Restoring save file...");
    mark_synch();	/* flush output */
    if(!dorecover(fd))
      goto not_recovered;

    check_special_room(FALSE);
    //wd_message();

    if (discover || wizard) {
      if(yn("Do you want to keep the save file?") == 'n')
          (void) delete_savefile();
      else {
          (void) chmod(fq_save,FCMASK); /* back to readable */
          compress(fq_save);
      }
    }
    flags.move = 0;
  } else {
not_recovered:
    player_selection();
    newgame();
    flags.move = 0;
    set_wear();
    (void) pickup(1);
  }

  moveloop();
  
  return JNI_TRUE;
}
Esempio n. 5
0
File: auto_ai.c Progetto: shouya/bar
static void dealkbd(int k, int mod) {
  switch (k) {
  case 'q':
    game_ctrl.quit = 1;
    break;
  case 'n':
    if (mod & BARKM_CTRL) {
      newgame();
    }
  default:;
  }
}
Esempio n. 6
0
MainUI::MainUI(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainUI)
{
    ui->setupUi(this);

    resize(457, 640);

    setWindowTitle("explosive-c4");

    board_local = new BoardWidget(BOARD_WIDGET_LOCAL);
    board_AI = new BoardWidget(BOARD_WIDGET_AI);

    ui->frmLocalGame->setVisible(false);
    ui->frmAIGame->setVisible(false);
    ui->frmAbout->setVisible(false);

    ui->frmLocalGame->layout()->addWidget(board_local);
    ui->frmAIGame->layout()->addWidget(board_AI);

    connect(ui->cmdNewLocalGame,SIGNAL(clicked()),board_local,SLOT(newgame()));
    connect(ui->cmdNewAIGame,SIGNAL(clicked()),board_AI,SLOT(newgame()));
}
Esempio n. 7
0
wbmain (struct WBStartup *wbmsg)
{
  char startdir[256];
  char *dir;

  strcpy (startdir, "");
  if (Icon = GetDiskObject (wbmsg->sm_ArgList[0].wa_Name))
  {
    if (dir = FindToolType (Icon->do_ToolTypes, "DIR"))
      strcpy (startdir, dir);
  }

  amiga_init (startdir);
  newgame (0);
  exit (0);
}
Esempio n. 8
0
int main(int argc  ,char **argv){
	GAME inGAME;	
	FILE *inFILE;
		 
			if (strcmp(*(argv+1),"-l")==0 ){
			 inFILE=fopen(*(argv+2),"rb");
				fread(&inGAME,1,sizeof(GAME),inFILE);
				restoregame(inGAME);
				
			}
						
			else	if (strcmp(*(argv+1),"-n")==0) newgame();
			
			else puts("Wrong arguments.\n");		
				
				
	return 1;
}
Esempio n. 9
0
int main()
{
    initncurses();
    game.brdwin = newwin(BRD_HEIGHT+PAD, BRD_WIDTH+PAD, BRD_TOP, BRD_LEFT);
    game.holdwin = newwin(HOLD_HEIGHT+PAD, HOLD_WIDTH+PAD, BRD_TOP, BRD_LEFT+BRD_WIDTH+2);
    game.sidewin = newwin(SIDE_HEIGHT+PAD, SIDE_WIDTH+PAD, BRD_TOP+HOLD_HEIGHT+2, BRD_LEFT+BRD_WIDTH+3);
    game.brdpan = new_panel(game.brdwin);
    game.holdpan = new_panel(game.holdwin);
    game.sidepan = new_panel(game.sidewin);
    newgame();

    int diff;
    struct timeval prev, now;
    gettimeofday(&prev, NULL);

    // game loop
    while (route(getch())) {

        // get time difference in milliseconds; move piece down if 'diff' is large enough
        gettimeofday(&now, NULL);
        diff = ((now.tv_sec-prev.tv_sec)*1000)+((now.tv_usec-prev.tv_usec)/1000);
        if (diff >= game.msecstep && (!game.ended && !game.paused)) {
            mvpcdown();
            gettimeofday(&prev, NULL);
        }

        // draw end screen if the game's over, otherwise draw our board (unless paused)
        if ((game.ended = istopped())) {
            drawend();
        } else 
        if (!game.paused) {
            addscore(clrcols());
            drawbrd(game.brdwin, game.holdwin);
            drawside();
        }

        // reflect changes in our panels onscreen
        update_panels();
        doupdate();

    } 

    return 0;
}
Esempio n. 10
0
int osdcmd_map(const osdfuncparm_t *parm)
{
	int i;
	char filename[256];

	if (parm->numparms != 1) return OSDCMD_SHOWHELP;
	
	strcpy(filename,parm->parms[0]);
	if( strchr(filename,'.') == 0)
        	strcat(filename,".map");

	if ((i = kopen4load(filename,0)) < 0) {
		OSD_Printf("map: file \"%s\" does not exist.\n", filename);
		return OSDCMD_OK;
	}
	kclose(i);

	strcpy(boardfilename, filename);
	
	if (ps[myconnectindex].gm & MODE_GAME) {
		// in-game behave like a cheat
		osdcmd_cheatsinfo_stat.cheatnum = 2;
		osdcmd_cheatsinfo_stat.volume = 0;
		osdcmd_cheatsinfo_stat.level = 7;
	} else {
		// out-of-game behave like a menu command
		osdcmd_cheatsinfo_stat.cheatnum = -1;

		ud.m_volume_number = 0;
		ud.m_level_number = 7;

                ud.m_monsters_off = ud.monsters_off = 0;

                ud.m_respawn_items = 0;
                ud.m_respawn_inventory = 0;

                ud.multimode = 1;
		
	 	newgame(ud.m_volume_number,ud.m_level_number,ud.m_player_skill);
                if (enterlevel(MODE_GAME)) backtomenu();
	}
       
	return OSDCMD_OK;
}
Esempio n. 11
0
bool route(int ch)
{
    if (ch == 'q') {
        freebrd();
        endwin();
        return false;
    }

    if (game.ended) { 
        if (ch != ERR)
            newgame();
        return true;
    }

    if (ch == 'p') {
        game.paused = (game.paused ? false : true);
        if (game.paused)
            drawpause();
        else
            clearall();
    }

    if (ch == '?') {
        game.paused = (game.paused ? false : true);
        if (game.paused)
            drawctrls();
        else
            clearall();
    }

    if (!game.paused) {
        switch (ch) {
            case 'k': case KEY_UP:    rotpc(); break;
            case 'j': case KEY_DOWN:  mvpcdown(); break;
            case 'h': case KEY_LEFT:  mvpcleft(); break;
            case 'l': case KEY_RIGHT: mvpcright(); break;
            case ' ':                 drppc(); break;
            default: break;
        }
    }

    return true;
}
Esempio n. 12
0
File: auto_ai.c Progetto: shouya/bar
static void do_auto_move(void) {
  move_sb(impl.sb, 0, 1);
  if (check_sb(impl.bm, impl.sb) != 0) {
    move_sb(impl.sb, 0, -1);
    lines_killed += check_bm_lines(impl.bm, 0, 0);
    if (steady_sb(impl.bm, impl.sb, shift_queue(impl.queue), 3) != 0) {
/*    if (steady_sb(impl.bm, impl.sb, 6, 3) != 0) {*/
      /*printf("game over, you may press C-n to start a new game.\n");*/
      printf("this AI cleared lines: %d, spend: %.2fs\n", lines_killed,
             (util_getticks()-beg_time)/1000.0f);
      game_ctrl.automove_interval = -1;
      clear_blockmap(impl.bm);
      reset_shapebuf(impl.sb, -1);
      newgame();
    } else {
      impl.ai = ai_calc(impl.bm, impl.sb, 0, 0);
    }
  }
}
Esempio n. 13
0
File: auto_ai.c Progetto: shouya/bar
void init_game(void) {
  srand(time(NULL));

  game.game_name = "Auto AI";
  game.author_name = "Ya Shou";
  game.author_email = "*****@*****.**";
  game.impl = &impl;

  game_ctrl.repeat_on = 0;
  game_ctrl.automove_interval = 10;
  game_ctrl.auto_move = &do_auto_move;
  game_ctrl.before_auto_move = &do_step_ai;
  game_ctrl.kill_bm_lines = &kill_lines_hook;
  game_ctrl.quit = 0;

  game_render.render = &do_render;
  game_render.clrscr = 0;
  game_render.draw_block = 0;
  game_render.update = 0;

  game_event.kbd_handler = &dealkbd;
  game_event.quit_handler = 0;

  g_cfg.scrw = WNDW;
  g_cfg.scrh = WNDH;
  g_cfg.ctrl = &game_ctrl;
  g_cfg.render = &game_render;
  g_cfg.event = &game_event;

  init_ui();
  init_graphic();
  
  default_init_shapes();

  impl.bm = create_blockmap(XRES, YRES);
  impl.queue = create_queue(7, 7);
  impl.sb = create_shapebuf(-1);
  impl.cvs = create_canvas(BOX_SZ*XRES, BOX_SZ*YRES);
  impl.pnl = create_canvas(WNDW-BOX_SZ*XRES, WNDH);

  newgame();
}
Esempio n. 14
0
boolean nh_start_game(int fd, const char *name, int irole, int irace, int igend,
		      int ialign, enum nh_game_modes playmode)
{
    unsigned int seed = 0;
    
    if (!api_entry_checkpoint())
	return FALSE; /* init failed; programmer error! */

    if (fd == -1 || !name || !*name)
	goto err_out;
    
    if (!program_state.restoring) {
	turntime = (unsigned long long)time(NULL);
	seed = turntime ^ get_seedval();
	/* initialize the random number generator */
	mt_srand(seed);
    } /* else: turntime and rng seeding are done in logreplay.c */
    
    startup_common(name, playmode);
    
    if (!validrole(irole) || !validrace(irole, irace) ||
	!validgend(irole, irace, igend) || !validalign(irole, irace, ialign))
	goto err_out;
    u.initrole = irole; u.initrace = irace;
    u.initgend = igend; u.initalign = ialign;

    /* write out a new logfile header "NHGAME ..." with all the initial details */
    log_init();
    log_newgame(fd, turntime, seed, playmode);

    newgame();
    was_on_elbereth = !sengr_at("Elbereth", u.ux, u.uy); /* force botl update later */
    wd_message();

    api_exit();
    return TRUE;
    
err_out:
    api_exit();
    return FALSE;
}
Esempio n. 15
0
/*
 * Here when we get a button down event.
 */
static void
dobutton(GR_EVENT_BUTTON *bp)
{
    if (bp->wid == boardwid) {
        movetopos(findcell(bp->x, bp->y));
        return;
    }

    if (bp->wid == quitwid) {
        GrFillRect(quitwid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        if (savefile)
            writegame(savefile);
        GrClose();
        exit(0);
    }

    if (bp->wid == savewid) {
        GrFillRect(savewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        if (savefile == NULL)
            savefile = SAVEFILE;
        if (writegame(savefile))
            write(1, "\007", 1);
        else
            delay();
        GrFillRect(savewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
    }

    if (bp->wid == newgamewid) {
        GrFillRect(newgamewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        /*if (playing)
        	write(1, "\007", 1);
        else {*/
        newgame();
        delay();
        /*}*/
        GrFillRect(newgamewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
    }
}
Esempio n. 16
0
void mainn(){
	WINDOW *wnd;
	sprintf(highscorespath, "%s/%s", getenv("HOME"), highscoresname);
	srand(time(NULL));
	wnd = initscr();
	start_color();
	init_pair(1, COLOR_BLACK, COLOR_CYAN);
	init_pair(2, COLOR_BLACK, COLOR_WHITE);
	init_pair(3, COLOR_CYAN, COLOR_BLACK);
	init_pair(4, COLOR_WHITE, COLOR_GREEN);
	//wbkgd(stdscr, COLOR_PAIR(1));
	wbkgd(wnd, COLOR_PAIR(4));
	refresh();
	wrefresh(wnd);
	keypad(stdscr, TRUE);
	cbreak();
	noecho();
	curs_set(0);
	getmaxyx(wnd, rmax, cmax);
	clear();
	newgame();
	endwin();
}
Esempio n. 17
0
int
main(int argc,char **argv)
{
    GR_COORD	x;
    GR_COORD	y;
    GR_SIZE		width;
    GR_SIZE		height;
    GR_COORD	rightx;		/* x coordinate for right half stuff */
    GR_BOOL		setsize;	/* TRUE if size of board is set */
    GR_BOOL		setmines;	/* TRUE if number of mines is set */
    GR_SIZE		newsize = 10;	/* desired size of board */
    GR_COUNT	newmines = 25;	/* desired number of mines */
    GR_WM_PROPERTIES props;

    setmines = GR_FALSE;
    setsize = GR_FALSE;

    argc--;
    argv++;
    while ((argc > 0) && (**argv == '-')) {
        switch (argv[0][1]) {
        case 'm':
            if (argc <= 0) {
                fprintf(stderr, "Missing mine count\n");
                exit(1);
            }
            argc--;
            argv++;
            newmines = atoi(*argv);
            setmines = GR_TRUE;
            break;

        case 's':
            if (argc <= 0) {
                fprintf(stderr, "Missing size\n");
                exit(1);
            }
            argc--;
            argv++;
            newsize = atoi(*argv);
            setsize = GR_TRUE;
            break;

        default:
            fprintf(stderr, "Unknown option \"-%c\"\n",
                    argv[0][1]);
            exit(1);
        }
        argc--;
        argv++;
    }
    if (argc > 0)
        savefile = *argv;

    srand(time(0));

    readgame(savefile);

    if (setsize) {
        if ((newsize < MINSIZE) || (newsize > MAXSIZE)) {
            fprintf(stderr, "Illegal board size\n");
            exit(1);
        }
        if (newsize != size) {
            if (steps && playing) {
                fprintf(stderr,
                        "Cannot change size while game is in progress\n");
                exit(1);
            }
            playing = GR_FALSE;
            size = newsize;
            if (!playing)
                mines = (size * size * MINEPERCENT) / 100;
        }
    }

    if (setmines) {
        if ((newmines <= 0) || ((newmines > (size * size) / 2))) {
            fprintf(stderr, "Illegal number of mines\n");
            exit(1);
        }
        if (newmines != mines) {
            if (steps && playing) {
                fprintf(stderr,
                        "Cannot change mines while game is in progress\n");
                exit(1);
            }
            playing = GR_FALSE;
            mines = newmines;
        }
    }

    findindex();

    /*
     * Parameters of the game have been verified.
     * Now open the graphics and play the game.
     */

    if (GrOpen() < 0) {
        fprintf(stderr, "Cannot open graphics\n");
        exit(1);
    }

    GrReqShmCmds(655360); /* Test by Morten Rolland for shm support */

    GrGetScreenInfo(&si);
    GrGetFontInfo(0, &fi);
    charheight = fi.height;

    /*
     * Create the main window which will contain all the others.
     */
#if 0
    COLS = si.cols - 40;
#else
    COLS = si.cols;
#endif
    ROWS = si.rows - 80;
    mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, COLS, ROWS,
                          0, BLACK, WHITE);

    /* set title */
    props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS;
    props.props = GR_WM_PROPS_APPFRAME | GR_WM_PROPS_CAPTION;
    props.title = "Land Mine";
    GrSetWMProperties(mainwid, &props);

    /*
     * Create the board window which lies at the left side.
     * Make the board square, and as large as possible while still
     * leaving room to the right side for statistics and buttons.
     */
    width = COLS - RIGHTSIDE - (si.xdpcm * RIGHTGAP / 10) - BOARDBORDER * 2;
    height = (((long) width) * si.ydpcm) / si.xdpcm;
    if (height > ROWS /* - y * 2*/) {
        height = ROWS - BOARDBORDER * 2;
        width = (((long) height) * si.xdpcm) / si.ydpcm;
    }
    xp = width / size;
    yp = height / size;

    width = xp * size - 1;
    height = yp * size - 1;
    x = BOARDBORDER;
    y = (ROWS - height) / 2;

    rightx = x + width + (si.xdpcm * RIGHTGAP / 10);
    boardwid = GrNewWindow(mainwid, x, y, width, height, BOARDBORDER,
                           BLUE, WHITE);
    /*
     * Create the buttons.
     */
    x = rightx;
    y = (si.ydpcm * BOARDGAP / 10);
    quitwid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT,
                          1, RED, WHITE);

    y += (si.ydpcm * BUTTONGAP / 10);
    savewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT,
                          1, GREEN, WHITE);

    y += (si.ydpcm * BUTTONGAP / 10);
    newgamewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT,
                             1, GREEN, WHITE);

    /*
     * Create the statistics window.
     */
    x = rightx;
    y += (si.ydpcm * STATUSGAP / 10);
    width = COLS - x;
    height = ROWS - y;
    statwid = GrNewWindow(mainwid, x, y, width, height, 0,
                          0, 0);
    statwidth = width;
    statheight = height;

    /*
     * Create the GC for drawing the board.
     */
    boardgc = GrNewGC();
    cleargc = GrNewGC();
    delaygc = GrNewGC();
    redgc = GrNewGC();
    greengc = GrNewGC();
    statgc = GrNewGC();
    blackgc = GrNewGC();
    buttongc = GrNewGC();
    xorgc = GrNewGC();
    GrSetGCBackground(boardgc, BLUE);
    GrSetGCForeground(cleargc, BLUE);
    GrSetGCForeground(redgc, RED);
    GrSetGCForeground(greengc, GREEN);
    GrSetGCForeground(statgc, GRAY);
    GrSetGCForeground(delaygc, BLACK);
    GrSetGCForeground(blackgc, BLACK);
    GrSetGCMode(delaygc, GR_MODE_XOR);
    GrSetGCMode(xorgc, GR_MODE_XOR);
    GrSetGCUseBackground(boardgc, GR_FALSE);
    GrSetGCUseBackground(buttongc, GR_FALSE);

    GrSelectEvents(mainwid, GR_EVENT_MASK_CLOSE_REQ);

    GrSelectEvents(boardwid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN);

    GrSelectEvents(statwid, GR_EVENT_MASK_EXPOSURE);

    GrSelectEvents(quitwid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN);

    GrSelectEvents(newgamewid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN);

    GrSelectEvents(savewid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN);

    setcursor();

    GrMapWindow(mainwid);
    GrMapWindow(boardwid);
    GrMapWindow(statwid);
    GrMapWindow(quitwid);
    GrMapWindow(savewid);
    GrMapWindow(newgamewid);

    if (!playing)
        newgame();

    while (GR_TRUE) {
        GR_EVENT event;

        GrGetNextEvent(&event);
        handleevent(&event);
    }
}
Esempio n. 18
0
void parse_command(char *buf, struct gameinfo *gi) {
	char *tok, *param;
	int i_param;
	tok = strtok(buf, " "); //split input
	if (tok != 0) {
		if (strcmp(tok, "newgame") == 0) {
			param = strtok(0, " "); //get parameter if there is one
			//call appropriate functions
			if (param == 0) {
				newgame(gi, gi->default_size);
				findlegal(gi);
				showstate(gi);
			}
			else {
				if (isnum(param)) {
					i_param = atoi(param);
					if (i_param >= 4 && i_param <= 26 && i_param%2 == 0) {
						newgame(gi, i_param);
						findlegal(gi);
						showstate(gi);
					}
					else printf("Invalid size for command newgame (4 <= size <= 26,  size is an even number)\n");
				}
				else printf("Invalid parameter for command newgame (parameter is an integer)\n");
			}
		}
		else if (strcmp(tok, "play") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Missing parameter for command play\n");
			else if (gi->gamestarted == 0) printf("No game in progress\n");
			else if (gi->gs->nowplaying != gi->playercolor) printf("It's not your turn to play\n");
			else if (play(gi, param) == 1) showstate(gi); //if it's a valid move
		}
		else if (strcmp(tok, "cont") == 0) cont(gi);
		else if (strcmp(tok, "undo") == 0) undo(gi);
		else if (strcmp(tok, "suggest") == 0) suggest(gi);
		else if (strcmp(tok, "showstate") == 0) showstate(gi);
		else if (strcmp(tok, "save") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Missing parameter for command save\n");
			else if(gi->gamestarted == 0) printf("No game in progress\n");
			else save(gi, param);
		}
		else if (strcmp(tok, "load") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Missing parameter for command load\n");
			else load(gi, param);
		}
		else if (strcmp(tok, "selectcolor") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Missing parameter for command selectcolor\n");
			else {
				if (strcmp(param, "black") == 0) gi->playercolor = 'B';
				else if (strcmp(param, "white") == 0) gi->playercolor = 'W';
				else printf("Invalid parameter for command selectcolor (parameter is 'black' or 'white')\n");
			}
		}
		else if (strcmp(tok, "showlegal") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Missing parameter for command showlegal\n");
			else {
				if (strcmp(param, "on") == 0) gi->showlegal = 1;
				else if (strcmp(param, "off") == 0) gi->showlegal = 0;
				else printf("Invalid parameter for command showlegal (parameter is 'on' or 'off')\n");
			}
		}
		else if (strcmp(tok, "level") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Current difficulty level: %d\n", gi->difficulty);
			else {
				if (isnum(param)) {
					i_param = atoi(param);
					if (i_param >= 1) gi->difficulty = i_param;
					else printf("Invalid parameter for command level (level >= 1)\n");
				}
				else printf("Invalid parameter for command level (parameter is an integer)\n");
			}
		}
		else if (strcmp(tok, "help") == 0) {
			printf("Available commands:\n"
				"newgame [<size>] - Start a new game,  optional parameter size (default %d)\n"
				"play <move> - Place a marker at the specified position\n"
				"cont - Allow the computer to play\n"
				"undo - Undo your last move\n"
				"suggest - Ask the computer to suggest a move\n"
				"selectcolor <black|white> - Select your color\n"
				"showlegal <on|off> - Show all possible moves\n"
				"level [<difficulty>] - Select a difficulty (difficulty >= 1) - If no parameter,  show the current difficulty\n"
				"save <filename> - Save the current game in a file\n"
				"load <filename> - Load game from a file\n"
				"showstate - Show the current state of the game\n"
				"quit - Exit the game\n"
				"help - Show the command list\n\n"
				, gi->default_size);
		}
		else printf("Unknown command %s (type help for a list of commands)\n", tok);
	}
}
Esempio n. 19
0
File: main.c Progetto: hwoy/uox
int main(int argc,char *argv[])
{
ox_player player;
static ox_aigp gameai;
FILE *fp;
char ch,ch2;
char ccom,cyou;
char *lmsg,*fname;
int fg,islog,keyid;
int i;

/*====================== Init default values =======================*/
		player=DPLAYER;
		fg=OX_FIRST;
		cyou=CYOU;
		ccom=CCOM;
		lmsg=HARD;
		gameai=ox_ai;
		islog=0;
		keyid=0;

/*====================== Parameters Processing =======================*/
for(i=1;i<argc;i++)
{
			if(!strcmp(argv[i],OPTLIST[0][0])) /*-x*/
	{
		cyou=toupper(*(OPTLIST[0][0]+1));
		ccom=toupper(*(OPTLIST[1][0]+1));
	}
		else if(!strcmp(argv[i],OPTLIST[1][0]))	/*-o*/
	{
		cyou=toupper(*(OPTLIST[1][0]+1));
		ccom=toupper(*(OPTLIST[0][0]+1));
	}
	
		else if(  (!strncmp(argv[i],OPTLIST[2][0],strlen(OPTLIST[2][0])))  && (strlen(argv[i])==strlen(OPTLIST[2][0])+2) ) /*-c:*/
	{
		cyou=argv[i][3];
		ccom=argv[i][4];
		if(cyou==ccom)
		{
			fprintf(stderr,"ERR: ccom isn't must be cyou\n\n");
			showhelp(croppath(argv[0]));
			return 1;
		}
	}
		else if(!strcmp(argv[i],OPTLIST[3][0]))	/*-yf*/
	{
		player=ox_you;
	}
	
		else if(!strcmp(argv[i],OPTLIST[4][0]))	/*-cf*/
	{
		player=ox_com;
	}
		else if(!strcmp(argv[i],OPTLIST[5][0]))	/*-e*/
	{
		gameai=easyai;
		lmsg=EASY;
	}
		else if(!strcmp(argv[i],OPTLIST[6][0]))	/*-n*/
	{
		gameai=normalai;
		lmsg=NORMAL;
	}
		else if(!strcmp(argv[i],OPTLIST[7][0]))	/*-h*/
	{
		gameai=ox_ai;
		lmsg=HARD;
	}
		else if(!strcmp(argv[i],OPTLIST[8][0]))	/*-l*/
	{
		islog=1;
	}
		else if(!strcmp(argv[i],OPTLIST[9][0]))	/*-nl*/
	{
		islog=0;
	}
		else if(!strcmp(argv[i],OPTLIST[10][0]))	/*-t*/
	{
		listtest((unsigned int *)TRILIST,NTRI,NTRIELEMENT,ccom,cyou);
		return 0;
	}
		else
	{
		showhelp(croppath(argv[0]));
		return 1;
	}
}





/*====================== End of Parameters Processing ======================*/

newgame(player,&fg,gameai,ccom,cyou);

while(1)
{
	
	do
	{
		ox_printtable(&game,OX_SQUAR,CBLANK);
		
		if(game.lyou>-1)
			{
				printf(KEYBARYOU,GYOU,cyou,game.lyou);
			}

		if(game.lcom>-1)
			{
				comlog[ox_getbit(game.com)]=game.lcom;
				printf(KEYBARCOM,game.lcom,ccom,GCOM,lmsg);
			}
		printf(TKEY,K_NEW,K_EXIT,cyou);
		ch=ox_getch(buff,BSIZE,0);
		
		/*-----------------  Key function returns an ID -----------------*/
		
		
			 if(!strcmp(buff,OPTLIST[5][0]))	/*-e*/
	{
		gameai=easyai;
		lmsg=EASY;
		keyid=1;break;
	}
		else if(!strcmp(buff,OPTLIST[6][0]))	/*-n*/
	{
		gameai=normalai;
		lmsg=NORMAL;
		keyid=1;break;
	}
		else if(!strcmp(buff,OPTLIST[7][0]))	/*-h*/
	{
		gameai=ox_ai;
		lmsg=HARD;
		keyid=1;break;
	}
	
		else if(!strcmp(buff,OPTLIST[0][0])) /*-x*/
	{
		cyou=toupper(*(OPTLIST[0][0]+1));
		ccom=toupper(*(OPTLIST[1][0]+1));
		keyid=2;break;
	}
		else if(!strcmp(buff,OPTLIST[1][0]))	/*-o*/
	{
		cyou=toupper(*(OPTLIST[1][0]+1));
		ccom=toupper(*(OPTLIST[0][0]+1));
		keyid=2;break;
	}
	
		else if(  (!strncmp(buff,OPTLIST[2][0],strlen(OPTLIST[2][0])))  && (strlen(buff)==strlen(OPTLIST[2][0])+2) ) /*-c:*/
	{
		if(buff[3]!=buff[4])
		{
			cyou=buff[3];
			ccom=buff[4];
			keyid=2;break;
		}
	}
	
		else if(!strcmp(buff,OPTLIST[8][0]))	/*-l*/
	{
		islog=1;keyid=3;break;
	}
		else if(!strcmp(buff,OPTLIST[9][0]))	/*-nl*/
	{
		islog=0;keyid=3;break;
	}
		
		
		/*----------------------------------------------------*/
		
		
	}while(strlen(buff)!=1);
	
	
	
	
	/*-------------Function by keyid----------------*/
	
	if(keyid)
	{
		switch(keyid)
		{
		
		case 1:
				printf("<Changed to %s level>\n",lmsg);
				resetlog(comlog,-1);resetlog(youlog,-1);
				player=ox_rnd;
				newgame(player,&fg,gameai,ccom,cyou);break;
					
		case 2:
				printf("<YOU=%c : COM=%c>\n",cyou,ccom);
				game.ccom=ccom;
				game.cyou=cyou;break;

		case 3:
				(islog==1) ? printf("<Activated Logfile>\n") : printf("<Inactivated Logfile>\n");
				break;
		}

		keyid=0;
		continue;
	}
	
	
	
	
	
	
	/*------------------------------------------------------------*/
	
	
	
	if(ch==K_EXIT)						/*press exit event*/
		{
	do
	{
		printf("Would you like to exit this game?(%c/%c)-> ",toupper(K_YES),K_NO);
		ch2=ox_getch(buff,BSIZE,K_YES);
		if(ch2==K_YES)
		{
			return 0;
		}
	}while(ch2!=K_NO);					/*press no event*/
		}
		
	else if(ch==K_NEW)					/*press new event*/
		{
			resetlog(comlog,-1);resetlog(youlog,-1);
			player=ox_rnd;
			newgame(player,&fg,gameai,ccom,cyou);continue;
		}
		
	
	you=ch-'0';
	com=ox_gameplay(&game,you);

		if( (com>-1) || (com==ID_ERR) || (com<=-100) || (com >=ID_GO_LOW_LEVEL && com<= ID_GO_HIGH_LEVEL) )
	{
		youlog[ox_getbit(game.you)]=game.lyou;
		comlog[ox_getbit(game.com)]=game.lcom;
	}
	if(com >=ID_GO_LOW_LEVEL && com<= ID_GO_HIGH_LEVEL) 
	{
		
		/*---------------Write game log file-------------------*/
		if((islog) || ((gameai==ox_ai) && (com==ID_YOUWIN)))
		{
				fname = ( (gameai==ox_ai) && (com==ID_YOUWIN) ) ?   EFILE : LFILE;
						if(!(fp=fopen(fname,"at")))
					{
						fprintf(stderr,"ERR DFILE: Can't access %s file to write log data.\n",fname);
					}
						else
					{
						fprintf(fp,"VERSION: %s\n",UOX_VERSION_STR);
						fprintf(fp,"LEVEL: %s\n",lmsg);
						fprintf(fp,"ISSUE: %d\n\n",com);

			
					ox_printtable_tofile(&game,fp,OX_SQUAR,CBLANK);
					writedumpfile(fp,&game,comlog,youlog);
					fprintf(fp,"\n*********************************************************************\n\n");
					fclose(fp);
					}		
		
		}
		
		/*--------------------------------------------------------------*/
		resetlog(comlog,-1);resetlog(youlog,-1);
		ox_printtable(&game,OX_SQUAR,CBLANK);
		if(com==ID_COMWIN) 	/*Com wins event*/
		{
			printf(COMPOS,GCOM);
			printf("\tCom wins by [%u , %u , %u]\n",WINLIST[game.indexwin][0],WINLIST[game.indexwin][1],WINLIST[game.indexwin][2]);
			printf(AKEY,K_EXIT);
			if(ox_getch(buff,BSIZE,0)==K_EXIT){break;}	/*press exit event*/
				
			player=ox_you;
			newgame(player,&fg,gameai,ccom,cyou);
			
			continue;

		}
		
		if(com==ID_YOUWIN) 	/*You win event*/
		{
				
			printf(YOUPOS,GYOU);
			printf("\tYou win by [%u , %u , %u]\n",WINLIST[game.indexwin][0],WINLIST[game.indexwin][1],WINLIST[game.indexwin][2]);
			printf(AKEY,K_EXIT);
			if(ox_getch(buff,BSIZE,0)==K_EXIT){break;}	/*press exit event*/
				
			player=ox_com;
			newgame(player,&fg,gameai,ccom,cyou);
			
			continue;

		}
		
		else if(com==ID_DRAW) 							/*You draw event*/
		{
			printf(DRAWPOS,GYOU);
			printf(AKEY,K_EXIT);
			if(ox_getch(buff,BSIZE,0)==K_EXIT){break;}	/*press exit event*/
			
			if(game.whofirst==ox_com)
			{
				player=ox_you;
			}
			else
			{
				player=ox_com;
			}
				newgame(player,&fg,gameai,ccom,cyou);
			
			continue;
			
		}
	}
	else if(com==ID_ERR || com<=-100) 
	{
		if(com==ID_ERR){fprintf(stderr,"ERR ID_ERR: Please send file %s to <%s>.\n",EFILE,EMAIL);}
		else {fprintf(stderr,"ERR ID_COMVALEXIST: Please send file %s to <%s>.\n",EFILE,EMAIL);}
		
		if(!(fp=fopen(EFILE,"at")))
		{
			fprintf(stderr,"ERR DFILE: Can't access %s file to write log data.\n",EFILE);
		}
		else
		{
			fprintf(fp,"VERSION: %s\n",UOX_VERSION_STR);
			fprintf(fp,"LEVEL: %s\n",lmsg);
			
			if(com<=-100)
			{
				fprintf(fp,"ISSUE: %d\n",com);
				fprintf(fp,"Repeated with: %d\n\n",(com/(-100))-1);
				
				/*
 
					if ai returns existed value , gameplay will return result=(value+1)*-100
					Can reverse value=(resualt/-100)+1
 
				*/
			}
			else
			{
				fprintf(fp,"ISSUE: %d\n\n",com);
			}
			
			ox_printtable_tofile(&game,fp,OX_SQUAR,CBLANK);
			writedumpfile(fp,&game,comlog,youlog);
			fprintf(fp,"\n*********************************************************************\n\n");
			fclose(fp);
		}
		return 1;
	}
	
}

	
	return 0;
}
Esempio n. 20
0
int get_key (UWORD * qualifier_addr, int c, int wait)
{
  struct IntuiMessage *imsg;
  ULONG class;
  UWORD code, qualifier;
  int old_height;

  os_flush ();
  while (1)
  {
    while (imsg = (struct IntuiMessage *) GetMsg (Window->UserPort))
    {
      class = imsg->Class;
      code = imsg->Code;
      qualifier = imsg->Qualifier;
      ReplyMsg ((struct Message *) imsg);
      if (qualifier_addr)
	*qualifier_addr = qualifier;
      switch (class)
      {
      case IDCMP_RAWKEY:
	switch (code)
	{
	case 0x4C:
	  return 129;
	case 0x4D:
	  return 130;
	case 0x4F:
	  return 131;
	case 0x4E:
	  return 132;
	case 0x5F:
	  help ();
	  break;
	}
	break;
      case IDCMP_VANILLAKEY:
	switch (code)
	{
	case 8:
	  return 127;
	case 13:
	  return 13;
	case 127:
	  return 260;
	default:
	  if (code >= 32 && code <= 126)
	    return code;
	  break;
	}
	break;
      case IDCMP_CLOSEWINDOW:
	exit (0);
	break;
      case IDCMP_CHANGEWINDOW:
	old_height = DisplayHeight;
	DisplayHeight = ((Window->Height - Window->BorderTop - Window->BorderBottom) / RastPort->TxHeight) - 1;

	if (PreviousHeight > DisplayHeight)
	{
	  rect (Window->BorderLeft,
		Window->BorderTop + (DisplayHeight * RastPort->TxHeight),
		Window->Width - Window->BorderRight - 1,
		Window->Height - Window->BorderBottom - 1, 0);

	  if (RastPort->cp_y + RastPort->TxHeight > Window->Height - Window->BorderBottom)
	  {
	    Move (RastPort, RastPort->cp_x, Window->BorderTop + (DisplayHeight * RastPort->TxHeight));
	    rect (Window->BorderLeft, RastPort->cp_y,
		  Window->Width - Window->BorderRight - 1,
		  RastPort->cp_y + RastPort->TxHeight - 1, 0);
	    PreviousHeight = DisplayHeight;
	    return 264;
	  }
	}
	PreviousHeight = DisplayHeight;
	break;
      case IDCMP_MENUPICK:
	if (code != MENUNULL)
	{
	  if (MENUNUM (code) == 0)
	  {
	    switch (ITEMNUM (code))
	    {
	    case 0:
	      if (c != -1)
	      {
		cursor (c);
		SetAPen (RastPort, 1);
		int r = newgame (0);
		SetAPen (RastPort, 2);
		cursor (c);
		if (r != 0)
		  return r;
	      }
	      break;
	    case 2:
	      if (c != -1)
		return -2;
	      break;
	    case 3:
	      if (c != -1)
		return -3;
	      break;
	    case 5:
	      help ();
	      break;
	    case 6:
	      about ();
	      break;
	    case 8:
	      exit (0);
	      break;
	    }
	  }
	}
	break;
      }
    }
    if (wait)
      WaitPort (Window->UserPort);
    else
      return 0;
  }
}
Esempio n. 21
0
int main (int argc, char **argv)
{
  amiga_init ("");
  newgame (argc > 1 ? argv[1] : 0);
  exit (0);
}
Esempio n. 22
0
int osdcmd_changelevel(const osdfuncparm_t *parm)
{
	int volume=0,level;
	char *p;

	if (!VOLUMEONE) {
		if (parm->numparms != 2) return OSDCMD_SHOWHELP;

		volume = strtol(parm->parms[0], &p, 10) - 1;
		if (p[0]) return OSDCMD_SHOWHELP;
		level = strtol(parm->parms[1], &p, 10) - 1;
		if (p[0]) return OSDCMD_SHOWHELP;
	} else {
		if (parm->numparms != 1) return OSDCMD_SHOWHELP;

		level = strtol(parm->parms[0], &p, 10) - 1;
		if (p[0]) return OSDCMD_SHOWHELP;
	}

	if (volume < 0) return OSDCMD_SHOWHELP;
	if (level < 0) return OSDCMD_SHOWHELP;

	if (!VOLUMEONE) {
		if (PLUTOPAK) {
			if (volume > 3) {
				OSD_Printf("changelevel: invalid volume number (range 1-4)\n");
				return OSDCMD_OK;
			}
		} else {
			if (volume > 2) {
				OSD_Printf("changelevel: invalid volume number (range 1-3)\n");
				return OSDCMD_OK;
			}
		}
	}

	if (volume == 0) {
		if (level > 5) {
			OSD_Printf("changelevel: invalid volume 1 level number (range 1-6)\n");
			return OSDCMD_OK;
		}
	} else {
		if (level > 10) {
			OSD_Printf("changelevel: invalid volume 2+ level number (range 1-11)\n");
			return OSDCMD_SHOWHELP;
		}
	}

	if (ps[myconnectindex].gm & MODE_GAME) {
		// in-game behave like a cheat
		osdcmd_cheatsinfo_stat.cheatnum = 2;
		osdcmd_cheatsinfo_stat.volume   = volume;
		osdcmd_cheatsinfo_stat.level    = level;
	} else {
		// out-of-game behave like a menu command
		osdcmd_cheatsinfo_stat.cheatnum = -1;
		
		ud.m_volume_number = volume;
		ud.m_level_number = level;
		
                ud.m_monsters_off = ud.monsters_off = 0;

                ud.m_respawn_items = 0;
                ud.m_respawn_inventory = 0;

                ud.multimode = 1;

                newgame(ud.m_volume_number,ud.m_level_number,ud.m_player_skill);
                if (enterlevel(MODE_GAME)) backtomenu();
	}

	return OSDCMD_OK;
}
Esempio n. 23
0
main()
{
	int i;
#ifdef BILL
	BillMode = 1;
#endif
	terminit();
	for(i=0;i<MAXGAMES;i++) {
		Highscore[i] = 0;
		MaxWave[i] = 0;
	}

	Lastscore = -1;
#ifdef HOSTCODE
	getscores();
#endif
	VolumeControl = 8;
	Abort = FALSE;
	Silent = FALSE;
	Running = TRUE;
	Paused = FALSE;
	Newgame = 0;
	/*
	 * For each game played...
	 */
	while ( Running ) {
		/*
		 * For each new wave...
		 */
		newgame();
		while ( Pacmen > 0 && Running ) {
			newwave();
			/*
			 * For each game scan...
			 */
			while ( Dotsrem > 0 ) {
				/*
				 * If the Pacman died, start a new one.
				 */
				if ( !Pacman.alive ) {
					addmen(-1);
					if ( Pacmen <= 0 )
						break;
					elinit();
					if ( Wallsoff ) {
						compwalls();
						Wallsoff = FALSE;
					}
					pacinit();
					moninit();
					fruitinit(FALSE);
				}
				do {
					kbpoll();
				} while ( Paused && Newgame==0);
				if ( Abort || Newgame )
					break;
				elpoll();
			}
			soundoff();
			if ( Abort || Newgame )
				break;
			paccomp();
			moncomp();
			fruitcomp();
			soundoff();
		}
		if (Game != 0) {
#ifdef HOSTCODE
			sndhost ("%s%s%d\n%s%D %D\n", SYNCSTRING, 
            		       GAMESTRING,  Game, 
	        	       SCORESTRING, (long)Score,
			       (long)KEY);
#endif
			Lastscore = Score;
			if ( Score > Highscore[Game-1] ) {
				Highscore[Game-1] = Score;
				MaxWave[Game-1] = Wave;
			}
		}
		if ( Abort )
			break;
	}
#ifdef HOSTCODE
	sndhost ("%s", EXITSTRING);
#endif
	termwrapup();
}
Esempio n. 24
0
int
main(int argc, char *argv[])
{
	int ch, done;
	char *bspec, *p, *seed;

	batch = debug = reuse = selfuse;
	bspec = seed = NULL;
	minlength = -1;
	tlimit = 180;		/* 3 minutes is standard */

	while ((ch = getopt(argc, argv, "Bbcds:t:w:")) != -1)
		switch(ch) {
		case 'B':
			grid = 5;
			break;
		case 'b':
			batch = 1;
			break;
		case 'c':
			challenge = 1;
			break;
		case 'd':
			debug = 1;
			break;
		case 's':
			seed = optarg;
			break;
		case 't':
			if ((tlimit = atoi(optarg)) < 1)
				errx(1, "bad time limit");
			break;
		case 'w':
			if ((minlength = atoi(optarg)) < 3)
				errx(1, "min word length must be > 2");
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	/* process final arguments */
	if (argc > 0) {
		if (strcmp(argv[0], "+") == 0)
			reuse = 1;
		else if (strcmp(argv[0], "++") == 0)
			selfuse = 1;
	}

	if (reuse || selfuse) {
		argc -= 1;
		argv += 1;
	}

	if (argc > 0) {
		if (islower(argv[0][0])) {
			if (strlen(argv[0]) != ncubes) {
				usage();
			} else {
				/* This board is assumed to be valid... */
				bspec = argv[0];
			}
		} else {
		  	usage();
		}
	}

	if (batch && bspec == NULL)
		errx(1, "must give both -b and a board setup");

	init();
	if (batch) {
		newgame(bspec);
		while ((p = batchword(stdin)) != NULL)
			(void) printf("%s\n", p);
		exit(0);
	}
	setup(seed);
	prompt("Loading the dictionary...");
	if ((dictfp = opendict(DICT)) == NULL) {
		warn("%s", DICT);
		cleanup();
		exit(1);
	}
#ifdef LOADDICT
	if (loaddict(dictfp) < 0) {
		warnx("can't load %s", DICT);
		cleanup();
		exit(1);
	}
	(void)fclose(dictfp);
	dictfp = NULL;
#endif
	if (loadindex(DICTINDEX) < 0) {
		warnx("can't load %s", DICTINDEX);
		cleanup();
		exit(1);
	}

	prompt("Type <space> to begin...");
	while (inputch() != ' ');

	for (done = 0; !done;) {
		newgame(bspec);
		bspec = NULL;	/* reset for subsequent games */
		playgame();
		prompt("Type <space> to continue, any cap to quit...");
		delay(10);	/* wait for user to quit typing */
		flushin(stdin);
		for (;;) {
			ch = inputch();
			if (ch == '\033')
				findword();
			else if (ch == '\014' || ch == '\022')	/* ^l or ^r */
				redraw();
			else {
				if (isupper(ch)) {
					done = 1;
					break;
				}
				if (ch == ' ')
					break;
			}
		}
	}
	cleanup();
	exit(0);
}
Esempio n. 25
0
int main(int argc, char* argv[])
{
	Game newgame(BLOCK_SIZE * WIDTH + 450, BLOCK_SIZE * HEIGHT);
	newgame.Start();
	return 0;
}
Esempio n. 26
0
void DreamGenContext::checkcoords(const RectWithCallback *rectWithCallbacks) {
	if (data.byte(kNewlocation) != 0xff)
		return;

	const RectWithCallback *rectWithCallback = rectWithCallbacks;
	while (rectWithCallback->xMin() != 0xffff) {
		if (rectWithCallback->contains(data.word(kMousex), data.word(kMousey))) {
			uint16 callback = rectWithCallback->callback();

			// common
			if(callback == addr_blank)
				blank();
			else if(callback == addr_getbackfromob)
				getbackfromob();
			else if(callback == addr_incryanpage)
				incryanpage();
			else if(callback == addr_getback1)
				getback1();
			else if(callback == addr_quitkey)
				quitkey();
			else if(callback == addr_dosreturn)
				dosreturn();
			else if(callback == addr_getbacktoops)
				getbacktoops();
			else if(callback == addr_selectslot)
				selectslot();
			// examlist
			else if(callback == addr_useobject)
				useobject();
			else if(callback == addr_selectopenob)
				selectopenob();
			else if(callback == addr_setpickup)
				setpickup();
			else if(callback == addr_examinventory)
				examinventory();
			// invlist1
			else if(callback == addr_dropobject)
				dropobject();
			else if(callback == addr_useopened)
				useopened();
			else if(callback == addr_setpickup)
				setpickup();
			else if(callback == addr_intoinv)
				intoinv();
			// withlist1
			else if(callback == addr_selectob)
				selectob();
			// talklist
			else if(callback == addr_moretalk)
				moretalk();
			// quitlist
			// destlist
			else if(callback == addr_nextdest)
				nextdest();
			else if(callback == addr_lastdest)
				lastdest();
			else if(callback == addr_lookatplace)
				lookatplace();
			else if(callback == addr_destselect)
				destselect();
			// keypadlist
			else if(callback == addr_buttonone)
				buttonone();
			else if(callback == addr_buttontwo)
				buttontwo();
			else if(callback == addr_buttonthree)
				buttonthree();
			else if(callback == addr_buttonfour)
				buttonfour();
			else if(callback == addr_buttonfive)
				buttonfive();
			else if(callback == addr_buttonsix)
				buttonsix();
			else if(callback == addr_buttonseven)
				buttonseven();
			else if(callback == addr_buttoneight)
				buttoneight();
			else if(callback == addr_buttonnine)
				buttonnine();
			else if(callback == addr_buttonnought)
				buttonnought();
			else if(callback == addr_buttonenter)
				buttonenter();
			// menulist
			// folderlist
			else if(callback == addr_nextfolder)
				nextfolder();
			else if(callback == addr_lastfolder)
				lastfolder();
			// symbollist
			else if(callback == addr_quitsymbol)
				quitsymbol();
			else if(callback == addr_settopleft)
				settopleft();
			else if(callback == addr_settopright)
				settopright();
			else if(callback == addr_setbotleft)
				setbotleft();
			else if(callback == addr_setbotright)
				setbotright();
			// diarylist
			else if(callback == addr_diarykeyn)
				diarykeyn();
			else if(callback == addr_diarykeyp)
				diarykeyp();
			else if(callback == addr_quitkey)
				quitkey();
			// opslist
			else if(callback == addr_getbackfromops)
				getbackfromops();
			else if(callback == addr_discops)
				discops();
			// discopslist
			else if(callback == addr_loadgame)
				loadgame();
			else if(callback == addr_savegame)
				savegame();
			// mainlist, mainlist2
			else if(callback == addr_look)
				look();
			else if(callback == addr_inventory)
				inventory();
			else if(callback == addr_zoomonoff)
				zoomonoff();
			else if(callback == addr_saveload)
				saveload();
			else if(callback == addr_madmanrun)
				madmanrun();
			else if(callback == addr_identifyob)
				identifyob();
			// decidelist
			else if(callback == addr_newgame)
				newgame();
			else if(callback == addr_loadold)
				loadold();
			// loadlist
			else if(callback == addr_actualload)
				actualload();
			// savelist
			else if(callback == addr_actualsave)
				actualsave();
			else {
				debug("__dispatch_call remaining in checkcoords! %d", (int)callback);
				__dispatch_call(callback);
			}
			return;
		}
		++rectWithCallback;
	}
}
Esempio n. 27
0
int main(int argc, char const *argv[])
{
	newgame();
	inst();
	printf("\nHow Many Milliseconds Per Move Would You Like Your Opponent To Take?\n");
	scanf("%d",inp);
	int mils = *inp;
	
	while(game==0) {

		checkMove();
		if(moves==0){
			cantMove[0]=1;
			legal=1;
		}
		screen();
		scanf("%s",pos);
		row=pos[0]-'1';
		col=letToNum(pos[2])-1;
		islegal(row,col);
		if(legal==1){
			retZero();
			putPiece(row,col);
		}
	nextTurn:
		retZero();
		if (legal == 1) {
			player = 2;
			checkMove();
			if(moves==0){
				cantMove[1]=1;
				legal=0;
				goto nextTurn1;
			}
			clock_t begin = clock(), runningTime;
			int ai = minimax(player, board, 6, turn, begin, runningTime, mils)[0];
			if (ai != 0) {
				yy = ai % 10;
			 	yy = yy - 1;
			 	xx = ai / 10;
			 	xx = xx - 1;
		 		printf("\n");
				printf("Opponent Moved To %d,%d\n", (xx + 1), (yy + 1));
				putPiece(xx, yy);
				retZero();
				player = 1;
			}
			legal=0;
		}
	nextTurn1:
		if(cantMove[0]==1 && cantMove[1]==1){
			game=1;
			if(cantMove[0]==0){
				printf("\nPlayer 1 Wins");
			}else{
				printf("\n AI Wins");
			}
		}else{
			game=0;
			cantMove[0]=0;
			cantMove[1]=0;
		}
	}
	return 0;
}
Esempio n. 28
0
static void initmenu(void)
{
// Allocate Menu Background backup.
   menuback = new Back(MENUXS, MENUYS);
// Load menu screen.

   demoTexture.loadPointer(SDL_CreateTexture(render.getBase(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, HWXMAX, YMAX), true);
	clearmenu();

// Take a snapshot of the plain menu screen.
   menuback->save(MENUX, MENUY);
// .. freeze overlapping part of Title.
   head = (Sprite *)loadfile("pic\\ravage.spr", NULL);
	sHead.load(head, false);

// Load pointer.
   pointer = (Sprite *)loadfile("pic\\pointer.spr", NULL);
	sPointer.load(pointer, false);

// Set mouse area.
   //setmouselimits(MENUX, MENUY, MENUX+MENUXS-pointer->xs, MENUY+MENUYS-pointer->ys);
    setmouselimits(-BORDER, 0, 320, 240);
// Initialize POINTER animation buffer.
   back = new Back(pointer->xs, pointer->ys);
// Set events to initial values.
   pointer_enabled = 1;
   keys_enabled = 0;
   joy_enabled = 0;

// Several buttons & fonts.
   blue = new Font("fonts\\blue.fnt");
   tiny = new Font("fonts\\tiny.fnt");

   addsub = (Sprite *)loadfile("pic\\addsub.spr", NULL);
   sAddSub.load(addsub, false);

   yesno = (Sprite *)loadfile("pic\\yesno.spr", NULL);
   sYesNo.load(yesno, false);

// Write version information.
#ifdef SHAREWARE
   tiny->vanilla(215, 65, "shareware 1.1", 10);
#else
   tiny->vanilla(215, 65, "registered 1.1", 10);
#endif

// Save current game state in case the menu is in SHOP mode.
   gsave = gstate;
   psave = player[nowplayer];
   psave2 = player[1-nowplayer];
   player[1-nowplayer].active = 0;     // Deactivate unused player.

// Initialize DEMO GAME.
   cheatsave = cheatlevel;
   cheatlevel |= CHEAT_INVUL | CHEAT_NOMONEY;
   playback_start("demo1\\demo1.rec");
   player[nowplayer].control = playback_device;
   gstate.nplayers = 1; gstate.difficulty = 3;
   newgame(1);
   newlevel("demo1\\demo1");
   weapon_releaseall(nowplayer, STARTX1, STARTY);
// Start playing background music.
   s_loadmod("mods\\menu.uni");
   s_startmod();
// Fade In
   fadein(level.palette);
}
Esempio n. 29
0
enum nh_restore_status nh_restore_game(int fd, struct nh_window_procs *rwinprocs,
				       boolean force_replay)
{
    int playmode, irole, irace, igend, ialign;
    char namebuf[PL_NSIZ];
    
    /* some compilers can't cope with the fact that all subsequent stores to error
     * are not dead, but become important if the error handler longjumps back
     * volatile is required to prevent invalid optimization based on that wrong
     * assumption. */
    volatile enum nh_restore_status error = GAME_RESTORED;
    
    if (fd == -1)
	return ERR_BAD_ARGS;
    
    switch (nh_get_savegame_status(fd, NULL)) {
	case LS_INVALID:	return ERR_BAD_FILE;
	case LS_DONE:		return ERR_GAME_OVER;
	case LS_CRASHED:	force_replay = TRUE; break;
	case LS_IN_PROGRESS:	return ERR_IN_PROGRESS;
	case LS_SAVED:		break; /* default, everything is A-OK */
    }
    
    if (!api_entry_checkpoint())
	goto error_out;
    
    error = ERR_BAD_FILE;
    replay_set_logfile(fd); /* store the fd and try to get a lock or exit */
    replay_begin();

    program_state.restoring = TRUE;
    iflags.disable_log = TRUE; /* don't log any of the commands, they're already in the log */

    /* Read the log header for this game. */
    replay_read_newgame(&turntime, &playmode, namebuf,
			&irole, &irace, &igend, &ialign);

    /* set special windowprocs which will autofill requests for user input
     * with data from the log file */
    replay_setup_windowprocs(rwinprocs);

    startup_common(namebuf, playmode);
    u.initrole = irole;
    u.initrace = irace;
    u.initgend = igend;
    u.initalign = ialign;

    if (!force_replay) {
	error = ERR_RESTORE_FAILED;
	replay_run_cmdloop(TRUE, FALSE, TRUE);
	replay_jump_to_endpos();
	if (!dorecover_fd(fd)) {
	    replay_undo_jump_to_endpos();
	    goto error_out2;
	}
	replay_undo_jump_to_endpos();
	wd_message();
	program_state.game_running = 1;
	post_init_tasks();
    } else {
	replay_run_cmdloop(TRUE, TRUE, FALSE); /* option setup only */
	newgame();
	/* try replaying instead */
	error = ERR_REPLAY_FAILED;
	replay_run_cmdloop(FALSE, FALSE, TRUE);
	replay_sync_save();
    }
    
    /* restore standard window procs */
    replay_restore_windowprocs();
    program_state.restoring = FALSE;
    iflags.disable_log = FALSE;

    /* clean up data used for replay */
    replay_end();
    log_truncate();
    log_init(); /* must be called before we start writing to the log */

    /* info might not have reached the ui while alternate window procs were set */
    doredraw();

    /* nh_start_game() does this via newgame(), but since this function doesn't
     * call newgame(), we have to do it here instead. */
    notify_levelchange(NULL);

    bot();
    flush_screen();
    was_on_elbereth = !sengr_at("Elbereth", u.ux, u.uy); /* force botl update later */

    welcome(FALSE);
    realtime_messages(TRUE, TRUE);
    update_inventory();
    
    api_exit();
    return GAME_RESTORED;

error_out2:
    api_exit();
    
error_out:
    replay_restore_windowprocs();
    program_state.restoring = FALSE;
    iflags.disable_log = FALSE;
    replay_end();
    unlock_fd(fd);
    
    if (error == ERR_RESTORE_FAILED) {
	raw_printf("Restore failed. Attempting to replay instead.\n");
	error = nh_restore_game(fd, rwinprocs, TRUE);
    }
    
    return error;
}