<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kép a tartalomban</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="content">
<div id="kep1">
</div>
</div>
</body>
</html>
//-
//- Source: com.nary.http.rouletteServlet.java
//- Author: A.R.Williamson ([email protected])
//- Company: N-ARY Limited (http://www.n-ary.com/)
//-
package com.nary.http.game;
import java.io.*;
import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.nary.http.*;
import com.nary.html.*;
public class rouletteServlet extends HttpServlet implements Runnable {
static private htmlTemplate rouletteTable = null;
static private htmlTemplate scoreTable = null;
static Thread mainThread = null;
static cBall lastBall = new cBall();
static long ballTime = 15000;
static Vector highScores;
public void init(ServletConfig _Config) throws ServletException {
loadScores();
mainThread = new Thread(this);
mainThread.start();
}
private synchronized void loadScores(){
try{
FileInputStream FS = new FileInputStream( "roulette.scores" );
ObjectInputStream IS = new ObjectInputStream(FS);
highScores = (Vector)IS.readObject();
}catch(Exception E){
System.out.println( E );
highScores = new Vector();
}
}
private synchronized void saveScores(){
try{
FileOutputStream FS = new FileOutputStream( "roulette.scores" );
ObjectOutputStream OS = new ObjectOutputStream(FS);
OS.writeObject( highScores );
}catch(Exception E){}
}
public void service(HttpServletRequest _req, HttpServletResponse _res) throws ServletException, IOException {
if ( _req.getParameter( "SYS_GAMEON" ) != null )
gameOn( _req, _res );
else if ( _req.getParameter( "SYS_NEWGAME" ) != null )
newGame( _req, _res );
else if ( _req.getParameter( "SYS_DISPLAY" ) != null )
displayScores( _req, _res );
}
public void run(){
for (;;){
try{
mainThread.sleep( ballTime );
lastBall = new cBall();
synchronized( mainThread ){
mainThread.notifyAll();
}
}catch( Exception E ){}
}
}
public void newGame(HttpServletRequest _req, HttpServletResponse _res) throws ServletException, IOException{
String email = _req.getParameter("EMAIL");
if ( email == null || email.indexOf("@") == -1 ){
_res.sendRedirect( _req.getParameter("URL_BADLOGIN") );
return;
}
if ( rouletteTable == null ){
rouletteTable = new htmlTemplate( true, _req.getParameter("URL_TABLE") );
}
roulInfo RI = new roulInfo();
RI.form = "<INPUT TYPE=HIDDEN NAME=START_TIME VALUE=" + System.currentTimeMillis() + ">\n" +
"<INPUT TYPE=HIDDEN NAME=BANK_ROLL VALUE=" + RI.bank + ">\n" +
"<INPUT TYPE=HIDDEN NAME=EMAIL VALUE=\"" + email + "\">\n" +
"<INPUT TYPE=HIDDEN NAME=ID VALUE=0>\n";
//- Set Cookie
com.nary.util.cookie.setCookie( _res, 1800, "ROULETTE", ".n-ary.com", "0" );
displayTable( _res, RI );
}
public void gameOn(HttpServletRequest _req, HttpServletResponse _res) throws ServletException, IOException{
//- Display the advert and ask for confirmation
//- Calculate Winnings
if ( rouletteTable == null ){
rouletteTable = new htmlTemplate( true, _req.getParameter("URL_TABLE") );
}
//- Check to see the Cookie hasnt got out of sync.
String ID = com.nary.util.cookie.getCookie( _req, "ROULETTE" );
if ( ID == null || ID.equals( _req.getParameter("ID") ) == false ){
_res.sendRedirect( _req.getParameter("URL_CHEAT") );
return;
}
roulInfo RI = new roulInfo();
RI.bank = Integer.parseInt( _req.getParameter("BANK_ROLL") );
RI.status = "<BR>";
int nextBet=0;
boolean bBadBet = false;
boolean bWin = false;
try{
nextBet = Integer.parseInt( _req.getParameter("NEXT_BET") );
}catch (Exception E){
RI.status = "Please insert a number";
bBadBet = true;
}
Vector bets = buildBets( _req );
if ( bets.size()*nextBet > RI.bank || nextBet > RI.bank )
RI.status = "You don't have enough in the bank for a bet that size";
else if ( bBadBet == false ){
try{
synchronized( mainThread ){
mainThread.wait();
}
}catch( InterruptedException E ){}
//- Remove bets from bank
RI.bank -= nextBet * bets.size();
//- Check for winnings
if ( bets.contains( lastBall.Ball + "" ) ){
bWin = true;
RI.bank += nextBet + (35*nextBet);
RI.lastwin += 35*nextBet;
}
if ( bets.contains( "00" ) && lastBall.Ball == 37 ){
bWin = true;
RI.bank += nextBet + (35*nextBet);
RI.lastwin += 35*nextBet;
}
//- Check
if ( bets.contains( "Green" ) && lastBall.Colour.equals("Green") ){
bWin = true;
RI.bank += nextBet + nextBet;
RI.lastwin += nextBet;
}
if ( bets.contains( "Red" ) && lastBall.Colour.equals("Red") ){
bWin = true;
RI.bank += nextBet + nextBet;
RI.lastwin += nextBet;
}
if ( bets.contains( "Odd" ) && lastBall.bOdd ){
bWin = true;
RI.bank += nextBet + nextBet;
RI.lastwin += nextBet;
}
if ( bets.contains( "even" ) && lastBall.bEven ){
bWin = true;
RI.bank += nextBet + nextBet;
RI.lastwin += nextBet;
}
if ( bets.contains( "118" ) && lastBall.b118 ){
bWin = true;
RI.bank += nextBet + nextBet;
RI.lastwin += nextBet;
}
if ( bets.contains( "1936" ) && lastBall.b1936 ){
bWin = true;
RI.bank += nextBet + nextBet;
RI.lastwin += nextBet;
}
}
//- Check to see if game over
long startG = Long.parseLong( _req.getParameter("START_TIME") );
if ( RI.bank <= 0 || startG+(60000*2) < System.currentTimeMillis() )
gameOver( _req, _res, RI );
//- Format display for sending
if ( bWin )
RI.status = "Congratulations you won";
if ( lastBall.Ball != 37 )
RI.lastball = lastBall.Colour + " " + lastBall.Ball;
else
RI.lastball = lastBall.Colour + " 00";
//- Set Cookie
int id = Integer.parseInt(ID) + 1;
com.nary.util.cookie.setCookie( _res, 1800, "ROULETTE", ".n-ary.com", id+"" );
id = Integer.parseInt( _req.getParameter("ID") ) + 1;
RI.form = "<INPUT TYPE=HIDDEN NAME=START_TIME VALUE=" + _req.getParameter("START_TIME") + ">\n" +
"<INPUT TYPE=HIDDEN NAME=BANK_ROLL VALUE=" + RI.bank + ">\n" +
"<INPUT TYPE=HIDDEN NAME=EMAIL VALUE=\"" + _req.getParameter("EMAIL") + "\">\n" +
"<INPUT TYPE=HIDDEN NAME=ID VALUE=" + id + ">\n";
displayTable( _res, RI );
}
private void gameOver( HttpServletRequest _req, HttpServletResponse _res, roulInfo RI ) throws ServletException, IOException{
//- Game over man!
if ( RI.bank <= 0 )
_res.sendRedirect( _req.getParameter("URL_GAMELOST") );
else{
//- Update tables and then redirect them to a good page
boolean bAdd = false;
Enumeration E = highScores.elements();
userInfo UI;
while ( E.hasMoreElements() ){
UI = (userInfo)E.nextElement();
if ( RI.bank > UI.money ){
bAdd = true;
break;
}
}
if ( bAdd || highScores.size() < 10 )
addUser( _req.getParameter("EMAIL"), RI.bank );
_res.sendRedirect( _req.getParameter("URL_GAMEWON") );
}
}
private void addUser( String _Email, int _money ){
userInfo UI = new userInfo();
userInfo oUI;
UI.email = _Email;
UI.money = _money;
for ( int x=0; x < highScores.size(); x++ ){
oUI = (userInfo)highScores.elementAt(0);
if ( UI.money >= oUI.money ){
highScores.insertElementAt(UI,0);
break;
}
}
if ( highScores.size() == 0 )
highScores.addElement( UI );
if ( highScores.size() > 10 )
highScores.setSize(10);
saveScores();
}
private void displayTable( HttpServletResponse _res, roulInfo RI ) throws ServletException, IOException{
String key[] = new String[5];
String dat[] = new String[5];
key[0] = "<!--BANK_ROLL-->";
dat[0] = RI.bank + "";
key[1] = "<!--LASTBALL-->";
dat[1] = RI.lastball + "";
key[2] = "<!--FORM-->";
dat[2] = RI.form;
key[3] = "<!--STATUS-->";
dat[3] = RI.status;
key[4] = "<!--LASTWIN-->";
dat[4] = RI.lastwin + "";
_res.setContentType("text/html");
PrintWriter Out = new PrintWriter( _res.getOutputStream() );
rouletteTable.print( Out, key, dat );
Out.flush();
}
private Vector buildBets(HttpServletRequest _req ){
Vector bets = new Vector(2,2);
//- Check the numbers
for ( int x=0; x < 37; x++ )
if ( _req.getParameter( x+"" ) != null )
bets.addElement( x+"" );
if ( _req.getParameter( "00" ) != null )
bets.addElement( "00" );
if ( _req.getParameter( "GREEN" ) != null )
bets.addElement( "Green" );
if ( _req.getParameter( "RED" ) != null )
bets.addElement( "Red" );
if ( _req.getParameter( "ODD" ) != null )
bets.addElement( "Odd" );
if ( _req.getParameter( "EVEN" ) != null )
bets.addElement( "Even" );
if ( _req.getParameter( "1-18" ) != null )
bets.addElement( "118" );
if ( _req.getParameter( "19-36" ) != null )
bets.addElement( "1936" );
return bets;
}
public void displayScores(HttpServletRequest _req, HttpServletResponse _res) throws ServletException, IOException{
if ( scoreTable == null )
scoreTable = new htmlTemplate( true, _req.getParameter("URL_SCORES") );
String key[] = new String[1];
String dat[] = new String[1];
key[0] = "<!--TABLE-->";
dat[0] = "";
Enumeration E = highScores.elements();
userInfo UI;
int x=1;
while ( E.hasMoreElements() ){
UI = (userInfo)E.nextElement();
dat[0] += "<TR><TD>" + x + "</TD>\r\n";
dat[0] += "<TD>" + UI.email + "</TD>\r\n";
dat[0] += "<TD> </TD><TD>$ \r\n";
dat[0] += UI.money + "</TD>\r\n";
x++;
}
_res.setContentType("text/html");
PrintWriter Out = new PrintWriter( _res.getOutputStream() );
scoreTable.print( Out, key, dat );
Out.flush();
}
}
class userInfo implements java.io.Serializable{
public String email;
public int money;
}
class roulInfo extends Object {
public int bank=1000;
public int lastwin=0;
public String lastball="-";
public String ballspun="-";
public String form="";
public String status="";
}
class cBall extends Object {
public boolean bEven=false;
public boolean bOdd=false;
public boolean bBlack=false;
public boolean b118=false;
public boolean b1936=false;
public String Colour;
public int Ball=0;
static String balls[] = { "Red",
"Red", "Green", "Red",
"Green", "Red", "Green",
"Red", "Green", "Red",
"Green", "Green", "Red",
"Green", "Red", "Green",
"Red", "Green", "Red",
"Red", "Green", "Red",
"Green", "Red", "Green",
"Red", "Green", "Red",
"Green", "Green", "Red",
"Green", "Red", "Green",
"Red", "Green", "Red" };
public cBall(){
//- Generates a new ball
String A;
for(;;){
Ball = (int)(Math.random() * 10000);
if ( Ball < 1000 )
continue;
A = Ball + "";
Ball = Integer.parseInt(A.substring( A.length()-2, A.length() ));
if ( Ball < 38 )
break;
}
//- Determine Colour
if ( Ball == 37 )
Colour = "Green";
else
Colour = balls[Ball];
//- Determine even or odd
if ( Ball == 37 || Ball == 0 ){
bEven = false;
bOdd = false;
}else if ( Ball%2 == 0 )
bEven = true;
else
bOdd = true;
//- Determine Range
if ( Ball >= 1 && Ball <= 18 )
b118 = true;
if ( Ball >= 19 && Ball <= 36 )
b1936 = true;
//- Determine Colour
if ( Colour.indexOf( "Green" ) != -1 )
bBlack = true;
}
}
//-------------
//- End of file
//-------------
/**
* Java Servlets by Example
* Alan R. Williamson
* http://manning.com/books/williamson
* ISBN: 188477766X
*/
#include<stdio.h>
#include<conio.h>
#include<ctype.h> // toupper();
#include<string.h> // strcpy();
#include<stdlib.h> // exit();
typedef int bool;
class Terem
{
protected:
char helye[10];
int ulohelyekSzama;
bool sotetitheto;
public:
char* Get_helye (void) {return helye;}
void Set_helye (char* akt_hely) { strcpy(helye, akt_hely); }
int Get_ulohelyekSzama (void) {return ulohelyekSzama;}
void Set_ulohelyekSzama (int akt_ulohelyek) {ulohelyekSzama = akt_ulohelyek;}
bool Get_sotetitheto (void) {return sotetitheto;}
void Set_sotetitheto (bool akt_sotetitheto) {sotetitheto = akt_sotetitheto;}
};
class Eloadoterem : public Terem
{
private:
bool hangosithato;
bool beepitettProjektor;
bool lepcsozetesPadsorok;
public:
bool Get_hangosithato (void) {return hangosithato;}
void Set_hangosithato (bool akt_hangosithato) {hangosithato = akt_hangosithato;}
bool Get_beepProj (void) {return beepitettProjektor;}
void Set_beepProj (bool akt_beepProj) {beepitettProjektor = akt_beepProj;}
bool Get_lepcsPad (void) {return lepcsozetesPadsorok;}
void Set_lepcsPad (bool akt_lepcsPad) {lepcsozetesPadsorok = akt_lepcsPad;}
};
enum OP_RENDSZER {Windows2000,WindowsXP,Linux,egyeb};
char opr [4][12] = {"Windows2000","Windows XP","Linux","egyeb"};
class Szamitogep_labor : public Terem
{
private:
int szamitogepekSzama;
bool halozatiKapcsolat;
OP_RENDSZER operaciosRendszer;
public:
int Get_szgSzam (void) {return szamitogepekSzama;}
void Set_szgSzam (int akt_szgszam) {szamitogepekSzama = akt_szgszam;}
bool Get_haloKapcs (void) {return halozatiKapcsolat;}
void Set_haloKapcs (bool akt_haloKapcs) {halozatiKapcsolat = akt_haloKapcs;}
OP_RENDSZER Get_opRendszer (void) {return operaciosRendszer;}
void Set_opRendszer (OP_RENDSZER akt_opRendszer) {operaciosRendszer = akt_opRendszer;}
};
void main()
{
clrscr();
printf ("Terem program\n\n");
printf ("___Elõadótermek adatainak feltöltése___\n");
int eaTermekSzama;
do
{
printf ("Elõadótermek száma=");
scanf ("%d", &eaTermekSzama);
} while (eaTermekSzama < 0 || eaTermekSzama > 32565);
Eloadoterem* EloadoteremP;
EloadoteremP = new Eloadoterem [eaTermekSzama];
if (EloadoteremP == NULL)
{
printf("Hiba! Sikertelen memóriafoglalás, program leáll!");
exit (0);
}
char hely [10];
int ulohelyek;
for (int i = 0; i < eaTermekSzama; i++)
{
printf ("%d. elõadóterem adatainak feltöltése:\n", i+1);
printf ("elõadóterem helye=");
scanf ("%s", &hely);
EloadoteremP[i].Set_helye (hely);
printf ("ülõhelyek száma=");
scanf ("%d", &ulohelyek);
EloadoteremP[i].Set_ulohelyekSzama (ulohelyek);
printf ("sötétíthetõ (I/N)?");
if (toupper(getch()) == 'I')
EloadoteremP[i].Set_sotetitheto (1);
else EloadoteremP[i].Set_sotetitheto (0);
printf ("\nhangosítható (I/N)?");
if (toupper(getch()) == 'I')
EloadoteremP[i].Set_hangosithato (1);
else EloadoteremP[i].Set_hangosithato (0);
printf ("\nbeépített projektor van (I/N)?");
if (toupper(getch()) == 'I')
EloadoteremP[i].Set_beepProj (1);
else EloadoteremP[i].Set_beepProj (0);
printf ("\nlépcsõzetesek a padsorok (I/N)?");
if (toupper(getch()) == 'I')
EloadoteremP[i].Set_lepcsPad (1);
else EloadoteremP[i].Set_lepcsPad (0);
clrscr();
}
printf ("A hangosítható és egyúttal projektorral is ellátott elõadótermek adatainak kilistázása:\n");
for (i = 0; i < eaTermekSzama; i++)
{
if (EloadoteremP[i].Get_hangosithato() == 1 && EloadoteremP[i].Get_beepProj() == 1)
{
printf ("%d. elõadóterem adatai:\n", i+1);
printf ("helye:"); puts(EloadoteremP[i].Get_helye());
printf ("\nülõhelyek száma:%d", EloadoteremP[i].Get_ulohelyekSzama());
if (EloadoteremP[i].Get_sotetitheto())
printf("\nsötétíthetõ");
else printf("\nnem sötétíthetõ");
if (EloadoteremP[i].Get_lepcsPad())
printf("\nlépcsõzetes padsorok vannak");
else printf("\nnincsenek lépcsõzetes padsorok");
printf ("\nNyomjon meg egy billentyût a folytatáshoz!");
getch();
}
}
delete EloadoteremP;
clrscr();
printf ("___Számítógép laborok adatainak feltöltése___");
int szgLaborokSzama;
int szgkSzama;
do
{
printf ("\nSzámítógép laborok száma=");
scanf ("%d", &szgLaborokSzama);
} while (szgLaborokSzama < 0 || szgLaborokSzama > 32565);
Szamitogep_labor* Szamitogep_laborP;
Szamitogep_laborP = new Szamitogep_labor [szgLaborokSzama];
if (Szamitogep_laborP == NULL)
{
printf("Hiba! Sikertelen memóriafoglalás, program leáll!");
exit (0);
}
for (i = 0; i < szgLaborokSzama; i++)
{
printf ("\n%d. számítógép labor adatainak feltöltése:", i+1);
printf ("\nhelye:");
scanf ("%s", &hely);
Szamitogep_laborP[i].Set_helye (hely);
printf ("ülõhelyek száma=");
scanf ("%d", &ulohelyek);
Szamitogep_laborP[i].Set_ulohelyekSzama (ulohelyek);
printf ("sötétíthetõ (I/N)?");
if (toupper(getch()) == 'I')
Szamitogep_laborP[i].Set_sotetitheto (1);
else Szamitogep_laborP[i].Set_sotetitheto (0);
printf("\nszámítógépek száma=");
scanf ("%d", &szgkSzama);
Szamitogep_laborP[i].Set_szgSzam (szgkSzama);
printf ("hálózati kapcsolat van (I/N)?");
if (toupper(getch()) == 'I')
Szamitogep_laborP[i].Set_haloKapcs (1);
else Szamitogep_laborP[i].Set_haloKapcs (0);
printf ("\n\n");
int y = 0;
for (OP_RENDSZER op = Windows2000; op <= 3; op++, y++)
printf ("%d: %s ", y, opr[op]);
printf ("\ntelepített operációs rendszer sorszáma (0..3)=");
int sorszam;
scanf ("%d", &sorszam);
Szamitogep_laborP[i].Set_opRendszer ( (OP_RENDSZER) sorszam );
clrscr();
}
float ulohelyosszeg;
float db = 0;
float atlag;
for (i = 0; i < szgLaborokSzama; i++)
{
if (Szamitogep_laborP[i].Get_opRendszer() == Windows2000)
{
ulohelyosszeg += Szamitogep_laborP[i].Get_ulohelyekSzama();
db++;
}
}
if (db != 0)
atlag = ulohelyosszeg / db;
else atlag = ulohelyosszeg;
printf ("\nA Windows 2000 operációs rendszert futtató számítógép laborok átlagos ülõhelyszáma= %f", atlag);
delete Szamitogep_laborP;
printf ("\n\nNyomjon meg egy billentyût a kilépéshez!");
getch();
}