当前位置: 首页>>代码示例>>C++>>正文


C++ Snake::CurY方法代码示例

本文整理汇总了C++中Snake::CurY方法的典型用法代码示例。如果您正苦于以下问题:C++ Snake::CurY方法的具体用法?C++ Snake::CurY怎么用?C++ Snake::CurY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Snake的用法示例。


在下文中一共展示了Snake::CurY方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {
	int c = 0;

	initscr();
	cbreak();				// Disable buffering, making input available to the program immediately
    timeout(500);
	keypad(stdscr, TRUE);	// Enable input from arrow keys
	curs_set(0); 			// Hide cursor
	getmaxyx(stdscr, maxY, maxX);	// Get max X and Y of the terminal

	//Snake* snake = Snake::Load(FILE_NAME);
    Snake* snake;
	
    snake = new Snake(maxX-1, maxY-1, UP);
    
	GenerateNewTarget();
	while(snake->SetTarget(targetX, targetY)==false)
        GenerateNewTarget();
        mvaddch(targetY, targetX, '$');
    
	while (true) {
        c = getch();
        if(c==32)
        {
            GenerateNewTarget();
            while(snake->SetTarget(targetX, targetY)==false)
                GenerateNewTarget();
            mvaddch(targetY, targetX, '$');
             
            
        }
        //運行AI
        if(isAutoMode==true)
        {
            autoMove(snake,snake->getTarX(),snake->getTarY(),maxX,maxY);
            c=moveQueue.front();
            moveQueue.pop();
        }
		switch (c) {
		case KEY_UP:    //259
			snake->SetDir(UP);
			break;
		case KEY_DOWN: //258
			snake->SetDir(DOWN);
			break;
		case KEY_LEFT: //260
			snake->SetDir(LEFT);
			break;
		case KEY_RIGHT://261
			snake->SetDir(RIGHT);
			break;
		default:
			break;
		}
		
		if (c == 'q' || c == 'Q') {
			break;
		}

		snake->Move();
		if (snake->CurX() < 0 || snake->CurX() >= maxX
            || snake->CurY() < 0 || snake->CurY() >= maxY)
        {
            printLog(log);
            //int i=0;
            //while(i==0)//停留在結束畫面
            //{
                //cout<<endl;
            //}
            break;
        }
        round=round+1;
		if (snake->CurX() == targetX && snake->CurY() == targetY) {
			GenerateNewTarget();
            while(snake->SetTarget(targetX, targetY)==false)
                GenerateNewTarget();
            mvaddch(targetY, targetX, '$');
			//snake->SetTarget(targetX, targetY);
            score+=1;
            //time.push_back(round);
            r.push_back("Round="+int2str(round)+" mean="+dbl2str(static_cast<double>(round)/score));
            //round=0;
		}
        printLog(r,"round");

	}
	
	//snake->Save(FILE_NAME);
	delete snake;
	endwin();	// Restores the terminal after Curses activity
    cout<<"你的得分是:"<<score<<endl;
}
开发者ID:steven810528,项目名称:Snake,代码行数:92,代码来源:main.cpp


注:本文中的Snake::CurY方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。