public Game(Context context, GameView view) { this.view = view; // Dialogs are context dependent so this check allows the view to validate in the layout viewer if (!view.isInEditMode()) { // Setup the positive button action for the new round dialog pop-up view.getNewRound() .setButton( -1, context.getString(R.string.okay), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); reset(); } }); } // Setup the 2 block resources brown = BitmapFactory.decodeResource(context.getResources(), R.drawable.brick_brown); red = BitmapFactory.decodeResource(context.getResources(), R.drawable.brick_red1); // Setup the rest setup(); }
/** sources a list of representions like this sample : 18|16|2|I3|0,-1|0,0|0,1 */ private void source() { List<Move> list = new ArrayList<Move>(); try { FileInputStream fis = openFileInput("moves.txt"); BufferedReader reader = new BufferedReader(new InputStreamReader(fis)); String line; reader.readLine(); // first line give the # of moves... while ((line = reader.readLine()) != null) { String[] data = line.split(":"); int i = new Integer(data[0]); int j = new Integer(data[1]); int color = new Integer(data[2]); Piece piece = game.game.boards.get(color).findPieceByType(data[3]); piece.reset(); for (int q = 4; q < data.length; q++) { String[] position = data[q].split(","); int x = new Integer(position[0]); int y = new Integer(position[1]); piece.add(new Square(x, y)); } Move move = new Move(piece, i, j); // Log.d(tag, "created move : " + move); list.add(move); } newgame(); game.replay(list); game.reorderPieces(); } catch (Exception e) { Log.e(tag, "yep error is :", e); } }
@Override public void run() { long tickPS = 1000 / FPS; long startTime; long sleepTime; while (isRunning) { Canvas c = null; startTime = System.currentTimeMillis(); try { c = gameView.getHolder().lockCanvas(); synchronized (gameView.getHolder()) { gameView.draw(c); } } finally { if (c != null) { gameView.getHolder().unlockCanvasAndPost(c); } } sleepTime = tickPS - (System.currentTimeMillis() - startTime); try { if (sleepTime > 0) sleep(sleepTime); else sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } }
@Override public void run() { long ticksPS = 1000 / FPS; long startTime; long sleepTime; while (running) { mGameCanvas = null; startTime = System.currentTimeMillis(); try { mGameCanvas = mGameView.getHolder().lockCanvas(); synchronized (mGameView.getHolder()) { mGameView.update(); if (mGameCanvas != null) mGameView.draw(mGameCanvas); } } finally { if (mGameCanvas != null) { mGameView.getHolder().unlockCanvasAndPost(mGameCanvas); } } sleepTime = ticksPS - (System.currentTimeMillis() - startTime); try { if (sleepTime > 0) sleep(sleepTime); else sleep(10); } catch (Exception e) { } } }
/** Initialize the Listener for the screen (general touch OR screenButtons) */ public void intializeTouch() { if (TouchInput.use) { gameView.setOnTouchListener(touch); } else if (OnScreenButtons.use) { Log.d("ButtonEnabled", "USING ON SCREEN BUTTONS"); gameView.setOnTouchListener(screenButtons); } }
public void showAttrBox() { final GameView view = GameView.getInstance(); final AttrBox box = new AttrBox(frame); final DisplayModes oldValue = view.getDisplayModes(); final DisplayModes newValue = box.run(oldValue); view.setDisplayModes(newValue); repaint(); }
public void showHintBox() { final GameView view = GameView.getInstance(); final HintBox box = new HintBox(frame); final HintStrength oldValue = view.getHintStrength(); final GameStyle style = Game.getStyle(); final HintStrength newValue = box.run(oldValue, style); view.setHintStrength(newValue); }
public TheGame(GameView gameView) { super(gameView); appleBitmap = BitmapFactory.decodeResource(gameView.getContext().getResources(), R.drawable.jabuka); mPaddle = BitmapFactory.decodeResource(gameView.getContext().getResources(), R.drawable.kosara); }
/** * Constructor de la clase, posiciona al jugador al medio del mapa * * @param bmp Una imagen */ public Player(Bitmap bmp, GameView view, Map map, GPS gps) { super(bmp); this.health = 10; this.view = view; this.map = map; this.gps = gps; this.x = view.getWidth() / 2 - this.width / 2; this.y = view.getHeight() / 2 - this.height / 2; }
public GameThread(GameView gameView) { mGameView = gameView; mSurfaceHolder = gameView.getHolder(); mHandler = gameView.getmHandler(); mContext = gameView.getContext(); mBackgroundImage = BitmapFactory.decodeResource( gameView.getContext().getResources(), R.drawable.background_hd); }
public void checkground() { if (y < gameView.getHeight() - 64 - playerheight) { vspeed += gravity; if (y > gameView.getHeight() - 64 - playerheight - vspeed) { vspeed = gameView.getHeight() - 64 - y - playerheight; } } else if (vspeed > 0) { y = gameView.getHeight() - 64 - playerheight; vspeed = 0; } y += vspeed; }
public void offerNewGame() { GameOpt gameOpt; if (Game.hasInstance()) { // Copy the game options of the active instance. gameOpt = new GameOpt(Game.getInstance().getOpt()); gameOpt.setRules(Rules.REPLAY); } else { // Start with the default game options. gameOpt = new GameOpt(); } final int maxHands = ParmBox3.HANDS_DEALT_MAX; final HandOpt handOpts[] = new HandOpt[maxHands]; for (int iHand = 0; iHand < maxHands; iHand++) { HandOpt handOpt; if (Game.hasInstance() && iHand < gameOpt.getHandsDealt()) { final ReadHand hand = Game.getInstance().getHand(iHand); handOpt = new HandOpt(hand.getOpt()); } else { handOpt = new HandOpt("User"); } handOpts[iHand] = handOpt; } final Wizard wizard = new Wizard(frame); final ParmBox1 parmBox1 = new ParmBox1(wizard); wizard.addCard(parmBox1); final WizardCard parmBox2 = new ParmBox2(wizard); wizard.addCard(parmBox2); final WizardCard parmBox3 = new ParmBox3(wizard); wizard.addCard(parmBox3); final WizardCard handBox = new HandBox(wizard); wizard.addCard(handBox); // pack and go final boolean completed = wizard.run(parmBox1, gameOpt, handOpts); if (!completed) { Console.print("New game aborted.\n"); return; } final GameView view = GameView.getInstance(); view.saveHand(); final GameStyle oldStyle = Game.getStyle(); new Game(gameOpt, handOpts); view.newGame(oldStyle); }
/** Request the device to draw */ @SuppressLint("WrongCall") private void updateEngine() { try { startDraw(); synchronized (view.getHolder()) { view.onDraw(c); } } finally { if (c != null) { endDraw(c); } } }
@Override public void mouseMoved(MouseEvent event) { assert event != null; assert GameView.hasInstance(); assert !dragBoard; assert !leftButtonDown; final Point point = event.getPoint(); if (GameView.getInstance().hasActiveTile()) { assert mouseLast != null; handleDragView(point); } mouseLast = point; }
public void setView(GameView gv) { this.view = gv; view.init(model.getCurrentGameState().getBoardState()); /*view.init(model.getCurrentGameState().getBoardState(), model .getPlayerInfo(PlayerID.Player1), model .getPlayerInfo(PlayerID.Player2));*/ }
@Override public void paintComponent(java.awt.Graphics context) { super.paintComponent(context); final Canvas canvas = new Canvas(context); GameView.getInstance().paintAll(canvas); }
public void bearOff() { int fromID = view.getCellIDForBearOff(); if (fromID != Move.NULL_ID) sendMove(fromID, Move.NULL_ID, true); else { // TODO Inform user of error } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); g = (GameView) findViewById(R.id.gameview); AnimView a = (AnimView) findViewById(R.id.animview); g.setAnimView(a); score = (TextView) findViewById(R.id.score); maxScore = (TextView) findViewById(R.id.max_score); Button restart = (Button) findViewById(R.id.restart); restart.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { g.startGame(); score.setText("0"); } }); initEnd(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("REFRESH"); intentFilter.addAction("END"); registerReceiver(receiver, intentFilter); }
private void leftButtonRelease(Point point) { assert point != null; assert GameView.hasInstance(); assert mouseLast != null; final Game game = Game.getInstance(); if (game != null) { if (game.isPaused()) { GameView.getInstance().startClock(); } else { handleReleaseView(point); } } leftButtonDown = false; mouseLast = point; }
@Override public void run() { while (running) { Canvas c = null; try { c = view.getHolder().lockCanvas(); synchronized (view.getHolder()) { view.onDraw(c); } } finally { if (c != null) { view.getHolder().unlockCanvasAndPost(c); } } } }
@Override protected void onCreate(Bundle savedInstanceState) { prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); state = getSharedPreferences(STATE_PREFS_NAME, MODE_PRIVATE); prefsSaver = PrefsSaver.get(this); games = getResources().getStringArray(R.array.games); gameTypes = new LinkedHashMap<Integer, String>(); applyFullscreen(false); // must precede super.onCreate and setContentView cachedFullscreen = startedFullscreen = prefs.getBoolean(FULLSCREEN_KEY, false); applyStayAwake(); super.onCreate(savedInstanceState); setContentView(R.layout.main); mainLayout = (RelativeLayout) findViewById(R.id.mainLayout); statusBar = (TextView) findViewById(R.id.statusBar); gameView = (GameView) findViewById(R.id.game); keyboard = (SmallKeyboard) findViewById(R.id.keyboard); actionBarCompat = ActionBarCompat.get(this); try { actionBarHomeId = android.R.id.class.getField("home").getInt(null); } catch (Exception e) { } setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT); gameView.requestFocus(); onNewIntent(getIntent()); }
void drawPoly(int[] points, int ox, int oy, int line, int fill) { path = new Path(); path.moveTo(points[0] + ox, points[1] + oy); for (int i = 1; i < points.length / 2; i++) path.lineTo(points[2 * i] + ox, points[2 * i + 1] + oy); path.close(); gameView.drawPoly(path, line, fill); }
private void handleDragView(Point point) { assert point != null; assert Game.hasInstance(); assert !Game.getInstance().isPaused(); assert GameView.hasInstance(); if (GameView.getInstance().hasActiveTile()) { assert !dragBoard; repaint(); } else if (dragBoard) { final int dx = point.x - mouseLast.x; final int dy = point.y - mouseLast.y; GameView.getInstance().translate(dx, dy); dragBoardPixelCount += Math.abs(dx) + Math.abs(dy); repaint(); } }
@Override protected void onCreate(Bundle savedInstanceState) { // No title. requestWindowFeature(Window.FEATURE_NO_TITLE); // Full screen. getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); // Prevent sleeping. getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // KitKat immersive mode. final View view = getWindow().getDecorView(); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { view.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } try { InputStream rom = getAssets().open("rom.retroboy"); File romfile = File.createTempFile("rom", "suff"); OutputStream outputStream = new FileOutputStream(romfile); IOUtils.copy(rom, outputStream); outputStream.close(); device = new Device(romfile); } catch (IOException e) { e.printStackTrace(); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final GameView gameView = (GameView) findViewById(R.id.surfaceView); gameView.setDevice(device); }
@Override public void onResume() { super.onResume(); try { mView.registerListener(); } catch (IndexOutOfBoundsException ex) { showToast(R.string.sensor_initialization_failure, Toast.LENGTH_LONG); destroyBTCommunicator(); finish(); } }
public GameController(GameView v, GameSystem g) { model = g; view = v; view.addQuitGameListener(new QuitGameListener()); view.addNewGameListener(new NewGameListener()); view.addCommandListener(new CommandListener()); view.addHelpGameListener(new HelpGameListener()); view.addDrawingMouseListener(new DrawingMouseListener()); view.addInventoryListener(new InventoryListener()); view.addRoomItemListener(new RoomItemListener()); view.addCommandListButtonListener(new CommandListButtonListener()); }
@Override protected void onStop() { try { gView.getThread().setRunning(false); gView = null; } catch (NullPointerException e) { } running = false; super.onStop(); }
private void handleReleaseView(Point point) { assert point != null; assert mouseLast != null; assert Game.hasInstance(); assert !Game.getInstance().isPaused(); final int dx = point.x - mouseLast.x; final int dy = point.y - mouseLast.y; final GameView view = GameView.getInstance(); if (view.hasActiveTile()) { assert !dragBoard; deactivateOnRelease = view.dropActiveTile(point, deactivateOnRelease); repaint(); } else if (dragBoard) { view.translate(dx, dy); dragBoardPixelCount += Math.abs(dx) + Math.abs(dy); if (dragBoardPixelCount < DRAG_THRESHOLD) { /* * Board drags shorter than six pixels (clicks, basically) * also serve to alter or un-target the target cell. */ view.toggleTargetCell(point); } // done dragging the board dragBoard = false; setCursor(Cursor.getDefaultCursor()); repaint(); } }
void startGame(final int which, final String savedGame) { Log.d( TAG, "startGame: " + which + ", " + ((savedGame == null) ? "null" : (savedGame.length() + " bytes"))); if (progress != null) { Log.e(TAG, "startGame while already starting!"); return; } showProgress((savedGame == null) ? R.string.starting : R.string.resuming); if (gameRunning) { gameView.clear(); stopNative(); solveEnabled = false; changedState(false, false); customVisible = false; setStatusBarVisibility(false); } if (ActionBarCompat.earlyHasActionBar() && !prefs.getBoolean(UNDO_REDO_KBD_KEY, false)) { maybeUndoRedo = ""; } setKeys("", SmallKeyboard.ARROWS_LEFT_RIGHT_CLICK); if (typeMenu != null) for (Integer i : gameTypes.keySet()) typeMenu.removeItem(i); gameTypes.clear(); gameRunning = true; gameView.keysHandled = 0; (worker = new Thread("startGame") { public void run() { init(gameView, which, savedGame); if (!gameRunning) return; // stopNative or abort was called helpTopic = htmlHelpTopic(); handler.obtainMessage(MsgType.DONE.ordinal(), htmlHelpTopic()).sendToTarget(); } }) .start(); }
/** Appelé à la première création de l'activité */ @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.lib_game); // récupération des éléments de l'activité gameView = (GameView) findViewById(R.id.game_view); infoText = (TextView) findViewById(R.id.info_turn); buttonNext = (Button) findViewById(R.id.next_turn); buttonQuit = (Button) findViewById(R.id.b_quit); // config et mise en place des listener sur les éléments gameView.setFocusable(true); gameView.setFocusableInTouchMode(true); gameView.setCellListener(new CellListener()); buttonNext.setOnClickListener(new NextButtonListener()); buttonQuit.setVisibility(View.INVISIBLE); buttonQuit.setOnClickListener(new QuitButtonListener()); game = new TttGame(); }