Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: caseman/gravita
base: 3a590ca40f
...
head fork: caseman/gravita
compare: 354f817a73
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
2  gravita/game.py
@@ -33,7 +33,7 @@ def add_player(self, player):
def begin_turn(self):
"""Begin a new turn in the game"""
- assert len(self.players) == 2, 'Too few players to start game'
+ #assert len(self.players) == 2, 'Too few players to start game'
self.turn += 1
for player in self.players:
player.begin_turn()
View
5 gravita/player.py
@@ -31,11 +31,12 @@ def begin_turn(self):
"""Begin a new turn for the player, update the resources,
research, move, and action counts
"""
- self.to_move = self.ships.copy()
self.actions_remaining = self.actions_per_turn
- resources, research = self.race.total_yields(self.planets)
+ resources, research = self.race.total_yield(self.planets)
self.resources += resources
self.research += research
+ for ship in self.ships:
+ ship.begin_turn()
def as_dict(self):
return {
View
9 gravita/restapi.py
@@ -77,7 +77,7 @@ def game(self):
def ship_moves(self):
profile, is_new = self.get_user_profile()
ship = profile.game.map.ships[self.request.GET['ship_id']]
- sectors = profile.game.map.sectors_in_circle(ship.location, ship.specs.range)
+ sectors = ship.available_moves()
return {
'ship': ship.as_dict(),
'sectors': [sector.as_dict() for sector in sectors if sector.ship is None],
@@ -92,6 +92,13 @@ def move_ship(self):
ship.move_to(location)
return ship.as_dict()
+ @view_config(name='end_turn', renderer='json', request_method='POST')
+ def end_turn(self):
+ params = self.request.POST
+ profile, is_new = self.get_user_profile()
+ profile.game.begin_turn()
+ return {}
+
View
12 gravita/ship.py
@@ -11,6 +11,7 @@
#
#############################################################################
import json
+import math
from collections import namedtuple
class Ship(object):
@@ -18,6 +19,7 @@ class Ship(object):
def __init__(self, owner, map, location, specs):
assert map[location].ship is None, "Ship already at %s" % location
self.owner = owner
+ owner.ships.add(self)
self.map = map
self.location = location
self.specs = specs
@@ -28,15 +30,22 @@ def __init__(self, owner, map, location, specs):
self.map[location].ship = self
self.hp = self.specs.max_hp
self.ap = self.specs.max_ap
+ self.remaining_range = float(self.specs.range)
def available_moves(self):
+ range = min(int(self.remaining_range), self.ap // self.specs.move_ap)
return [sector for sector in
- self.map.sectors_in_circle(self.location, self.specs.range)
+ self.map.sectors_in_circle(self.location, range)
if sector.ship is None]
def move_to(self, location):
assert self.map[location].ship is None, "Ship already at %s" % location
old_location = self.location
+ dx = location[0] - old_location[0]
+ dy = location[1] - old_location[1]
+ dist = math.sqrt(dx*dx + dy*dy)
+ self.remaining_range = max(0, self.remaining_range - dist)
+ self.ap = max(0, self.ap - int(dist) * self.specs.move_ap)
self.map[old_location].ship = None
self.map[location].ship = self
self.location = location
@@ -44,6 +53,7 @@ def move_to(self, location):
def begin_turn(self):
self.ap = self.specs.max_ap
+ self.remaining_range = self.specs.range
def damage(self, amount):
self.hp = max(0, self.hp - amount)
View
4 gravita/www/gravita.js
@@ -32,6 +32,10 @@ $gravita.createGame = function() {
});
}
+$gravita.endTurn = function() {
+ $.post('/end_turn');
+}
+
$gravita.renderMap = function(map) {
$gravita.ships = map.ships;
$gravita.showTmpl("map-template", map);

No commit comments for this range

Something went wrong with that request. Please try again.