예제 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     //create game
     $game = Game::create(\Input::all());
     $letters = Letters::all();
     foreach ($letters as $letter) {
         GameLetters::create(array('game_id' => $game->id, 'letter_id' => $letter->id, 'letter_count' => $letter->count));
     }
     UserGame::create(array('user_id' => \Auth::User()->id, 'game_id' => $game->id, 'points' => 0, 'user_class' => "", 'ready' => "N"));
     GameController::generate_letters($game->id);
     return $game->id;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     try {
         $game = \App\Models\Game::create(\Input::all());
         \Event::fire(new \App\Events\GamesRefresh($game));
         return redirect('gamejoin/' . $game->id);
     } catch (\Illuminate\Database\QueryException $ABError) {
         return redirect('games')->withWarning('Error, try again.');
     } catch (Exception $a) {
         return redirect('games')->withWarning('Error, try again.');
     }
 }
예제 #3
0
 public function generateGame($user_id = null)
 {
     $genres = $this->getRandomGenres();
     $occupiedIds = [];
     $tasks = [];
     foreach ($genres as $genre) {
         $bands = $this->getBandsByGenre($genre, $occupiedIds);
         $occupiedIds = array_merge($occupiedIds, array_pluck($bands->toArray(), 'id'));
         $band = $bands[array_rand($bands->toArray())];
         $images = $band->images->toArray();
         $tasks[] = ['genre' => $genre, 'band' => $band->toArray(), 'image' => $images[array_rand($images)]['link'], 'choices' => array_merge([$genre['name']], $this->getWrongChoices($band))];
     }
     $game = Game::create(['data' => json_encode($tasks), 'user_id' => $user_id]);
     return ['id' => $game->id, 'tasks' => $tasks, 'user_id' => $user_id];
 }
예제 #4
0
 /**
  * Handle the event.
  *
  * @param  \App\WS\Message $message
  * @param  \App\WS\Connection $conn
  * @return void
  */
 public function handle($message, $conn)
 {
     if ($message->user()->activeGame()) {
         return $message->reply(['You\'ve already started a game.'], 422);
     }
     $this->validate($message, ['name' => 'required|between:2,100', 'players' => 'required|numeric|min:2|max:4', 'matches' => 'required|numeric|min:1|max:4', 'points' => 'required|numeric|min:10']);
     $game = Game::create(['hash' => Str::random(32), 'name' => $message->get('name'), 'players' => $message->get('players'), 'matches' => $message->get('matches'), 'points' => $message->get('points'), 'user_id' => $message->user()->id]);
     // Add the current user to the game.
     $game->addUser($message->user());
     $game->load('user', 'countUsers');
     // Send response the the user that created the game.
     $message->reply($game, 201);
     // Notify all users of a new game.
     foreach ($conn->clients() as $client) {
         $this->send($client, 'game.new', $game, 201);
     }
 }
예제 #5
0
 public function addParsedGame(GameMlsEntity $gameEntity)
 {
     $gameBO = new GameMlsBO($gameEntity);
     $data = $gameBO->toArray();
     $validator = Validator::make($data, GameRequest::getRules());
     if (!$validator->fails()) {
         $game = Game::where('mls_url', $data['mls_url'])->first();
         if (!$game) {
             $game = Game::create($data);
             if (strpos($data['icon'], 'players-ico.png') === false && $data['icon'] != config('mls.domain')) {
                 copy($data['icon'], public_path() . '/img/team_logos/' . str2url($game->team) . '.png');
             }
             return $game;
         }
     }
     return false;
 }
 public function store(Request $request)
 {
     $request->merge(['slug' => $this->createSlugFromRequest($request)]);
     $v = Validator::make($request->all(), ['slug' => 'required|min:3|unique:Games', 'capacity' => 'required|integer|min:' . config('game.capacity.min') . '|max:' . config('game.capacity.max'), 'spec_capacity' => 'required|integer|min:' . config('game.spec_capacity.min') . '|max:' . config('game.spec_capacity.max')]);
     $v->sometimes('password', 'min:6', function () {
         return Auth::check();
     });
     $this->validateWith($v);
     if (Auth::check()) {
         $data = $request->all();
         if ($data['password']) {
             $data['private'] = true;
         }
     } else {
         $data = $request->only(['name', 'slug', 'capacity', 'spec_capacity']);
     }
     $game = Game::create($data);
     return redirect()->route('game.show', [$game]);
 }
예제 #7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Clear the DB first
     $con = Propel::getWriteConnection(GameTableMap::DATABASE_NAME);
     //$sql = "DELETE FROM game WHERE name<>'test'";
     $queries = array('DELETE FROM game');
     $tables = array('game_match', 'match_state', 'turn', 'empire_order', 'empire', 'territory_template');
     foreach ($tables as $t) {
         $queries[] = "ALTER TABLE {$t} AUTO_INCREMENT = 1";
     }
     foreach ($queries as $q) {
         $stmt = $con->prepare($q);
         $stmt->execute();
     }
     //$config->system->db->useDebug(true);
     // Create or use
     $game = null;
     $games = GameQuery::create()->filterByName('test%', Criteria::LIKE);
     $game_base_name = 'test';
     $game_name = $game_base_name . '_' . $games->count();
     $p_objs = json_decode(file_get_contents(Config::get('paths.games') . "/{$game_base_name}/empires.json"), false);
     $t_objs = json_decode(file_get_contents(Config::get('paths.games') . "/{$game_base_name}/territories.json"), false);
     $game = Game::create($game_name, 1861, 'spring');
     $game->loadEmpires($p_objs);
     $game->loadTerritories($t_objs);
     $game->save();
     // $texas   = Territory::findTerritoryByName($territories, 'Texas');
     // $sequoia = Territory::findTerritoryByName($territories, 'Sequoia');
     // $ohio    = Territory::findTerritoryByName($territories, 'Ohio');
     // print "Texas-Sequoia? " . ($texas->isNeighbour($sequoia) ? 'PASS':'******') . "\n";
     // print "Sequoia-Texas? " . ($sequoia->isNeighbour($texas) ? 'PASS':'******') . "\n";
     // print "Texas-Ohio? "    . ($texas->isNeighbour($ohio) ? 'FAIL':'PASS') . "\n";
     // Empires
     $red = EmpireQuery::create()->filterByGame($game)->filterByAbbr('RED')->findOne();
     $blue = EmpireQuery::create()->filterByGame($game)->filterByAbbr('BLU')->findOne();
     $green = EmpireQuery::create()->filterByGame($game)->filterByAbbr('GRN')->findOne();
     $match = Match::create($game, "Matt Test");
     $turn = $match->getCurrentTurn();
     print "\n" . $match . "\n";
     // Territories
     // Crate the $t_<territory> magic variables.
     $t_names = array('A', 'B', 'C', 'D', 'E');
     foreach ($t_names as $n) {
         $c = new Criteria();
         $c->add(TerritoryTemplateTableMap::COL_NAME, $n);
         $tt = $game->getGameTerritories($c);
         $varname = "t_" . strtolower($n);
         ${$varname} = StateQuery::create()->filterByTerritory($tt)->findOne();
     }
     print "{$t_a} neighbours:\n";
     $neighbours = $t_a->getTerritory()->getNeighbours();
     foreach ($neighbours as $n) {
         print "{$n}\n";
     }
     print "\n" . Unit::printUnitTable($match->getCurrentTurn());
     $case = 3;
     switch ($case) {
         case 1:
             // Test move conflict
             $turn->addOrder(Move::createNS($red, $t_a, $t_b));
             $turn->addOrder(Move::createNS($red, $t_a, $t_c));
             $turn->addOrder(Move::createNS($blue, $t_a, $t_b));
             $turn->addOrder(Move::createNS($green, $t_e, $t_d));
             $turn->save();
             break;
         case 2:
             // Test support
             $turn->addOrder(Move::createNS($red, $t_a, $t_b));
             $turn->addOrder(Move::createNS($blue, $t_b, $t_c));
             $turn->addOrder(Support::createNS($green, $t_a, $t_e, $t_b));
             $turn->save();
             break;
         case 3:
             //$config->system->db->useDebug(true);
             try {
                 $turn->addOrder(Order::interpretText('MOVE "A" "B"', $match, $red));
             } catch (\DiplomacyOrm\InvalidOrderException $e) {
                 print "[" . Config::get('ansi.red') . "Error" . Config::get('ansi.clear') . "]: Red cannot MOVE A-B: " . $e->getMessage() . "\n";
                 exit;
             } catch (DiplomacyOrm\TurnClosedToOrdersException $e) {
                 print "[" . Config::get('ansi.red') . "Error" . Config::get('ansi.clear') . "]: Some how the turn state is empty again: " . $e->getMessage() . "\n";
                 exit;
             }
             $turn->addOrder(Order::interpretText('SUPPORT "E" "A" "B"', $match, $green));
             $turn->save();
             break;
         case 4:
             // Test the case with multiple contendors stalemat. standoff.svg
             $turn->addOrder(Order::interpretText('MOVE "A" "B"', $match, $red));
             $turn->addOrder(Order::interpretText('SUPPORT "A" "F" "B"', $match, $red));
             $turn->addOrder(Order::interpretText('MOVE "I" "B"', $match, $green));
             $turn->addOrder(Order::interpretText('SUPPORT "E" "H" "B"', $match, $green));
             $turn->save();
             // RED and GREEN should loose in statemates, B should belong to BLUE
             break;
         case 5:
             $turn->addOrder(Order::interpretText('MOVE "E" "C"', $match, $green));
             break;
         case 6:
             // No orders
             $result = $match->getCurrentTurn()->processOrders();
             print $match . "\n";
             $result = $match->getCurrentTurn()->processOrders();
             $result = $match->getCurrentTurn()->processOrders();
             $result = $match->getCurrentTurn()->processOrders();
             break;
     }
     $match->getCurrentTurn()->printOrders();
     $result = $match->getCurrentTurn()->processOrders();
     //print "\n" . Unit::printUnitTable($match->getCurrentTurn());
     //$match->getCurrentTurn()->printOrders();
     //print_r($result->__toArray());
     //print json_encode($result->__toArray());
     if ($result->retreatsRequired()) {
         //print $result;
         $retreat = Retreat::createNS($blue, $t_b, $t_c);
         print "Adding retreat order: {$retreat}\n";
         $match->getCurrentTurn()->addOrder($retreat);
         print "----------------------------------------\n";
         print "After adding retreat order..\n";
         $match->getCurrentTurn()->printOrders();
         $result = $match->getCurrentTurn()->processOrders();
         print $result;
     }
     // Show which orders have failed, etc
     print "\n" . $match . "\n";
 }
예제 #8
0
 public function store(GameRequest $request)
 {
     Game::create($request->all());
     Flash::success(trans('general.created_msg'));
     return redirect(route('admin.games'));
 }