Mine sisusse
Otsi siit
  • Rohkem valikuid...
Otsi tulemusi mis sisaldab...
Otsi tulemusi...

Programmeerijate jutunurk

Soovitatud postitused

Keegi teaks mingit veebilehte kust saaks neid veebilehe kavandeid(disaini pilt) orsmth ja võib tasuta võtta ja selle järgi teha? ;) Endal ideid eriti üldse pole :S

http://www.vahvel.net/showthread.php?142241-Lihtne-%F5petus-kuidas-teha-endale-koduleht

Jaga seda postitust


Postituse link
Share on other sites
Free game! :D Kunagi sai niisama ajaviiteks tehtud >_>.

 

Preview: http://alynn.kz.ee/asd.php

Ülialgeline kood:

$start_int = 1;
$end_int = 5;
$guess = $_POST['guess'];
$random = rand($start_int, $end_int);
if(isset($guess)&&!empty($guess)&&is_numeric($guess)) {
if($guess == $random) {
	echo "Correct!";
} else {
	echo "Wrong answer!";
}
}
?>
</pre><form method="post" action="<?php%20echo%20%24PHP_SELF;?>">
Number 1-5: 



</for

 

:)

$arr = array(1, 5);
if(isset($_POST['submit']) && isset($_POST['guess'])) {
$guess = (int)$_POST['guess'];
$random = rand($arr[0], $arr[1]);
echo ($guess == $random ? "Correct!" : "Wrong. Try again.");
}
?>
</pre><form method="post" action="#">
Enter number from =$arr[0]?> to =$arr[1]?> 
<

Muudetud liikme MartL'i poolt

Veebiprogrammeerija & kujundaja

Jaga seda postitust


Postituse link
Share on other sites
Külaline misterx
:)

$arr = array(1, 5);
if(isset($_POST['submit']) && isset($_POST['guess'])) {
   $guess = (int)$_POST['guess'];
   $random = rand($arr[0], $arr[1]);
   echo ($guess == $random ? "Correct!" : "Wrong. Try again.");
}
?>
</pre><form method="post" action="#">
Enter number from =$arr[0]?> to =$arr[1]?> 
<

 

Kontrollime, et number ikka lubatud piirides ka oleks. :)

 

$arr = array(1, 5);
if(isset($_POST['submit']) && isset($_POST['guess'] &&  (int)$_POST['guess']>=$arr[0] &&  (int)$_POST['guess']    $guess = (int)$_POST['guess'];
   $random = rand($arr[0], $arr[1]);
   echo ($guess == $random ? "Correct!" : "Wrong. Try again.");
}
?>
</pre><form method="post" action="#">
Enter number from =$arr[0]?> to =$arr[1]?> 
</for

Muudetud liikme misterx'i poolt

Jaga seda postitust


Postituse link
Share on other sites
Kontrollime, et number ikka lubatud piirides ka oleks. :)

 

$arr = array(1, 5);
if(isset($_POST['submit']) && isset($_POST['guess'])) {
   $guess = (int)$_POST['guess'];
   $random = rand($arr[0], $arr[1]);
   echo ($guess == $random ? "Correct!" : "Wrong. Try again.");
}
?>
</pre><form method="post" action="#">
Enter number from =$arr[0]?> to =$arr[1]?> 
</for

 

:cool:


Veebiprogrammeerija & kujundaja

Jaga seda postitust


Postituse link
Share on other sites
Külaline misterx

Veateade ikka ka. :)

 

$arr = array(1, 5);
if(isset($_POST['submit']) && isset($_POST['guess']) {
   if((int)$_POST['guess']$arr[1])
       print 'Viga!';
   $guess = (int)$_POST['guess'];
   $random = rand($arr[0], $arr[1]);
   echo ($guess == $random ? "Correct!" : "Wrong. Try again.");
}
?>
</pre><form method="post" action="#">
Enter number from =$arr[0]?> to =$arr[1]?> 
</for

Jaga seda postitust


Postituse link
Share on other sites
VIP

Java kood ka :D

import java.util.*;
public class random {
public static void main(String args[]){
	int number = 0, random = 0;
	Scanner scanner = new Scanner(System.in);
        Random randomgenerator = new Random();
        random = randomgenerator.nextInt(5);
	System.out.println("Sisesta number 1-5:");
	number = scanner.nextInt();
         if(random != number){
		System.out.println("Vale arv, proovi uuesti.");
	 }
	 else{
		System.out.println("Õige arv!"); System.out.println("");
	 }		
}
}

Jaga seda postitust


Postituse link
Share on other sites

Javascripti kood ka :D

<br />
function check() {<br />
	var number = document.getElementById('guess').value<br />
	<br />
	var random = Math.floor(Math.random()*6);<br />
	if(random == 0)<br />
		random = 1;<br />
	<br />
	if(random == number)<br />
		document.getElementById('result').innerHTML = 'Tubli! Õige number';<br />
	else<br />
		document.getElementById('result').innerHTML = 'Vale! Proovi uuesti';<br />
}<br />

Enter number from 1 to 5 


Veebiprogrammeerija & kujundaja

Jaga seda postitust


Postituse link
Share on other sites
VIP

Njaa... Javascript veel ei oska. :D

 

Aga btw. uuendasin koodi. Nüüd on ka levelid. :D

Arvad esimese numbri ära, saad teise levelisse ja nii edasi. 5 levelit kokku. :D

BTW. Kuidas saada nii, et random arv pole mitte 0 - x vaid 1-5? Et alustaks lugemist mitte 0 vaid 1-ga.

Kood ise:

import java.util.*;
public class random {
public static void main(String args[]){
	int number = 0, random = 0, number2 = 0, random2 = 0, number3 = 0, random3 = 0, number4 = 0, random4 = 0, number5 = 0, random5 = 0;
	Scanner scanner = new Scanner(System.in);
    Random randomgenerator = new Random();
    random = randomgenerator.nextInt(5);
    System.out.println("LEVEL 1");
	System.out.println("Sisesta number 1-5:");
	number = scanner.nextInt();
	if(random != number){
		System.out.println("Vale arv, proovi uuesti.");
	}
	else{
		System.out.println("Õige arv!"); System.out.println("Läbisite 1. Taseme! Palju õnne!"); System.out.println("");
		System.out.println("----------------------------------------------------------");
	}	

	if(random == number){
		System.out.println(); 
		Scanner scanner2 = new Scanner(System.in);
	    Random randomgenerator2 = new Random();
	    random2 = randomgenerator2.nextInt(5);
	    System.out.println("LEVEL 2");
		System.out.println("Sisesta number 1-5:");
		number2 = scanner2.nextInt();
		if(random2 != number2){
			System.out.println("Vale arv...");
		}
		else{
			System.out.println("Õige arv!"); System.out.println("Läbisite 2. Taseme! Palju õnne!"); System.out.println("");
			System.out.println("----------------------------------------------------------");
		}	

		if(random == number){
			System.out.println(); 
			Scanner scanner3 = new Scanner(System.in);
		    Random randomgenerator3 = new Random();
		    random3 = randomgenerator3.nextInt(5);
		    System.out.println("LEVEL 3");
			System.out.println("Sisesta number 1-5:");
			number3 = scanner3.nextInt();
			if(random3 != number3){
				System.out.println("Vale arv...");
			}
			else{
				System.out.println("Õige arv!"); System.out.println("Läbisite 2. Taseme! Palju õnne!"); System.out.println("");
				System.out.println("----------------------------------------------------------");

			}	

			if(random == number){
				System.out.println(); 
				Scanner scanner4 = new Scanner(System.in);
			    Random randomgenerator4 = new Random();
			    random4 = randomgenerator4.nextInt(5);
			    System.out.println("LEVEL 3");
				System.out.println("Sisesta number 1-5:");
				number4 = scanner4.nextInt();
				if(random4 != number4){
					System.out.println("Vale arv...");
				}
				else{
					System.out.println("Õige arv!"); System.out.println("Läbisite 2. Taseme! Palju õnne!"); System.out.println("");
					System.out.println("----------------------------------------------------------");

				}	

				if(random == number){
					System.out.println(); 
					Scanner scanner5 = new Scanner(System.in);
				    Random randomgenerator5 = new Random();
				    random5 = randomgenerator5.nextInt(5);
				    System.out.println("LEVEL 3");
					System.out.println("Sisesta number 1-5:");
					number5 = scanner4.nextInt();
					if(random5 != number5){
						System.out.println("Vale arv...");
					}
					else{
						System.out.println("Õige arv!"); System.out.println("Tegite mängu läbi! Palju õnne!"); System.out.println("");
					}
				}
			}
		}
	}
}
}

Jaga seda postitust


Postituse link
Share on other sites
VIP
Javascripti kood ka :D

<br />
function check() {<br />
	var number = document.getElementById('guess').value<br />
	<br />
	var random = Math.floor(Math.random()*6);<br />
	if(random == 0)<br />
		random = 1;<br />
	<br />
	if(random == number)<br />
		document.getElementById('result').innerHTML = 'Tubli! Õige number';<br />
	else<br />
		document.getElementById('result').innerHTML = 'Vale! Proovi uuesti';<br />
}<br />

Enter number from 1 to 5 

 

 

Javascript ikka palju lühem, kui Java ise. :D

Jaga seda postitust


Postituse link
Share on other sites
Javascript ikka palju lühem, kui Java ise. :D

Pigem on sinu kood pikk.


"What is happening to our young people? They disrespect their elders, they disobey their parents. They ignore the law. They riot in the streets inflamed with wild notions. Their morals are decaying. What is to become of them?"

Plato, 4th Century BC

Jaga seda postitust


Postituse link
Share on other sites
VIP

Seda ka muidugi. :D

 

Njah, ma olengi veel javaga suht alguses. Kood tekib minu käte vahel kohe liiga pikk. :D

Jaga seda postitust


Postituse link
Share on other sites

Levelitega PHP versioon, igal levelil muutuvad numbrid suuremaks :)

 

session_start();

if(!isset($_SESSION['level']))
$_SESSION['level'] = 1;

$arr = array(1, $_SESSION['level']*5);
if(isset($_POST['submit']) && isset($_POST['guess'])) {
$guess = (int)$_POST['guess'];
$random = rand($arr[0], $arr[1]);
if ($guess == $random)
	$_SESSION['level']++;
}

echo "Oled ".$_SESSION['level'].". levelil! Edu!
";

if(isset($random)) {
echo ($guess == $random ? "Õige! Said järgmisele levelile!" : "Vale! Jääd seda levelit kordama!");
}
?>
</pre><form method="post" action="#">
Enter number from =$arr[0]?> to =$arr[1]?> 

</for


Veebiprogrammeerija & kujundaja

Jaga seda postitust


Postituse link
Share on other sites
VIP

Iga leveliga random suuremaks... sõnatu.. Vähemalt ei saa sa enam kunagi öelda, et sul pole tegevust. :D

 

Mitmendasse levelisse ise jõudnud oled ka? :D

Ise jõudisin oma mängus 4. levelisse. :D Kokku 5. :D

Jaga seda postitust


Postituse link
Share on other sites
VIP

Uuendasin ka oma koodi. :D

import java.util.Random;
import java.util.Scanner;
public class lol {
public static void main(String args[]){
	int random991 = 0, number = 0, random = 0, number2 = 0, random2 = 0, number3 = 0, random3 = 0, number4 = 0, random4 = 0, number5 = 0, random5 = 0;
	Scanner scanner = new Scanner(System.in);
    Random randomgenerator = new Random();
    random = randomgenerator.nextInt(4);
    random991 = random + 1;
	System.out.println("----------------------------------------------------------");
    System.out.println("LEVEL 1");
	System.out.println("Sisesta number 1-5:");

	while(true){number = scanner.nextInt();
	if(random991 != number){
		System.out.println("Vale arv, proovi uuesti.");
	}
	else{
		System.out.println("Õige arv!"); System.out.println("Läbisite 1. Taseme! Palju õnne!"); System.out.println("");
		System.out.println("----------------------------------------------------------");

		if(random991 == number){
			System.out.println(); 
			Scanner scanner2 = new Scanner(System.in);
			Random randomgenerator2 = new Random();
			random2 = randomgenerator2.nextInt(5);
			System.out.println("LEVEL 2");
			System.out.println("Sisesta number 1-5:");
			number2 = scanner2.nextInt();
			if(random2 != number2){
			System.out.println("Vale arv, proovi uuesti.");
		}
		else{
			System.out.println("Õige arv!"); System.out.println("Läbisite 2. Taseme! Palju õnne!"); System.out.println("");
			System.out.println("----------------------------------------------------------");	

		if(random991 == number){
			System.out.println(); 
			Scanner scanner3 = new Scanner(System.in);
		    Random randomgenerator3 = new Random();
		    random3 = randomgenerator3.nextInt(5);
		    System.out.println("LEVEL 3");
			System.out.println("Sisesta number 1-5:");
			number3 = scanner3.nextInt();
			if(random3 != number3){
				System.out.println("Vale arv, proovi uuesti.");
			}
			else{
				System.out.println("Õige arv!"); System.out.println("Läbisite 2. Taseme! Palju õnne!"); System.out.println("");
				System.out.println("----------------------------------------------------------");

			if(random991 == number){
				System.out.println(); 
				Scanner scanner4 = new Scanner(System.in);
			    Random randomgenerator4 = new Random();
			    random4 = randomgenerator4.nextInt(5);
			    System.out.println("LEVEL 3");
				System.out.println("Sisesta number 1-5:");
				number4 = scanner4.nextInt();
				if(random4 != number4){
					System.out.println(", proovi uuesti.");
				}
				else{
					System.out.println("Õige arv!"); System.out.println("Läbisite 2. Taseme! Palju õnne!"); System.out.println("");
					System.out.println("----------------------------------------------------------");

				if(random991 == number){
					System.out.println(); 
					Scanner scanner5 = new Scanner(System.in);
				    Random randomgenerator5 = new Random();
				    random5 = randomgenerator5.nextInt(5);
				    System.out.println("LEVEL 3");
					System.out.println("Sisesta number 1-5:");
					number5 = scanner5.nextInt();
					if(random5 != number5){
						System.out.println("Vale arv, proovi uuesti.");
					}
					else{
						System.out.println("Õige arv!"); System.out.println("Tegite mängu läbi! Palju õnne!"); System.out.println("");
					}
				}
				}
			}
			}
		}
		}
		}
	}
}
}
}


Jaga seda postitust


Postituse link
Share on other sites
Uuendasin ka oma koodi. :D

import java.util.Random;
import java.util.Scanner;
public class lol {
   public static void main(String args[]){
       int random991 = 0, number = 0, random = 0, number2 = 0, random2 = 0, number3 = 0, random3 = 0, number4 = 0, random4 = 0, number5 = 0, random5 = 0;
       Scanner scanner = new Scanner(System.in);
       Random randomgenerator = new Random();
       random = randomgenerator.nextInt(4);
       random991 = random + 1;
       System.out.println("----------------------------------------------------------");
       System.out.println("LEVEL 1");
       System.out.println("Sisesta number 1-5:");

       while(true){number = scanner.nextInt();
       if(random991 != number){
           System.out.println("Vale arv, proovi uuesti.");
       }
       else{
           System.out.println("Õige arv!"); System.out.println("Läbisite 1. Taseme! Palju õnne!"); System.out.println("");
           System.out.println("----------------------------------------------------------");

           if(random991 == number){
               System.out.println(); 
               Scanner scanner2 = new Scanner(System.in);
               Random randomgenerator2 = new Random();
               random2 = randomgenerator2.nextInt(5);
               System.out.println("LEVEL 2");
               System.out.println("Sisesta number 1-5:");
               number2 = scanner2.nextInt();
               if(random2 != number2){
               System.out.println("Vale arv, proovi uuesti.");
           }
           else{
               System.out.println("Õige arv!"); System.out.println("Läbisite 2. Taseme! Palju õnne!"); System.out.println("");
               System.out.println("----------------------------------------------------------");    

           if(random991 == number){
               System.out.println(); 
               Scanner scanner3 = new Scanner(System.in);
               Random randomgenerator3 = new Random();
               random3 = randomgenerator3.nextInt(5);
               System.out.println("LEVEL 3");
               System.out.println("Sisesta number 1-5:");
               number3 = scanner3.nextInt();
               if(random3 != number3){
                   System.out.println("Vale arv, proovi uuesti.");
               }
               else{
                   System.out.println("Õige arv!"); System.out.println("Läbisite 2. Taseme! Palju õnne!"); System.out.println("");
                   System.out.println("----------------------------------------------------------");

               if(random991 == number){
                   System.out.println(); 
                   Scanner scanner4 = new Scanner(System.in);
                   Random randomgenerator4 = new Random();
                   random4 = randomgenerator4.nextInt(5);
                   System.out.println("LEVEL 3");
                   System.out.println("Sisesta number 1-5:");
                   number4 = scanner4.nextInt();
                   if(random4 != number4){
                       System.out.println(", proovi uuesti.");
                   }
                   else{
                       System.out.println("Õige arv!"); System.out.println("Läbisite 2. Taseme! Palju õnne!"); System.out.println("");
                       System.out.println("----------------------------------------------------------");

                   if(random991 == number){
                       System.out.println(); 
                       Scanner scanner5 = new Scanner(System.in);
                       Random randomgenerator5 = new Random();
                       random5 = randomgenerator5.nextInt(5);
                       System.out.println("LEVEL 3");
                       System.out.println("Sisesta number 1-5:");
                       number5 = scanner5.nextInt();
                       if(random5 != number5){
                           System.out.println("Vale arv, proovi uuesti.");
                       }
                       else{
                           System.out.println("Õige arv!"); System.out.println("Tegite mängu läbi! Palju õnne!"); System.out.println("");
                       }
                   }
                   }
               }
               }
           }
           }
           }
       }
   }
}
}


 

Proovi see teha universaalsemaks, ehk seal ei oleks limiiti.

Lisasin siis ise XPi sisse :)

´session_start();

if(!isset($_SESSION['level']))
   $_SESSION['level'] = 1;
if(!isset($_SESSION['xp']))
   $_SESSION['xp'] = 0;

$arr = array(1, $_SESSION['level']*5);
if(isset($_POST['submit']) && isset($_POST['guess'])) {
   $guess = (int)$_POST['guess'];
   $random = rand($arr[0], $arr[1]);
   if ($guess == $random){
       $_SESSION['xp'] += 10;
       if($_SESSION['xp'] >= toLevel($_SESSION['level'] + 1)){
           echo "Õnnitlused uue leveli puhul!";
           $_SESSION['level']++;
       }
   }
}

echo "Oled ".$_SESSION['level'].". levelil ".$_SESSION['xp']." kogemusega, ".(toLevel($_SESSION['level'] + 1) - $_SESSION['xp'])." veel järgmise levelini!
";

if(isset($random)) {
   echo ($guess == $random ? "Õige! Said 10 kogemust juurde." : "Vale! Ei saa kogemust juurde!");
}

function toLevel($wanted){
   return 20*$wanted;
}
?>
</pre><form method="post" action="#">
Enter number from  to 

<


"What is happening to our young people? They disrespect their elders, they disobey their parents. They ignore the law. They riot in the streets inflamed with wild notions. Their morals are decaying. What is to become of them?"

Plato, 4th Century BC

Jaga seda postitust


Postituse link
Share on other sites
VIP

Tegin koodi lühemaks. Nüüd on lõpmatuseni leveleid ka. :D

 

   import java.util.Random;
   import java.util.Scanner;
   public class kjh {
           public static void main(String args[]){

                   int number = 0, random, level=1, random0=0, random20;
               Random randomgenerator = new Random();

               while(true){
               System.out.println("-----------------");
                   System.out.println("LEVEL "+level);

                   random0 = randomgenerator.nextInt(4);
               random = random0 + 1;

               Scanner scanner = new Scanner(System.in);
                   number = scanner.nextInt();
                   if(random == number){
                           System.out.println("Õige arv! Said järgmisesse levelisse!");
                            level++;
                   }
                   if(random != number){
                           System.out.println("Vale arv.. ");
                           int arv2 = level - 1;
                           System.out.println("Sinu score: "+arv2);
                           level = 1;
                   }

               }
           }
   }

Jaga seda postitust


Postituse link
Share on other sites
VIP

Tegin omal random arvu ära arvamise ka paremaks. :D

10 arvu peab ära arvama. Mida täpsemalt pakud, seda rohkem punkte saad. Arvud on vahemikus 1-5. Kui arvad õigesti, saad 5 punkti. Ühega mööda - 4 punkti jne.

 

import java.util.Random;
import java.util.Scanner;
public class random {
public static void main(String args[]){
	int number = 0, random, level=1, random0=0, viga, score=0, score2=0;
    Random randomgenerator = new Random();
    Scanner scanner = new Scanner(System.in);
    System.out.println("Suvalise numbri ära arvamise mäng."); 
    System.out.println("Arva ära 10 numbrit. Numbrid on vahemikus 1-5. Mida täpsemalt numbri ära arvad, seda rohkem punkte kogud. Max punktide arv: 50");
    while(level		    try{
    	System.out.println("-----------------");
    	System.out.println("LEVEL "+level);
    	System.out.print("Teie valitud number: ");
    	random0 = randomgenerator.nextInt(4);
    	random0 = randomgenerator.nextInt(4);
    	random = random0 + 1;
    	//System.out.println("Random: "+random);
    	//System.out.println("Score: "+score);
    	scanner.reset();
    	number = scanner.nextInt();
    	if(number = 1){
    		if(number=1){
    			if(random == number){
    				level++;
    				score2 = 5;
    				score = score + score2;
    			}
    			if(random != number){
    				level++;
    				viga = random - number;
    				viga = Math.abs(viga);
    				score2 = 5 - viga;
    				score = score + score2;
    			}
    		}
    	}
    	if(number>=6){
    		System.out.println("--Vale number--");
    	}
    }catch(Exception e){ 
    	System.out.println("--Vale number--");
    	scanner = new Scanner(System.in);
    }
    }
    System.out.println("-----------------");
   	System.out.println("Mäng läbi");
	System.out.println("Koguseite "+score+" punkti.");
}
}

Jaga seda postitust


Postituse link
Share on other sites
VIP

Jaga seda postitust


Postituse link
Share on other sites

Kommentaari lisamiseks loo konto või logi sisse

Kommenteerimiseks peate olema liige

Loo konto

Liituge meie kommuuni uue kontoga. See on lihtne!

Loo uus konto

Logi sisse

On juba konto? Logi sisse siit.

Logi sisse nüüd

×
×
  • Loo uus...

Oluline informatsioon

Selle veebisaidi paremaks muutmiseks oleme teie seadmesse paigutanud küpsised . Võite kohandada oma küpsiste seadeid , vastasel juhul eeldame, et te olete küpsiste kasutamisega nõus kui jätkate veebisaidil sirvimist.. Palun lugege läbi Kasutustingimused ja Privaatsuspoliitika.