Jump to content
php.lv forumi

Seal

Reģistrētie lietotāji
  • Posts

    8
  • Joined

  • Last visited

Posts posted by Seal

  1. Spēles kods tic tac toe

    
    #include <iostream>
    
    using namespace std;
    
    int main(){
    //This array of chars represents the game board, and it holds the content of each square (x,o or empty)
    char square[3][3] = {{' ',' ',' '},{' ',' ',' '},{' ',' ',' '}};
    //The current player (x or o)
    char turn = 'X';
    //These variables will hold the number of the row and column selected by the players.
    int row;
    int column;
    //The winner (x, o, t(if it`s a tie) or empty)
    char winner = ' ';
    //Required variables to check if a move is valid or not
    bool validmove;
    bool validrow;
    bool validcolumn;
    //The game loop`s again and again until the game is over
    while(winner == ' '){
    //Draw the board
    cout << " 1 2 3" << endl << " +---+---+---+" << endl;
    for(int i=1;i<4;i++){
    cout << " " << i << " | " << square[i-1][0] << " | " << square[i-1][1] << " | " << square[i-1][2] << " |" << endl << " +---+---+---+" << endl;
    }
    //Check for an eventual winner of for a tie
    for(int i=0;i<3;i++){
    if(square[i][0] == square[i][1] && square[i][1] == square[i][2] && square[i][0] != ' '){
    winner = square[i][0];
    }
    }
    for(int i=0;i<3;i++){
    if(square[0][i] == square[1][i] && square[1][i] == square[2][i] && square[0][i] != ' '){
    winner = square[0][i];
    }
    }
    if(square[0][0] == square[1][1] && square[1][1] == square[2][2] && square[0][0] != ' '){
    winner = square[0][0];
    }
    if(square[0][2] == square[1][1] && square[1][1] == square[2][0] && square[0][2] != ' '){
    winner = square[0][2];
    }
    if(square[0][0] == square[0][1] && square[0][1] == square[0][2] && square[0][2] == square[1][0] && square[1][0] == square[1][1] && square[1][1] == square[1][2] && square[1][2] == square[2][0] && square[2][0] == square[2][1] && square[2][1] == square[2][2] && square[0][0] != ' '){
    winner = 't';
    }
    //If somebody won
    if(winner == 'X' || winner == 'O'){
    //Display congratulations message
    cout << "Congratulations! Player ";
    if(winner == 'X'){
    cout << 1;
    }
    else{
    cout << 2;
    }
    cout << " is the winner!" << endl;
    break;
    }
    else if(winner == 't'){
    //Display a message if it`s tie
    cout << "Tie!" << endl;
    break;
    }
    //If the game is not yet over show who`s the next player to move
    cout << "Player ";
    if(turn == 'X'){
    cout << 1;
    }
    else{
    cout << 2;
    } 
    cout << "'s turn:" << endl;
    //Loop until the player selects a valid square
    validmove = false;
    while(!validmove){
    validrow = false;
    //Loop until the player selects a valid row
    while(!validrow){
    cout << "Row: ";
    cin >> row;
    if(row == 1 || row == 2 || row == 3){
    validrow = true;
    }
    else{
    cout << endl << "Invalid row!" << endl;
    }
    }
    validcolumn = false;
    //Loop until the player selects a valid column
    while(!validcolumn){
    cout << "Column: ";
    cin >> column;
    if(column == 1 || column == 2 || column == 3){
    validcolumn = true;
    }
    else{
    cout << endl << "Invalid column!" << endl;
    }
    }
    //Change the turn to the next player
    if(square[row-1][column-1] == ' '){
    square[row-1][column-1] = turn;
    validmove = true;
    if(turn == 'X'){
    turn = 'O';
    }
    else{
    turn = 'X';
    }
    }
    //If the selected square is occupied display a message and loop again
    else{
    cout << "The selected square is occupied!" << endl << "Select again:" << endl;
    }
    }
    }
    system("pause");
    }
    

     

    Ko tieši dara šīs rindas ? Daļēji saprotu, bet līdz galam nesaprotu )

     

     

    
    

     

    for(int i=0;i<3;i++){
    if(square[0][i] == square[1][i] && square[1][i] == square[2][i] && square[0][i] != ' '){
    winner = square[0][i];
    }
    }
    if(square[0][0] == square[1][1] && square[1][1] == square[2][2] && square[0][0] != ' '){
    winner = square[0][0];
    }
    if(square[0][2] == square[1][1] && square[1][1] == square[2][0] && square[0][2] != ' '){
    winner = square[0][2];
    }
    if(square[0][0] == square[0][1] && square[0][1] == square[0][2] && square[0][2] == square[1][0] && square[1][0] == square[1][1] && square[1][1] == square[1][2] && square[1][2] == square[2][0] && square[2][0] == square[2][1] && square[2][1] == square[2][2] && square[0][0] != ' '){
    winner = 't';

     

  2. *Esejas ievadā parādi savu attieksmi pret ekonomistu uzskatiem par tirgus, valsts lomu un valsts funkcijām jauktas ekonomikas sistēmā; galvenos jēdzienus.

     

    Man vajag uzrakstīt eseju, bet nevaru atrast nekur ekonomistu uzskatus :( par tirgus, valsts lomu un valsts funkcijām jauktās ekonomikas sistēmā.

     

    Varbūt kāds var "vijibnutsa" ar google skill? Varbūt es slikti meklēju. Vismaz par tirgus lomu un valsts lomu jauktajā ekonomikā. (Latvijā)

  3. Sveiki, es izveidoju šo kodu

     

    <?php
    $mysqlconnnect = mysql_connect ('localhost','root','85221802');
    if (!$mysqlconnnect){
    die ('Savienojums ar datubāzi netika veikts, ievadi pareizos datus!');
    }
    mysql_select_db ("cms", $mysqlconnnect);
    $sql = "CREATE TABLE RegisteredUsers
    (
    Login varchar(15) NOT NULL,
    Password varchar(15) NOT NULL,
    Age int
    )";
    mysql_query ($sql,$mysqlconnnect);
    mysql_select_db ("cms", $mysqlconnnect);
    $sql2 ="INSERT INTO RegisteredUsers (Login, Password, Age)
    VALUES
    ('$_POST[Login]','$_POST[Password]','$_POST[age]')";
    if (!mysql_query($sql2,$mysqlconnnect))
    {
    die ('' . mysql_error());
    }
    else
    echo '<b>Tika pievienota informācija datubāzē!</b>'
    ?>
    

     

    Tad es mēģināju izdzēst tabulas kurās jau bija informāciju, kuru es ieguvu caur FORM (Login, parole, vecums un submit poga).Itkā izdzēsās tabulas ar informāciju, bet to vietā parādās vienmēr viens un tāds pats skaits rindu. Kad es FORMā ievadu tukšas ailes, pievienojas vēl tās rindas un izdzēst man viņas neizdodas.

     

     

    Varbūt vajag kaut ko pie SQL koda pierakstīt lai neveidotos bezjēdzīgas tabulas ar tukšumiem?

    post-8465-0-39237600-1323631358_thumb.jpg

  4. Sveiki, man ir neliela problēma, sāku mācīties php+mysql un izveidoju šo kodu

     

    <?php
    $connect = mysql_connect('localhost','root','pw')or die ('<center><b>Lūdzu ievadi pareizus datus lai varētu pieslēgties datubāzei</b></center>');
    if (mysql_query("CREATE DATABASE datubaze", $connect)){
    echo 'Datubāze tika izveidota';
    }
    else{
    echo '<b>Notika kļūda datubāzes izveidē: </b><br>' . mysql_error();
    }
    mysql_select_db ('datubaze', $connect);
    $sql = "CREATE TABLE Registretieslietotaji
    (
    Login varchar(15)
    Password varchar(15)
    Age int
    )";
    if (!$sql){
    echo '<b>Nevar izveidot jaunas tabulas</b>' . mysql_error();
    }
    else{
    echo '<br><b>Tabulas tika veiksmīgi izveidotas</b>';
    }
    mysql_query($connect,$sql);
    mysql_close($connect);
    ?>
    

     

    Iegāju apskatīties google chrome un ieraudzīju šo brīdinājumu:

     

    Warning: mysql_query() expects parameter 1 to be string, resource given in D:\AppServ\www\map\data.php on line 22

     

    Kā var tikt vāļā no šī brīdnājuma?

×
×
  • Create New...