elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
27 Mayo 2012, 10:13  


Tema destacado: Únete al Grupo Steam elhacker.NET

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Ejercicios
| | | |-+  juego de la serpiente en c++
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: juego de la serpiente en c++  (Leído 4,748 veces)
ybag

Desconectado Desconectado

Mensajes: 1


Ver Perfil
juego de la serpiente en c++
« en: 21 Enero 2008, 22:19 »

hola necesito un juego de la serpiente en c++ >:(


En línea
bug_over

Desconectado Desconectado

Mensajes: 173


mv Linux GNU/linux


Ver Perfil WWW
Re: juego de la serpiente en c++
« Respuesta #1 en: 17 Febrero 2008, 19:21 »

Hi tengo uno pero está en su hijo en javascript, bueno ve la logica y lo pasas a C/C++  yo lo haria pero la neta no tengo time prueba este code corre unicamente en Internet explorer bueno saludos pess

Código:
<!-- THREE STEPS TO INSTALL SNAKE:

  1.  Put the first code in your opening HTMl document -->
  2.  Save the remaining code to a new file, save as snake.html  -->
  3.  Upload all the snake images to the same web site directory -->

<!-- STEP ONE: Paste this code into the opening HTML document  -->

<center>
<form name="open-snake">
<input type=button value="Play Snake" onClick="window.open('snake.html','snake','top=100,left=100,width=575,height=400');">
</form>
</center>

<!-- STEP TWO: Paste this code into a new document, save it as snake.html  -->

<HEAD>

<STYLE TYPE="text/css">
.item{}
.worm1 {
  font-weight:bold;
  font-size:12pt;
  color:blue;
  background:white;
  width:150px;
  BORDER-BOTTOM: #ffffff solid 0px;
  BORDER-TOP: #ffffff solid 0px;
  BORDER-LEFT: #ffffff solid 0px;
  BORDER-RIGHT: #ffffff solid 0px;
}
.worm2 {
  font-weight:bold;
  font-size:12pt;
  color:red;
  background:white;
  width:150px;
  BORDER-BOTTOM: #ffffff solid 0px;
  BORDER-TOP: #ffffff solid 0px;
  BORDER-LEFT: #ffffff solid 0px;
  BORDER-RIGHT: #ffffff solid 0px;
}
.info {
  font-weight:bold;
  font-size:10pt;
  color:black;
  background:white;
  width:150px;
  height:100px;
  BORDER-BOTTOM: #ffffff solid 0px;
  BORDER-TOP: #ffffff solid 0px;
  BORDER-LEFT: #ffffff solid 0px;
  BORDER-RIGHT: #ffffff solid 0px;
}
</style>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="javascript">
<!-- Original:  Clayton Carlson (clayton@awebmaker.com) -->
<!-- Web Site:  http://www.awebmaker.com -->

<! >
<! >

<!-- Begin
var height = 20; //height of the game area
var width = 20; //width of the game area
var speed = 100 //speed, higher = slower
width += 2;
var a = 0;
var b = 0;
document.write("<table bgcolor=white bordercolor=black ");
document.write("align=center border=1 cellpadding=0 cellspacing=0><tr><td>");
for (b = 0; b < height+2; b++) {
document.write("<img src=end.gif width=0 height=0>");
for (a = 0; a < width- 2; a++) {
if ((b == 0) || (b == height+1)) {
document.write("<img src=end.gif width=0 height=0>");
}
else {
document.write("<img src=blank.gif width=15 height=15>");
   }
}
document.write("<img src=end.gif width=0 height=0><br>");
}
document.write("</td>");
document.write("<td valign=top align=center bgcolor=white>");
document.write("<p align=center><strong><font color=blue>Snake</font></strong></p>");
document.write("<br>");
document.write("<form name=info>");
document.write("<input type=button size=28 value=0 class=worm1></form>");
document.write("<br><font size=-2>Press any arrow key to start</font></td></tr></table>");

var points = 0;
var go = 1;
var di = 0;
var x = 0;
var y = 0;
var n = 0;
document.images[1].src = "blank.gif";
var blank = document.images[1].src;
var hw = (height * width);
var o = Math.floor(Math.random() * hw - 2);
do {
o = Math.floor(Math.random() * hw-2);
} while(document.images[o].src != blank);
var i = o;
var food = 0;
do {
food = Math.floor(Math.random() * hw-2);
} while (document.images[food].src != blank);
document.images[i].src = "worm.gif";
document.images[width-1].src="end.gif";
var end = document.images[width-1].src;
var file = document.images[i].src;
var length = 1;
var worm = new Array();
var k = 0;
var ie = document.all ? 1 : 0;
var  enableScroll = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >3)) ;
var height = document.images[0].height;
var tScroll;
var d = 0;
function runTimer() {
if (d != 0) { n++; }
if (d == 1) { i--; }
if (d == 2) { i++; }
if (d == 3) { i += width; }
if (d == 4) { i -= width; }
if (document.images[i].src == end) {
speed -= 400; i = worm[n-1]; di = 1; die();
}
worm[n] = i;
if(i == food) {
length++; points += (10*length);
do {
food = Math.floor(Math.random() * hw-2);
} while (document.images[food].src != blank);
if (di == 0) {
document.info.elements[0].value = points;
   }
}
if (n > length){
o = worm[n-length];
}
if ((document.images[i].src == file) && (n > 1)) {
speed -= 400; d = 0; di = 1; die();
}
if(di == 0) {
document.images[o].src = "blank.gif";
document.images[i].src = "worm.gif";
document.images[food].src = "food.gif";
tScroll = window.setTimeout("runTimer();", speed);
   }
}
if (enableScroll){
if (ie) window.onload = runTimer;
if (ie) window.onunload = new Function("clearTimeout(tScroll)");
}
systm = "";
ver = navigator.appVersion;
len = ver.length;
for (iln = 0;iln < len; iln++) if (ver.charAt(iln) == "(") break;
systm = ver.charAt(iln+1).toUpperCase();
document.onkeydown = keyDown;
if (systm != "C") {
document.captureEvents(Event.KEYDOWN);
}
function keyDown(DnEvents) {
if (systm != "C") {
k = DnEvents.which;
} else {
k = window.event.keyCode;
}
if (k == 37) { d = 1; }
if (k == 39) { d = 2; }
if (k == 40) { d = 3; }
if (k == 38) { d = 4; }
}
function die() {
i = 0;
o = 0;
food = 0;
document.info.elements[0].value = "Died with " + document.info.elements[0].value;
var restart=confirm("Play Again?");
if(restart){ location.reload(); }
}
// End -->
</script>


<!-- STEP THREE: You will need these images for this game: -->
<!-- ../img/snake/snake.zip -->


<p><center>
<font face="arial, helvetica" SIZE="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">javascript Source Code 3000</a></font>
</center><p>


En línea
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
juego de la serpiente
Programación C/C++
inegue 1 664 Último mensaje 8 Noviembre 2011, 17:40
por Eternal Idol
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines