View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Implementing Smalltalk in a website - Dan Ardelean

For our M9 we had to place a web front-end on our Oregon Trail game and you might have to do that as well.

These were our requirements:

1. The first part of the assignment is not that hard, you have to do a couple of things.

Everything that is in red is not part of the html, but my explanation of what is going on
This page is called nameLogin.ssp
<html>
<head>

This is the link for the css sheet
<link rel="stylesheet" href="style.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Oregon Trail</title>
</head>

 <body>

 <center>
  <h1>Welcome to Oregon Trail</h1>
  &nbsp;

  <table>
  <img src=images/oregon-trail.jpg> 
  </table>	

All the code bellow is smalltalk code that reads to see if there is cookie.
Message = 111 means there is a cookie so display a something. If there is no message then don't display anything
	<% 

            message := request anyParameterValueAt: 'msg'. 

           (message size) > 0 

            ifTrue: [ 

                 response write: '<font color=red>'. 

                 (message = '111') 

                      ifTrue: [ response write: 'Login incorrect. Name not long enough'.]. 

                 (message = '222') 

                      ifTrue: [ response write: 'Cookie has crumbled. Please login again'.]. 

                 response write: '</font>'. 

             ] 

            ifFalse: 

                [ response write: '<br>'. ]. 

          %> 

This the page that tests to see if the name is longer then 6 characters.
  <form name=nameTest action="nameTest.ssp" method="post">

Takes in the input from the user.
  <table width=600>
   <tr>
    <td align=right width=200>
     Name: 
    </td>
    <td align=left width=400>
     <input type=text name="txtName" size=20>
    </td>
   </tr>
  </table>

  <br>
  <input type=submit value="Send">&nbsp;&nbsp;
  <input type=reset value="Reset">
 </form>
 </center>
 </body>
</html>


2. The second part is to test if the code is longer then 6 characters
This page is called nameTest.ssp
<%
txtName := request anyFormValueAt: 'txtName'.

( txtName size ) > 6
	
	ifTrue: [ 	oregonCookie := HTTPCookie named: 'oregonTrail' value: txtName.
        		oregonCookie expireAfterDays: 90.
        		response addCookie: oregonCookie.
			response redirectTo: 'gameTime.ssp'.
		]
 	ifFalse: [ 	response redirectTo: 'nameLogin.ssp?msg=111'.].
%> 


3. The name passed now you have to get some data from the user.
This page is called gameTime.ssp
<html>
<head>

<link rel="stylesheet" href="style.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Oregon Trail</title>
</head>

 <body>

 <center>
  <h1>Welcome to Oregon Trail</h1>
  &nbsp;

  <table>
  <img src=images/oregon-trail.jpg> 
  </table>	

	<% 

	        oregonCookie := request cookieValueAt: 'oregonTrail'. 

	        response write: ('<h3>Hello ',oregonCookie,'</h3>'). 

    	%> 


   <form name=engine action="engine.ssp" method="post">
   <table>


   <tr>
   <td>
     Pace: 
   </td>
   <td>
     <select name=paceList size=1>
      <option value="#stopped"> Stopped
      <option value="#leisurely"> Leisurely
      <option value="#steady"> Steady
      <option value="#grueling"> Grueling
     </select>
   </td>
   </tr>

   <tr>
   <td>
     Ration: 
   </td>
   <td>
     <select name=rationList size=1>
      <option value="#none"> None
      <option value="#barebones"> BareBones
      <option value="#meager"> Meager
      <option value="#normal"> Normal
      <option value="#wellfed"> WellFed
     </select>
   </td>
   </tr>

   <tr>
   <td>
     Profession: 
   </td>
   <td>
     <select name=professionList size=1>
      <option value="#banker"> Banker
      <option value="#carpenter"> Carpenter
      <option value="#farmer"> Farmer
     </select>
   </td>
   </tr>

   

   </table>
  <br>
  <input type=submit value="Send">&nbsp;&nbsp;
  <input type=reset value="Reset">
 
  </form>  

 </center>
 </body>
</html>


4. Now you have to hook up the game and display the results
This page is called engine.ssp
<html>
<head>

<link rel="stylesheet" href="style.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Oregon Trail</title>
</head>

 <body>

 <center>
  <h1>Welcome to Oregon Trail</h1>
  &nbsp;

  <table>
  <img src=images/oregon-trail.jpg> 
  </table>	


	<br>
<%
paceWeb := request anyFormValueAt: 'paceList'.
rationWeb := request anyFormValueAt: 'rationList'.
professionWeb := request anyFormValueAt: 'professionList'.
personName := request cookieValueAt: 'oregonTrail'.

	wagon :=  OregonTrail.Wagon new.
	item := OregonTrail.Item named: 'food' weight: 10 price: 2.
	wagon addItem: item.
 	p1 := OregonTrail.Person named: personName.
 	wagon addPerson: p1.
	wagon pace: paceWeb.
	wagon ration: rationWeb.
	wagon profession: professionWeb.
	response write: wagon wagonStatsPrintreport.
	response write: wagon wagonPeoplePrint.
	response write: wagon wagonProfessionPrint.
        engineCookie := HTTPCookie named: 'engine' value: ( paceWeb, ' ',rationWeb, ' ', professionWeb ).
        engineCookie expireAfterDays: 90.
        response addCookie: engineCookie.
  	

%> 

</center>
</body>
</html>


Links to this Page