CodingJavascript help

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Peter (BOUGHTONP)  
 To:  Wattsy (SLAYERPUNX)      
37533.14 
And one more post, in a last ditch attempt to not have to go write a really boring report thing - this is all based on there only ever being two players.

It's good practise to write more modular code that can be used for other purposes - for this example, multi-player turn-based switching can be done with very little extra work:

code:
function switchCurrentPlayer()
{
	currentPlayer++
 
	if ( currentPlayer > PlayerCount )
	{
		currentPlayer=1
	}
 
}


Set PlayerCount to any number, and this will cycle through them in order, whether there is 2 or 20 players.

(The "++" just means "add one")


Anyway, I better get on with wasting time doing what I'm supposed to be doing right now. :(
0/0
 Reply   Quote More 

 From:  koswix  
 To:  Drew (X3N0PH0N)     
37533.15 In reply to 37533.11 
Don't show me these things when I am busy k thx :(


GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

 From:  Drew (X3N0PH0N)  
 To:  koswix     
37533.16 In reply to 37533.15 
(giggle)

0/0
 Reply   Quote More 

 From:  Wattsy (SLAYERPUNX)   
 To:  Peter (BOUGHTONP)     
37533.17 In reply to 37533.14 

Wow, just wow.

 

Peter, why are you not ruling the world, or even just Britain by now?

 

The last email made a lot more sense to me and is in the style of scripting that the OU is teaching.

 

Come one peter, become that evil genius we all know and love.

Web Shite Mail Me

0/0
 Reply   Quote More 

 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  Peter (BOUGHTONP)     
37533.18 In reply to 37533.14 
Huh? I don't get that. Surely to cycle through you'll need a while or for loop?

bastard by name, bastard by nature

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  99% of gargoyles look like (MR_BASTARD)     
37533.19 In reply to 37533.18 
Possibly badly worded - by "cycle through" I just meant each time called you'd get the appropriate next player - you'd call the function at the end of each player's turn (which in most games is a manually triggered event).
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Wattsy (SLAYERPUNX)      
37533.20 In reply to 37533.17 
I don't know why. :(

Am I not allowed to be a non-evil one?
0/0
 Reply   Quote More 

 From:  koswix  
 To:  Peter (BOUGHTONP)     
37533.21 In reply to 37533.20 
No, Google called dibs on that one.


GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

 From:  Wattsy (SLAYERPUNX)   
 To:  koswix     
37533.22 In reply to 37533.21 
Google is teh evil, you just wait! They will have chickens with lasers on their heads before long.

Web Shite Mail Me

0/0
 Reply   Quote More 

 From:  koswix  
 To:  Wattsy (SLAYERPUNX)      
37533.23 In reply to 37533.22 
As long as they still do regular firmware updates for Android, who cares?


GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

 From:  Wattsy (SLAYERPUNX)   
 To:  koswix     
37533.24 In reply to 37533.23 
My desire is lacking the 2.2 goodness, therefore they are evil.

Web Shite Mail Me

0/0
 Reply   Quote More 

 From:  koswix  
 To:  Wattsy (SLAYERPUNX)      
37533.25 In reply to 37533.24 
Soon, my precious.


GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

 From:  koswix  
 To:  Wattsy (SLAYERPUNX)      
37533.26 In reply to 37533.24 
http://www.phonesreview.co.uk/2010/06/21/htc-desire-android-2-2-ota-update-on-its-way/


GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  koswix     
37533.27 In reply to 37533.21 
Google is more of just a non-evil empire.

If they were really geniuses they would have created a proper GUI API for Android, instead of the ridiculous shit they actually used.
0/0
 Reply   Quote More 

 From:  koswix  
 To:  Peter (BOUGHTONP)     
37533.28 In reply to 37533.27 

I want to make a really simple app for Android, just three or 4 input boxes which then give a mathematical answer when you press submit.

 

How hard should that be?



GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  koswix     
37533.29 In reply to 37533.28 
It shouldn't be hard at all.

But I'd recommend doing it with HTML and using PhoneGap (or similar) to convert it, to avoid really icky XML.



Here's a quick example - if you want to do this with Android:




The Android UI example code for that is this:
XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Type here:"/>
    <EditText
        android:id="@+id/entry"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background"
        android:layout_below="@id/label"/>
    <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/entry"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="10dip"
        android:text="OK" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/ok"
        android:layout_alignTop="@id/ok"
        android:text="Cancel" />
</RelativeLayout>


All those silly android:layout_ bits do my head in.

A far nicer (though still not perfect) way would have been:
XML code:
<RelativeLayout layout="width:fill;height:fill">
 
	<Text id="label" text="Type Here:" />
 
	<Edit id="entry" />
 
	<Button id="ok" text="OK" />
 
	<Button id="cancel" text="Cancel" />
 
	<Layout>
		#label
		{
			width:fill; height:wrap;
		}
		#entry
		{
			width:fill; height:wrap;
			below:#label;
		}
		#ok
		{
			width:wrap; height:wrap;
			below:#id;
			alignRight:parent;
			marginLeft:10dip;
		}
		#cancel
		{
			width:wrap; height:wrap;
			toLeftOf:#ok;
			alignTop:#ok;
		}
	</Layout>
 
</RelativeLayout>



Which could be compared to a HTML+CSS equivalent:

HTML code:
<body style="width:100%;height:100%">
 
	<label id="label">Type Here:</div>
 
	<input type="text" id="entry" />
 
	<button id="ok">OK</button>
 
	<button id="cancel">Cancel</button>
 
	<style>
		#label
		{
			width:100%; height:auto;
			display:block;
		}
		#entry
		{
			width:100%; height:auto;
			display:block;
		}
		#ok
		{
			width:auto; height:auto;
			float:right; clear: right;
			margin-left:10px;
		}
		#cancel
		{
			width:auto; height:auto;
			float:right; clear: none;
		}
	</style>
 
</body>



But anyway, that's just me ranting and not really what you asked. :S
0/0
 Reply   Quote More 

 From:  koswix  
 To:  Peter (BOUGHTONP)     
37533.30 In reply to 37533.29 
Tell you what, you make it for me and I'll buy you a pint at Teh Invasion.


GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

 From:  koswix  
 To:  Peter (BOUGHTONP)     
37533.31 In reply to 37533.29 
Oh, and your link doesn't work :@


GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  koswix     
37533.32 In reply to 37533.31 
Ooops. Fixed it. Was just phonegap.com anyhow.

Tell me what you want, and if it will only take a few minutes I'll maybe do it tonight or tomorrow. :)
0/0
 Reply   Quote More 

 From:  koswix  
 To:  Peter (BOUGHTONP)     
37533.33 In reply to 37533.32 
Aww, bless.

Input the following:

Number of beers in a pack

Size of beers in ml

ABV of beer

Price of pack of beer

output:

Price of beer per litre

Price per can/bottle

units of alcohol per litre (10 ml of alcohol = 1 unit)

price of of a unit of alcohol.


GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

Reply to All  
 

1–20  21–40  41–47

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats