Exemplo n.º 1
0
void	start_playing(int *game, t_opt *options)
{
  int	remain;

  remain = line_left(game, options);
  if (options->turn == 1)
    while (remain != 0)
      {
	player(game, options);
	remain = line_left(game, options);
	if (remain != 0)
	  computer(game, options);
	remain = line_left(game, options);
	if (remain != 0)
	  aff_game(game, options);
      }
  else
    while (remain != 0)
      {
	computer(game, options);
	remain = line_left(game, options);
	if (remain != 0)
	  player(game, options);
	remain = line_left(game, options);
	if (remain != 0)
	  aff_game(game, options);
      }
}
Exemplo n.º 2
0
int main(void)
{
	int a[10][10] = {0};
	int n = 1;

	chessboard(a);
	printf("You can input 4 4 to put a chess on board!\n");
	while (1) {
		if (n == 1) {
			play_chess(a, n);
			n = det_chess(a, n);
			if (n) break;
			n = 2;
		}
		if (n == 2) {
			computer(a, n);
			n = det_chess(a, n);
			if (n) {
				n++;
				break;
			}
			n = 1;
		}
	}
	if (n == 1) 
		printf("Congratulations, Play %d WIN!\n",n);
	else 
		printf("Congratulations, Computer WIN!\n");

	return 0;
}
Exemplo n.º 3
0
ScFileWidget::ScFileWidget(QWidget * parent)
	: QFileDialog(parent, Qt::Widget)
{
	setSizeGripEnabled(false);
	setModal(false);
	setViewMode(QFileDialog::List);
	setWindowFlags(Qt::Widget);


#ifdef Q_OS_MAC
	QList<QUrl> urls;
	QUrl computer(QUrl::fromLocalFile(QLatin1String("")));
	if (!urls.contains(computer))
		urls << computer;
	QUrl volumes(QUrl::fromLocalFile("/Volumes"));
	if (!urls.contains(volumes))
		urls << volumes;
	//desktop too?	QUrl computer(QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)));
	setSidebarUrls(urls);
#endif
	QList<QPushButton *> b = findChildren<QPushButton *>();
	QListIterator<QPushButton *> i(b);
	while (i.hasNext())
		i.next()->setVisible(false);
	setMinimumSize(QSize(480, 310));
	setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
}
Exemplo n.º 4
0
void PowerTray::monitorLid()
{
    bool do_suspend = false;
    QStringList lids;
    lids << "/proc/acpi/button/lid/LID/state" << "/proc/acpi/button/lid/LID0/state";
    for (int i = 0; i < lids.size(); ++i)
    {
        QFile lid(lids.at(i));
        if (lid.exists())
        {
            if (lid.open(QIODevice::ReadOnly))
            {
                QString line;
                QTextStream textStream(&lid);
                line = textStream.readAll().simplified();
                if (line == "state: closed")
                {
                    do_suspend = true;
                }
                lid.close();
            }
        }
    }

    if (do_suspend)
    {
        QDBusConnection conn = QDBusConnection::systemBus();
        QDBusInterface computer("org.freedesktop.Hal","/org/freedesktop/Hal/devices/computer","org.freedesktop.Hal.Device.SystemPowerManagement",conn);
        computer.call("Suspend",1);
    }

    QTimer::singleShot(1000,this,SLOT(monitorLid())); // loop
}
Exemplo n.º 5
0
void plConvexHullGetVertex(plConvexHull hull, int n, float coords[3],
						   int *original_index)
{
	btConvexHullComputer *computer(reinterpret_cast< btConvexHullComputer* >(hull));
	const btVector3 &v(computer->vertices[n]);
	coords[0] = v[0];
	coords[1] = v[1];
	coords[2] = v[2];
	(*original_index) = computer->original_vertex_index[n];
}
Exemplo n.º 6
0
int plConvexHullGetFaceSize(plConvexHull hull, int n)
{
	btConvexHullComputer *computer(reinterpret_cast< btConvexHullComputer* >(hull));
	const btConvexHullComputer::Edge *e_orig, *e;
	int count;

	for (e_orig = &computer->edges[computer->faces[n]], e = e_orig, count = 0;
		 count == 0 || e != e_orig;
		 e = e->getNextEdgeOfFace(), count++);
	return count;
}
Exemplo n.º 7
0
void TestEndgameAccuracy(){
	int i;
	CNodeStats start,end, start1,end1,delta1;
	CValue value;

	// create computer
	CComputerDefaults cd;
	cd.booklevel=CComputerDefaults::kNoBook;
	CPlayerComputer computer(cd);

	start.Read();

	for (i=0; i<nEndgames; i++) {
		::nBBFlips=0;


		bool fBlackMove=false;

		Pos2 pos2;
		pos2.Initialize(bds[i].board, fBlackMove);
		computer.Clear();
		if (printDetails > 1) {
			pos2.Print();
		}

		start1.Read();

		CMVK mvk;
		CSearchInfo si=computer.DefaultSearchInfo(fBlackMove, CSearchInfo::kNeedValue+CSearchInfo::kNeedMove, 1e6, 0);
		CQPosition qpos(pos2.GetBB(), pos2.BlackMove());
		computer.GetChosen(si,qpos,mvk, true);
		value=mvk.value/kStoneValue;
		end1.Read();
		delta1=end1-start1;

		assertEquals(bds[i].nResultNoEmpties, value);
		if (printDetails) {
			std::cout << std::setw(2) << i;
			std::cout << ": Value: " << std::setw(3) << value;
			std::cout << ". Nodes: " << std::setw(6) << (int)delta1.Nodes();
			std::cout << ". Board: " << bds[i].board << "\n";
			if (printDetails > 1) {
				std::cout << end1-start1 << "\n";
				std::cout << "-------------------------------------------\n";
			}
		}
	}

	end.Read();
	if (printDetails) {
		std::cout << end-start << "\n";
	}
}
Exemplo n.º 8
0
void plConvexHullGetFaceVertices(plConvexHull hull, int n, int *vertices)
{
	btConvexHullComputer *computer(reinterpret_cast< btConvexHullComputer* >(hull));
	const btConvexHullComputer::Edge *e_orig, *e;
	int count;

	for (e_orig = &computer->edges[computer->faces[n]], e = e_orig, count = 0;
		 count == 0 || e != e_orig;
		 e = e->getNextEdgeOfFace(), count++)
	{
		vertices[count] = e->getTargetVertex();
	}
}
Exemplo n.º 9
0
void practice()
{	
	int get,i,count=0,win=0,lose=0;
	srand(time(0));
	shouming();
	while(1){
	get=scan_data();
	if(get==0)
		break;
	i=computer();
	win_or_lose(get,i,&win,&lose,&count);
	}
	printf("胜利:%d盘\t失败:%d盘\t总盘数:%d盘\n",win,lose,count);
}
int main(int argc, char* argv[])
{
    MinimaxSearcher ms;
    AlphaBetaSearcher abs;
    NegamaxSearcher ns;
    NegamaxAlphaBetaSearcher nabs;


    AlphaBetaSearcher as;
    HumanPlayer human("张三");
    //ComputerPlayer computer1("KA47");
    //computer1.SetSearcher(&as, SEARCH_DEPTH);
    ComputerPlayer computer("ThinkPad X200");
    computer.SetSearcher(&nabs, SEARCH_DEPTH);

    WzEvaluator wzFunc;
    FeEvaluator feFunc;
    GameState init_state;
    init_state.InitGameState(PLAYER_A);
    init_state.SetEvaluator(&feFunc);
    /*
        init_state.SetGameCell(0, PLAYER_A);
        init_state.SetGameCell(1, PLAYER_B);
        init_state.SetGameCell(3, PLAYER_B);
        init_state.SetGameCell(4, PLAYER_B);
        init_state.SetGameCell(5, PLAYER_A);
        init_state.SetGameCell(6, PLAYER_A);
    */
    /*
        init_state.SetGameCell(0, PLAYER_B);
        init_state.SetGameCell(3, PLAYER_B);
        init_state.SetGameCell(4, PLAYER_A);
        init_state.SetGameCell(5, PLAYER_A);
        init_state.SetGameCell(6, PLAYER_A);
        init_state.SetGameCell(8, PLAYER_B);
    */
    GameControl gc;
    gc.SetPlayer(&computer, PLAYER_A);
    gc.SetPlayer(&human, PLAYER_B);
    //gc.SetPlayer(&computer1, PLAYER_B);
    gc.InitGameState(init_state);
    gc.Run();

    return 0;
}
Exemplo n.º 11
0
void CCommandProcessor::OnClientLogin(BYTE *pBuffer, size_t bufLen)
{
	MANAGER_COMPUT_INFO ci = {0};
	GetBody(pBuffer, &ci, sizeof(ci));

	CComputerInfo computer(ci);

	// 2011/06/10-gxx: 
	if (computer.GetComputerStatus() != CComputerInfo::ECS_ONLINE)
	{
		CActiveMember ActiveMember;
		if (m_lpLocalServer->ActiveMemberList.GetActiveMember( computer.GetTerminalID(), ActiveMember, TRUE))
		{
			computer.AttachActiveMember(ActiveMember);
		}	
	}

	m_lpLocalServer->ComputerList.AddComputer(computer);

	IBA_TRACE(_T("OnClientLogin = %s\r\n"), computer.GetTerminalID());

	for (INT i = 0; i < m_QuestionComputerList.GetCount(); i++)
	{
		if (m_QuestionComputerList.GetAt(i).Find(computer.GetTerminalID()) >= 0)
		{
			m_QuestionComputerList.RemoveAt(i);
		}
	}

	m_lpLocalServer->GetComputerListView()->Refresh(FALSE);

	//重启挂机的情况
	if (computer.GetComputerStatus() == CComputerInfo::ECS_SUSPEND)
	{
		CActiveMember ActiveMember;

		if (m_lpLocalServer->ActiveMemberList.GetActiveMember(computer.GetTerminalID(), ActiveMember))
		{
			ActiveMember.SetActive(TRUE);
			m_lpLocalServer->ActiveMemberList.UpdateActiveMember(ActiveMember, TRUE);
			m_lpLocalServer->GetActiveMemberView()->Refresh(FALSE);
		}
	}

}
Exemplo n.º 12
0
//----------------------------------------------------------------------   
void AtvUsbCreatorLinux::detect_removable_drives()
{
  m_devices.clear();
  QDBusInterface computer("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal.Manager", QDBusConnection::systemBus());

  //TODO how to get force flag here?
//         if self.opts.force:
//           devices = self.hal.FindDeviceStringMatch('block.device',
//               self.opts.force)
//         else:
//           devices = self.hal.FindDeviceByCapability("storage")
  //get storage devices
  QStringList devices = callAndReturnResponse<QVariant::StringList>(computer, "FindDeviceByCapability", "storage" ).toStringList();
  for(unsigned int i = 0; i< devices.size(); ++i){
    QString current_device_string = devices[i];
    //get few infos about this device
    QDBusInterface device("org.freedesktop.Hal", current_device_string, "org.freedesktop.Hal.Device" , QDBusConnection::systemBus());
    QString bus = callAndReturnResponse<QVariant::String>(device, "GetPropertyString", "storage.bus" ).toString();
    bool removable = callAndReturnResponse<QVariant::Bool>(device, "GetPropertyBoolean", "storage.removable" ).toBool();
    if(bus == "usb" && removable){
      if(callAndReturnResponse<QVariant::Bool>(device, "GetPropertyBoolean", "block.is_volume" ).toBool()){
        m_devices << callAndReturnResponse<QVariant::String>(device, "GetPropertyString", "block.device").toString();
      } else {
        QStringList children = callAndReturnResponse<QVariant::StringList>(computer, "FindDeviceStringMatch", "info.parent", current_device_string).toStringList();
        for(unsigned int k = 0; k<children.size(); ++k){
          QString child_device_string = children[k];
          QDBusInterface child_device("org.freedesktop.Hal", child_device_string, "org.freedesktop.Hal.Device" , QDBusConnection::systemBus());
          if(callAndReturnResponse<QVariant::Bool>(child_device, "GetPropertyBoolean", "block.is_volume" ).toBool()){
            m_devices << callAndReturnResponse<QVariant::String>(device, "GetPropertyString", "block.device").toString();
          }
      }
    }
     //TODO
//       mount = str(dev.GetProperty('volume.mount_point'))
//       self.drives[str(dev.GetProperty('block.device'))] = {
//     'mount'   : mount,
//     'udi'     : dev,
//     'mounted' : False,
//       }
    }
  }
  if (m_devices.empty())
    throw AtvUsbCreatorException("Unable to find any USB drives");
}
Exemplo n.º 13
0
uint64 getCurrentProcessorSpeed() {
	uint64 result = 0;
#ifdef ANDROID
	unsigned long long tmpResult = 0;
	int cpuId = 0;
	while (true) {
		FILE* fd = _getIntFd(SYS_DEVICES_SYSTEM_CPU_CPUID_CPUFREQ_SCALING_CUR_FREQ, cpuId);
		if (NULL != fd) {
			unsigned long long freq = 0;
			int res = fscanf(fd, "%llu", &freq);
			if (res > 0) {
				tmpResult += freq;
			}
	    	fclose(fd);
		} else {
			break;
		}
		cpuId++;
	};
	if (cpuId > 0) {
		result = tmpResult / cpuId;
	}
#else
    hwNode computer("computer",
      hw::system);
	unsigned long long sum = 0;
	unsigned long long count = 0;
	scan_cpuinfo(computer);
	scan_cpuid(computer);
	hwNode *core = computer.getChild("core");
	if (NULL != core) {
		int childs = core->countChildren();
		for (int c=0; c < childs; c++) {
			hwNode *cpu = core->getChild(c);
			sum += cpu->getSize();
			count++;
		}
	}
	if (count > 0) {
		result = (uint64) (sum / ((double) count));
	}
#endif
    return result;
}
Exemplo n.º 14
0
uint64 getMaxProcessorSpeed() {
    unsigned long long result = 0;
#ifdef ANDROID
	int cpuId = 0;
	while (true) {
		FILE* fd = _getIntFd(SYS_DEVICES_SYSTEM_CPU_CPUID_CPUFREQ_CPUINFO_MAX_FREQ, cpuId);
		if (NULL != fd) {
			unsigned long long freq = 0;
			int res = fscanf(fd, "%llu", &freq);
			if (res > 0) {
				result = MAX(result, freq);
			}
	    	fclose(fd);
		} else {
			break;
		}
		cpuId++;
	};
#else
    hwNode computer("computer", hw::system);
	scan_cpuinfo(computer);
	scan_cpuid(computer);
	scan_cpufreq(computer);
	hwNode *core = computer.getChild("core");
	if (NULL != core) {
		int childs = core->countChildren();
		for (int c=0; c < childs; c++) {
			hwNode *cpu = core->getChild(c);
			unsigned long long capacity = cpu->getCapacity();
			if (0 == capacity) {
				// rule... if cpufreq is not available, then
				// the CPU is running on maximum frequency cpu->getSize()
				// checked by sudo dmidecode
				capacity = cpu->getSize();
			}
			if (capacity > result) {
				result = capacity;
			}
		}
	}
#endif
    return result;
}
Exemplo n.º 15
0
void duizhanmoshi(struct user *p)
{
	int get,i,count=0,win=0,lose=0;
	srand(time(0));
	shouming();
	while((win!=2)&&(lose!=2)){
	get=scan_data();
	i=computer();
	win_or_lose(get,i,&win,&lose,&count);
	}
	printf("胜利:%d盘\t失败:%d盘\t总盘数:%d盘\n",win,lose,count);
	if(win==2) {printf("You win! \n");}
	else {printf("Sorry,you lose!!!\n");}
	printf("大侠,请留名:");
	getchar();
	gets(stu[N].name);
	stu[N].win=win;
	stu[N].count=count;
	save_data(&stu[N]);
}
Exemplo n.º 16
0
int result(char fir[],int plus) //算出结果 
{
    char c,ch;
    int x,y,i = 0;
    count1 = 0;
    count2 = 0;
    push2('#');
    while( fir[i]!='#' || optr[count2-1]!='#')
    {
        c = fir[i];
        if( isdigit(c) )
        {
            push1(c-'0');
            i++;
            continue;
        }
        if( isalpha(c) )
        {
            push1(c-'a'+plus);
            i++;
            continue;
        }
        if(c == '+' || c== '-'||c=='*' || c=='('||c==')'||c=='#')
        {
            switch( record(optr[count2-1],c) )
            {
                
                case -1: push2(c); i++; break;
                case 0 : pop2(); i++; break;
                case 1 : ch = pop2();
                         y = pop1();
                         x = pop1(); 
                         push1(computer(x,y,ch));
                         break;
            }
        }
        else
            i++;
    }
return opnd[count1-1];
}
Exemplo n.º 17
0
void CCommandProcessor::OnGetComputerList(BYTE *pBuffer, size_t bufLen)
{
	MANAGER_COMPUT_INFO* pComputerInfo = 
		reinterpret_cast<MANAGER_COMPUT_INFO*>(pBuffer + sizeof(NET_HEAD_MAN));

	size_t nComputerCount = (bufLen - sizeof(NET_HEAD_MAN)) / sizeof(MANAGER_COMPUT_INFO);

	m_lpLocalServer->ComputerList.Clear();

	for (size_t i = 0; i < nComputerCount; i++)
	{
		CComputerInfo computer(*(pComputerInfo + i));

		std::map<CString, UINT>::const_iterator pos = m_PCClassMap.find(computer.GetTerminalID());
		
		if (pos != m_PCClassMap.end())
		{
			computer.SetPCClassID(pos->second);
		}

		CComputerInfo::ECOMPUTERSTATUS nStatus = computer.GetComputerStatus();
		if (nStatus!=CComputerInfo::ECS_ONLINE)
		{
			CActiveMember ActiveMember;
			if (m_lpLocalServer->ActiveMemberList.GetActiveMember(computer.GetTerminalID(),
				ActiveMember, TRUE))
			{
				computer.AttachActiveMember(ActiveMember);
			}
		}

		m_lpLocalServer->ComputerList.AddComputer(computer);
	}
	
	m_lpLocalServer->ComputerList.MakeComputerKeyMap();

	DecodeQuestionComputer();

	m_lpLocalServer->GetComputerListView()->Refresh(TRUE);
}
Exemplo n.º 18
0
void AbstractRPM::addView(View *view)
{
	bool alreadyExists = false;

	viewsLock.lock();
	if (views.find(view->sessionId()) == views.end())
		views[view->sessionId()] = view;
	else
		alreadyExists = true;
	viewsLock.unlock();

	if (alreadyExists)
		return;

	for (size_t i = 0; i < _computers.size(); i++) {
		Wt::WString computerName = _computers[i].name;

		if (!currentUserIsInAccessList(computerName, READ))
			continue;

		bool writeAccess = currentUserIsInAccessList(computerName, WRITE);

		std::shared_ptr<ComputerView> computer(new ComputerView(view, computerName, writeAccess));

		/* view --> backend */
		computer->sig_atxForceOff.connect(boost::bind(&AbstractRPM::atx_force_off, this, computerName));
		computer->sig_atxForceOn.connect(boost::bind(&AbstractRPM::atx_force_on, this, computerName));
		computer->sig_atxReset.connect(boost::bind(&AbstractRPM::atx_reset, this, computerName));
		computer->sig_pwSwitchPress.connect(boost::bind(&AbstractRPM::pw_switch_press, this, computerName));
		computer->sig_pwSwitchForceOff.connect(boost::bind(&AbstractRPM::pw_switch_force_off, this, computerName));

		/* send the current logs */
		Wt::WString logs = _computerLogs[computerName];
		server->post(view->sessionId(), boost::bind(&ComputerView::consoleDataAdded, computer.get(), logs));

		view->addComputer(computerName, computer);
	}
}
Exemplo n.º 19
0
Arquivo: main.c Projeto: xuusheng/code
int main(void)
{
  while(1)
    computer();
}
Exemplo n.º 20
0
void CCommandProcessor::OnClientUpdateData(BYTE *pBuffer, size_t bufLen)
{
	MANAGER_COMPUT_INFO ci = {0};
	GetBody(pBuffer, &ci, sizeof(ci));
	
	CComputerInfo computer(ci);
	
	//清除相同的用户信息,可能是之前换机的那台信息等
	INT_PTR nIndex = m_lpLocalServer->ComputerList.Find(computer.GetMemberID());

	if (nIndex >= 0)
	{
		CComputerInfo& computer2 = m_lpLocalServer->ComputerList.GetComputer(nIndex);
		computer2.ClearUserInfo();
		m_lpLocalServer->ComputerList.UpdateComputer(nIndex, computer2);	
	}

	//先清除后增加
	m_lpLocalServer->ComputerList.AddComputer(computer);
	m_lpLocalServer->GetComputerListView()->Refresh(FALSE);

	//更新ActiveMember

	BOOL bExists = FALSE;

	CActiveMember ActiveMember;

	if (m_lpLocalServer->ActiveMemberList.GetActiveMember(computer.GetMemberID(), ActiveMember))
	{
		bExists = TRUE;
	}

	ActiveMember.Attach(ci);
	ActiveMember.SetPCClassID(computer.GetPCClassID());
	ActiveMember.SetActive(TRUE);

	// 2011/10/27-8210-gxx: 
	if (bExists)
	{
		if (ActiveMember.GetRoomMemberId() == 0)
		{
			UINT nRoomMemberID = 0;
			CLocalServer::GetInstance()->ActiveMemberList.IsRoomArea(computer.GetPCClassID(), nRoomMemberID);
			if (nRoomMemberID > 0)
			{
				ActiveMember.SetRoomMemberId(nRoomMemberID);
				bExists = FALSE;
			}
		}
	}
	

	//不存在要更新数据库的预付款和备注等
	if (!bExists)
	{
		CIBALog::GetInstance()->WriteFormat(_T("%d is not exists in ActiveMemberList"), ActiveMember.GetMemberID());

		ActiveMember.SetActivationTime( ActiveMember.GetCheckInTime() );
		ActiveMember.SetAdvancePayment(ActiveMember.GetAvailavleBalance());
		ActiveMember.SetCreditProcess(ActiveMember.GetAvailavleBalanceAsString());
	}

	m_lpLocalServer->ActiveMemberList.UpdateActiveMember(ActiveMember, TRUE);//!bExists);
	m_lpLocalServer->GetActiveMemberView()->Refresh(FALSE);
}
Exemplo n.º 21
0
//main
int main(int argc, char* argv[])
{
    int fd, fd_mouse;
    struct fb_var_screeninfo fb_var;
    int bits;
    int player_flag = -1;
    int i, j ;

    //open fb0
    fd = open("/dev/fb0", O_RDWR);
    if(fd < 0)
    {
        printf("open fb0 error!\n");
        exit(0);
    }

    ioctl(fd, FBIOGET_VSCREENINFO, &fb_var);
    w = fb_var.xres;
    h = fb_var.yres;
    bits = fb_var.bits_per_pixel;
    printf("Framebuffer:%d * %d\n", w ,h);
    printf("Bits:%d\n", bits);
    fbmem = mmap(0, w*h*sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 		//use 32
//	fbmem = mmap(0, w*h*sizeof(short), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);		//use 16

    //draw background
    fb_bg(X - 30, Y - 30,  0xeedc82);
    fb_grid(X, Y,  0x000000);

    fb_small_black_point(7 * SPACE + X, 7 * SPACE + Y);
    fb_small_black_point(3 * SPACE + X, 3 * SPACE + Y);
    fb_small_black_point(11 * SPACE + X, 3 * SPACE + Y);
    fb_small_black_point(3 * SPACE + X, 11 * SPACE + Y);
    fb_small_black_point(11 * SPACE + X, 11 * SPACE + Y);

    fb_black_point(7 * SPACE + X, 7 * SPACE + Y);
    pos_flag[7][7] = 2;
    fb_num(chess_num++, 7 * SPACE + X, 7 * SPACE + Y, 0xffffff);

    //mouse
    fd_mouse = open_mouse();
    cx = w / 2;
    cy = h / 2;

    while(1)
    {
        move_mouse(&fd_mouse);
        player(&fd_mouse, &player_flag);

        if(player_flag == 0)
        {
            computer();						//computer
            player_flag = -1;
        }

    }

    close(fd_mouse);
    close(fd);

    return 0;
}
Exemplo n.º 22
0
void Game()
{
	SDL::Screen screen;
	SDL::GetVideoSurface(screen);
	SDL::Event events;
	SDL::Rect updaterects[6];
	SDL::Rect all(0, 0, 640, 480);
	SDL::Rect ballrect, play1rect, comrect;
	int ballvx, ballvy;
	bool playerwon = false;

	Score score;
	Ball ball(309, 229, 11, 11, ((rand() % 4) + 2), -((rand() % 4) + 2));
	Computer computer(629, 187, 11, 106);

	Paddle playerone(0, 187, 11, 106);
	HandleInput handleinput(playerone);

	while(!handleinput)
	{
		// Update everything
		ball.Update();
		playerone.Update();
		computer.UpdateAI(ball);

		// needed for game logic
		ballrect = ball.Get(ballvx, ballvy);
		play1rect = playerone.Get();
		comrect = computer.Get();

		// check if it hit the paddle for player and then the same for computer
		if((ballrect.x <= 11) &&
				(ballrect.y >= play1rect.y) &&
				((ballrect.y+11) <= play1rect.y + 106))
		{
			ball.SetVel(-ballvx, ballvy);
		}

		if(((ballrect.x + 11) >= 629) &&
				(ballrect.y >= comrect.y) &&
				((ballrect.y+11) <= comrect.y + 106))
		{
			ball.SetVel(-ballvx, ballvy);
		}

		// scoring if it goes past either paddle
		if(ballrect.x+10 < 11)
		{
			ball.Set(309, 229, 11, 11, ((rand() % 4) + 2), ((rand() % 4) + 2));
			score.m_Two++;
		}

		if(ballrect.x+10 > 629)
		{
			ball.Set(309, 229, 11, 11, -((rand() % 4) + 2), -((rand() % 4) + 2));
			score.m_One++;
		}

		// somene's won
		if(score.m_One > 9)
		{
			std::cout << "Congrats, you won." << std::endl;
			playerwon = true;
			break;
		}
		if(score.m_Two > 9)
		{
			std::cout << "Sorry, you lost, try again." << std::endl;
			break;
		}

		// drawing code
		screen.FillRect(all, 0);

		updaterects[0] = ball.Draw(screen);
		updaterects[1] = computer.Draw(screen);
		updaterects[2] = playerone.Draw(screen);
		score.Draw(screen, updaterects[3], updaterects[4]);

		// see if we're double buffering, if so, do a screen Flip
		if((screen.Get()->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
			screen.Flip();
		else
		{
			updaterects[5] = all;
			screen.UpdateRects(6, updaterects);
		}

		// Poll for new events, then wait a bit
		events.Poll(handleinput);
		Delay();
	}
}
Exemplo n.º 23
0
int plConvexHullNumFaces(plConvexHull hull)
{
	btConvexHullComputer *computer(reinterpret_cast< btConvexHullComputer* >(hull));
	return computer->faces.size();
}
void screen2()
{
	if(po==0 && sound==1)
	{
		PlaySound("GAMESOUND.WAV",NULL,SND_FILENAME|SND_ASYNC);po=1;
	}
			hurdle();
		
			snake_or_rat_tra(2);
			ck_if_ea_it();
			update_sna();
			eatable();
		check();
	
		if(hurdle_check(t[1][0],t[1][1]) && no_of_pl==1 )
		{
			
			
			glutPostRedisplay();
			if(sound==1)
			PlaySound("1.WAV",NULL,SND_FILENAME|SND_ASYNC);
			plife=plife-1;
			if(plife==0)
			{
			screen=3;
			screen3();
			}		
		}
		if(no_of_pl==2)
		{
		
		if(hurdle_check(t[1][0],t[1][1]))
		{
			
			
		//	glutPostRedisplay();
			if(sound==1)
			PlaySound("1.WAV",NULL,SND_FILENAME|SND_ASYNC);
			if(compu==0)
			{
				t[size][0]=0;t[size][1]=0;state[size]=0;
				size--;
			}
			vitoa(size,si);
			//		screen=3;
	//		screen3();
		}
			if(compu==1)
			computer();
		if(hurdle_check(t2[1][0],t2[1][1]))
		{
			
		

		//	glutPostRedisplay();
			if(sound==1)
			PlaySound("1.WAV",NULL,SND_FILENAME|SND_ASYNC);
				
			if(compu==0)
			{
				t2[size2][0]=0;t2[size2][1]=0;state2[size2]=0;
				size2--;
			}

			vitoa(size2,si2);			
		//		screen=3;
//			screen3();
		}

		if(size==0 || size2==0 || count==20 )
		{		screen=3;
				screen3();
		}

		}
		if(no_of_pl==1)
		{
		write("LIFE",850,20);
		if(plife==3)
		{
			for(i=0;i<3;i++)
				lifedraw(950+i*25,20);
		}
		else if(plife==2)
		{
			for(i=0;i<2;i++)
				lifedraw(950+i*25,20);
		}
		else if(plife==1)
		{
			for(i=0;i<1;i++)
				lifedraw(950+i*25,20);
		}
		}
}
Exemplo n.º 25
0
void cover()
{
 s=18;sp=6;
 w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2
 w1=wi=s/4;
 wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3
 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4
 h=s;//1

///////////////////

 xnxt=-52;ynxt=370;
 computer();
 xnxt+=s/2;
 graphics();

 xnxt=0;ynxt-=2*s-4;
 mini();
 xnxt+=s/2;
 project();

 /////////////////

 s=28;sp=8;
 w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2
 w1=wi=s/4;
 wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3
 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4
 h=s;//1

///////////////////
 glPointSize(3.0);
 xnxt=-100;ynxt-=2*s;
 balloon1();
 xnxt+=s/2;
 shooting();

////////////////

 s=16;sp=4;
 w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2
 w1=wi=s/4;
 wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3
 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4
 h=s;//1

//////////////
 glPointSize(2.0);
 xnxt=320;ynxt-=4*s;
 glPointSize(1.5);
 by();

////////////////

 s=16;sp=6;
 w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2
 w1=wi=s/4;
 wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3
 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4
 h=s;//1

 xnxt=170;ynxt-=3*s;
 arahant();

 xnxt=160;ynxt-=2*s;
 ashrith();

 xnxt=170;ynxt-=2*s;
 dhanush();

 xnxt=138;ynxt-=2*s;
 harsha();
 
 xnxt=184;ynxt-=2*s;
 shreeman();
///////////////////////////
 
 xnxt=-190;ynxt=124;
 guidance();

 xnxt=-190;ynxt-=3*s;
 sir();

 xnxt=-190;ynxt-=2*s;
 madam();
}