Exemplo n.º 1
0
 void multiPlayer() {
        int myMove;
        int oppMove = 0;
	int connect = 0;
	
	// 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
			myMove = pickMove();
			// Send Move
				sendMove(myMove);
			// Receive new score after opponent takes damage
				game.oppScore = recieveScore();
		} else {				
			// Receive player move and take damage
			game.myScore = attack(recieveMove(), game.myScore);
			// Send new score
			sendScore(game.myScore);
		}		
		// Check game status
		game.gameOver = gameStatus();
		!game.turn;
	}
	if (!connect) {
		printBSOD();
	} else {
		printResults();
	}
}
Exemplo n.º 2
0
void singlePlayer(gameData game) {
	// Setup new game
	setup();
	game.turn = rand() % 2;
	
	// Begin game with computer
	while(!game.gameOver) {
		// Situation depends on game.turn
		if(game.turn) {
			game.myMove = pickMove(globalData);
			game.oppScore = attack(game.myMove, game.oppScore);
		} else {
			// Computer randomly picks an attack with damage b/w 0 and 50
			game.oppMove = rand() % 50 + 1;
			game.myScore = attack(game.oppMove, game.myScore);
		}
		// Check game status
		game.gameOver = gameStatus();
		!game.turn;
	}
	// Display results once there is a lost
	printResults();
}
Exemplo n.º 3
0
void singlePlayer(GlobalState* globalData) {
    static int tempScore = 0;
    static int transition = 0;
    static int movedone = 0;
    // First time playing?
    // Read first time from SRAM
    if (globalData->firstTime == TRUE) {
        if (globalData->newKeyboard) {
            printKeyboard(globalData, "NAME?", 5);
        } else {
            processKeyboard(globalData, game.name, 5);
        }
    }
    if (globalData->doneKeyboard) {
        globalData->firstTime = FALSE;


        if (globalData->newGame) {
            globalData->newGame = 0;
            // Setup new game
            setupGame();
            tempScore = 0;
            transition = 0;
            game.turn = rand() % 2;
            printGame(globalData);
            getCards(); // Assume cards already read by interrupts on switches (?)
        }


        // Wait till someone presses D to continue
        if (globalData->keyPress == 0x0D) {
            transition = 1;
        }

        // Begin game with computer
        if (transition) {
            if (!game.gameOver) {
                // Situation depends on game.turn
                if (game.turn) {
                    if (game.moveSel == 0) {
                        pickMove(globalData);
                    }
                    if (game.moveSel == 1) {

                        tempScore = game.oppScore;
                        game.oppScore = attack(game.myMove, game.myMonster, game.oppScore);
                        if (game.oppScore == tempScore) {
                            prints(0, 10, RED, BLACK, "                    ", 1);
                            prints(0, 18, RED, BLACK, "                    ", 1);
                            prints(0, 26, RED, BLACK, "                    ", 1);
                            prints(0, 10, RED, BLACK, "Missed!", 1);
                        } else {
                            prints(0, 10, RED, BLACK, "                    ", 1);
                            prints(0, 18, RED, BLACK, "                    ", 1);
                            prints(0, 26, RED, BLACK, "                    ", 1);
                            prints(0, 10, RED, BLACK, "Your", 1);
                            printrs(30, 10, RED, BLACK, game.myMonster->monsterName, 1);
                            prints(84, 10, RED, BLACK, "used", 1);
                            printrs(0, 18, RED, BLACK, game.myMove->moveName, 1);
                            prints(0, 26, RED, BLACK, "-    ", 1);
                            integerprint(6, 26, RED, BLACK, tempScore - game.oppScore, 1);
                        }
                        game.moveSel = 0;
                        movedone = 1;
                    }
                } else {
                    // Computer randomly picks a monster and attack
                    game.oppMonster = &myMonsterList[rand() % 3 ];
                    game.oppMove = &game.oppMonster->movelist[rand() % 3];
                    tempScore = game.myScore;
                    game.myScore = attack(game.oppMove, game.oppMonster, game.myScore);
                    if (game.myScore == tempScore) {
                        prints(0, 10, RED, BLACK, "                    ", 1);
                        prints(0, 18, RED, BLACK, "                    ", 1);
                        prints(0, 26, RED, BLACK, "                    ", 1);
                        prints(0, 10, RED, BLACK, "Enmy Missed!", 1);
                    } else {
                        prints(0, 10, RED, BLACK, "                    ", 1);
                        prints(0, 18, RED, BLACK, "                    ", 1);
                        prints(0, 26, RED, BLACK, "                    ", 1);
                        prints(0, 10, RED, BLACK, "Enmy", 1);
                        printrs(30, 10, RED, BLACK, game.oppMonster->monsterName, 1);
                        prints(84, 10, RED, BLACK, "used", 1);
                        printrs(0, 18, RED, BLACK, game.oppMove->moveName, 1);
                        prints(0, 26, RED, BLACK, "-    ", 1);
                        integerprint(6, 26, RED, BLACK, tempScore - game.myScore, 1);
                    }
                    movedone = 1;
                }

                if (movedone == 1) {
                    prints(0, 40, YELLOW, BLACK, "Your Score: ", 1);
                    prints(0, 55, YELLOW, BLACK, "     ", 1);
                    integerprint(0, 55, YELLOW, BLACK, game.myScore, 1);
                    prints(0, 70, WHITE, BLACK, "Opponent Score: ", 1);
                    prints(0, 85, WHITE, BLACK, "     ", 1);
                    integerprint(0, 85, WHITE, BLACK, game.oppScore, 1);
                    // Check game status
                    game.gameOver = gameStatus();
                    game.turn = !game.turn;
                    transition = 0;
                    movedone = 0;
                }
                //                if (game.gameOver == 1) {
                //                    if (globalData->newGame == 0) {
                //                        printResults();
                //                    }
                //                }
            } else {
                if (globalData->newGame == 0) {
                    printResults();
                }
            }
        }
        // Display results once there is a lost
    }
}
Exemplo n.º 4
0
vector<StringGameStatePtr>& TicTacToe::getPossibleMoves(GameStatePtr state)
{
	static vector<StringGameStatePtr> posMoves;
// 	for(int i = 0; i < posMoves.size(); i++) {
// 		delete posMoves[i];
// 		posMoves[i] = NULL;
// 	}
	posMoves.clear();
	posMoves.reserve(100);
	/*
	if(gameStatus(state)==Game::status::ONGOING)
	{
		string& str = state->toString();
		char activePlayer = str.back();
		//char activePlayer = state.toString().charAt(state.toString().length() - 1);
		for(int i = 0; i < str.length() - 1; i++)
		{
			if(str.at(i) == '_')
			{
				string temp = str.substr(0,i);
				temp += activePlayer;
				temp += str.substr(i+1, str.length() - i);
				if(activePlayer == 'X')
				{
					temp += 'O';
				}
				else
				{
					temp += 'X';
				}
				posMoves.push_back(new StringGameState(temp));
			}
		}
		//cout<<"possible moves: "<<posMoves.size()<<endl;
	}
	*/
	if(gameStatus(state)==Game::status::ONGOING)
	{
		char activePlayer = state->toString().at(state->toString().length()-1);
		//char activePlayer = state.toString().charAt(state.toString().length() - 1);
		for(int i = 0; i < state -> toString().length() - 1; i++)
		{
			if(state->toString().at(i) == '_')
			{
				string temp = state->toString().substr(0,i);
				temp += activePlayer;
				temp += state->toString().substr(i+1, state->toString().length() - (i+1)-1);
				if(activePlayer == 'X')
				{
					temp += 'O';
				}
				else
				{
					temp += 'X';
				}
				posMoves.push_back(StringGameStatePtr(new StringGameState(temp)));
			}
		}
		//cout<<"possible moves: "<<posMoves.size()<<endl;
	}

	return posMoves;
}