snakegame multi-controller functionality
This commit is contained in:
parent
cd6527afb3
commit
e2ad89c25e
|
@ -218,6 +218,7 @@ namespace RPI_Matrix {
|
|||
isSnake = true;
|
||||
isInGame = true;
|
||||
selection = false;
|
||||
SnakeGame.SnakeGame.players = gamepadListeners;
|
||||
SnakeGame.SnakeGame.Main(new[] { arg });
|
||||
}
|
||||
|
||||
|
@ -246,17 +247,21 @@ namespace RPI_Matrix {
|
|||
IEnumerable<string> files = from retrieved in Directory.EnumerateFiles(dir)
|
||||
where retrieved.Contains("js")
|
||||
select retrieved;
|
||||
foreach (string f in files)
|
||||
if (!gamepadListeners.Contains(f)) {
|
||||
gamepadListeners.Add(f);
|
||||
foreach (string f in files) {
|
||||
string name = f.Replace(dir, "");
|
||||
if (!gamepadListeners.Contains(name)) {
|
||||
gamepadListeners.Add(name);
|
||||
new Thread(() => {
|
||||
try {
|
||||
WatchInputFile(dir, f);
|
||||
} catch (Exception) {
|
||||
gamepadListeners.Remove(f);
|
||||
}
|
||||
catch (Exception) {
|
||||
gamepadListeners.Remove(name);
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
@ -299,7 +304,7 @@ namespace RPI_Matrix {
|
|||
private static void RightArrowPressed(string player) {
|
||||
// Code for Arrow-Right Press
|
||||
// If in SnakeGame, Steer the Snake to the right
|
||||
if (isSnake) SnakeGame.SnakeGame.SteerRight(SnakeGame.SnakeGame.self);
|
||||
if (isSnake) SnakeGame.SnakeGame.SteerRight(SnakeGame.SnakeGame.snakes[player]);
|
||||
// If in Tetris, move current Block to the right
|
||||
else if (isTetris) Tetris.Tetris.moveRightSide();
|
||||
}
|
||||
|
@ -307,7 +312,7 @@ namespace RPI_Matrix {
|
|||
private static void LeftArrowPressed(string player) {
|
||||
// Code for Arrow-Left Press
|
||||
// If in SnakeGame, Steer the Snake to the left
|
||||
if (isSnake) SnakeGame.SnakeGame.SteerLeft(SnakeGame.SnakeGame.self);
|
||||
if (isSnake) SnakeGame.SnakeGame.SteerLeft(SnakeGame.SnakeGame.snakes[player]);
|
||||
// If in Tetris, move current Block to the left
|
||||
else if (isTetris) Tetris.Tetris.moveLeftSide();
|
||||
}
|
||||
|
@ -323,7 +328,7 @@ namespace RPI_Matrix {
|
|||
if (SnakeGame.SnakeGame.selection && SnakeGame.SnakeGame.selectionIndex < 1)
|
||||
SnakeGame.SnakeGame.selectionIndex++;
|
||||
// If in SnakeGame, Steer the Snake downwards
|
||||
else SnakeGame.SnakeGame.SteerDown(SnakeGame.SnakeGame.self);
|
||||
else SnakeGame.SnakeGame.SteerDown(SnakeGame.SnakeGame.snakes[player]);
|
||||
// If in Tetris and in Tetris' 'GameOver' Screen, decrement its index.
|
||||
}
|
||||
else if (isTetris)
|
||||
|
@ -354,7 +359,7 @@ namespace RPI_Matrix {
|
|||
if (SnakeGame.SnakeGame.selection && SnakeGame.SnakeGame.selectionIndex > 0)
|
||||
SnakeGame.SnakeGame.selectionIndex--;
|
||||
// If in SnakeGame, Steer the Snake upwards
|
||||
else SnakeGame.SnakeGame.SteerUp(SnakeGame.SnakeGame.self);
|
||||
else SnakeGame.SnakeGame.SteerUp(SnakeGame.SnakeGame.snakes[player]);
|
||||
// If in Tetris and in Tetris' 'GameOver' Screen, decrement its index.
|
||||
}
|
||||
else if (isTetris && Tetris.Tetris.selection && Tetris.Tetris.selectionIndex > 0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user