Example #1
0
int main(){
	setlocale(LC_ALL, "ptb");//Set pt-br locale
	initscr();//Initialize cursor mode
	start_color();//Initialize color mode
	getmaxyx(stdscr,row,col);//Get screen dimensions
	attron(A_BOLD);

	//Configure color pairs
	init_pair(1, COLOR_WHITE, COLOR_BLACK);//Our default
	init_pair(2, COLOR_BLUE, COLOR_BLACK);//For Player 1
	init_pair(3, COLOR_RED, COLOR_BLACK);//For Player 2
	//Set default color pair
	wbkgd(stdscr, COLOR_PAIR(1));
	//Refresh screen to apply
	refresh();

	//Splash screen
	splashScreen();

	//wclear(stdscr);

	//Ready!

	char playAgain = 's';//Answer to the play again question on the end
	//Restart the game while play again answer is positive
	while(playAgain == 's'){
		initializeGameTable();//Initialize game table
		showHeader();//Show header with only title
		requestPlayerNames();//Request players for typing their names
		showHeader();//Show header with the title and players names
		refreshGame();//Show the game table
		//Print a divisor line after a blank line
		printw("\n");
		for(short int i = 0; i < col; i++){
			printw("-");
		}

		/* Here is the game, we'll request a match and refresh the game table while the game is not won or tied (tied is defined by number of matches) */
		//Matches counter
		int matchesCounter = 1;
		//Disable cursor
		curs_set(0);
		//While the game is not won and matches counter is under/equal 9
		while(checkWin() == 0 && matchesCounter <= 9){
			//Request match
			requestMatch();
			//Refresh the game table
			refreshGame();
			//Increase matches counter
			matchesCounter++;
		}

		//Clear line 13
		move(13,0);
		clrtoeol();
		//Check who won, or if the game tied
		if(checkWin() == 1){
			//Player 1 won
			//Increase score
			player1Score++;
			//Show congratulations on player color
			attron(COLOR_PAIR(2));
			mvprintw(13, 0, "Parabéns %s, você ganhou!\n", player1);
			attron(COLOR_PAIR(1));
		}
		if(checkWin() == 2){
			if(!strcmp(player2, "")){
				//PC won
				//Increase score
				player2Score++;
				//Show congratulations on player color
				attron(COLOR_PAIR(3));
				mvprintw(13, 0, "O PC ganhou!\n", player2);
				attron(COLOR_PAIR(1));
			}else{
				//Player2 won
				//Increase score
				player2Score++;
				//Show congratulations on player color
				attron(COLOR_PAIR(3));
				mvprintw(13, 0, "Parabéns %s, você ganhou!\n", player2);
				attron(COLOR_PAIR(1));
			}
		}
		if(checkWin() == 0){
			//Game tied
			mvprintw(13, 0, "Deu velha! O jogo terminou em empate.\n");
		}

		//Refresh scores
		refreshScores();

		//Reset play again var
		playAgain = ' ';
		//Enable cursor
		curs_set(1);
		//Validate play again answer
		while(!(playAgain == 's' | playAgain == 'n')){
			//Clear line 15, removing possible wrong answers from screen
			move(15, 0);
			clrtoeol();
			//Ask user
			printw("Desejam jogar novamente?[s/n] ");
			playAgain = getch();
		}
	}

	
	//Disable cursor
	curs_set(0);
	//Clear screen and show the header
	showHeader();
	//Print the thanks on center
	mvprintw(6, (col-strlen("Obrigado por jogar!"))/2,"Obrigado por jogar!\n");
	//Delay
	refresh(); delay(600);
	//Print the credits
	mvprintw(9, 0, "Desenvolvido por:\n");
	printw("Renan Galeno <*****@*****.**>\n");
	printw("Marcos Antuanny <*****@*****.**>\n");
	printw("Victor Patrick <*****@*****.**>\n");
	printw("\n");
	//Delay
	refresh(); delay(600);
	printw("Este trabalho está licenciado sob uma Licença Creative Commons Atribuição-CompartilhaIgual 4.0 Internacional.\nPara ver uma cópia desta licença, visite http://creativecommons.org/licenses/by-sa/4.0/.\n\n");
	//Delay
	refresh(); delay(1000);
	//Print the press anything to exit message
	printw("Pressione qualquer tecla para sair.");
	getch();


	//End curses mode
	endwin();

	//Return 0, as the program had no errors
	return(0);
}
Example #2
0
	void GameListScreen::load() {
		network::Packet packet(network::Network::getSocket(), network::PacketType::SESSION_ASKGAME);
		packet.send();
		game::GameList::clear();

		m_buttonContainer = new Container();
		m_buttonContainer->setBackground("ressources/gui/background_characterFrame.png", full);
		this->add(m_buttonContainer);

		m_buttonUpContainer = new Container();
		m_buttonUpContainer->setLayout(new VerticalFixedLayout(VerticalFixedLayout::fixed, VerticalFixedLayout::fixed));
		m_buttonContainer->add(m_buttonUpContainer);

		m_buttonDownContainer = new Container();
		m_buttonDownContainer->setLayout(new VerticalFixedLayout(VerticalFixedLayout::full, VerticalFixedLayout::fixed));
		m_buttonContainer->add(m_buttonDownContainer);

		m_buttonContainer->setLayout(new SplitFixedLayout(SplitFixedLayout::horizontal, SplitFixedLayout::second, 60));

		m_mainContainer = new Container();
		m_mainContainer->setBackgroundColor(sf::Color(30, 30, 30));
		this->add(m_mainContainer);

		this->setLayout(new SplitFixedLayout(SplitFixedLayout::vertical, SplitFixedLayout::first, 250));

		m_matchmakingButton = new Button("Matchmaking", GUIStyle::button());
		m_matchmakingButton->setSize(200, 50);
		m_matchmakingButton->addListener(new GameListScreen_MainButton(this));
		m_buttonUpContainer->add(m_matchmakingButton);

		m_joinButton = new Button("Join Game", GUIStyle::button());
		m_joinButton->setSize(200, 50);
		m_joinButton->addListener(new GameListScreen_MainButton(this));
		m_joinButton->setEnable(false);
		m_buttonUpContainer->add(m_joinButton);

		m_createButton = new Button("Create Game", GUIStyle::button());
		m_createButton->setSize(200, 50);
		m_createButton->addListener(new GameListScreen_MainButton(this));
		m_buttonUpContainer->add(m_createButton);

		m_returnButton = new Button("Return", GUIStyle::button());
		m_returnButton->setSize(200, 50);
		m_returnButton->addListener(new GameListScreen_MainButton(this));
		m_buttonDownContainer->add(m_returnButton);

		std::vector<std::string> columns;
		columns.push_back("Name");
		columns.push_back("Creator");
		columns.push_back("Players");
		m_table = new Table(columns, GUIStyle::table());
		m_mainContainer->add(m_table);
		m_table->addListener(new GameListScreen_Table(this));
		m_table->setColumnsWidth(2, 100);

		m_tableStyle = new BasicStyle();
		m_tableStyle->setFontColor(sf::Color::White);

		refreshGame();

	}