Exemplo n.º 1
0
char* CNWNXNames::OnRequest(char* gameObject, char* Request, char* Parameters)
{
    Log(2, "Request: \"%s\"\n", Request);
    Log(2, "Params:  \"%s\"\n", Parameters);
    this->pGameObject = gameObject;
    this->nGameObjectID = *(dword *)(gameObject + 0x4);
    if (strncmp(Request, "INITPLAYERNAMELIST", 18) == 0) {
        InitPlayerList(Parameters);
        return NULL;
    } else if (strncmp(Request, "GETDYNAMICNAME", 14) == 0) {
        return GetDynamicName(Parameters);
    } else if (strncmp(Request, "SETDYNAMICNAME", 14) == 0) {
        SetDynamicName(Parameters);
        return NULL;
    } else if (strncmp(Request, "UPDATEDYNAMICNAME", 17) == 0) {
        UpdateDynamicName(Parameters);
        return NULL;
    } else if (strncmp(Request, "UPDATEPLAYERLIST", 16) == 0) {
        UpdatePlayerList(Parameters);
        return NULL;
    } else if (strncmp(Request, "DELETEDYNAMICNAME", 17) == 0) {
        DeleteDynamicName(Parameters);
        return NULL;
    } else if (strncmp(Request, "CLEARPLAYERNAMELIST", 19) == 0) {
        ClearPlayerList(Parameters);
        return NULL;
    } else if (strncmp(Request, "SETNAMESENABLED", 15) == 0) {
        EnableDisableNames(Parameters);
        return NULL;
    }
    return NULL;
}
Exemplo n.º 2
0
int main(int argc, char * argv) {
	if (argc > 1) {
		printf("\n\tTicTacToe by scruff3y, 2016.\n\n");
		printf("How to play:\n");
		printf("The rules are the same as regular tic-tac-toe, fill a row, column or diagonal\n");
		printf("with your tile, and you win!\n\n");
		printf("To make a move, enter the row and column number of the tile you'd like to play on.\n\n");
		printf("If you really want to get a party going, try playing on a size 10 board\n");
		printf("with 10 players!\n\n");
		printf("Or, for the masochists, play a game against the computer. Hint: you will lose.\n");
		printf("(This is only availiable on a board size of 2 or 3\n");
		exit(0);
	}

	// This is just used to clear stdin between inputs.
	int c;

	// Welcome.
	printf("\n\tWelcome to TicTacToe!\n\n");
	printf("What size game would you like to play?: ");
	scanf("%i", &NUMBER_OF_GAME_SQUARES);

	while ((NUMBER_OF_GAME_SQUARES < 2) || (NUMBER_OF_GAME_SQUARES > 10)) {
		while ((c = getc(stdin)) != '\n');

		printf("Sorry, the game size must be between 2 and 10 squares.\n");
		printf("Please enter another value: ");
		scanf("%i", &NUMBER_OF_GAME_SQUARES);
	}

	while ((c = getc(stdin)) != '\n');

	// Init game board.
	GameBoard game = {0};

	char numberOfPlayers = 0;
	printf("How many players?: ");
	scanf("%i", &numberOfPlayers);

	while ((numberOfPlayers < 2) || (numberOfPlayers > 26)) {
		while ((c = getc(stdin)) != '\n');

		printf("Please specify a number between 2 and 26: ");
		scanf("%i", &numberOfPlayers);
	}

	// init playerlist.
	PlayerList playerList = InitPlayerList(numberOfPlayers);

	if ((numberOfPlayers == 2) && (NUMBER_OF_GAME_SQUARES <= 3)) {
		while ((c = getc(stdin)) != '\n');
		printf("Human or computer opponent (Y/N)?: ");
		char input;
		scanf("%c", &input);

		while ((input != 'Y') && (input != 'N') && (input != 'y') && (input != 'n')) {
			while ((c = getc(stdin)) != '\n');

			printf("Please try again: ");
			scanf("%c", &input);
		}

		if ((input == 'Y') || (input == 'y')) playerList.players[0].human = FALSE;
	}

	/*
	Main game loop:

	1. Check if game is over.
	2. If it isn't, do the next turn (data on whos turn it is stored in PlayerList)
	3. Otherwise, exit.
	*/
	while (TRUE) {
		printBoard(game);
		int gamestate = IsWon(game);
		if (gamestate != TRUE) {
			gameEnd(gamestate);
			exit(0);
		}
		else {
			nextTurn(&game, &playerList);
		}
	}
	return 0;
}