void BoardWindow::revokeMoves() { while (!moves.empty()) moves.removeLast(); updateLabel(); resetBoard(); loadBoard(); }
void getBoard(Cell board[BOARD_HEIGHT][BOARD_WIDTH],char * token){ if(strcmp(token,"1") == 0) { loadBoard(board, BOARD_1); displayBoard(board,NULL); } else if(strcmp(token,"2") == 0) { loadBoard(board, BOARD_2); displayBoard(board,NULL); } else { printf("ERROR : INVALID INPUT.\n\n"); printf("Please enter a correct command.\n"); } }
void BoardTheme::setEnabled(bool enabled) { if(enabled) { AppSettings->beginGroup("/Board/"); setColor(BoardTheme::LightSquare, AppSettings->getValue("lightColor").value<QColor>()); setColor(BoardTheme::DarkSquare, AppSettings->getValue("darkColor").value<QColor>()); QString boardTheme = AppSettings->getValue("boardTheme").toString(); AppSettings->endGroup(); loadBoard(boardTheme); } else { setColor(BoardTheme::LightSquare, QColor(Qt::lightGray)); setColor(BoardTheme::DarkSquare, QColor(Qt::darkGray)); loadBoard(QString()); } }
void BoardWindow::parseResponse() { QString data = Socket::readData(); QJsonDocument d = QJsonDocument::fromJson(data.toUtf8()); QJsonObject json = d.object(); if (json.contains("request")) { std::string request_type = json["request"].toString().toStdString(); if (request_type == "message") { QDateTime timestamp; timestamp.setTime_t(json["timestamp"].toString().toInt()); ui->chatTextEdit->append("[" + timestamp.toString("hh:mm") + "] " + json["nick"].toString() + ": " + json["message"].toString()); } else if (request_type == "board") { waiting = false; resetBoard(); time = json["time"].toString(); ui->turnsLabel->setText("Turn: " + json["current color"].toString()); yourTurn = json["current color"].toString() == color ? true : false; // ui->chatTextEdit->append("Loading board"); for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) board[i][j] = json["board"].toArray()[i].toArray()[j].toString()[0].toLatin1(); loadBoard(); } else if (request_type == "game_over") { ui->chatTextEdit->append("GAME OVER!"); if (json["winner"] == color) { ui->chatTextEdit->append("Congratulatons, you won!"); } else { ui->chatTextEdit->append("Unfortunately, you lost. Maybe next time?"); } } } else if (json.contains("status")) { auto status = json["status"].toString(); if (status != "ok") { if (status == "wrong move") { waiting = false; revokeMoves(); } ui->chatTextEdit->append("Error: " + status); } } }
void Editor::topToolbarOption(int option) { switch(option) { case ID_TOOL_NEW: newBoard(); break; case ID_TOOL_LOAD: loadBoard(); break; case ID_TOOL_SAVE: saveBoard(); break; case ID_TOOL_LEFT: theBoard.shiftLeft(); repaint(false); break; case ID_TOOL_RIGHT: theBoard.shiftRight(); repaint(false); break; case ID_TOOL_UP: theBoard.shiftUp(); repaint(false); break; case ID_TOOL_DOWN: theBoard.shiftDown(); repaint(false); break; case ID_TOOL_DEL: mode=remove; break; case ID_TOOL_MOVE: mode=move; break; case ID_TOOL_ADD: mode = insert; break; case ID_META_EXIT: close(); break; default: break; } }
/* * Initializes the Boggle object */ Boggle::Boggle(Lexicon& dictionary, string boardTextIn) { this->dictionary = dictionary; //Initialize Variables humanScore = 0; computerScore = 0; usedWords = {}; board.resize(DIMENSIONS, DIMENSIONS); boardText = boardTextIn; if (boardText == "") { randGenBoard(board, boardText); } else { loadBoard(boardText, board); } }
void BoardTheme::configure() { AppSettings->beginGroup("/Board/"); setColor(BoardTheme::LightSquare, AppSettings->getValue("lightColor").value<QColor>()); setColor(BoardTheme::DarkSquare, AppSettings->getValue("darkColor").value<QColor>()); setColor(BoardTheme::Highlight, AppSettings->getValue("highlightColor").value<QColor>()); setColor(BoardTheme::Frame, AppSettings->getValue("frameColor").value<QColor>()); setColor(BoardTheme::CurrentMove, AppSettings->getValue("currentMoveColor").value<QColor>()); setColor(BoardTheme::StoredMove, AppSettings->getValue("storedMoveColor").value<QColor>()); setColor(BoardTheme::Threat, AppSettings->getValue("threatColor").value<QColor>()); setColor(BoardTheme::Target, AppSettings->getValue("targetColor").value<QColor>()); setColor(BoardTheme::Check, AppSettings->getValue("checkColor").value<QColor>()); setColor(BoardTheme::Wall, AppSettings->getValue("wallColor").value<QColor>()); setColor(BoardTheme::UnderProtected, AppSettings->getValue("underprotectedColor").value<QColor>()); QString pieceTheme = AppSettings->getValue("pieceTheme").toString(); int pieceEffect = AppSettings->getValue("pieceEffect").toInt(); QString boardTheme = AppSettings->getValue("boardTheme").toString(); AppSettings->endGroup(); if(!loadPieces(pieceTheme, pieceEffect)) { static bool errorShown = false; if (!errorShown) { errorShown = true; MessageDialog::error(tr("Cannot find piece data.\nPlease check your installation.")); } } if (!loadBoard(boardTheme)) { static bool errorShown = false; if (!errorShown) { errorShown = true; MessageDialog::error(tr("Cannot find board data.\nPlease check your installation.")); } } }
int main(int argc, char *argv[]) { Board board = loadBoard(argc, argv); int scoreOrig = ScoreBoard(board); if (scoreOrig == orangeWins) { puts("I win\n"); exit(-1); } else if (scoreOrig == yellowWins) { puts("You win\n"); exit(-1); } else { int move, score; abMinimax(true,Orange,g_maxDepth,board,move,score); if (g_debug) printf("Cached:%d Processed:%d\n", hits, losses); if (move != -1) { printf("%d\n",move); dropDisk(board, move, Orange); scoreOrig = ScoreBoard(board); if (scoreOrig == orangeWins) { puts("I win\n"); exit(-1); } else if (scoreOrig == yellowWins) { puts("You win\n"); exit(-1); } else exit(0); } else { puts("No move possible"); exit(-1); } } return 0; }
int main(int argc, char *argv[]){ int i, j; bool quit = false; SDL_Event event; SDL_Surface *screen = NULL; SDL_Surface *clipboard = NULL; GameBoard board; Object defs[10]; SDL_Rect land, water; if(argc < 2){ printf("Passe o nome do arquivo de level\n"); return 0; } land.x = 5*TILE_WIDTH; land.y = 2*TILE_HEIGHT; water.x = 4*TILE_WIDTH; water.y = 2*TILE_HEIGHT; land.h = water.h = TILE_HEIGHT; land.w = water.h = TILE_WIDTH; /* incializa tela */ if(SDL_Init(SDL_INIT_EVERYTHING) == -1) return 1; screen = SDL_SetVideoMode(WIDTH, HEIGHT, RESOLUTION, SDL_SWSURFACE); if(screen == NULL) return 1; /*inicializa clipboard */ clipboard = loadBMP("ClipBoard.bmp"); /*inicializa objetos */ loadObjectDefinitions(defs, "objects.dat"); /*inicializa level*/ loadBoard(&board, defs, argv[1]); /*desenha*/ for(i=0;i<BOARD_HEIGHT;i++){ for(j=0;j<BOARD_WIDTH;j++){ switch(board.scenario[i][j]){ case LAND: applyClipToBoard(screen, clipboard, j, i, land); break; case WATER: applyClipToBoard(screen, clipboard, j, i, water); break; default:; } if(board.objects[i][j]){ applyClipToBoard(screen, clipboard, j, i, board.objects[i][j]->clip); } } } SDL_Flip(screen); while(!quit){ while(SDL_PollEvent(&event)){ if(event.type == SDL_QUIT){ quit = true; } else if(event.type == SDL_KEYDOWN){ if(event.key.keysym.sym == SDLK_ESCAPE){ quit = true; } } } } SDL_Quit(); return 0; }
int Game(SDL_Surface *screen){ int i, j; bool quit = false; SDL_Event event; SDL_Surface *clipboard = NULL; GameBoard board; Object objetos[255]; Terrain terrenos[255]; Jogador jogador; SDL_Rect *pos = NULL; SDL_Surface* clipboard_jogador; loadTerrainDefinitions(terrenos,"terreno.dat"); loadObjectDefinitions(objetos, "objects.dat"); rke_carrega_jogador(&jogador, TILE_WIDTH, TILE_HEIGHT); clipboard_jogador = loadBMP("navio.bmp"); pos = loadBoard(&board,objetos,"level1.lvl"); jogador.x = pos->x; jogador.y = pos->y; jogador.direcao = E; jogador.hp = 1000; jogador.poder_flecha=3; jogador.poder_bomba=10; jogador.bombas=5; free(pos); screen = SDL_GetVideoSurface(); SDL_FillRect(screen, NULL, 0x000000); while(!quit) { for (i = 0; i < BOARD_HEIGHT ; i++) { for (j = 0; j < BOARD_WIDTH; j++) { applyClipToBoard(screen, clipboard, j, i, terrenos[(int)board.scenario[i][j]].retangulo); if ((int)(board.objects[i][j])) applyClipToBoard(screen, clipboard, j, i, objetos[(int)board.objects[i][j]].clip); } } applyClipToBoard(screen, clipboard_jogador, jogador.y, jogador.x, jogador.retangulo[jogador.direcao]); SDL_Flip(screen); while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) { quit = 1; } else { if(event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_ESCAPE: quit = 1; break; case SDLK_UP: rke_move_jogador(&jogador, board, terrenos, objetos, -1, 0); break; case SDLK_DOWN: rke_move_jogador(&jogador, board, terrenos, objetos, 1, 0); break; case SDLK_LEFT: rke_move_jogador(&jogador, board, terrenos, objetos, 0, -1); break; case SDLK_RIGHT: rke_move_jogador(&jogador, board, terrenos, objetos, 0, 1); break; case SDLK_SPACE: rke_jogador_atira(&jogador, board, terrenos, objetos, FLECHA); break; case SDLK_RETURN: rke_jogador_atira(&jogador, board, terrenos, objetos, BOMBA); break; default: break; } } } } } SDL_FillRect(screen, NULL, 0x000000); return QUIT; }