Meeskond "Valmis!"

From ICO wiki
Jump to navigationJump to search

Meeskond "Valmis!"

Liikmed: Artur Šarõpin, Leonid Dikušin, Marko Kurm

Projekti eesmärk

Projekti eesmärgid olid:

1. Luua veebiteenused, mis võimaldavad kasutajatel omavahel sõnumeid saata.
2. Luua veebiteenuse klient (kasutajaliides), mis võimaldaks neid veebiteenuseid kasutada.

Tööjaotus

Kuna projekti realiseerimisega oli äärmiselt kiire ja projekti maht suhteliselt väike, siis otsustasime, et ei hakka tööd väga süstemaatiliselt jagama ning saame paaril õhtul kokku IT-Kolledži raamatukogus või arvutiklassis ning teeme. Mõeldud, tehtud. Alamtööde jaotus kujunes välja järgmiseks:

1. Veebiteenuste interface klassi loomine
2. Veebiteenuste realiseerimine
3. Veebiteenuse kliendi realiseerimine (paralleelselt veebiteenuste realiseerimisega)
4. Testimine

Kokkuvõttes kujunes tööde mahuks ~10h x 3 = 30h

Lahenduse kirjeldus

TODO

XML

Kuna olen ise pokkerihuviline, siis tegin XML faili, mis kirjeldab ühte pokkeri mängu. Mäng koosneb mängu andmetest (tüüp, valuuta, panused), mängija andmetest (nimi, hüüdnimi, sünniaeg) ja kätest, mis antud mängu jooksul läbi mängiti. Käsi omakorda koosneb siis kaartidest (mängija kaardid, laua kaardid) ja toimingutest(raise, call, all-in, fold jne.).

XML Fail (pokker.xml)

<?xml version="1.0" encoding="utf-8" ?>
<game id="99483673666" xmlns="http://tempuri.org/pokker.xsd"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://tempuri.org/pokker.xsd pokker.xsd">
  <type>Cash-Game</type>
  <playType>Texas Hold'em</playType>
  <currency>EUR</currency>
  <playerCount>6</playerCount>
  <blinds>
    <sb>0.5</sb>
    <bb>1</bb>
    <ante>0</ante>
  </blinds>
  <player>
    <nickname>OzzuPozzu</nickname>
    <firstName>Marko</firstName>
    <lastName>Kurm</lastName>
    <dateOfBirth>1984-07-05</dateOfBirth>
  </player>
  <hands>
    <count>2</count>
    <hand id="134954854">
      <position>3</position>
      <duration>126</duration>
      <cards>
        <player>
          <card>
            <suit>Hearts</suit>
            <value>10</value>
          </card>
          <card>
            <suit>Spades</suit>
            <value>6</value>
          </card>
        </player>
        <community>
          <card>
            <suit>Clubs</suit>
            <value>6</value>
          </card>
          <card>
            <suit>Spades</suit>
            <value>6</value>
          </card>
          <card>
            <suit>Diamonds</suit>
            <value>2</value>
          </card>
          <card>
            <suit>Hearts</suit>
            <value>3</value>
          </card>
          <card>
            <suit>Diamonds</suit>
            <value>Q</value>
          </card>
        </community>
      </cards>
      <actions>
        <action>
          <type>SB</type>
          <amount>0.5</amount>
        </action>
        <action>
          <type>Raise</type>
          <amount>2</amount>
        </action>
        <action>
          <type>Call</type>
          <amount>3.5</amount>
        </action>
        <action>
          <type>MUCK</type>
          <amount>0</amount>
        </action>
        <action>
          <type>Win</type>
          <amount>8.5</amount>
        </action>
      </actions>
    </hand>
    <hand id="55678345">
      <position>3</position>
      <duration>126</duration>
      <cards>
        <player>
          <card>
            <suit>Clubs</suit>
            <value>J</value>
          </card>
          <card>
            <suit>Clubs</suit>
            <value>A</value>
          </card>
        </player>
        <community>
          <card>
            <suit>Hearts</suit>
            <value>J</value>
          </card>
          <card>
            <suit>Spades</suit>
            <value>J</value>
          </card>
          <card>
            <suit>Clubs</suit>
            <value>K</value>
          </card>
          <card>
            <suit>Clubs</suit>
            <value>3</value>
          </card>
          <card>
            <suit>Clubs</suit>
            <value>9</value>
          </card>
        </community>
      </cards>
      <actions>
        <action>
          <type>Call</type>
          <amount>2</amount>
        </action>
        <action>
          <type>Raise</type>
          <amount>5</amount>
        </action>
        <action>
          <type>All-In</type>
          <amount>15</amount>
        </action>
        <action>
          <type>Muck</type>
          <amount>0</amount>
        </action>
        <action>
          <type>Win</type>
          <amount>44</amount>
        </action>
      </actions>
    </hand>
  </hands>
</game>

XSD Fail (pokker.xsd)

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="pokker"
    targetNamespace="http://tempuri.org/pokker.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/pokker.xsd"
    xmlns:mstns="http://tempuri.org/pokker.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  
  <xs:element name="game">
	<xs:complexType>
	  <xs:all>
	    <xs:element name="type" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
	      <xs:element name="playType" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
	      <xs:element name="currency" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
	      <xs:element name="playerCount" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
	      <xs:element name="blinds" type="typeBlinds" minOccurs="1" maxOccurs="1"></xs:element>
	      <xs:element name="player" type="typePlayer" minOccurs="1" maxOccurs="1"></xs:element>
	      <xs:element name="hands" type="typeHands" minOccurs="1" maxOccurs="1"></xs:element>
	    </xs:all>
	  <xs:attribute name="id" type="xs:integer" use="required"></xs:attribute>
	</xs:complexType>
  </xs:element>
  
  <xs:complexType name="typeBlinds">
    <xs:all>
      <xs:element name="sb" type="xs:decimal" minOccurs="1" maxOccurs="1"></xs:element>
      <xs:element name="bb" type="xs:decimal" minOccurs="1" maxOccurs="1"></xs:element>
      <xs:element name="ante" type="xs:decimal" minOccurs="1" maxOccurs="1"></xs:element>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="typePlayer">
    <xs:all>
      <xs:element name="nickname" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
      <xs:element name="firstName" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
      <xs:element name="lastName" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
      <xs:element name="dateOfBirth" type="xs:date" minOccurs="0" maxOccurs="1"></xs:element>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="typeHands">
    <xs:sequence>
      <xs:element name="count" type="xs:integer" minOccurs="1" maxOccurs="1"></xs:element>
      <xs:element name="hand" type="typeHand" minOccurs="1" maxOccurs="unbounded"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="typeHand">
    <xs:all>
      <xs:element name="position" type="xs:integer" minOccurs="1" maxOccurs="1"></xs:element>
      <xs:element name="duration" type="xs:integer" minOccurs="1" maxOccurs="1"></xs:element>
      <xs:element name="cards" type="typeCards" minOccurs="1" maxOccurs="1"></xs:element>
      <xs:element name="actions" type="typeActions" minOccurs="1" maxOccurs="1"></xs:element>
    </xs:all>
    <xs:attribute name="id" type="xs:integer" use="required"></xs:attribute>
  </xs:complexType>

  <xs:complexType name="typeCards">
    <xs:all>
      <xs:element name="player" type="typePlayerCards" minOccurs="1" maxOccurs="1"></xs:element>
      <xs:element name="community" type="typeCommunityCards" minOccurs="1" maxOccurs="1"></xs:element>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="typePlayerCards">
    <xs:sequence>
      <xs:element name="card" type="cardType" minOccurs="1" maxOccurs="unbounded"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="typeCommunityCards">
    <xs:sequence>
      <xs:element name="card" type="cardType" minOccurs="1" maxOccurs="unbounded"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="cardType">
    <xs:all>
      <xs:element name="suit" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
      <xs:element name="value" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="typeActions">
    <xs:sequence>
      <xs:element name="action" type="typeAction" minOccurs="1" maxOccurs="unbounded"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="typeAction">
    <xs:all>
      <xs:element name="type" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
      <xs:element name="amount" type="xs:decimal" minOccurs="1" maxOccurs="1"></xs:element>
    </xs:all>
  </xs:complexType>
  

</xs:schema>


XSLT HTML tegemiseks (pokkerHTML.xslt)

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  
  <xsl:output method="xml" indent="yes"/>

 
      <xsl:template match="game">
         <html xmlns="http://www.w3.org/1999/xhtml">

            <div>
              <table style="background-color: #555555; color: #FFFFFF">
                <tr>
                  <td style="font-weight: bold;">Game ID:</td>
                  <td style="background-color: #FFFFFF; color: #555555;">
                    <xsl:value-of select="@id"/>
                  </td>
                </tr>
                <tr>
                  <td style="font-weight: bold;">Type</td>
                  <td style="background-color: #FFFFFF; color: #555555;">
                    <xsl:value-of select="type"/>
                  </td>
                </tr>
                <tr>
                  <td style="font-weight: bold;">Play Type</td>
                  <td style="background-color: #FFFFFF; color: #555555;">
                    <xsl:value-of select="playType"/>
                  </td>
                </tr>
                <tr>
                  <td style="font-weight: bold;">Currency</td>
                  <td style="background-color: #FFFFFF; color: #555555;">
                    <xsl:if test="currency = 'EUR'">
                      €
                    </xsl:if>
                    <xsl:if test="currency = 'USD'">
                      $
                    </xsl:if>
                  </td>
                </tr>
                <tr>
                  <td style="font-weight: bold;">Player</td>
                  <td style="background-color: #FFFFFF; color: #555555;">
                    <xsl:value-of select="player/nickname"/> (<xsl:value-of select="player/firstName "/><xsl:text> </xsl:text><xsl:value-of select="player/lastName"/>)
                  </td>
                </tr>
              </table>
            </div>

           <div>
             <xsl:apply-templates select="hands/hand"/>
           </div>
           
        </html>
      </xsl:template>

      <xsl:template match="game/hands/hand">
        <table style="background-color: #555555; color: #FFFFFF; margin-top: 20px;">
          <tr>
            <td style="font-weight: bold;">Hand ID</td>
            <td style="background-color: #FFFFFF; color: #555555;">
              <xsl:value-of select="@id"/>
            </td>
          </tr>
          <tr>
            <td style="font-weight: bold;">Player Cards</td>
            <td style="background-color: #FFFFFF; color: #555555;">
              <xsl:for-each select="cards/player/card">
                <xsl:apply-templates select="."/>,
              </xsl:for-each>
            </td>
          </tr>
          <tr>
            <td style="font-weight: bold;">Community Cards</td>
            <td style="background-color: #FFFFFF; color: #555555;">
              <xsl:for-each select="cards/community/card">
                <xsl:apply-templates select="."/>, 
              </xsl:for-each>
            </td>
          </tr>

          <xsl:for-each select="actions/action">
            <tr>
              <td style="font-weight: bold;">Player Action</td>
              <td style="background-color: #FFFFFF; color: #555555;">
                <xsl:apply-templates select="type"/> (<xsl:apply-templates select="amount"/>)
              </td>
            </tr>
          </xsl:for-each>
          
        </table>
      </xsl:template>

      <xsl:template match="card">
        <xsl:value-of select="value"/>
        <xsl:choose>
          <xsl:when test="suit = 'Hearts'">h</xsl:when>
          <xsl:when test="suit = 'Clubs'">c</xsl:when>
          <xsl:when test="suit = 'Spades'">s</xsl:when>
          <xsl:when test="suit = 'Diamonds'">d</xsl:when>
        </xsl:choose>
      </xsl:template>
  
</xsl:stylesheet>

XSLT XML tegemiseks (pokkerXML.xslt)

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

  <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" omit-xml-declaration="no" />

  <xsl:template match="game">
    <hands>
      <xsl:apply-templates select="hands/hand"/>
    </hands>
  </xsl:template>

  <xsl:template match="game/hands/hand">
    <hand>
      <id>
        <xsl:value-of select="@id"/>
      </id>
      <cards>
        <xsl:for-each select="cards/player/card">
            <xsl:apply-templates select="."/>       
        </xsl:for-each>
      </cards>
      <communityCards>
        <xsl:for-each select="cards/community/card">
          <xsl:apply-templates select="."/>
        </xsl:for-each>
      </communityCards>
      <actions>
        <xsl:for-each select="actions/action">
          <action type="{type}">
            
            <xsl:apply-templates select="amount"/>
          </action>
        </xsl:for-each>
      </actions>
    </hand>
  </xsl:template>

  <xsl:template match="card">
    <xsl:value-of select="value"/>
    <xsl:choose>
      <xsl:when test="suit = 'Hearts'">h</xsl:when>
      <xsl:when test="suit = 'Clubs'">c</xsl:when>
      <xsl:when test="suit = 'Spades'">s</xsl:when>
      <xsl:when test="suit = 'Diamonds'">d</xsl:when>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

Kood XSLT transformatsiooni tegemiseks

XPathDocument myXPathDoc = new XPathDocument("pokker.xml");

XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load("pokkerHTML.xslt");

XmlTextWriter myWriter = new XmlTextWriter("pokkerResult.html", null);
myXslTrans.Transform(myXPathDoc, null, myWriter);