示例#1
0
文件: ttt.cpp 项目: J4Y1450/TicTacToe
ttt::ttt(){
	game = true;
	initializeGrid();
	printGrid();
	while(game){
		playerTurn(false);
		printGrid();
		gameCheck(false);
		if(game){
			playerTurn(true);
			printGrid();
			gameCheck(true);
		}
	}
	
}
示例#2
0
void main() {

    int numEn;
    printf("How many enemies?: ");
    scanf("%d", &numEn);
    printf("\n");
    //Initialize enemy types
    Enemies = malloc(sizeof(int)*numEn);
    int k;
    for (k = 0; k < numEn; k++) {
        Enemies[k] = 100;
    }
    //Initialize player
    //{0 Str; 1 Per; 2 Fort; 3 Cha; 4 Int; 5 Dex; 6 Luk;
    //7 primary miss; 8 primary dam; 9 primary in mag;
    //10 primary mag size; 11 primary mags; 12 Health; 13 Hunkered}
    char* input = malloc(sizeof(char)*10);
    int* playerStats = malloc(sizeof(int)*13);
    printf("Enter player stats:\nStrength: ");
    scanf("%d", &playerStats[0]);
    printf("\nPerception: ");
    scanf("%d", &playerStats[1]);
    printf("\nFortitude: ");
    scanf("%d", &playerStats[2]);
    printf("\nCharisma: ");
    scanf("%d", &playerStats[3]);
    printf("\nIntelligence: ");
    scanf("%d", &playerStats[4]);
    printf("\nDexterity: ");
    scanf("%d", &playerStats[5]);
    printf("\nLuck: ");
    scanf("%d", &playerStats[6]);

    printf("\nMiss Chance of Primary: ");
    scanf("%d", &playerStats[7]);
    printf("\nPrimary Damage: ");
    scanf("%d", &playerStats[8]);
    printf("\nRounds in Magazine: ");
    scanf("%d", &playerStats[9]);
    printf("\nSize of Magazine: ");
    scanf("%d", &playerStats[10]);
    printf("\nNumber of Magazines: ");
    scanf("%d", &playerStats[11]);
    playerStats[12] = (playerStats[2] *10 +50);
    playerStats[13] = 0;
    //roll initiative
    //Take first turn
    while (playerStats[12] > 0) {
        playerTurn(numEn, playerStats);
        int u;
        for (u = 0; u < numEn; u++) {
            if ()
            enemyTurn(u);
        }
    }
}
示例#3
0
gboolean
button_press_event_handler(GtkWidget *widget, GdkEventButton *event,
        gpointer data) {
    cairo_t *pointCr = gdk_cairo_create(widget->window),
            *lineCr = gdk_cairo_create(widget->window),
            *player1BoxCr = gdk_cairo_create(widget->window),
            *player2BoxCr = gdk_cairo_create(widget->window);

    cairo_set_source_rgba_from_string(pointCr, POINT_COLOR, 1);
    cairo_set_source_rgba_from_string(lineCr, LINE_COLOR, 1);
    cairo_set_source_rgba_from_string(player1BoxCr, PLAYER_1_BOX_COLOR, 1);
    cairo_set_source_rgba_from_string(player2BoxCr, PLAYER_2_BOX_COLOR, 1);

    cairo_set_line_width(lineCr, pointRadius * 1.4);

    gint x = (gint) event->x, y = (gint) event->y;

    if (isClickInsideFrame(x, y)) {

        timer = true;
        fadingLineAlpha = -1;
        gtk_widget_queue_draw(event_box);
        timer = false;
        fadingLineAlpha = 1;

        buttonPressCount %= 2;
        TurnResult result;
        if (!buttonPressCount) {
            result = playerTurn(lineCr, player1BoxCr, pointCr, head, x,
                    y, lineLength, pointRadius, &BoxOfPlayer1, firstPlayerBox);
            if (result == lineDrawn) {
                gtk_statusbar_pop(GTK_STATUSBAR(data), status_context_id);
                if (opponent == HUMAN)
                    buttonPressCount++;
                else {
                    g_signal_handler_block(event_box, button_press_handler_id);
                    computerPoints = computerTurn(head, lineCr, player2BoxCr,
                            pointCr, lineLength, pointRadius, &BoxOfPlayer2,
                            secondPlayerBox, &event_box, difficulty);
                    g_signal_handler_unblock(event_box, button_press_handler_id);
                    if (!computerPoints) {
                        gtk_statusbar_push(GTK_STATUSBAR(data), status_context_id,
                                "Game Over");
                        timer = false;
                        result_message(player1Name, player2Name, BoxOfPlayer1, BoxOfPlayer2);
                    } else {
                        gtk_statusbar_push(GTK_STATUSBAR(data), status_context_id,
                                player1Name);
                        if ((*computerPoints)->x == (*(computerPoints + 1))->x)
                            (*computerPoints)->verticalDown =
                                (*(computerPoints + 1))->verticalUp = true;
                        else
                            (*computerPoints)->horizontalRight =
                                (*(computerPoints + 1))->horizontalLeft = true;
                        timer = true;
                        g_timeout_add(fadeTimeInterval, (GSourceFunc) fade_out_handler, NULL);
                    }
                }
            }
            if (result == frameIsFull) {
                gtk_statusbar_push(GTK_STATUSBAR(data), status_context_id,
                        "Game Over");
                result_message(player1Name, player2Name, BoxOfPlayer1, BoxOfPlayer2);
            }
        } else {
            result = playerTurn(lineCr, player2BoxCr, pointCr, head, x,
                    y, lineLength, pointRadius, &BoxOfPlayer2, secondPlayerBox);
            if (result == lineDrawn) {
                buttonPressCount++;
                gtk_statusbar_push(GTK_STATUSBAR(data), status_context_id,
                        player1Name);
            }
            if (result == frameIsFull) {
                gtk_statusbar_push(GTK_STATUSBAR(data), status_context_id,
                        "Game Over");
                result_message(player1Name, player2Name, BoxOfPlayer1, BoxOfPlayer2);
            }
        }
    }

    cairo_destroy(pointCr);
    cairo_destroy(lineCr);
    cairo_destroy(player1BoxCr);
    cairo_destroy(player2BoxCr);

    return TRUE;
}
示例#4
0
int main()
{
	//prototypes for main
    void printTitle(), setGridSize(), clearGrid(int grid[column_size][row_size]), playerTurn(int player, int grid[column_size][row_size]);
    int checkWinner(int grid[column_size][row_size]), continueGame();
	
	//variable initilisation.
	int player, winner;

    printTitle();
		
		do
    	{
			//construction of new game
            player = 1; //resets player
			winner = 0; // resets winner
    		setGridSize();
    		int grid[column_size][row_size]; // constructs grid
            clearGrid(grid); // sets all grid values to 0
    		clearScreen();

			//game plays out inside until winner or draw.
    		while(winner == 0)
    		{

    			playerTurn(player, grid);
    			winner = checkWinner(grid);
    			if(winner == 0) 
				{
					//switches player
    				if(player == 1)
					{
    					player = 2;
					}
    				else
					{
    					player = 1;
					}
				}
    			else
    			{
						//clears screen and prints grid between turns.
    		        	clearScreen();
                        printGrid(grid);
                        spacer(); //spacer called repeatedly to move print to center of console
    					printf("\n\n");
    					spacer();
						
    				if(winner != 3) //checks if winner was a player or a draw. A winner of '3' is a draw
					{
                        printf("Winner is Player %d!!!", winner);
					}
                    else
					{
                        printf("Draw!!!");
					}
                }
    		}
		//starts a new game if true
    	}while(continueGame());

		return(0);
}