#!/usr/local/bin/python
# -*- coding: UTF-8 -*-

import cgi
import cgitb; cgitb.enable()  # for troubleshooting
import Player

scores = open("scores.txt", "w")

print "Content-type: text/html"
print

print """
<html>

<head><title>Sample CGI Script</title></head>

<body>

  <h3> Sample CGI Script </h3>
"""

form = cgi.FieldStorage()
placeIt1 = form.getvalue("place1", "0")
placeIt2 = form.getvalue("place2", "0")
fireIt1 = form.getvalue("fire1", "0")
fireIt2 = form.getvalue("fire2", "0")
ls1 = form.getvalue("p1", "0")
ls2 = form.getvalue("p2", "0")
#scores.write(message)
scores.close()

p1 = Player.Player(ls1,17)
p2 = Player.Player(ls2,17)



if placeIt1 != "0":
	p1.place(int(placeIt1[0]),int(placeIt1[1]))
if placeIt2 != "0":
	p2.place(int(placeIt2[0]),int(placeIt2[1]))
if fireIt1 != "0":
	p1.fire(int(fireIt1[0]),int(fireIt1[1]))
if fireIt2 != "0":
	p2.fire(int(fireIt2[0]),int(fireIt2[1]))
	
print "<p> Player 1 array %s</p>"%p1.position
print "<p> Player 2 array %s</p>"%p2.position	

print """

  <p>Previous message:</p>

  <p>form

  <form method="post" action="form.cgi">
    <p>Place P1: <input type="text" name="place1"  maxlength="2" /></p>
	<p>Place P2: <input type="text" name="place2"  maxlength="2" /></p>
	<p>Fire P1: <input type="text" name="fire1"  maxlength="2" /></p>
	<p>Fire P2: <input type="text" name="fire2"  maxlength="2" /></p>
	<input type='hidden' name='p1' value='%s' />
	<input type='hidden' name='p2' value='%s' />
	<input type="submit"/>
  </form>

</body>

</html>

""" % (p1.position,p2.position)



		