






Hotspots: Admin Pages | Turn-in Site |
Current Links: Case 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:
- Display a welcome screen and allow input of a leader name
- If name > 6 characters, allow the wagon to be configured as below, otherwise reprompt for leader name with error message
- Configure the wagon by setting the pace, ration, and choosing a profession.
- Display back a game status showing that your game has accepted the input parameters
- Any additional gameplay functionality (buying items etc) would be extra credit for M9.
1. The first part of the assignment is not that hard, you have to do a couple of things.
- use html code to create a simple, but creative website.
- create a input field on your website
- create a form that will link you page to another page with smalltalk code
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>
<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">
<input type=reset value="Reset">
</form>
</center>
</body>
</html>
2. The second part is to test if the code is longer then 6 characters
- Create a ssp page. With is a page with small talk code
- This is the page that the code from the page above links to
- If the name is longer then 6 characters then go to the next pager
- If name is not longer then 6 create the error message 111 and pass it back to the first page.
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.
- Create input fields for Pace, Ration and Profession
- You have to pass these fields into the game.
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>
<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">
<input type=reset value="Reset">
</form>
</center>
</body>
</html>
4. Now you have to hook up the game and display the results
- One thing that took me a while to get is how to call a specific class from the game. You have to call it by Namespace.Class
- Also printString won't print to the website, you will have to use return to print to the website
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>
<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
- Case last edited on 29 July 2009 at 11:50 pm by c-76-97-208-233.hsd1.ga.comcast.net
- Index of Individual Cases last edited on 28 July 2009 at 3:01 pm by lwc029.ats.gatech.edu