当前位置: 首页>>代码示例>>PHP>>正文


PHP game::add_new_game方法代码示例

本文整理汇总了PHP中game::add_new_game方法的典型用法代码示例。如果您正苦于以下问题:PHP game::add_new_game方法的具体用法?PHP game::add_new_game怎么用?PHP game::add_new_game使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在game的用法示例。


在下文中一共展示了game::add_new_game方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test

 public function test()
 {
     $username = "howdy";
     $password = "123456";
     $email = "gg@gmail.com";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "gr@gmmail.com";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $game_size = 6;
     $this->assertTrue(game::add_new_game($user1ID, $game_size, $user1ID, $user2ID), "failed to add a new game");
     $game_id1 = game::$last_inserted_id;
     $this->assertTrue(game::add_new_game($user2ID, $game_size, $user2ID, $user1ID), "failed to add a new game");
     $game_id2 = game::$last_inserted_id;
     //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
     //message::get_all_messages_for_game_id($game_id)
     //message::add_new_message($game_id,$user_id,$message)
     $message = "helllo";
     $this->assertNull(message::get_all_messages_for_game_id($game_id1), "null should be returned because no messages added for the given game_id [get_all_messages_for_game_id()]");
     $this->assertNull(message::get_all_messages_for_game_id("rr"), "null should be returned because an invalid game_id was passed [get_all_messages_for_game_id()]");
     $this->assertFalse(message::add_new_message("hhh", $user1ID, $message), "false should be reutnred because an invalid game_id was passed [add_new_message()]");
     $this->assertFalse(message::add_new_message($game_id1, "blla", $message), "false should be reutnred because an invalid user_id was passed [add_new_message()]");
     $this->assertTrue(message::add_new_message($game_id1, $user1ID, $message), "falied to add new message [add_new_message()]");
     $this->assertEquals(1, count(message::get_all_messages_for_game_id($game_id1)), "expecting to get an array with one message [get_all_messages_for_game_id()]");
     $messages = message::get_all_messages_for_game_id($game_id1);
     $this->assertEquals($message, $messages[0]['message_text'], "[add_new_message()]");
     $this->assertEquals($game_id1, $messages[0]['gameID'], "[add_new_message()]");
     $this->assertEquals($user1ID, $messages[0]['userID'], "[add_new_message()]");
     $this->assertTrue(message::add_new_message($game_id2, $user1ID, "yolooo"), "falied to add new message [add_new_message()]");
     $message2 = "where are you";
     $this->assertTrue(message::add_new_message($game_id1, $user2ID, $message2), "falied to add new message [add_new_message()]");
     $this->assertEquals(2, count(message::get_all_messages_for_game_id($game_id1)), "expecting to get an array with two messages [get_all_messages_for_game_id()]");
     //message::get_message_count($game_id)
     $this->assertEquals(2, message::get_message_count($game_id1), "[message::get_message_count()]");
     $this->assertEquals(-1, message::get_message_count("asdasdasd"), "providing an invalid game_id so it should be rejected[message::get_message_count()]");
     message::clear_table();
     $this->assertEquals(0, message::get_message_count($game_id1), "[message::get_message_count()]");
     $this->assertTrue(message::add_new_message($game_id1, $user1ID, $message), "falied to add new message [add_new_message()]");
     $this->assertTrue(message::add_new_message($game_id1, $user2ID, $message2), "falied to add new message [add_new_message()]");
     $this->assertTrue(message::add_new_message($game_id2, $user1ID, "yolooo"), "falied to add new message [add_new_message()]");
     $this->assertEquals(1, message::get_message_count($game_id2), "[message::get_message_count()]");
     $messages = message::get_all_messages_for_game_id($game_id1);
     //message::get_all_messages_after_given_date($game_id,$date)
     $this->assertNull(message::get_all_messages_after_given_date(0, 0), "get_all_messages_after_given_date()");
     $this->assertNull(message::get_all_messages_after_given_date($messages[1]['gameID'], $messages[1]['date']), "get_all_messages_after_given_date()");
     $this->assertEquals(1, count(message::get_all_messages_after_given_date($messages[0]['gameID'], $messages[0]['date'])), "get_all_messages_after_given_date()");
     $this->assertEquals(2, count(message::get_all_messages_after_given_date($messages[0]['gameID'], $messages[0]['date'] - 0.1)), "get_all_messages_after_given_date()");
     //message::delete_message($message_id)
     $this->assertFalse(message::delete_message("dddd"), "[delete_message()]");
     $this->assertTrue(message::delete_message($messages[0]['id']), "[delete_message()]");
     $this->assertEquals(1, count(message::get_all_messages_after_given_date($messages[0]['gameID'], $messages[0]['date'] - 0.1)), "get_all_messages_after_given_date()");
     //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
 }
开发者ID:uunuu,项目名称:dot_boxes,代码行数:58,代码来源:table_messageTest.php

示例2: test

 public function test()
 {
     $username = "howdy";
     $password = "123456";
     $email = "gg@gmail.com";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "gr@gmmail.com";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $gmae_size = 6;
     $this->assertFalse(game::add_new_game($user1ID, "z", $user1ID, $user2ID), "invalid size went through OK!");
     $this->assertFalse(game::add_new_game("s", $gmae_size, $user1ID, $user2ID), "invalid curent player id went through OK!");
     $this->assertFalse(game::add_new_game($user1ID, $gmae_size, "x", $user2ID), "invalid player 1 id went through OK!");
     $this->assertFalse(game::add_new_game($user1ID, $gmae_size, $user1ID, "d"), "invalid player 2 id went through OK!");
     $this->assertFalse(game::add_new_game(20, $gmae_size, $user1ID, $user2ID), "current turn id was different from p1 and p2 and it when through!");
     $this->assertTrue(game::add_new_game($user1ID, $gmae_size, $user1ID, $user2ID), "failed to add a new game");
     $this->assertEquals($gmae_size, game::getGameById(1)['size'], "incorrect game size");
     $this->assertEquals($user1ID, game::getGameById(1)['player1ID'], "incorrect player 1 id ");
     $this->assertEquals($user2ID, game::getGameById(1)['player2ID'], "incorrect player 2 id ");
     $this->assertNull(game::getGameById(1)['winnerID'], "winnder ID should be null");
     $this->assertNull(game::getGameById(1)['lastActivityDate'], "lastActivityDate should be null");
     $this->assertEquals(1, game::getNumberOfGames(), "number of games should be equal to 1");
     game::clear_table();
     $this->assertEquals(0, game::getNumberOfGames(), "number of games should be equal to 0");
     game::add_new_game($user1ID, $gmae_size, $user1ID, $user2ID);
     $game_id = game::$last_inserted_id;
     $this->assertTrue(game::setLastActivityDate($game_id), "setLastActivityDate is not working");
     $this->assertEquals(time() / 60 % 60, game::getGameById($game_id)['lastActivityDate'] / 60 % 60);
     game::clear_table();
     //security test: passing a user id that is not a number
     $this->assertEquals(-1, game::getNumberOfGamesForUserId("ff"), "getNumberOfGamesForUserId() should accept only numbers");
     //the user shouldn't have any games
     $this->assertEquals(0, game::getNumberOfGamesForUserId($user2ID), "The player shouldn't have any games [getNumberOfGamesForUserId()]");
     game::add_new_game($user1ID, $gmae_size, $user1ID, $user2ID);
     $game_id1 = game::$last_inserted_id;
     $this->assertEquals(1, game::getNumberOfGamesForUserId($user1ID), "player should have 1 game [getNumberOfGamesForUserId()]");
     $username3 = "bla3";
     $password3 = "pass3";
     $email3 = "bla3@gmmail.com";
     user::create_new_user($username3, $password3, $email3);
     $user3ID = user::getUserByUsername($username3)['id'];
     $this->assertEquals(3, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $this->assertTrue(game::add_new_game($user3ID, $gmae_size, $user3ID, $user1ID), "failed to add a new game");
     $game_id2 = game::$last_inserted_id;
     $this->assertEquals(2, game::getNumberOfGames(), "number of games should be equal to 2");
     $this->assertEquals(2, game::getNumberOfGamesForUserId($user1ID), "player should have two games [getNumberOfGamesForUserId()]");
     $this->assertEquals(1, game::getNumberOfGamesForUserId($user2ID), "player should have one game [getNumberOfGamesForUserId()]");
     $this->assertEquals(1, game::getNumberOfGamesForUserId($user3ID), "player should have one game [getNumberOfGamesForUserId()]");
     $this->assertEquals(2, count(game::getAllGamesForUserId($user1ID)), "two games should be returned [game::getAllGamesForUserId()]");
     $this->assertEquals($user1ID, game::getAllGamesForUserId($user1ID)[0]['player1ID'], "[game::getAllGamesForUserId()]");
     $this->assertEquals($user1ID, game::getAllGamesForUserId($user1ID)[1]['player2ID'], "[game::getAllGamesForUserId()]");
     $this->assertNull(game::getAllGamesForUserId(88), "should return null because player doesn't have games [game::getAllGamesForUserId()]");
     $this->assertNull(game::getOpponentId(1000, 1000), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId(1000, 1000), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId($game_id1, 1000), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId(1000, $user1ID), "[game::getOpponentId]");
     $this->assertEquals($user2ID, game::getOpponentId($game_id1, $user1ID), "[game::getOpponentId]");
     $this->assertEquals($user1ID, game::getOpponentId($game_id1, $user2ID), "[game::getOpponentId]");
     $this->assertEquals($user1ID, game::getOpponentId($game_id2, $user3ID), "[game::getOpponentId]");
     $this->assertEquals($user3ID, game::getOpponentId($game_id2, $user1ID), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId($game_id2, $user2ID), "[game::getOpponentId]");
 }
开发者ID:uunuu,项目名称:dot_boxes,代码行数:67,代码来源:table_gameTest.php

示例3: test

 public function test()
 {
     $username = "howdy";
     $password = "123456";
     $email = "gg@gmail.com";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "gr@gmmail.com";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $game_size = 6;
     $this->assertTrue(game::add_new_game($user1ID, $game_size, $user1ID, $user2ID), "failed to add a new game");
     $game_id1 = game::$last_inserted_id;
     $this->assertFalse(move::add_new_move(100, 1, 1, 1, $user1ID), "accepted invalid game_id [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, -1, 1, 1, $user1ID), "accepted invalid x coordinate [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 1, -5, 1, $user1ID), "accepted invalid y coordinate [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 8, 1, 1, $user1ID), "accepted invalid x coordinate (larger than the size) [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 1, 8, 1, $user1ID), "accepted invalid y coordinate (larger than the size) [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 1, 1, 5, $user1ID), "accepted invalid edge position  [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 1, 1, 2, 90), "accepted invalid playerID (ID doesn't even exist)  [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 1, 1, 2, $user2ID), "accepted invalid playerID (not the player turn)  [move::add_new_move]");
     $game_info = game::getGameById($game_id1);
     $this->assertNull($game_info['lastActivityDate'], "when move fails the transaction is not rolledback![move::add_new_move]");
     $this->assertTrue(move::add_new_move($game_id1, 1, 1, 1, $user1ID), "failed to add new move");
     $game_info = game::getGameById($game_id1);
     $this->assertTrue($game_info['currentTurnPlayerID'] == $user2ID, "when adding a new move, method failed to change the player's turn");
     //get_last_move_for_game_id($game_id)
     $move = move::get_last_move_for_game_id($game_id1);
     $this->assertEquals($game_id1, $move['gameID'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(1, $move['x'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(1, $move['y'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(1, $move['edgePosition'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals($user1ID, $move['playerID'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals($game_info['lastActivityDate'], $move['date'], "the last activity date in the game table is not consistent with the move table! [move::add_new_move]");
     $this->assertTrue(move::add_new_move($game_id1, 2, 3, 4, $user2ID), "failed to add new move");
     $move2 = move::get_last_move_for_game_id($game_id1);
     $this->assertEquals($user2ID, $move2['playerID'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(2, $move2['x'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(3, $move2['y'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(4, $move2['edgePosition'], "inccorect last move [get_last_move_for_game_id()]");
     move::add_new_move($game_id1, 2, 1, 4, $user1ID);
     move::add_new_move($game_id1, 2, 2, 4, $user2ID);
     $move3 = move::get_last_move_for_game_id($game_id1);
     $this->assertEquals($user2ID, $move3['playerID'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(2, $move3['y'], "inccorect last move [get_last_move_for_game_id()]");
     move::clear_table();
     $this->assertFalse(move::get_last_move_for_game_id($game_id1), "inccorect last move [get_last_move_for_game_id()]");
     //count_moves($game_id)
     $this->assertEquals(0, move::count_moves($game_id1), "number of moves should be ZERO [count_moves()]");
     $this->assertTrue(move::add_new_move($game_id1, 2, 3, 4, $user1ID), "failed to add new move");
     $this->assertEquals(1, move::count_moves($game_id1), "number of moves should be ONE [count_moves()]");
     //get_all_moves_after_given_date($game_id,$timestamp)
     $move4 = move::get_last_move_for_game_id($game_id1);
     $this->assertNull(move::get_all_moves_after_given_date($game_id1, $move4['date']), "[move::get_all_moves_after_given_date()]");
     $this->assertTrue(move::add_new_move($game_id1, 4, 3, 1, $user2ID), "failed to add new move");
     $this->assertEquals(2, move::count_moves($game_id1), "number of moves should be two [count_moves()]");
     $move5 = move::get_all_moves_after_given_date($game_id1, $move4['date']);
     $this->assertEquals(1, count($move5), "number of moves returned should be one [move::get_all_moves_after_given_date()]");
     $this->assertEquals($game_id1, $move5[0]['gameID'], "[move::get_all_moves_after_given_date()]");
     $this->assertTrue(move::add_new_move($game_id1, 5, 5, 2, $user1ID), "failed to add new move");
     $this->assertEquals(2, count(move::get_all_moves_after_given_date($game_id1, $move4['date'])), "number of moves returned should be two [move::get_all_moves_after_given_date()]");
     //move::delete_move($move_id)
     $move_id = $move5[0]['gameID'];
     move::delete_move($move_id);
     $this->assertEquals(1, count(move::get_all_moves_after_given_date($game_id1, $move5[0]['date'])), "[move::delet_move()]");
     //move::get_all_moves_for_game_id($game_id)
     $this->assertEquals(move::count_moves($game_id1), count(move::get_all_moves_for_game_id($game_id1)), "[move::get_all_moves_for_game_id()]");
     $this->assertNull(move::get_all_moves_for_game_id("bla"), "[move::get_all_moves_for_game_id()]");
     $this->assertNull(move::get_all_moves_for_game_id("0"), "[move::get_all_moves_for_game_id()]");
 }
开发者ID:uunuu,项目名称:dot_boxes,代码行数:74,代码来源:table_moveTest.php


注:本文中的game::add_new_game方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。