Skip to content

Instantly share code, notes, and snippets.

@blazarecki
Created November 22, 2017 09:28
Show Gist options
  • Save blazarecki/67ae7af0dd84aa91d8542caf01a260b8 to your computer and use it in GitHub Desktop.
Save blazarecki/67ae7af0dd84aa91d8542caf01a260b8 to your computer and use it in GitHub Desktop.
{% extends 'base.html.twig' %}
{% block body %}
{{ form(form) }}
{% endblock %}
<?php
namespace App\Controller;
use App\Fight\DamageCalculator;
use App\Form\FightType;
use Doctrine\ORM\EntityManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class FightController extends Controller
{
/**
* @Route(path="/fight", name="fight")
*/
public function indexAction(Request $request, EntityManager $manager)
{
$form = $this->createForm(FightType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var \App\Fight\Fight $fight */
$fight = $form->getData();
}
return $this->render('Fight/index.html.twig', ['form' => $form->createView()]);
}
}
{% extends 'base.html.twig' %}
{% block body %}
<a href="{{ path('player_new') }}">Create player</a>
<table>
<thead>
<th>Status</th>
<th>Name</th>
<th>HP</th>
<th>Weapon</th>
<th>Damage</th>
<th>Coef</th>
<th>Fire rate</th>
</thead>
<tbody>
{% for player in players %}
<tr>
<td>{{ player.healthPoint < 0 ? 'DEAD' : 'Alive' }}</td>
<td>{{ player.name }}</td>
<td>{{ player.healthPoint }}</td>
<td>{{ player.currentWeapon.name }}</td>
<td>{{ player.currentWeapon.damage }}</td>
<td>{{ player.currentWeapon.damageDistanceCoef }}</td>
<td>{{ player.currentWeapon.fireRate }}/s</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
<?php
namespace App\Controller;
use App\Entity\Player;
use App\Form\PlayerType;
use Doctrine\ORM\EntityManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class PlayerController extends Controller
{
/**
* @Route(path="/", name="player_list")
*/
public function indexAction()
{
$players = $this->getDoctrine()->getRepository(Player::class)->findAll();
return $this->render('Player/index.html.twig', ['players' => $players]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment