Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. package edu.upenn.cis350.hwk2;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.v7.app.AppCompatActivity;
  6.  
  7. public class GameActivity extends AppCompatActivity{
  8.  
  9. public String difficulty;
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_game);
  15. difficulty = getIntent().getStringExtra("DIFFICULTY");
  16. GameView.setup(difficulty);
  17. }
  18. }
  19.  
  20.  
  21. package edu.upenn.cis350.hwk2;
  22.  
  23. import android.content.Context;
  24. import android.graphics.Canvas;
  25. import android.graphics.Color;
  26. import android.graphics.Paint;
  27. import android.util.AttributeSet;
  28. import android.util.Log;
  29. import android.view.MotionEvent;
  30. import android.view.View;
  31.  
  32. public class GameView extends View {
  33. //instance variables that hold the first tap
  34. private static String difficulty;
  35. private static int matchesRemaining;
  36. private String[] cards = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
  37. private String[] suits = {"Hearts", "Clubs", "Diamonds", "Spades"};
  38. private static boolean[][] easyArray;
  39. private static boolean[][] mediumArray;
  40. private static boolean[][] hardArray;
  41. private static int moves;
  42. private static int totalMatches;
  43.  
  44. public GameView(Context c) {
  45. super(c);
  46. }
  47.  
  48. public GameView(Context c, AttributeSet a) {
  49. super(c, a);
  50. }
  51.  
  52. public static void setup(String diff) {
  53. difficulty = diff;
  54. if (difficulty.equals("Easy")) {
  55. matchesRemaining = 3;
  56. }
  57. else if (difficulty.equals("Medium")) {
  58. matchesRemaining = 6;
  59. }
  60. else {
  61. matchesRemaining = 12;
  62. }
  63.  
  64. reset();
  65. }
  66.  
  67. public static void reset() {
  68. easyArray = new boolean[2][3];
  69. mediumArray = new boolean[2][3];
  70. hardArray = new boolean[2][3];
  71. moves = 0;
  72. }
  73.  
  74. public void onDraw(Canvas canvas) {
  75. if(difficulty.equals("Easy")) {
  76. Paint s = new Paint();
  77. s.setColor(Color.BLACK);
  78.  
  79. for(int i = 0; i < 2; i++) {
  80. for (int j = 0; j < 3; j++) {
  81. if(easyArray[i][j]) {
  82.  
  83. }
  84. }
  85. }
  86.  
  87. canvas.drawRect(100, 150, 400, 450, s);
  88. canvas.drawRect(100, 500, 400, 800, s);
  89. canvas.drawRect(700, 150, 1000, 450, s);
  90. canvas.drawRect(700, 500, 1000, 800, s);
  91. canvas.drawRect(1300, 150, 1600, 450, s);
  92. canvas.drawRect(1300, 500, 1600, 800, s);
  93.  
  94. }
  95. else if (difficulty.equals("Medium")) {
  96. Paint s = new Paint();
  97. s.setColor(Color.BLACK);
  98. s.setStrokeWidth(20);
  99. canvas.drawRect(200, 200, 200, 200, s);
  100. }
  101. else {
  102. Paint s = new Paint();
  103. s.setColor(Color.BLACK);
  104. s.setStrokeWidth(20);
  105. canvas.drawRect(200, 200, 200, 200, s);
  106. }
  107.  
  108. Paint p = new Paint();
  109. p.setColor(Color.BLACK);
  110. p.setTextSize(42);
  111. canvas.drawText("Moves: " + moves, 30, 70, p);
  112. canvas.drawText("Matches Remaining: " + matchesRemaining, 400, 70, p);
  113. canvas.drawText("Difficulty: " + difficulty, 1400, 70, p);
  114.  
  115. //initialize to all false
  116. //takes in the array and draws according to that
  117. //invalidate();
  118. }
  119.  
  120. public boolean onTouchEvent(MotionEvent e) {
  121. //determines if cards should be face up or face down
  122.  
  123. int x = Math.round(e.getX());
  124. int y = Math.round(e.getY());
  125.  
  126. return false;
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement