Пример #1
0
int main(int argc, char *argv[]) {
	int ret;
	void *p;
	
	/* this is the connection we will make... again, you don't have access to the struct */
	struct xbee_con *conA;
	struct xbee_con *conB;
	
	/* the packet that is recieved... you have access to this! (see xbee.h) */
	struct xbee_pkt *pkt;
	
	/* set the log level REALLY high, so we can see all the messages. default is 0 */
	//xbee_logSetLevel(100);

	/* setup the xbee instances! */
	if (setupXbee(&xbeeA, "/dev/ttyUSB0", &conA, 0x0013A200, 0x402D607E)) exit(1);
	if (setupXbee(&xbeeB, "/dev/ttyUSB1", &conB, 0x0013A200, 0x402D607B)) exit(2);

	usleep(25000);

	/* start the chain reaction! */
	xbee_conTx(xbeeA, conA, "Hello!");

	/* the main loop */
	for (;;) {
		sleep(5);
	}
	
	/* shutdown the libxbee instance */
	xbee_shutdown(xbeeA);
	xbee_shutdown(xbeeB);
	
	return 0;
}
Пример #2
0
void multiPlayer(GlobalState* globalData) {
    int connect = 0;
    int hostOrFind = 0; // 0 host game, 1 find game
    char* mySelections[2] = {"Host Game", "Find Game"};
    setupXbee();
    printMenu(mySelections, BLACK, GRAY, WHITE, YELLOW, 2);
    prints(25, 7, YELLOW, GRAY, "Multiplayer", 1);
    processPrintCursor(globalData, 2, BLACK, YELLOW);
    switch (hostOrFind) {
        case 0:
            prints(3, 48, YELLOW, GRAY, "Waiting for players...", 1);
            hostGame();
            break;
        case 1:
            prints(3, 88, YELLOW, GRAY, "Looking for games...", 1);
            findGame();
            break;
        case 0xFF:
            return;
            break;
    }



    setupGame();

    //    // Find other players
    //    while (!connect) {
    //        connect = findPlayer();
    //    }
    //
    //    // NOTE: Need to build something to determine who goes first
    //    // Compare Xbee ID's perhaps?
    //
    //    // Begin game
    //    while (!game.gameOver && connect) {
    //        if (game.turn) {
    //            // Pick Move
    //            game.myMove = pickMove(globalData);
    //            // Send Move
    //            sendMove();
    //            // Receive new score after opponent takes damage
    //            game.oppScore = receiveScore();
    //            printGame(globalData);
    //            prints(0, 10, RED, BLACK, "                    ", 1);
    //            prints(0, 10, RED, BLACK, "Opponent took damage:", 1);
    //            prints(0, 21, RED, BLACK, "-", 1);
    //            integerprint(6, 21, RED, BLACK, game.myMove, 1);
    //        } else {
    //            // Receive player move and take damage
    //            game.myScore = attack(receiveMove(), game.myScore);
    //            prints(0, 10, RED, BLACK, "                    ", 1);
    //            prints(0, 10, RED, BLACK, "Taken damage:", 1);
    //            prints(0, 21, RED, BLACK, "-", 1);
    //            integerprint(6, 21, RED, BLACK, game.oppMove, 1);
    //            // Send new score
    //            sendScore();
    //        }
    //        prints(0, 45, YELLOW, BLACK, "        ", 1);
    //        integerprint(0, 45, YELLOW, BLACK, game.myScore, 1);
    //        prints(0, 75, WHITE, BLACK, "        ", 1);
    //        integerprint(0, 75, WHITE, BLACK, game.oppScore, 1);
    //        // Check game status
    //        game.gameOver = gameStatus();
    //        game.turn =!game.turn;
    //    }
    //    if (!connect) {
    //        printBSOD();
    //    } else {
    //        printResults();
    //    }
}