Example #1
0
/*******************************************************************************
 * Description: the setup function that doesn't actually setup the game, but
 * does the ncurses window setup, other system-related calls
 * 
 * Inputs: 
 * 
 * Returns: 
 ******************************************************************************/
void presetup( void )
{
  getHighscores();

  /* prepare the screen */
  initscr();
  cbreak();
  noecho(); // turns off echoing characters read by getch()
  curs_set(0); // hide the cursor
  MAX_ROW = LINES;
  MAX_COL = COLS;
  srand(time(NULL)); // seed for random number generator

  /* check for size of terminal window bigger than 30 by 30 */
  if( MAX_ROW <= 30 || MAX_COL <= 30 )
  {
    teardown();
    printf( "your terminal window is too small! try again.\n" );
    exit(-1);
  }

  /* clear screen */
  clear();

  /* draw border */
  drawBorder( '#', '#', '#', '#' ); 

  /* write a message that says press something to start */
  char welcomeMesg1[] = "Welcome to Snake!";
  char welcomeMesg2[] = "Press any key to begin playing";
  mvprintw( MAX_ROW/2 - 5, (MAX_COL-strlen(welcomeMesg1))/2, "%s", welcomeMesg1 );
  mvprintw( MAX_ROW/2 - 2, (MAX_COL-strlen(welcomeMesg2))/2, "%s", welcomeMesg2 );

  showHighScores();

  /* wait for something to be pressed, then return */
  getch();
}
Example #2
0
/*!
  Initializes all of the QActions used by the game
*/
void QixWindow::createActions() {
    // New game
    newGameAction = new QAction(tr("&New"), this);
    newGameAction->setIcon(QIcon(":/images/new.png"));
    newGameAction->setShortcut(tr("Ctrl+N"));
    newGameAction->setStatusTip(tr("Start a new game"));
    connect(newGameAction, SIGNAL(triggered()), this, SLOT(newGame()));

    // About
    aboutAction = new QAction(tr("About"), this);
    aboutAction->setIcon(QIcon(":/images/about.png"));
    aboutAction->setShortcut(tr("Ctrl+A"));
    aboutAction->setStatusTip(tr("About Qix"));
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));

    // About QT
    aboutQtAction = new QAction(tr("About QT"), this);
    aboutQtAction->setIcon(QIcon(":/images/about.png"));
    aboutQtAction->setStatusTip(tr("About Qix"));
    connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));

    // Exit
    quitAction = new QAction(tr("Exit"), this);
    quitAction->setIcon(QIcon(":/images/quit.png"));
    quitAction->setShortcut(tr("Ctrl+Q"));
    quitAction->setStatusTip(tr("Quit"));
    connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));//quit()));

    // Show High Scores dialog box
    highScoresAction = new QAction(tr("High Scores"), this);
    highScoresAction->setStatusTip(tr("Show high scores"));
    connect(highScoresAction, SIGNAL(triggered()), this, SLOT(showHighScores()));

    timeAction = new QAction(tr("0"), this);
    timeAction->setStatusTip(tr("Time"));
}
Example #3
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !Layer::init() )
	{
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	/////////////////////////////
	// 2. add a menu item with "X" image, which is clicked to quit the program
	//    you may modify it.

	// add a "close" icon to exit the progress. it's an autorelease object
	auto closeItem = MenuItemImage::create(
										   "CloseNormal.png",
										   "CloseSelected.png",
										   CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));

	closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
								origin.y + closeItem->getContentSize().height/2));

	// create menu, it's an autorelease object
	auto menu = Menu::create(closeItem, NULL);
	menu->setPosition(Point::ZERO);
	this->addChild(menu, 1);

	/////////////////////////////
	// 3. add your codes below...

	// add a label shows "Hello World"
	// create and initialize a label

	labelGameTitle = ColorfulLabel::create("CatchMe", "Fonts/NextGames.ttf", 72);

	// position the label on the center of the screen
	labelGameTitle->setPosition(Point(origin.x + visibleSize.width/2,
							origin.y + visibleSize.height - labelGameTitle->getContentSize().height));

	// add the label as a child to this layer
	this->addChild(labelGameTitle, 1);

#if 0
	// add "HelloWorld" splash screen"
	auto sprite = Sprite::create("HelloWorld.png");

	// position the sprite on the center of the screen
	sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

	// add the sprite as a child to this layer
	this->addChild(sprite, 0);
#endif

	schedule( schedule_selector(HelloWorld::update) );
	animateGameTitle();
	setEventHandlers();
	showHighScores();

	return true;
}
Example #4
0
void Game::menu()
{

    game = new QPopupMenu();
    CHECK_PTR( game );
    game->insertItem( klocale->translate("New"), this, SLOT(newGame()),Key_F2);
    pauseID = game->insertItem( klocale->translate("Pause"), this , SLOT(pauseGame()), Key_F3);
    game->insertItem( klocale->translate("High Scores..."), this, SLOT(showHighScores()));
    game->insertSeparator();
    game->insertItem( klocale->translate("&Quit"),  this, SLOT(quitGame()), CTRL+Key_Q );
    game->setCheckable( TRUE );

    balls = new QPopupMenu;
    CHECK_PTR( balls );
    ballsID[0] = balls->insertItem( klocale->translate("0"));
    ballsID[1] = balls->insertItem( klocale->translate("1"));
    ballsID[2] = balls->insertItem( klocale->translate("2"));
    ballsID[3] = balls->insertItem( klocale->translate("3"));
    balls->setCheckable( TRUE );
    connect(balls, SIGNAL(activated(int)), this, SLOT ( ballsChecked(int) ));

    snakes = new QPopupMenu;
    CHECK_PTR( snakes );
    snakesID[0] = snakes->insertItem( klocale->translate("0"));
    snakesID[1] = snakes->insertItem( klocale->translate("1"));
    snakesID[2] = snakes->insertItem( klocale->translate("2"));
    snakesID[3] = snakes->insertItem( klocale->translate("3"));
    snakes->setCheckable( TRUE );
    connect(snakes, SIGNAL(activated(int)), this,
	    SLOT ( snakesChecked(int) ));


    pix = new QPopupMenu;
    lookupBackgroundPixmaps();
    pixID.resize(backgroundPixmaps.count());

    if(backgroundPixmaps.count() == 0)
	pix->insertItem(klocale->translate("none"));
    else
	for(unsigned i = 0; i < backgroundPixmaps.count(); i++) {
	    // since the filename may contain underscore, they
	    // are replaced with spaces in the menu entry
	    QString s(backgroundPixmaps.at(i)->baseName());
	    s = s.replace(QRegExp("_"), " ");
	    pixID[i] = pix->insertItem((const char *)s);
	}
    pix->setCheckable( TRUE );
    connect(pix, SIGNAL(activated(int)), this,
	    SLOT ( pixChecked(int) ));

    options = new QPopupMenu();
    CHECK_PTR( options );
    skillID[0] = options->insertItem( klocale->translate("Beginner"));
    skillID[1] = options->insertItem( klocale->translate("Intermediate"));
    skillID[2] = options->insertItem( klocale->translate("Advanced"));
    skillID[3] = options->insertItem( klocale->translate("Expert"));
    options->insertSeparator();
    options->insertItem(klocale->translate("Balls"), balls);
    options->insertItem(klocale->translate("Computer Snakes"), snakes);
    options->insertSeparator();
    options->insertItem(klocale->translate("Select background color..."), this, SLOT(backgroundColor()));
    options->insertItem(klocale->translate("Select background pixmap"), pix);
    options->insertSeparator();
    options->insertItem(klocale->translate("Change keys..."),this, SLOT(confKeys()));
    options->insertSeparator();
    options->insertItem(klocale->translate("Starting Room..."), this, SLOT(startingRoom()));

    options->setCheckable( TRUE );
    connect(options, SIGNAL(activated(int)), this, SLOT ( skillChecked(int) ));

    QPopupMenu *help = kapp->getHelpMenu(true, QString(klocale->translate("Snake Race"))
                                         + " " + KSNAKE_VERSION
                                         + klocale->translate("\n\nby Michel Filippi"
                                         " ([email protected])")); 
    menubar = new KMenuBar( this );
    CHECK_PTR( menubar );
    menubar->insertItem( klocale->translate("&Game"), game );
    menubar->insertItem( klocale->translate("&Options"), options );
    menubar->insertSeparator();
    menubar->insertItem( klocale->translate("&Help"), help);
}
Example #5
0
void Kolf::initGUI()
{
	newAction = KStdGameAction::gameNew(this, SLOT(newGame()), actionCollection());
	newAction->setText(newAction->text() + QString("..."));

	endAction = KStdGameAction::end(this, SLOT(closeGame()), actionCollection());
	printAction = KStdGameAction::print(this, SLOT(print()), actionCollection());

	(void) KStdGameAction::quit(this, SLOT(close()), actionCollection());
	saveAction = KStdAction::save(this, SLOT(save()), actionCollection(), "game_save");
	saveAction->setText(i18n("Save &Course"));
	saveAsAction = KStdAction::saveAs(this, SLOT(saveAs()), actionCollection(), "game_save_as");
	saveAsAction->setText(i18n("Save &Course As..."));

	saveGameAction = new KAction(i18n("&Save Game"), 0, this, SLOT(saveGame()), actionCollection(), "savegame");
	saveGameAsAction = new KAction(i18n("&Save Game As..."), 0, this, SLOT(saveGameAs()), actionCollection(), "savegameas");

	loadGameAction = KStdGameAction::load(this, SLOT(loadGame()), actionCollection());
	loadGameAction->setText(i18n("Load Saved Game..."));

	highScoreAction = KStdGameAction::highscores(this, SLOT(showHighScores()), actionCollection());

	editingAction = new KToggleAction(i18n("&Edit"), "pencil", CTRL+Key_E, this, SLOT(emptySlot()), actionCollection(), "editing");
	newHoleAction = new KAction(i18n("&New"), "filenew", CTRL+SHIFT+Key_N, this, SLOT(emptySlot()), actionCollection(), "newhole");
	clearHoleAction = new KAction(KStdGuiItem::clear().text(), "locationbar_erase", CTRL+Key_Delete, this, SLOT(emptySlot()), actionCollection(), "clearhole");
	resetHoleAction = new KAction(i18n("&Reset"), CTRL+Key_R, this, SLOT(emptySlot()), actionCollection(), "resethole");
	undoShotAction = KStdAction::undo(this, SLOT(emptySlot()), actionCollection(), "undoshot");
	undoShotAction->setText(i18n("&Undo Shot"));
	//replayShotAction = new KAction(i18n("&Replay Shot"), 0, this, SLOT(emptySlot()), actionCollection(), "replay");

	holeAction = new KListAction(i18n("Switch to Hole"), 0, this, SLOT(emptySlot()), actionCollection(), "switchhole");
	nextAction = new KAction(i18n("&Next Hole"), "forward", KStdAccel::shortcut(KStdAccel::Forward), this, SLOT(emptySlot()), actionCollection(), "nexthole");
	prevAction = new KAction(i18n("&Previous Hole"), "back", KStdAccel::shortcut(KStdAccel::Back), this, SLOT(emptySlot()), actionCollection(), "prevhole");
	firstAction = new KAction(i18n("&First Hole"), "gohome", KStdAccel::shortcut(KStdAccel::Home), this, SLOT(emptySlot()), actionCollection(), "firsthole");
	lastAction = new KAction(i18n("&Last Hole"), CTRL+SHIFT+Key_End, this, SLOT(emptySlot()), actionCollection(), "lasthole");
	randAction = new KAction(i18n("&Random Hole"), "goto", 0, this, SLOT(emptySlot()), actionCollection(), "randhole");

	useMouseAction = new KToggleAction(i18n("Enable &Mouse for Moving Putter"), 0, this, SLOT(emptySlot()), actionCollection(), "usemouse");
	useMouseAction->setCheckedState(i18n("Disable &Mouse for Moving Putter"));
	connect(useMouseAction, SIGNAL(toggled(bool)), this, SLOT(useMouseChanged(bool)));
	KConfig *config = kapp->config();
	config->setGroup("Settings");
	useMouseAction->setChecked(config->readBoolEntry("useMouse", true));

	useAdvancedPuttingAction = new KToggleAction(i18n("Enable &Advanced Putting"), 0, this, SLOT(emptySlot()), actionCollection(), "useadvancedputting");
	useAdvancedPuttingAction->setCheckedState(i18n("Disable &Advanced Putting"));
	connect(useAdvancedPuttingAction, SIGNAL(toggled(bool)), this, SLOT(useAdvancedPuttingChanged(bool)));
	useAdvancedPuttingAction->setChecked(config->readBoolEntry("useAdvancedPutting", false));

	showInfoAction = new KToggleAction(i18n("Show &Info"), "info", CTRL+Key_I, this, SLOT(emptySlot()), actionCollection(), "showinfo");
	showInfoAction->setCheckedState(i18n("Hide &Info"));
	connect(showInfoAction, SIGNAL(toggled(bool)), this, SLOT(showInfoChanged(bool)));
	showInfoAction->setChecked(config->readBoolEntry("showInfo", false));

	showGuideLineAction = new KToggleAction(i18n("Show Putter &Guideline"), 0, this, SLOT(emptySlot()), actionCollection(), "showguideline");
	showGuideLineAction->setCheckedState(i18n("Hide Putter &Guideline"));
	connect(showGuideLineAction, SIGNAL(toggled(bool)), this, SLOT(showGuideLineChanged(bool)));
	showGuideLineAction->setChecked(config->readBoolEntry("showGuideLine", true));

	KToggleAction *act=new KToggleAction(i18n("Enable All Dialog Boxes"), 0, this, SLOT(enableAllMessages()), actionCollection(), "enableAll");
	act->setCheckedState(i18n("Disable All Dialog Boxes"));

	soundAction = new KToggleAction(i18n("Play &Sounds"), 0, this, SLOT(emptySlot()), actionCollection(), "sound");
	connect(soundAction, SIGNAL(toggled(bool)), this, SLOT(soundChanged(bool)));
	soundAction->setChecked(config->readBoolEntry("sound", true));

	(void) new KAction(i18n("&Reload Plugins"), 0, this, SLOT(initPlugins()), actionCollection(), "reloadplugins");
	(void) new KAction(i18n("Show &Plugins"), 0, this, SLOT(showPlugins()), actionCollection(), "showplugins");

	aboutAction = new KAction(i18n("&About Course"), 0, this, SLOT(emptySlot()), actionCollection(), "aboutcourse");
	tutorialAction = new KAction(i18n("&Tutorial"), 0, this, SLOT(tutorial()), actionCollection(), "tutorial");

	statusBar();
	setupGUI();
}