• Create Account

# Cuajin

Member Since 10 Aug 2007
Offline Last Active Aug 14 2012 06:14 PM

### Android Shake Method

14 August 2012 - 07:20 AM

In my game I want the player to shake his phone, at any point during the game, and every shake will result in switching weapons.
Example: Player has knife, [shakes phone] and switches to a katana.

```if (accelerometer.x >= 5 || accelerometer.x <= -5
|| accelerometer.y >= 5 || accelerometer.y <= -5
|| accelerometer.z >= 5 || accelerometer.z <= -5 )
switchWep();
```

This works, the problem is it has a side effect.When the player shakes the phone sometimes it switches weapons twice. So I want to limit it so that if there is a big shake the game doesn't switch from weapon 0 to weapon 2.

### LC-3 Assembly problem

11 July 2012 - 09:42 PM

So I am trying to create a game in assembly just for fun.

EDIT: Please read my second post, it simplifies my question a lot.

In the game you have an inventory and some items. Must the game is actually finished already, and each subroutine works. However, I am having problems printing to the screen.

I have printed to the screen before but it was a pain.

I’m trying to create a function (subroutine) to display the binary content of R0 to the console. So I want it to print 1 or 0 for each bit; which will mean something in the game. I start in R0[15]…R0[0] end there.

```PRINT
ST R7, PRS7
ST R3, PRS3
;AND  R3, R3, #0

LOOP
AND  R0, R0, R3
BRp CHECK
TRAP  x21
BRnzp DOWN
ELSE AND  R0, R0, #0
TRAP  x21
DOWN
LD R3, PRS3
LD R7, PRS7
PRS7 .BLKW 1
PRS3 .BLKW 1
```

### Array Find Largest Recursively

18 April 2012 - 04:28 PM

Hi. I understand recursion is not good for this sort of operation, but I am trying to learn.

I want to find the position of the largest int in an array recursively.

myList = {5, 2, 3 , 1, 22, 4, 9} ;

```public int findIndex(int[] myList, int size)
{
if (size == 1)
return size-1;

return myList[size-1] > findIndex(myList, size-1) ? size-1 : size ;
}
```

My code produces this output: position 6. Which is wrong.

How do I do this?

### Exchange the position of two Nodes [Java]

06 April 2012 - 01:21 PM

I’m trying to exchange the position of two nodes a and b.

I have the Node class that helps me create a list.
```class Node
{
E info;
Node next;

Node (E x)
{
next = null;
info = x;
}
}
```

Then I have class List.
```public class List<E>
{
// some methods like addToList(). They work.

// Problem here!
public void exchangeNodes(int a, int b)
{

{
// here I wrote a bunch of noob code that if you looked at it your eyes would hurt.
}
}
```

TestClass
```public class TestClass
{
List myList = new List();
// populating the list with strings.

myList.exchange(2, 5); // giving it position numbers to exchange.
}
```

The big problem is I can't get it to switch the Node's position on the list without destroying Nodes (I lose the reference to pointers when I switch). Clearly Nodes and me don't like each other

From the TestClass I want to say exchange what's on position 2 with what is on position 5.

### Reading from a File [Java]

05 April 2012 - 05:53 AM

I am trying to read the inventory for a game in a text file. The inventory looks like this:
```Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5
```

I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1 int. The ints are the stats of the item.

```Scanner read = new Scanner(new File("inventory.txt")) ;